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 23, 2023
1 parent 3c10ed7 commit e5ddf29
Show file tree
Hide file tree
Showing 43 changed files with 732 additions and 639 deletions.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ set(dxFeedNativeAPIInternalSources
src/internal/Common.cpp
)

set(dxFeedNativeAPIInternalUtilsDebugSources
src/internal/utils/debug/Debug.cpp
)

set(dxFeedNativeAPIAPISources
src/api/DXEndpoint.cpp
src/api/DXFeed.cpp
Expand Down Expand Up @@ -118,6 +122,7 @@ set(dxFeedNativeAPIEventOptionSources

add_library(dxFeedGraalCxxApi
${dxFeedNativeAPIInternalSources}
${dxFeedNativeAPIInternalUtilsDebugSources}
${dxFeedNativeAPIAPISources}
${dxFeedNativeAPISystemSources}
${dxFeedNativeAPIEventSources}
Expand Down
1 change: 1 addition & 0 deletions include/dxfeed_graal_cpp_api/api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "internal/managers/DXEndpointManager.hpp"
#include "internal/managers/DXFeedSubscriptionManager.hpp"
#include "internal/managers/EntityManager.hpp"
#include "internal/utils/debug/Debug.hpp"

#include "api/DXEndpoint.hpp"
#include "api/DXFeed.hpp"
Expand Down
54 changes: 27 additions & 27 deletions include/dxfeed_graal_cpp_api/api/DXEndpoint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

namespace dxfcpp {

struct DXPublisher : std::enable_shared_from_this<DXPublisher> {
struct DXPublisher : SharedEntity {
virtual ~DXPublisher() = default;
};

Expand Down Expand Up @@ -176,7 +176,7 @@ struct DXFeed;
*
* [Javadoc.](https://docs.dxfeed.com/dxfeed/api/com/dxfeed/api/DXEndpoint.html)
*/
struct DXEndpoint : std::enable_shared_from_this<DXEndpoint> {
struct 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 @@ -480,15 +480,15 @@ struct DXEndpoint : std::enable_shared_from_this<DXEndpoint> {

protected:
DXEndpoint() : handler_{}, role_{}, feed_{}, publisher_{}, stateChangeListenerHandler_{}, onStateChange_{} {
if constexpr (isDebug) {
debug("DXEndpoint()");
if constexpr (Debugger::isDebug) {
Debugger::debug("DXEndpoint()");
}
}

public:
virtual ~DXEndpoint() {
if constexpr (isDebug) {
debug("DXEndpoint{{{}}}::~DXEndpoint()", handler_.toString());
if constexpr (Debugger::isDebug) {
Debugger::debug("DXEndpoint{{{}}}::~DXEndpoint()", handler_.toString());
}
}

Expand All @@ -506,8 +506,8 @@ struct DXEndpoint : std::enable_shared_from_this<DXEndpoint> {
* @see #getInstance(Role)
*/
static std::shared_ptr<DXEndpoint> getInstance() {
if constexpr (isDebug) {
debug("DXEndpoint::getInstance()");
if constexpr (Debugger::isDebug) {
Debugger::debug("DXEndpoint::getInstance()");
}

return getInstance(Role::FEED);
Expand All @@ -533,8 +533,8 @@ struct DXEndpoint : std::enable_shared_from_this<DXEndpoint> {
* @return The DXEndpoint instance
*/
static std::shared_ptr<DXEndpoint> getInstance(Role role) {
if constexpr (isDebug) {
debug("DXEndpoint::getInstance(role = {})", roleToString(role));
if constexpr (Debugger::isDebug) {
Debugger::debug("DXEndpoint::getInstance(role = {})", roleToString(role));
}

std::lock_guard lock(MTX);
Expand All @@ -555,8 +555,8 @@ struct DXEndpoint : std::enable_shared_from_this<DXEndpoint> {
* @return the created endpoint.
*/
static std::shared_ptr<DXEndpoint> create() {
if constexpr (isDebug) {
debug("DXEndpoint::create()");
if constexpr (Debugger::isDebug) {
Debugger::debug("DXEndpoint::create()");
}

return newBuilder()->build();
Expand All @@ -572,8 +572,8 @@ struct DXEndpoint : std::enable_shared_from_this<DXEndpoint> {
* @return the created endpoint.
*/
static std::shared_ptr<DXEndpoint> create(Role role) {
if constexpr (isDebug) {
debug("DXEndpoint::create(role = {})", roleToString(role));
if constexpr (Debugger::isDebug) {
Debugger::debug("DXEndpoint::create(role = {})", roleToString(role));
}

return newBuilder()->withRole(role)->build();
Expand Down Expand Up @@ -748,8 +748,8 @@ struct DXEndpoint : std::enable_shared_from_this<DXEndpoint> {
* [Javadoc.](https://docs.dxfeed.com/dxfeed/api/com/dxfeed/api/DXEndpoint.html#close--)
*/
void close() {
if constexpr (isDebug) {
debug("DXEndpoint{{{}}}::close()", handler_.toString());
if constexpr (Debugger::isDebug) {
Debugger::debug("DXEndpoint{{{}}}::close()", handler_.toString());
}

closeImpl();
Expand Down Expand Up @@ -813,8 +813,8 @@ struct DXEndpoint : std::enable_shared_from_this<DXEndpoint> {
std::unordered_map<std::string, std::string> properties_;

Builder() : handler_{}, properties_{} {
if constexpr (isDebug) {
debug("DXEndpoint::Builder::Builder()");
if constexpr (Debugger::isDebug) {
Debugger::debug("DXEndpoint::Builder::Builder()");
}
}

Expand All @@ -837,8 +837,8 @@ struct DXEndpoint : std::enable_shared_from_this<DXEndpoint> {
public:
/// Releases the GraalVM handle
virtual ~Builder() {
if constexpr (isDebug) {
debug("DXEndpoint::Builder{{{}}}::~Builder()", handler_.toString());
if constexpr (Debugger::isDebug) {
Debugger::debug("DXEndpoint::Builder{{{}}}::~Builder()", handler_.toString());
}
}

Expand All @@ -853,8 +853,8 @@ struct DXEndpoint : std::enable_shared_from_this<DXEndpoint> {
*/
std::shared_ptr<Builder> withName(const std::string &name) {
// TODO: check invalid utf-8
if constexpr (isDebug) {
debug("DXEndpoint::Builder{{{}}}::withName(name = {})", handler_.toString(), name);
if constexpr (Debugger::isDebug) {
Debugger::debug("DXEndpoint::Builder{{{}}}::withName(name = {})", handler_.toString(), name);
}

return withProperty(NAME_PROPERTY, name);
Expand Down Expand Up @@ -891,8 +891,8 @@ struct DXEndpoint : std::enable_shared_from_this<DXEndpoint> {
* @see ::withProperty(const std::string&, const std::string&)
*/
template <typename Properties> std::shared_ptr<Builder> withProperties(Properties &&properties) {
if constexpr (isDebug) {
debug("DXEndpoint::Builder{{{}}}::withProperties(properties[{}])", handler_.toString(),
if constexpr (Debugger::isDebug) {
Debugger::debug("DXEndpoint::Builder{{{}}}::withProperties(properties[{}])", handler_.toString(),
properties.size());
}

Expand Down Expand Up @@ -928,13 +928,13 @@ struct DXEndpoint : std::enable_shared_from_this<DXEndpoint> {
* @return the created endpoint builder.
*/
static std::shared_ptr<Builder> newBuilder() noexcept {
if constexpr (isDebug) {
debug("DXEndpoint::newBuilder()");
if constexpr (Debugger::isDebug) {
Debugger::debug("DXEndpoint::newBuilder()");
}

return Builder::create();
}

std::string toString() const { return fmt::format("DXEndpoint{{{}}}", handler_.toString()); }
std::string toString() const noexcept override;
};
} // namespace dxfcpp
20 changes: 10 additions & 10 deletions include/dxfeed_graal_cpp_api/api/DXFeed.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class EventTypeEnum;
/**
* Main entry class for dxFeed API (<b>read it first</b>).
*/
struct DXFeed : std::enable_shared_from_this<DXFeed> {
struct DXFeed : SharedEntity {
friend struct DXEndpoint;

private:
Expand All @@ -35,15 +35,15 @@ struct DXFeed : std::enable_shared_from_this<DXFeed> {

protected:
DXFeed() noexcept : handler_{} {
if constexpr (isDebug) {
debug("DXFeed()");
if constexpr (Debugger::isDebug) {
Debugger::debug("DXFeed()");
}
}

public:
virtual ~DXFeed() noexcept {
if constexpr (isDebug) {
debug("{}::~DXFeed()", toString());
if constexpr (Debugger::isDebug) {
Debugger::debug("DXFeed{{{}}}::~DXFeed()", handler_.toString());
}
}

Expand All @@ -67,8 +67,8 @@ struct DXFeed : std::enable_shared_from_this<DXFeed> {

template <typename EventTypeIt>
std::shared_ptr<DXFeedSubscription> createSubscription(EventTypeIt begin, EventTypeIt end) noexcept {
if constexpr (isDebug) {
debug("{}::createSubscription(eventTypes = {})", namesToString(begin, end));
if constexpr (Debugger::isDebug) {
Debugger::debug("{}::createSubscription(eventTypes = {})", namesToString(begin, end));
}

auto sub = DXFeedSubscription::create(begin, end);
Expand All @@ -86,8 +86,8 @@ struct DXFeed : std::enable_shared_from_this<DXFeed> {
requires requires { ElementTypeIs<EventTypesCollection, EventTypeEnum>; }
#endif
{
if constexpr (isDebug) {
debug("{}::createSubscription(eventTypes = {})", toString(),
if constexpr (Debugger::isDebug) {
Debugger::debug("{}::createSubscription(eventTypes = {})", toString(),
namesToString(std::begin(eventTypes), std::end(eventTypes)));
}

Expand All @@ -98,7 +98,7 @@ struct DXFeed : std::enable_shared_from_this<DXFeed> {
return sub;
}

std::string toString() const { return fmt::format("DXFeed{{{}}}", handler_.toString()); }
std::string toString() const noexcept override;
};

} // namespace dxfcpp
42 changes: 21 additions & 21 deletions include/dxfeed_graal_cpp_api/api/DXFeedSubscription.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace dxfcpp {

struct DXFeed;

class DXFeedSubscription : public std::enable_shared_from_this<DXFeedSubscription> {
class DXFeedSubscription : public SharedEntity {
friend struct DXFeed;

mutable std::recursive_mutex mtx_{};
Expand All @@ -32,8 +32,8 @@ class DXFeedSubscription : public std::enable_shared_from_this<DXFeedSubscriptio
template <typename EventTypeIt>
DXFeedSubscription(EventTypeIt begin, EventTypeIt end) noexcept
: mtx_{}, handler_{}, eventListenerHandler_{}, onEvent_{} {
if constexpr (isDebug) {
debug("DXFeedSubscription(eventTypes = {})", namesToString(begin, end));
if constexpr (Debugger::isDebug) {
Debugger::debug("DXFeedSubscription(eventTypes = {})", namesToString(begin, end));
}

auto list = handler_utils::EventClassList::create(begin, end);
Expand Down Expand Up @@ -68,11 +68,11 @@ class DXFeedSubscription : public std::enable_shared_from_this<DXFeedSubscriptio
void removeSymbolImpl(const char *symbol) noexcept;

public:
std::string toString() const { return fmt::format("DXFeedSubscription{{{}}}", handler_.toString()); }
std::string toString() const noexcept override;

virtual ~DXFeedSubscription() {
if constexpr (isDebug) {
debug("{}::~DXFeedSubscription()", toString());
~DXFeedSubscription() override {
if constexpr (Debugger::isDebug) {
Debugger::debug("DXFeedSubscription{{{}}}::~DXFeedSubscription()", handler_.toString());
}

tryCallWithLock(mtx_, [this] { closeImpl(); });
Expand All @@ -84,8 +84,8 @@ class DXFeedSubscription : public std::enable_shared_from_this<DXFeedSubscriptio
* @param eventType the event type.
*/
static std::shared_ptr<DXFeedSubscription> create(const EventTypeEnum &eventType) noexcept {
if constexpr (isDebug) {
debug("DXFeedSubscription::create(eventType = {})", eventType.getName());
if constexpr (Debugger::isDebug) {
Debugger::debug("DXFeedSubscription::create(eventType = {})", eventType.getName());
}

auto sub = std::shared_ptr<DXFeedSubscription>(new DXFeedSubscription(eventType));
Expand All @@ -106,8 +106,8 @@ class DXFeedSubscription : public std::enable_shared_from_this<DXFeedSubscriptio
*/
template <typename EventTypeIt>
static std::shared_ptr<DXFeedSubscription> create(EventTypeIt begin, EventTypeIt end) noexcept {
if constexpr (isDebug) {
debug("DXFeedSubscription::create(eventTypes = {})", namesToString(begin, end));
if constexpr (Debugger::isDebug) {
Debugger::debug("DXFeedSubscription::create(eventTypes = {})", namesToString(begin, end));
}

auto sub = std::shared_ptr<DXFeedSubscription>(new DXFeedSubscription(begin, end));
Expand Down Expand Up @@ -177,8 +177,8 @@ class DXFeedSubscription : public std::enable_shared_from_this<DXFeedSubscriptio
* can be added.
*/
void close() noexcept {
if constexpr (isDebug) {
debug("{}::close()", toString());
if constexpr (Debugger::isDebug) {
Debugger::debug("{}::close()", toString());
}

std::lock_guard lock(mtx_);
Expand Down Expand Up @@ -226,8 +226,8 @@ class DXFeedSubscription : public std::enable_shared_from_this<DXFeedSubscriptio
const auto &onEvent() noexcept { return onEvent_; }

template <typename Symbol> void addSymbol(Symbol &&symbol) noexcept {
if constexpr (isDebug) {
debug("{}::addSymbol(symbol = {})", toString(), symbol);
if constexpr (Debugger::isDebug) {
Debugger::debug("{}::addSymbol(symbol = {})", toString(), symbol);
}

if constexpr (std::is_same_v<std::decay_t<Symbol>, std::string>) {
Expand All @@ -244,8 +244,8 @@ class DXFeedSubscription : public std::enable_shared_from_this<DXFeedSubscriptio
}

template <typename Symbol> void removeSymbol(Symbol &&symbol) noexcept {
if constexpr (isDebug) {
debug("{}::removeSymbol(symbol = {})", toString(), symbol);
if constexpr (Debugger::isDebug) {
Debugger::debug("{}::removeSymbol(symbol = {})", toString(), symbol);
}

if constexpr (std::is_same_v<std::decay_t<Symbol>, std::string>) {
Expand All @@ -271,8 +271,8 @@ class DXFeedSubscription : public std::enable_shared_from_this<DXFeedSubscriptio
* Clears the set of subscribed symbols.
*/
void clear() noexcept {
if constexpr (isDebug) {
debug("{}::clear()", toString());
if constexpr (Debugger::isDebug) {
Debugger::debug("{}::clear()", toString());
}

std::lock_guard lock(mtx_);
Expand All @@ -288,8 +288,8 @@ class DXFeedSubscription : public std::enable_shared_from_this<DXFeedSubscriptio
* @see ::close
*/
bool isClosed() noexcept {
if constexpr (isDebug) {
debug("{}::isClosed()", toString());
if constexpr (Debugger::isDebug) {
Debugger::debug("{}::isClosed()", toString());
}

std::lock_guard lock(mtx_);
Expand Down
7 changes: 7 additions & 0 deletions include/dxfeed_graal_cpp_api/entity/SharedEntity.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ struct SharedEntity : public Entity, std::enable_shared_from_this<SharedEntity>
template <typename T> std::shared_ptr<T> sharedAs() const noexcept {
return std::dynamic_pointer_cast<T>(shared_from_this());
}

/**
* Returns a string representation of the current object.
*
* @return a string representation
*/
virtual std::string toString() const noexcept { return "SharedEntity{}"; }
};

} // namespace dxfcpp
8 changes: 2 additions & 6 deletions include/dxfeed_graal_cpp_api/event/EventType.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,8 @@ struct EventType : public SharedEntity {
// The default implementation is empty
};

/**
* Returns a string representation of the current object.
*
* @return a string representation
*/
virtual std::string toString() const noexcept { return "EventType{}"; }
///
std::string toString() const noexcept override { return "EventType{}"; }

friend std::ostream &operator<<(std::ostream &os, const EventType &e) { return os << e.toString(); }

Expand Down
Loading

0 comments on commit e5ddf29

Please sign in to comment.