From 70a29b1e1413fc1c51716840b0e7b740fb3b7986 Mon Sep 17 00:00:00 2001 From: Anatoly Kalin Date: Mon, 4 Sep 2023 13:44:08 +0300 Subject: [PATCH 01/14] [EN-7412] Implement DXFeedConnect sample --- CMakeLists.txt | 1 + include/dxfeed_graal_cpp_api/api.hpp | 1 + .../internal/utils/EnumUtils.hpp | 21 +++++++++++++ samples/cpp/DXFeedFileParser/CMakeLists.txt | 2 -- samples/cpp/DXFeedFileParser/src/main.cpp | 9 +----- src/internal/utils/EnumUtils.cpp | 31 +++++++++++++++++++ 6 files changed, 55 insertions(+), 10 deletions(-) create mode 100644 include/dxfeed_graal_cpp_api/internal/utils/EnumUtils.hpp create mode 100644 src/internal/utils/EnumUtils.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index c0a2a743..13db6a82 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -104,6 +104,7 @@ set(dxFeedNativeAPIInternalSources set(dxFeedNativeAPIInternalUtilsSources src/internal/utils/StringUtils.cpp + src/internal/utils/EnumUtils.cpp src/internal/utils/CmdArgsUtils.cpp ) diff --git a/include/dxfeed_graal_cpp_api/api.hpp b/include/dxfeed_graal_cpp_api/api.hpp index a4753ff8..efc47a3b 100644 --- a/include/dxfeed_graal_cpp_api/api.hpp +++ b/include/dxfeed_graal_cpp_api/api.hpp @@ -22,6 +22,7 @@ #include "internal/managers/ErrorHandlingManager.hpp" #include "internal/utils/StringUtils.hpp" #include "internal/utils/CmdArgsUtils.hpp" +#include "internal/utils/EnumUtils.hpp" #include "internal/utils/debug/Debug.hpp" #include "api/ApiModule.hpp" diff --git a/include/dxfeed_graal_cpp_api/internal/utils/EnumUtils.hpp b/include/dxfeed_graal_cpp_api/internal/utils/EnumUtils.hpp new file mode 100644 index 00000000..59b45b23 --- /dev/null +++ b/include/dxfeed_graal_cpp_api/internal/utils/EnumUtils.hpp @@ -0,0 +1,21 @@ +// Copyright (c) 2023 Devexperts LLC. +// SPDX-License-Identifier: MPL-2.0 + +#pragma once + +#include "../Conf.hpp" + +#include + +namespace dxfcpp::enum_utils { + +/** + * Returns a separated list of names of EventTypeEnum elements. + * + * @param separator The list separator + * @return A separated list of names + */ +DXFCPP_EXPORT std::string getEventTypeEnumNamesList(std::string separator = std::string(",")) noexcept; + +} + diff --git a/samples/cpp/DXFeedFileParser/CMakeLists.txt b/samples/cpp/DXFeedFileParser/CMakeLists.txt index 79140a51..b4b0a679 100644 --- a/samples/cpp/DXFeedFileParser/CMakeLists.txt +++ b/samples/cpp/DXFeedFileParser/CMakeLists.txt @@ -35,8 +35,6 @@ endif () add_executable(${PROJECT_NAME} src/main.cpp) -target_include_directories(${PROJECT_NAME} PRIVATE ../../../third_party/range-v3-0.12/include) - if (DXFCXX_ENABLE_VS_ASAN) target_compile_options(${PROJECT_NAME} PRIVATE "/fsanitize=address") target_link_options(${PROJECT_NAME} PRIVATE "/fsanitize=address") diff --git a/samples/cpp/DXFeedFileParser/src/main.cpp b/samples/cpp/DXFeedFileParser/src/main.cpp index 9ff64bc2..5397097f 100644 --- a/samples/cpp/DXFeedFileParser/src/main.cpp +++ b/samples/cpp/DXFeedFileParser/src/main.cpp @@ -3,8 +3,6 @@ #include -#include - #include #include @@ -13,11 +11,6 @@ using namespace dxfcpp::literals; using namespace std::literals; void printUsage() { - auto evenTypeEnumNames = EventTypeEnum::ALL | ranges::views::transform([](const auto &enumElement) { - return enumElement.get().getName(); - }) | - ranges::views::join(',') | ranges::to; - auto usageString = R"( Usage: DxFeedFileParser @@ -25,7 +18,7 @@ DxFeedFileParser Where: file - Is a file name. type - Is comma-separated list of dxfeed event types ()" + - evenTypeEnumNames + R"(). + dxfcpp::enum_utils::getEventTypeEnumNamesList() + R"(). symbol - Is comma-separated list of symbol names to get events for (e.g. "IBM,AAPL,MSFT").)"; std::cout << usageString << std::endl; diff --git a/src/internal/utils/EnumUtils.cpp b/src/internal/utils/EnumUtils.cpp new file mode 100644 index 00000000..f961af29 --- /dev/null +++ b/src/internal/utils/EnumUtils.cpp @@ -0,0 +1,31 @@ +// Copyright (c) 2023 Devexperts LLC. +// SPDX-License-Identifier: MPL-2.0 + +#include + +#include +#include + +#include +#include +#include +#include + +#include + +#include +#include +#include +#include + +#include + +using namespace std::literals; + +namespace dxfcpp::enum_utils { + +std::string getEventTypeEnumNamesList(std::string separator) noexcept { + return EventTypeEnum::ALL_BY_NAME | ranges::views::keys | ranges::views::join(separator) | ranges::to; +} + +} // namespace dxfcpp::enum_utils From 1e5ca277246014a202dfcaf4316bec824eb45f49 Mon Sep 17 00:00:00 2001 From: Anatoly Kalin Date: Mon, 4 Sep 2023 13:45:57 +0300 Subject: [PATCH 02/14] [EN-7412] Implement DXFeedConnect sample --- CMakeLists.txt | 2 +- .../cpp/{DXFeedFileParser => DXFeedFileParserr}/CMakeLists.txt | 0 .../cpp/{DXFeedFileParser => DXFeedFileParserr}/src/main.cpp | 0 3 files changed, 1 insertion(+), 1 deletion(-) rename samples/cpp/{DXFeedFileParser => DXFeedFileParserr}/CMakeLists.txt (100%) rename samples/cpp/{DXFeedFileParser => DXFeedFileParserr}/src/main.cpp (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 13db6a82..ef21634c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -329,7 +329,7 @@ if (DXFCXX_BUILD_SAMPLES) add_subdirectory(samples/cpp/DxFeedSample) add_subdirectory(samples/cpp/WriteTapeFile) add_subdirectory(samples/cpp/ConvertTapeFile) - add_subdirectory(samples/cpp/DXFeedFileParser) + add_subdirectory(samples/cpp/DXFeedFileParserr) endif () if (DXFCXX_BUILD_TOOLS) diff --git a/samples/cpp/DXFeedFileParser/CMakeLists.txt b/samples/cpp/DXFeedFileParserr/CMakeLists.txt similarity index 100% rename from samples/cpp/DXFeedFileParser/CMakeLists.txt rename to samples/cpp/DXFeedFileParserr/CMakeLists.txt diff --git a/samples/cpp/DXFeedFileParser/src/main.cpp b/samples/cpp/DXFeedFileParserr/src/main.cpp similarity index 100% rename from samples/cpp/DXFeedFileParser/src/main.cpp rename to samples/cpp/DXFeedFileParserr/src/main.cpp From 2b26a91b3551d4abd385f7abd261c6bd9ec2d510 Mon Sep 17 00:00:00 2001 From: Anatoly Kalin Date: Mon, 4 Sep 2023 13:47:22 +0300 Subject: [PATCH 03/14] [EN-7412] Implement DXFeedConnect sample --- CMakeLists.txt | 2 +- README.md | 2 +- .../cpp/{DXFeedFileParserr => DxFeedFileParser}/CMakeLists.txt | 0 .../cpp/{DXFeedFileParserr => DxFeedFileParser}/src/main.cpp | 0 4 files changed, 2 insertions(+), 2 deletions(-) rename samples/cpp/{DXFeedFileParserr => DxFeedFileParser}/CMakeLists.txt (100%) rename samples/cpp/{DXFeedFileParserr => DxFeedFileParser}/src/main.cpp (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index ef21634c..8c89dd4f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -329,7 +329,7 @@ if (DXFCXX_BUILD_SAMPLES) add_subdirectory(samples/cpp/DxFeedSample) add_subdirectory(samples/cpp/WriteTapeFile) add_subdirectory(samples/cpp/ConvertTapeFile) - add_subdirectory(samples/cpp/DXFeedFileParserr) + add_subdirectory(samples/cpp/DxFeedFileParser) endif () if (DXFCXX_BUILD_TOOLS) diff --git a/README.md b/README.md index 036708e2..164260f4 100644 --- a/README.md +++ b/README.md @@ -247,7 +247,7 @@ be downloaded from [Release](https://github.com/dxFeed/dxfeed-graal-cxx-api/rele * [DxFeedConnect](https://github.com/dxFeed/dxfeed-graal-cxx-api/blob/main/samples/cpp/DxFeedConnect/src/main.cpp) demonstrates how to subscribe various market events for the specified symbols --> -* [DxFeedFileParser](https://github.com/dxFeed/dxfeed-graal-cxx-api/blob/main/samples/cpp/DXFeedFileParser/src/main.cpp) +* [DxFeedFileParser](https://github.com/dxFeed/dxfeed-graal-cxx-api/blob/main/samples/cpp/DxFeedFileParser/src/main.cpp) is a simple demonstration of how events are read form a tape file * [DxFeedSample](https://github.com/dxFeed/dxfeed-graal-cxx-api/blob/main/samples/cpp/DxFeedSample/src/main.cpp) is a simple demonstration of how to create multiple event listeners and subscribe to `Quote` and `Trade` events diff --git a/samples/cpp/DXFeedFileParserr/CMakeLists.txt b/samples/cpp/DxFeedFileParser/CMakeLists.txt similarity index 100% rename from samples/cpp/DXFeedFileParserr/CMakeLists.txt rename to samples/cpp/DxFeedFileParser/CMakeLists.txt diff --git a/samples/cpp/DXFeedFileParserr/src/main.cpp b/samples/cpp/DxFeedFileParser/src/main.cpp similarity index 100% rename from samples/cpp/DXFeedFileParserr/src/main.cpp rename to samples/cpp/DxFeedFileParser/src/main.cpp From cb6c947a6ee02100c0c1a07642de080aa8e4a467 Mon Sep 17 00:00:00 2001 From: Anatoly Kalin Date: Mon, 4 Sep 2023 15:31:17 +0300 Subject: [PATCH 04/14] [EN-7412] Implement DXFeedConnect sample --- samples/cpp/DxFeedFileParser/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/cpp/DxFeedFileParser/CMakeLists.txt b/samples/cpp/DxFeedFileParser/CMakeLists.txt index b4b0a679..0d81c767 100644 --- a/samples/cpp/DxFeedFileParser/CMakeLists.txt +++ b/samples/cpp/DxFeedFileParser/CMakeLists.txt @@ -11,7 +11,7 @@ if (POLICY CMP0135) cmake_policy(SET CMP0135 NEW) endif () -project(DXFeedFileParser LANGUAGES CXX) +project(DxFeedFileParser LANGUAGES CXX) set(CMAKE_CXX_STANDARD 20) set(CMAKE_C_STANDARD 11) From 5da8d4562742ad498b2fdb9d24eed578477aeaac Mon Sep 17 00:00:00 2001 From: Anatoly Kalin Date: Mon, 4 Sep 2023 16:24:36 +0300 Subject: [PATCH 05/14] [EN-7412] Implement DXFeedConnect sample --- CMakeLists.txt | 61 ++++++++++-------- README.md | 2 - samples/cpp/DxFeedConnect/CMakeLists.txt | 81 ++++++++++++++++++++++++ samples/cpp/DxFeedConnect/src/main.cpp | 70 ++++++++++++++++++++ src/internal/CMakeLists.txt | 52 +++++++++++++++ src/internal/utils/CmdArgsUtils.cpp | 2 + 6 files changed, 240 insertions(+), 28 deletions(-) create mode 100644 samples/cpp/DxFeedConnect/CMakeLists.txt create mode 100644 samples/cpp/DxFeedConnect/src/main.cpp create mode 100644 src/internal/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 8c89dd4f..3dabc7a2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -93,24 +93,26 @@ add_subdirectory(third_party/fmt-10.0.0) # find_package(utf8cpp) # find_package(fmt) -set(dxFeedNativeAPIInternalSources - src/internal/CEntryPointErrors.cpp - src/internal/Isolate.cpp - src/internal/JavaObjectHandler.cpp - src/internal/EventClassList.cpp - src/internal/SymbolList.cpp - src/internal/Common.cpp -) - -set(dxFeedNativeAPIInternalUtilsSources - src/internal/utils/StringUtils.cpp - src/internal/utils/EnumUtils.cpp - src/internal/utils/CmdArgsUtils.cpp -) - -set(dxFeedNativeAPIInternalUtilsDebugSources - src/internal/utils/debug/Debug.cpp -) +#set(dxFeedNativeAPIInternalSources +# src/internal/CEntryPointErrors.cpp +# src/internal/Isolate.cpp +# src/internal/JavaObjectHandler.cpp +# src/internal/EventClassList.cpp +# src/internal/SymbolList.cpp +# src/internal/Common.cpp +#) +# +#set(dxFeedNativeAPIInternalUtilsSources +# src/internal/utils/StringUtils.cpp +# src/internal/utils/EnumUtils.cpp +# src/internal/utils/CmdArgsUtils.cpp +#) +# +#set(dxFeedNativeAPIInternalUtilsDebugSources +# src/internal/utils/debug/Debug.cpp +#) + +add_subdirectory(src/internal) set(dxFeedNativeAPIAPISources src/api/DXEndpoint.cpp @@ -208,9 +210,12 @@ elseif (UNIX) endif () add_library(${PROJECT_NAME}_static STATIC - ${dxFeedNativeAPIInternalSources} - ${dxFeedNativeAPIInternalUtilsSources} - ${dxFeedNativeAPIInternalUtilsDebugSources} +# ${dxFeedNativeAPIInternalSources} +# ${dxFeedNativeAPIInternalUtilsSources} +# ${dxFeedNativeAPIInternalUtilsDebugSources} + +# $ + ${dxFeedNativeAPIAPISources} ${dxFeedNativeAPIAPIOsubSources} ${dxFeedNativeAPISymbolsSources} @@ -224,9 +229,12 @@ add_library(${PROJECT_NAME}_static STATIC ) add_library(${PROJECT_NAME} SHARED - ${dxFeedNativeAPIInternalSources} - ${dxFeedNativeAPIInternalUtilsSources} - ${dxFeedNativeAPIInternalUtilsDebugSources} +# ${dxFeedNativeAPIInternalSources} +# ${dxFeedNativeAPIInternalUtilsSources} +# ${dxFeedNativeAPIInternalUtilsDebugSources} + +# $ + ${dxFeedNativeAPIAPISources} ${dxFeedNativeAPIAPIOsubSources} ${dxFeedNativeAPISymbolsSources} @@ -305,8 +313,8 @@ if (DXFCXX_USE_PRECOMPILED_HEADERS) target_precompile_headers(${PROJECT_NAME}_static PRIVATE include/dxfeed_graal_cpp_api/internal/PrecompiledHeaders.hpp) endif () -target_link_libraries(${PROJECT_NAME}_static PUBLIC DxFeedGraalNativeSdk utf8cpp fmt::fmt-header-only) -target_link_libraries(${PROJECT_NAME} PUBLIC DxFeedGraalNativeSdk utf8cpp fmt::fmt-header-only) +target_link_libraries(${PROJECT_NAME}_static PUBLIC DxFeedGraalNativeSdk dxfcxx::internal utf8cpp fmt::fmt-header-only) +target_link_libraries(${PROJECT_NAME} PUBLIC DxFeedGraalNativeSdk dxfcxx::internal utf8cpp fmt::fmt-header-only) if (DXFCXX_ENABLE_ASAN_UBSAN) target_compile_options(${PROJECT_NAME} PRIVATE "-fsanitize=address" "-fsanitize=undefined") @@ -330,6 +338,7 @@ if (DXFCXX_BUILD_SAMPLES) add_subdirectory(samples/cpp/WriteTapeFile) add_subdirectory(samples/cpp/ConvertTapeFile) add_subdirectory(samples/cpp/DxFeedFileParser) + add_subdirectory(samples/cpp/DxFeedConnect) endif () if (DXFCXX_BUILD_TOOLS) diff --git a/README.md b/README.md index 164260f4..1782b3ad 100644 --- a/README.md +++ b/README.md @@ -243,10 +243,8 @@ be downloaded from [Release](https://github.com/dxFeed/dxfeed-graal-cxx-api/rele ## Samples * [ConvertTapeFile](https://github.com/dxFeed/dxfeed-graal-cxx-api/blob/main/samples/cpp/ConvertTapeFile/src/main.cpp) demonstrates how to convert one tape file to another tape file with optional intermediate processing or filtering - * [DxFeedFileParser](https://github.com/dxFeed/dxfeed-graal-cxx-api/blob/main/samples/cpp/DxFeedFileParser/src/main.cpp) is a simple demonstration of how events are read form a tape file * [DxFeedSample](https://github.com/dxFeed/dxfeed-graal-cxx-api/blob/main/samples/cpp/DxFeedSample/src/main.cpp) diff --git a/samples/cpp/DxFeedConnect/CMakeLists.txt b/samples/cpp/DxFeedConnect/CMakeLists.txt new file mode 100644 index 00000000..69c7a0ef --- /dev/null +++ b/samples/cpp/DxFeedConnect/CMakeLists.txt @@ -0,0 +1,81 @@ +# Copyright (c) 2023 Devexperts LLC. +# SPDX-License-Identifier: MPL-2.0 + +cmake_minimum_required(VERSION 3.21) + +if (POLICY CMP0092) + cmake_policy(SET CMP0092 NEW) +endif () + +if (POLICY CMP0135) + cmake_policy(SET CMP0135 NEW) +endif () + +project(DxFeedConnect LANGUAGES CXX) + +set(CMAKE_CXX_STANDARD 20) +set(CMAKE_C_STANDARD 11) +set(CXX_EXTENSIONS OFF) +set(C_EXTENSIONS OFF) + +if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") + set(CMAKE_MACOSX_RPATH ON) + set(CMAKE_SKIP_BUILD_RPATH ON) + set(CMAKE_BUILD_WITH_INSTALL_RPATH ON) + set(CMAKE_INSTALL_RPATH_USE_LINK_PATH OFF) + set(CMAKE_BUILD_RPATH_USE_ORIGIN ON) + set(CMAKE_INSTALL_RPATH "@loader_path/../${CMAKE_INSTALL_LIBDIR};@loader_path;@executable_path;@executable_path/../Frameworks") +elseif (UNIX) + set(CMAKE_SKIP_BUILD_RPATH ON) + set(CMAKE_BUILD_WITH_INSTALL_RPATH ON) + set(CMAKE_INSTALL_RPATH_USE_LINK_PATH OFF) + set(CMAKE_BUILD_RPATH_USE_ORIGIN ON) + set(CMAKE_INSTALL_RPATH "$ORIGIN/../${CMAKE_INSTALL_LIBDIR}:$ORIGIN/../lib64:$ORIGIN/../lib:$ORIGIN") +endif () + +add_executable(${PROJECT_NAME} src/main.cpp) + +if (DXFCXX_ENABLE_VS_ASAN) + target_compile_options(${PROJECT_NAME} PRIVATE "/fsanitize=address") + target_link_options(${PROJECT_NAME} PRIVATE "/fsanitize=address") + + target_compile_definitions(${PROJECT_NAME} + PUBLIC + $<$: + _DISABLE_VECTOR_ANNOTATION + _DISABLE_STRING_ANNOTATION + > + ) +endif () + +if (DXFCXX_ENABLE_ASAN_UBSAN) + target_link_libraries(${PROJECT_NAME} PRIVATE dxfcxx) + target_compile_definitions(${PROJECT_NAME} PRIVATE DXFCPP_USE_DLLS) + add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different + $ + $ + $) + + target_compile_options(${PROJECT_NAME} PRIVATE "-fsanitize=address" "-fsanitize=undefined") + target_link_options(${PROJECT_NAME} PRIVATE "-fsanitize=address" "-fsanitize=undefined") +else () + target_link_libraries(${PROJECT_NAME} PRIVATE dxfcxx) + target_compile_definitions(${PROJECT_NAME} PRIVATE DXFCPP_USE_DLLS) + add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different + $ + $ + $) +# target_link_libraries(${PROJECT_NAME} PRIVATE dxfcxx::static) +# +# add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different +# $ +# $) +endif () + +if (DXFCXX_INSTALL AND DXFCXX_INSTALL_SAMPLES) + install(TARGETS ${PROJECT_NAME}) + + if (WIN32) + install(FILES $ DESTINATION ${CMAKE_INSTALL_BINDIR}) + endif () +endif () \ No newline at end of file diff --git a/samples/cpp/DxFeedConnect/src/main.cpp b/samples/cpp/DxFeedConnect/src/main.cpp new file mode 100644 index 00000000..5397097f --- /dev/null +++ b/samples/cpp/DxFeedConnect/src/main.cpp @@ -0,0 +1,70 @@ +// Copyright (c) 2023 Devexperts LLC. +// SPDX-License-Identifier: MPL-2.0 + +#include + +#include +#include + +using namespace dxfcpp; +using namespace dxfcpp::literals; +using namespace std::literals; + +void printUsage() { + auto usageString = R"( +Usage: +DxFeedFileParser + +Where: + file - Is a file name. + type - Is comma-separated list of dxfeed event types ()" + + dxfcpp::enum_utils::getEventTypeEnumNamesList() + R"(). + symbol - Is comma-separated list of symbol names to get events for (e.g. "IBM,AAPL,MSFT").)"; + + std::cout << usageString << std::endl; +} + +int main(int argc, char *argv[]) { + if (argc < 4) { + printUsage(); + + return 0; + } + + std::atomic eventCounter{}; + std::mutex ioMtx{}; + + // Parse args. + std::string fileName = argv[1]; + auto types = CmdArgsUtils::parseTypes(argv[2]); + auto symbols = CmdArgsUtils::parseSymbols(argv[3]); + + // Create endpoint specifically for file parsing. + auto endpoint = DXEndpoint::create(DXEndpoint::Role::STREAM_FEED); + auto feed = endpoint->getFeed(); + + // Subscribe to a specified event and symbol. + auto sub = feed->createSubscription(types); + sub->addEventListener([&eventCounter, &ioMtx](const auto &events) { + std::lock_guard lock{ioMtx}; + + for (auto &&e : events) { + std::cout << (++eventCounter) << ": " << e << "\n"; + } + }); + + // Add symbols. + sub->addSymbols(symbols); + + // Connect endpoint to a file. + endpoint->connect("file:" + fileName + "[speed=max]"); + + // Wait until file is completely parsed. + endpoint->awaitNotConnected(); + + // Close endpoint when we're done. + // This method will gracefully close endpoint, waiting while data processing completes. + endpoint->closeAndAwaitTermination(); + + return 0; +} \ No newline at end of file diff --git a/src/internal/CMakeLists.txt b/src/internal/CMakeLists.txt new file mode 100644 index 00000000..a36efea4 --- /dev/null +++ b/src/internal/CMakeLists.txt @@ -0,0 +1,52 @@ +# Copyright (c) 2023 Devexperts LLC. +# SPDX-License-Identifier: MPL-2.0 + +cmake_minimum_required(VERSION 3.21) + +project(dxFeedGraalCxxApi_Internal) + +if (POLICY CMP0092) + cmake_policy(SET CMP0092 NEW) +endif () + +if (POLICY CMP0135) + cmake_policy(SET CMP0135 NEW) +endif () + +set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_C_STANDARD 11) +set(CMAKE_C_STANDARD_REQUIRED ON) +set(CXX_EXTENSIONS OFF) +set(C_EXTENSIONS OFF) + +set(dxFeedGraalCxxApi_Internal_Sources + CEntryPointErrors.cpp + Isolate.cpp + JavaObjectHandler.cpp + EventClassList.cpp + SymbolList.cpp + Common.cpp +) + +set(dxFeedGraalCxxApi_Internal_Utils_Sources + utils/StringUtils.cpp + utils/EnumUtils.cpp + utils/CmdArgsUtils.cpp +) + +set(dxFeedGraalCxxApi_Internal_UtilsDebug_Sources + utils/debug/Debug.cpp +) + + +add_library(dxFeedGraalCxxApi_Internal OBJECT + ${dxFeedGraalCxxApi_Internal_Sources} + ${dxFeedGraalCxxApi_Internal_Utils_Sources} + ${dxFeedGraalCxxApi_Internal_UtilsDebug_Sources} +) + +add_library(dxfcxx::internal ALIAS dxFeedGraalCxxApi_Internal) + +target_include_directories(dxFeedGraalCxxApi_Internal PRIVATE ../../include ../../third_party/range-v3-0.12/include) +target_link_libraries(dxFeedGraalCxxApi_Internal PRIVATE DxFeedGraalNativeSdk utf8cpp fmt::fmt-header-only) \ No newline at end of file diff --git a/src/internal/utils/CmdArgsUtils.cpp b/src/internal/utils/CmdArgsUtils.cpp index df97ef5e..0079f7a2 100644 --- a/src/internal/utils/CmdArgsUtils.cpp +++ b/src/internal/utils/CmdArgsUtils.cpp @@ -18,6 +18,8 @@ #include #include +#include + namespace dxfcpp { From 21e5efc7fbdbf599bef37c51ad9f5984368aa2a5 Mon Sep 17 00:00:00 2001 From: Anatoly Kalin Date: Mon, 4 Sep 2023 17:32:22 +0300 Subject: [PATCH 06/14] [EN-7412] Implement DXFeedConnect sample --- CMakeLists.txt | 110 ++++++++++++++++-------------------- src/internal/CMakeLists.txt | 52 ----------------- 2 files changed, 48 insertions(+), 114 deletions(-) delete mode 100644 src/internal/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 3dabc7a2..7e4d3200 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -93,50 +93,48 @@ add_subdirectory(third_party/fmt-10.0.0) # find_package(utf8cpp) # find_package(fmt) -#set(dxFeedNativeAPIInternalSources -# src/internal/CEntryPointErrors.cpp -# src/internal/Isolate.cpp -# src/internal/JavaObjectHandler.cpp -# src/internal/EventClassList.cpp -# src/internal/SymbolList.cpp -# src/internal/Common.cpp -#) -# -#set(dxFeedNativeAPIInternalUtilsSources -# src/internal/utils/StringUtils.cpp -# src/internal/utils/EnumUtils.cpp -# src/internal/utils/CmdArgsUtils.cpp -#) -# -#set(dxFeedNativeAPIInternalUtilsDebugSources -# src/internal/utils/debug/Debug.cpp -#) - -add_subdirectory(src/internal) - -set(dxFeedNativeAPIAPISources +set(dxFeedGraalCxxApi_Internal_Sources + src/internal/CEntryPointErrors.cpp + src/internal/Isolate.cpp + src/internal/JavaObjectHandler.cpp + src/internal/EventClassList.cpp + src/internal/SymbolList.cpp + src/internal/Common.cpp +) + +set(dxFeedGraalCxxApi_InternalUtils_Sources + src/internal/utils/StringUtils.cpp + src/internal/utils/EnumUtils.cpp + src/internal/utils/CmdArgsUtils.cpp +) + +set(dxFeedGraalCxxApi_InternalUtilsDebug_Sources + src/internal/utils/debug/Debug.cpp +) + +set(dxFeedGraalCxxApi_API_Sources src/api/DXEndpoint.cpp src/api/DXFeed.cpp src/api/DXFeedSubscription.cpp src/api/DXPublisher.cpp ) -set(dxFeedNativeAPIAPIOsubSources +set(dxFeedGraalCxxApi_APIOsub_Sources src/api/osub/WildcardSymbol.cpp src/api/osub/TimeSeriesSubscriptionSymbol.cpp src/api/osub/IndexedEventSubscriptionSymbol.cpp ) -set(dxFeedNativeAPISymbolsSources +set(dxFeedGraalCxxApi_Symbols_Sources src/symbols/StringSymbol.cpp src/symbols/SymbolWrapper.cpp ) -set(dxFeedNativeAPISystemSources +set(dxFeedGraalCxxApi_System_Sources src/system/System.cpp ) -set(dxFeedNativeAPIEventSources +set(dxFeedGraalCxxApi_Event_Sources src/event/EventTypeEnum.cpp src/event/IndexedEventSource.cpp src/event/EventFlag.cpp @@ -144,7 +142,7 @@ set(dxFeedNativeAPIEventSources src/event/EventMapper.cpp ) -set(dxFeedNativeAPIEventCandleSources +set(dxFeedGraalCxxApi_EventCandle_Sources src/event/candle/Candle.cpp src/event/candle/CandleAlignment.cpp src/event/candle/CandleExchange.cpp @@ -156,7 +154,7 @@ set(dxFeedNativeAPIEventCandleSources src/event/candle/CandleSymbol.cpp ) -set(dxFeedNativeAPIEventMarketSources +set(dxFeedGraalCxxApi_EventMarket_Sources src/event/market/AnalyticOrder.cpp src/event/market/Direction.cpp src/event/market/IcebergType.cpp @@ -182,18 +180,34 @@ set(dxFeedNativeAPIEventMarketSources src/event/market/TradingStatus.cpp ) -set(dxFeedNativeAPIEventOptionSources +set(dxFeedGraalCxxApi_EventOption_Sources src/event/option/Greeks.cpp src/event/option/Underlying.cpp src/event/option/TheoPrice.cpp src/event/option/Series.cpp ) -set(dxFeedNativeAPIScheduleSources +set(dxFeedGraalCxxApi_Schedule_Sources src/schedule/SessionFilter.cpp src/schedule/SessionType.cpp ) +set(dxFeedGraalCxxApi_Sources + ${dxFeedGraalCxxApi_Internal_Sources} + ${dxFeedGraalCxxApi_InternalUtils_Sources} + ${dxFeedGraalCxxApi_InternalUtilsDebug_Sources} + ${dxFeedGraalCxxApi_API_Sources} + ${dxFeedGraalCxxApi_APIOsub_Sources} + ${dxFeedGraalCxxApi_Symbols_Sources} + ${dxFeedGraalCxxApi_System_Sources} + ${dxFeedGraalCxxApi_Event_Sources} + ${dxFeedGraalCxxApi_EventCandle_Sources} + ${dxFeedGraalCxxApi_EventMarket_Sources} + ${dxFeedGraalCxxApi_EventOption_Sources} + ${dxFeedGraalCxxApi_EventOption_Sources} + ${dxFeedGraalCxxApi_Schedule_Sources} +) + if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") set(CMAKE_MACOSX_RPATH ON) set(CMAKE_SKIP_BUILD_RPATH ON) @@ -210,40 +224,12 @@ elseif (UNIX) endif () add_library(${PROJECT_NAME}_static STATIC -# ${dxFeedNativeAPIInternalSources} -# ${dxFeedNativeAPIInternalUtilsSources} -# ${dxFeedNativeAPIInternalUtilsDebugSources} - -# $ - - ${dxFeedNativeAPIAPISources} - ${dxFeedNativeAPIAPIOsubSources} - ${dxFeedNativeAPISymbolsSources} - ${dxFeedNativeAPISystemSources} - ${dxFeedNativeAPIEventSources} - ${dxFeedNativeAPIEventCandleSources} - ${dxFeedNativeAPIEventMarketSources} - ${dxFeedNativeAPIEventOptionSources} - ${dxFeedNativeAPIScheduleSources} + ${dxFeedGraalCxxApi_Sources} src/api.cpp ) add_library(${PROJECT_NAME} SHARED -# ${dxFeedNativeAPIInternalSources} -# ${dxFeedNativeAPIInternalUtilsSources} -# ${dxFeedNativeAPIInternalUtilsDebugSources} - -# $ - - ${dxFeedNativeAPIAPISources} - ${dxFeedNativeAPIAPIOsubSources} - ${dxFeedNativeAPISymbolsSources} - ${dxFeedNativeAPISystemSources} - ${dxFeedNativeAPIEventSources} - ${dxFeedNativeAPIEventCandleSources} - ${dxFeedNativeAPIEventMarketSources} - ${dxFeedNativeAPIEventOptionSources} - ${dxFeedNativeAPIScheduleSources} + ${dxFeedGraalCxxApi_Sources} src/api.cpp ) @@ -313,8 +299,8 @@ if (DXFCXX_USE_PRECOMPILED_HEADERS) target_precompile_headers(${PROJECT_NAME}_static PRIVATE include/dxfeed_graal_cpp_api/internal/PrecompiledHeaders.hpp) endif () -target_link_libraries(${PROJECT_NAME}_static PUBLIC DxFeedGraalNativeSdk dxfcxx::internal utf8cpp fmt::fmt-header-only) -target_link_libraries(${PROJECT_NAME} PUBLIC DxFeedGraalNativeSdk dxfcxx::internal utf8cpp fmt::fmt-header-only) +target_link_libraries(${PROJECT_NAME}_static PUBLIC DxFeedGraalNativeSdk utf8cpp fmt::fmt-header-only) +target_link_libraries(${PROJECT_NAME} PUBLIC DxFeedGraalNativeSdk utf8cpp fmt::fmt-header-only) if (DXFCXX_ENABLE_ASAN_UBSAN) target_compile_options(${PROJECT_NAME} PRIVATE "-fsanitize=address" "-fsanitize=undefined") diff --git a/src/internal/CMakeLists.txt b/src/internal/CMakeLists.txt deleted file mode 100644 index a36efea4..00000000 --- a/src/internal/CMakeLists.txt +++ /dev/null @@ -1,52 +0,0 @@ -# Copyright (c) 2023 Devexperts LLC. -# SPDX-License-Identifier: MPL-2.0 - -cmake_minimum_required(VERSION 3.21) - -project(dxFeedGraalCxxApi_Internal) - -if (POLICY CMP0092) - cmake_policy(SET CMP0092 NEW) -endif () - -if (POLICY CMP0135) - cmake_policy(SET CMP0135 NEW) -endif () - -set(CMAKE_CXX_STANDARD 20) -set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_C_STANDARD 11) -set(CMAKE_C_STANDARD_REQUIRED ON) -set(CXX_EXTENSIONS OFF) -set(C_EXTENSIONS OFF) - -set(dxFeedGraalCxxApi_Internal_Sources - CEntryPointErrors.cpp - Isolate.cpp - JavaObjectHandler.cpp - EventClassList.cpp - SymbolList.cpp - Common.cpp -) - -set(dxFeedGraalCxxApi_Internal_Utils_Sources - utils/StringUtils.cpp - utils/EnumUtils.cpp - utils/CmdArgsUtils.cpp -) - -set(dxFeedGraalCxxApi_Internal_UtilsDebug_Sources - utils/debug/Debug.cpp -) - - -add_library(dxFeedGraalCxxApi_Internal OBJECT - ${dxFeedGraalCxxApi_Internal_Sources} - ${dxFeedGraalCxxApi_Internal_Utils_Sources} - ${dxFeedGraalCxxApi_Internal_UtilsDebug_Sources} -) - -add_library(dxfcxx::internal ALIAS dxFeedGraalCxxApi_Internal) - -target_include_directories(dxFeedGraalCxxApi_Internal PRIVATE ../../include ../../third_party/range-v3-0.12/include) -target_link_libraries(dxFeedGraalCxxApi_Internal PRIVATE DxFeedGraalNativeSdk utf8cpp fmt::fmt-header-only) \ No newline at end of file From 49c77cbb421d4bd609647219b2527d5595d18365 Mon Sep 17 00:00:00 2001 From: Anatoly Kalin Date: Tue, 5 Sep 2023 18:06:26 +0300 Subject: [PATCH 07/14] [EN-7412] Implement DXFeedConnect sample --- CMakeLists.txt | 1 + include/dxfeed_graal_cpp_api/api.hpp | 1 + .../internal/utils/TimeFormat.hpp | 142 ++++++++++++++++++ samples/cpp/DxFeedConnect/src/main.cpp | 104 ++++++++++--- samples/cpp/DxFeedFileParser/src/main.cpp | 6 +- src/internal/utils/TimeFormat.cpp | 14 ++ 6 files changed, 244 insertions(+), 24 deletions(-) create mode 100644 include/dxfeed_graal_cpp_api/internal/utils/TimeFormat.hpp create mode 100644 src/internal/utils/TimeFormat.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 7e4d3200..753cda2f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -105,6 +105,7 @@ set(dxFeedGraalCxxApi_Internal_Sources set(dxFeedGraalCxxApi_InternalUtils_Sources src/internal/utils/StringUtils.cpp src/internal/utils/EnumUtils.cpp + src/internal/utils/TimeFormat.cpp src/internal/utils/CmdArgsUtils.cpp ) diff --git a/include/dxfeed_graal_cpp_api/api.hpp b/include/dxfeed_graal_cpp_api/api.hpp index efc47a3b..1d4aa441 100644 --- a/include/dxfeed_graal_cpp_api/api.hpp +++ b/include/dxfeed_graal_cpp_api/api.hpp @@ -23,6 +23,7 @@ #include "internal/utils/StringUtils.hpp" #include "internal/utils/CmdArgsUtils.hpp" #include "internal/utils/EnumUtils.hpp" +#include "internal/utils/TimeFormat.hpp" #include "internal/utils/debug/Debug.hpp" #include "api/ApiModule.hpp" diff --git a/include/dxfeed_graal_cpp_api/internal/utils/TimeFormat.hpp b/include/dxfeed_graal_cpp_api/internal/utils/TimeFormat.hpp new file mode 100644 index 00000000..2f41a1d8 --- /dev/null +++ b/include/dxfeed_graal_cpp_api/internal/utils/TimeFormat.hpp @@ -0,0 +1,142 @@ +// Copyright (c) 2023 Devexperts LLC. +// SPDX-License-Identifier: MPL-2.0 + +#pragma once + +#include "../Conf.hpp" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace dxfcpp { + +/** + * Utility class for parsing and formatting dates and times in ISO-compatible format. + */ +struct DXFCPP_EXPORT TimeFormat { + template + requires requires(Entry e) { + { Entry{typename Entry::KeyType{}, typename Entry::ValueType{}} }; + { Entry::STUB } -> std::convertible_to; + { e.getKey() } -> std::convertible_to; + { e.getValue() } -> std::convertible_to; + } + class Cache { + std::vector data_{maxSize, Entry::STUB}; + + public: + void add(const Entry &entry) noexcept { + auto index = static_cast(entry.getKey()) % maxSize; + + data_[index] = entry; + } + + void add(const Entry::KeyType &key, const Entry::ValueType &value) { + add({key, value}); + } + + template const Entry &get(const Key &key) const noexcept { + auto index = static_cast(key) % maxSize; + + if (data_[index].getKey() == key) { + return data_[index]; + } + + return Entry::STUB; + } + + template + std::optional> + getEntryValue(const Key &key) const noexcept { + auto index = static_cast(key) % maxSize; + + if (data_[index].getKey() == key) { + return data_[index].getValue(); + } + + return std::nullopt; + } + }; + + private: + struct DXFCPP_EXPORT MinuteCacheEntry { + using KeyType = std::int64_t; + using ValueType = std::string; + + static const MinuteCacheEntry STUB; + + private: + KeyType minute_{}; + ValueType template_{}; + + public: + MinuteCacheEntry(KeyType minute, const ValueType &templat) noexcept : minute_{minute}, template_{templat} { + } + + MinuteCacheEntry() noexcept : MinuteCacheEntry(std::numeric_limits::min(), "") { + } + + KeyType getKey() const noexcept { + return minute_; + } + + const ValueType &getValue() const noexcept { + return template_; + } + + KeyType getMinute() const { + return minute_; + } + + const ValueType &getTemplate() const { + return template_; + } + + bool operator==(const MinuteCacheEntry &minuteCacheEntry) const noexcept { + return minute_ == minuteCacheEntry.minute_ && template_ == minuteCacheEntry.template_; + } + }; + + struct DXFCPP_EXPORT CacheEntry { + using KeyType = std::int64_t; + using ValueType = std::string; + + static const CacheEntry STUB; + + private: + KeyType key_{}; + ValueType value_{}; + + public: + CacheEntry(KeyType key, const ValueType &value) noexcept : key_{key}, value_{value} { + } + + CacheEntry() noexcept : CacheEntry(std::numeric_limits::min(), "") { + } + + KeyType getKey() const noexcept { + return key_; + } + + const ValueType &getValue() const noexcept { + return value_; + } + + bool operator==(const CacheEntry &cacheEntry) const noexcept { + return key_ == cacheEntry.key_ && value_ == cacheEntry.value_; + } + }; + + class Format {}; +}; + +} // namespace dxfcpp \ No newline at end of file diff --git a/samples/cpp/DxFeedConnect/src/main.cpp b/samples/cpp/DxFeedConnect/src/main.cpp index 5397097f..474a83a4 100644 --- a/samples/cpp/DxFeedConnect/src/main.cpp +++ b/samples/cpp/DxFeedConnect/src/main.cpp @@ -13,18 +13,83 @@ using namespace std::literals; void printUsage() { auto usageString = R"( Usage: -DxFeedFileParser +DxFeedConnect
[