Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DXFC-404] Implement PrintQuoteEvents sample #10

Merged
merged 6 commits into from
Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 70 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
# Copyright (c) 2023 Devexperts LLC.
# SPDX-License-Identifier: MPL-2.0

cmake_minimum_required(VERSION 3.10)
cmake_minimum_required(VERSION 3.15)

if (POLICY CMP0092)
cmake_policy(SET CMP0092 NEW)
endif ()

if (POLICY CMP0135)
cmake_policy(SET CMP0135 NEW)
endif ()

project(dxFeedGraalCxxApi)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_C_STANDARD 11)

cmake_policy(SET CMP0135 NEW)

if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
set(DXFC_IS_ROOT_PROJECT ON)
else ()
set(DXFC_ROOT_PROJECT OFF)
endif ()

option(DXFC_BUILD_UNIT_TESTS "" ON)

option(DXFC_BUILD_SHARED "" ON)
option(DXFC_USE_DXFEED_GRAAL_NATIVE_SDK_JFROG "" ON)
set(DXFEED_GRAAL_NATIVE_SDK_VERSION "1.0.0" CACHE STRING "")
set(DXFEED_GRAAL_NATIVE_SDK_JFROG_BASE_URL "https://dxfeed.jfrog.io/artifactory/maven-open/com/dxfeed/graal-native-sdk/" CACHE STRING "")
Expand Down Expand Up @@ -130,7 +136,22 @@ set(dxFeedNativeAPIEventOptionSources
src/event/option/Series.cpp
)

