Skip to content

Commit

Permalink
[DXFC-402] Implement adding multiple symbols and removing symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
AnatolyKalin committed May 26, 2023
1 parent 2955594 commit 8de20f4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
31 changes: 12 additions & 19 deletions include/dxfeed_graal_cpp_api/api/DXFeedSubscription.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,12 @@ class DXFeedSubscription : public SharedEntity {

void addSymbolImpl(const char *symbol) noexcept;

void addSymbolImpl(void* graalSymbol) noexcept;
void addSymbolImpl(void *graalSymbol) noexcept;

void removeSymbolImpl(const char *symbol) noexcept;

void removeSymbolImpl(void *graalSymbol) noexcept;

public:
std::string toString() const noexcept override;

Expand Down Expand Up @@ -237,33 +239,24 @@ class DXFeedSubscription : public SharedEntity {

if constexpr (std::is_same_v<std::decay_t<Symbol>, WildcardSymbol>) {
addSymbolImpl(symbol.toGraal());
} if constexpr (ConvertibleToStringSymbol<Symbol>) {
} else if constexpr (ConvertibleToStringSymbol<Symbol>) {
addSymbolImpl(StringSymbol(std::forward<Symbol>(symbol)).toGraal());
} else if constexpr (std::is_same_v<std::decay_t<Symbol>, std::string>) {
addSymbolImpl(symbol.c_str());
}
else if constexpr (std::is_same_v<std::decay_t<Symbol>, std::string_view>) {
addSymbolImpl(symbol.data());
}
else {
} else {
addSymbolImpl(symbol);
}
}

template <typename Symbol> void removeSymbol(Symbol &&symbol) noexcept {
if constexpr (Debugger::isDebug) {
Debugger::debug(toString() + "::removeSymbol(symbol = " + symbol + ")");
Debugger::debug(toString() + "::removeSymbol<" + typeid(symbol).name() +
">(symbol = " + std::string(symbol) + ")");
}

if constexpr (std::is_same_v<std::decay_t<Symbol>, std::string>) {
removeSymbolImpl(symbol.c_str());
}
#if __cpp_lib_string_view
else if constexpr (std::is_same_v<std::decay_t<Symbol>, std::string_view>) {
removeSymbolImpl(symbol.data());
}
#endif
else {
if constexpr (std::is_same_v<std::decay_t<Symbol>, WildcardSymbol>) {
removeSymbolImpl(symbol.toGraal());
} else if constexpr (ConvertibleToStringSymbol<Symbol>) {
removeSymbolImpl(StringSymbol(std::forward<Symbol>(symbol)).toGraal());
} else {
removeSymbolImpl(symbol);
}
}
Expand Down
9 changes: 9 additions & 0 deletions src/api/DXFeedSubscription.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@ void DXFeedSubscription::removeSymbolImpl(const char *symbol) noexcept {
false);
}

void DXFeedSubscription::removeSymbolImpl(void *graalSymbol) noexcept {
runIsolatedOrElse(
[handler = bit_cast<dxfg_subscription_t *>(handler_.get()), graalSymbol](auto threadHandle) {
return dxfg_DXFeedSubscription_removeSymbol(threadHandle, handler,
bit_cast<dxfg_symbol_t *>(graalSymbol)) == 0;
},
false);
}

void DXFeedSubscription::closeImpl() noexcept {
if (!handler_) {
return;
Expand Down

0 comments on commit 8de20f4

Please sign in to comment.