add_library(dxFeedGraalCxxApi

add_library(dxFeedGraalCxxApi_static STATIC
${dxFeedNativeAPIInternalSources}
${dxFeedNativeAPIInternalUtilsSources}
${dxFeedNativeAPIInternalUtilsDebugSources}
${dxFeedNativeAPIAPISources}
${dxFeedNativeAPIAPIOsubSources}
${dxFeedNativeAPISymbolsSources}
${dxFeedNativeAPISystemSources}
${dxFeedNativeAPIEventSources}
${dxFeedNativeAPIEventMarketSources}
${dxFeedNativeAPIEventOptionSources}
src/api.cpp
)

add_library(dxFeedGraalCxxApi SHARED
${dxFeedNativeAPIInternalSources}
${dxFeedNativeAPIInternalUtilsSources}
${dxFeedNativeAPIInternalUtilsDebugSources}
Expand All @@ -144,16 +165,56 @@ add_library(dxFeedGraalCxxApi
src/api.cpp
)

add_library(dxFeedGraalCxxApi_Clang INTERFACE)
#set_target_properties(dxFeedGraalCxxApi PROPERTIES CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)

add_library(dxFeedGraalCxxApi_CompilerOptions INTERFACE)

if ((${CMAKE_CXX_COMPILER_ID} MATCHES "AppleClang") OR (${CMAKE_CXX_COMPILER_ID} MATCHES "Clang"))
# Ignore undefined template var warning
target_compile_options(dxFeedGraalCxxApi_Clang INTERFACE -Wno-undefined-var-template)
target_compile_options(dxFeedGraalCxxApi_CompilerOptions INTERFACE "-Wall" "-Wextra" "-Wpedantic" "-Werror")
target_compile_options(dxFeedGraalCxxApi_CompilerOptions INTERFACE "-Wno-undefined-var-template" "-Wno-unused-private-field")
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_compile_options(dxFeedGraalCxxApi_CompilerOptions INTERFACE "-Wall" "-Wextra" "-Wpedantic" "-Werror")
target_compile_options(dxFeedGraalCxxApi_CompilerOptions INTERFACE "-fPIC" "-no-pie")
target_link_options(dxFeedGraalCxxApi_CompilerOptions INTERFACE "-fPIC")
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
target_compile_options(dxFeedGraalCxxApi_CompilerOptions INTERFACE "/W4" "/WX")
target_compile_options(dxFeedGraalCxxApi_CompilerOptions INTERFACE "/wd4996" "/wd4251")
endif ()

add_library(dxFeedGraalCxxApi_Shared INTERFACE)

if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set_target_properties(dxFeedGraalCxxApi_Shared PROPERTIES
CMAKE_MACOSX_RPATH ON
CMAKE_SKIP_BUILD_RPATH ON
CMAKE_BUILD_WITH_INSTALL_RPATH ON
CMAKE_INSTALL_RPATH_USE_LINK_PATH OFF
CMAKE_BUILD_RPATH_USE_ORIGIN ON
CMAKE_INSTALL_RPATH "@loader_path"
)
elseif (UNIX)
set_target_properties(dxFeedGraalCxxApi_Shared PROPERTIES
CMAKE_SKIP_BUILD_RPATH ON
CMAKE_BUILD_WITH_INSTALL_RPATH ON
CMAKE_INSTALL_RPATH_USE_LINK_PATH OFF
CMAKE_BUILD_RPATH_USE_ORIGIN ON
CMAKE_INSTALL_RPATH "$ORIGIN"
)
endif()

target_include_directories(dxFeedGraalCxxApi_static PUBLIC include)
target_compile_definitions(dxFeedGraalCxxApi_static PRIVATE
FMT_HEADER_ONLY=1)
target_include_directories(dxFeedGraalCxxApi PUBLIC include)
target_link_libraries(dxFeedGraalCxxApi PUBLIC DxFeedGraalNativeSdk utf8cpp fmt::fmt PUBLIC dxFeedGraalCxxApi_Clang)
target_compile_definitions(dxFeedGraalCxxApi PRIVATE
DXFCPP_USE_DLLS LIBDXFCPP_EXPORTS FMT_HEADER_ONLY=1)

target_link_libraries(dxFeedGraalCxxApi_static PUBLIC DxFeedGraalNativeSdk utf8cpp fmt::fmt-header-only PUBLIC dxFeedGraalCxxApi_CompilerOptions)
target_link_libraries(dxFeedGraalCxxApi PUBLIC DxFeedGraalNativeSdk utf8cpp fmt::fmt-header-only PUBLIC dxFeedGraalCxxApi_CompilerOptions dxFeedGraalCxxApi_Shared)

add_custom_command(TARGET dxFeedGraalCxxApi_static POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different
$<TARGET_FILE:DxFeedGraalNativeSdk> $<TARGET_FILE_DIR:dxFeedGraalCxxApi_static>)
add_custom_command(TARGET dxFeedGraalCxxApi POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different
$<TARGET_FILE:DxFeedGraalNativeSdk> $<TARGET_FILE_DIR:dxFeedGraalCxxApi>)

Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,13 @@ Download zip bundle, add to CMake project.
#include <dxfeed_graal_cpp_api/api.hpp>

int main() {
using namespace dxfcpp;

auto endpoint = DXEndpoint::newBuilder()
->withProperty("dxfeed.address", "demo.dxfeed.com:7300")
->build();

auto subscription = endpoint->getFeed()->createSubscription(Quote::type);
auto subscription = endpoint->getFeed()->createSubscription(Quote::TYPE);

subscription->addEventListener([](auto&& events) {
for (auto&& e : events) {
Expand All @@ -178,6 +180,8 @@ int main() {
});

subscription->addSymbols({"AAPL"});

std::cin.get();
}
```

Expand Down
2 changes: 2 additions & 0 deletions include/dxfeed_graal_cpp_api/api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#pragma once

#include "internal/Conf.hpp"

#include "internal/CEntryPointErrors.hpp"
#include "internal/Common.hpp"
#include "internal/Enum.hpp"
Expand Down
9 changes: 6 additions & 3 deletions include/dxfeed_graal_cpp_api/api/DXEndpoint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@

#pragma once

#include "../internal/Conf.hpp"

#include "../internal/CEntryPointErrors.hpp"
#include "../internal/Common.hpp"
#include "../internal/Handler.hpp"
#include "../internal/Isolate.hpp"
#include "../internal/JavaObjectHandler.hpp"
#include "DXFeed.hpp"

#include <filesystem>
Expand All @@ -19,7 +22,7 @@

namespace dxfcpp {

struct DXPublisher : SharedEntity {
struct DXFCPP_EXPORT DXPublisher : SharedEntity {
virtual ~DXPublisher() = default;
};

Expand Down Expand Up @@ -176,7 +179,7 @@ struct DXFeed;
*
* [Javadoc.](https://docs.dxfeed.com/dxfeed/api/com/dxfeed/api/DXEndpoint.html)
*/
struct DXEndpoint : SharedEntity {
struct DXFCPP_EXPORT DXEndpoint : SharedEntity {
/**
* Defines property for endpoint name that is used to distinguish multiple endpoints
* in the same process in logs and in other diagnostic means.
Expand Down Expand Up @@ -804,7 +807,7 @@ struct DXEndpoint : SharedEntity {
/**
* Builder class for DXEndpoint that supports additional configuration properties.
*/
class Builder : public std::enable_shared_from_this<Builder> {
class DXFCPP_EXPORT Builder : public std::enable_shared_from_this<Builder> {
friend DXEndpoint;

// mutable std::recursive_mutex mtx_{};
Expand Down
5 changes: 4 additions & 1 deletion include/dxfeed_graal_cpp_api/api/DXFeed.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@

#pragma once

#include "../internal/Conf.hpp"

#include "../internal/CEntryPointErrors.hpp"
#include "../internal/Common.hpp"
#include "../internal/Handler.hpp"
#include "../internal/Isolate.hpp"
#include "../internal/JavaObjectHandler.hpp"

#include "../event/DXEvent.hpp"
#include "DXFeedSubscription.hpp"
Expand All @@ -23,7 +26,7 @@ class EventTypeEnum;
/**
* Main entry class for dxFeed API (<b>read it first</b>).
*/
struct DXFeed : SharedEntity {
struct DXFCPP_EXPORT DXFeed : SharedEntity {
friend struct DXEndpoint;

private:
Expand Down
17 changes: 11 additions & 6 deletions include/dxfeed_graal_cpp_api/api/DXFeedSubscription.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@

#pragma once

#include <memory>
#include "../internal/Conf.hpp"

#include "../event/DXEvent.hpp"
#include "../internal/Common.hpp"
#include "../internal/Handler.hpp"
#include "../internal/JavaObjectHandler.hpp"
#include "../symbols/StringSymbol.hpp"
#include "../symbols/SymbolWrapper.hpp"
#include "dxfeed_graal_cpp_api/api/osub/WildcardSymbol.hpp"
Expand All @@ -15,6 +17,7 @@
# include <execution>
#endif

#include <memory>
#include <unordered_set>

namespace dxfcpp {
Expand All @@ -24,7 +27,7 @@ struct DXFeed;
/**
* Subscription for a set of symbols and event types.
*/
class DXFeedSubscription : public SharedEntity {
class DXFCPP_EXPORT DXFeedSubscription : public SharedEntity {
friend struct DXFeed;

mutable std::recursive_mutex mtx_{};
Expand Down Expand Up @@ -177,7 +180,8 @@ class DXFeedSubscription : public SharedEntity {
*
* Example:
* ```cpp
* auto sub = dxfcpp::DXFeedSubscription::create(std::unordered_set{dxfcpp::Quote::Type, dxfcpp::TimeAndSale::Type});
* auto sub = dxfcpp::DXFeedSubscription::create(std::unordered_set{dxfcpp::Quote::Type,
* dxfcpp::TimeAndSale::Type});
* ```
*
* @tparam EventTypesCollection The type of the collection of event types
Expand Down Expand Up @@ -301,18 +305,19 @@ class DXFeedSubscription : public SharedEntity {
* ```
*
* @tparam EventT The event type (EventType's child with field Type, convertible to EventTypeEnum
* @param listener The listener. Listener can be callable with signature: `void(const std::vector<std::shared_ptr<EventT>&)`
* @param listener The listener. Listener can be callable with signature: `void(const
* std::vector<std::shared_ptr<EventT>&)`
* @return The listener id
*/
template <typename EventT>
std::size_t addEventListener(std::function<void(const std::vector<std::shared_ptr<EventT>> &)> &&listener) noexcept
#if __cpp_concepts
requires std::is_base_of_v<EventType, EventT> && requires {
{ EventT::Type } -> std::convertible_to<EventTypeEnum>;
{ EventT::TYPE } -> std::convertible_to<EventTypeEnum>;
}
#endif
{
if (!containsEventType(EventT::Type)) {
if (!containsEventType(EventT::TYPE)) {
return onEvent_ += [](auto) {};
}

Expand Down
10 changes: 6 additions & 4 deletions include/dxfeed_graal_cpp_api/api/osub/WildcardSymbol.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@

#pragma once

#include "../../internal/Conf.hpp"

#include <cstdint>
#include <memory>
#include <utility>

namespace dxfcpp {

struct WildcardSymbol final {
struct DXFCPP_EXPORT WildcardSymbol final {
static const WildcardSymbol ALL;

private:
Expand Down Expand Up @@ -38,15 +40,15 @@ struct WildcardSymbol final {

inline namespace literals {

inline WildcardSymbol operator""_ws(const char *string, size_t length) noexcept { return WildcardSymbol::ALL; }
inline WildcardSymbol operator""_ws(const char *, size_t) noexcept { return WildcardSymbol::ALL; }

inline WildcardSymbol operator""_wcs(const char *string, size_t length) noexcept { return WildcardSymbol::ALL; }
inline WildcardSymbol operator""_wcs(const char *, size_t) noexcept { return WildcardSymbol::ALL; }

} // namespace literals

} // namespace dxfcpp

template <> struct std::hash<dxfcpp::WildcardSymbol> {
template <> struct DXFCPP_EXPORT std::hash<dxfcpp::WildcardSymbol> {
std::size_t operator()(const dxfcpp::WildcardSymbol &wildcardSymbol) const noexcept {
return std::hash<std::string>{}(wildcardSymbol.getSymbol());
}
Expand Down
4 changes: 3 additions & 1 deletion include/dxfeed_graal_cpp_api/entity/Entity.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@

#pragma once

#include "../internal/Conf.hpp"

namespace dxfcpp {

/// Base abstract class for all dxFeed C++ API entities
struct Entity {
struct DXFCPP_EXPORT Entity {
/// The default virtual d-tor
virtual ~Entity() = default;
};
Expand Down
4 changes: 3 additions & 1 deletion include/dxfeed_graal_cpp_api/entity/SharedEntity.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@

#pragma once

#include "../internal/Conf.hpp"

#include <memory>

#include "Entity.hpp"

namespace dxfcpp {

/// Base abstract "shared entity" class. Has some helpers for dynamic polymorphism
struct SharedEntity : public Entity, std::enable_shared_from_this<SharedEntity> {
struct DXFCPP_EXPORT SharedEntity : public Entity, std::enable_shared_from_this<SharedEntity> {
/// The simple type synonym for the SharedEntity type
using Ptr = std::shared_ptr<SharedEntity>;

Expand Down
2 changes: 2 additions & 0 deletions include/dxfeed_graal_cpp_api/event/DXEvent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#pragma once

#include "../internal/Conf.hpp"

#include <cassert>
#include <memory>
#include <string>
Expand Down
4 changes: 3 additions & 1 deletion include/dxfeed_graal_cpp_api/event/EventFlag.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#pragma once

#include "../internal/Conf.hpp"

#include <algorithm>
#include <cstdint>
#include <numeric>
Expand Down Expand Up @@ -92,7 +94,7 @@ namespace dxfcpp {
* and `snapshotEnd` or `snapshotSnip` flags. In case of an empty snapshot, `removeEvent` on this event is
* also set to `true`.
*/
class EventFlag final {
class DXFCPP_EXPORT EventFlag final {
std::uint32_t flag_;
std::string name_;

Expand Down
4 changes: 3 additions & 1 deletion include/dxfeed_graal_cpp_api/event/EventMapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@

#pragma once

#include "../internal/Conf.hpp"

#include <memory>
#include <vector>

#include "EventType.hpp"

namespace dxfcpp {

struct EventMapper {
struct DXFCPP_EXPORT EventMapper {
static std::vector<std::shared_ptr<EventType>> fromGraalNativeList(void *graalNativeList);
};

Expand Down
Loading