From dfc1219e8e63067b74031ae92fcc0fc89ab19ba4 Mon Sep 17 00:00:00 2001 From: AnatolyKalin Date: Wed, 24 May 2023 19:32:02 +0300 Subject: [PATCH] [DXFC-402] Implement adding multiple symbols and removing symbols --- .../dxfeed_graal_cpp_api/api/DXEndpoint.hpp | 18 ++--- include/dxfeed_graal_cpp_api/api/DXFeed.hpp | 8 +-- .../api/DXFeedSubscription.hpp | 18 ++--- .../dxfeed_graal_cpp_api/internal/Isolate.hpp | 51 ++++++++------- .../internal/managers/EntityManager.hpp | 16 ++--- .../internal/utils/debug/Debug.hpp | 9 ++- src/api/DXEndpoint.cpp | 38 ++++++----- src/api/DXFeed.cpp | 18 ++--- src/api/DXFeedSubscription.cpp | 8 +-- src/internal/Common.cpp | 50 +++++++------- src/internal/utils/debug/Debug.cpp | 65 ++++--------------- src/system/System.cpp | 14 ++-- tests/api/DXEndpointTest.cpp | 2 +- 13 files changed, 141 insertions(+), 174 deletions(-) diff --git a/include/dxfeed_graal_cpp_api/api/DXEndpoint.hpp b/include/dxfeed_graal_cpp_api/api/DXEndpoint.hpp index 374eea47..cde71f95 100644 --- a/include/dxfeed_graal_cpp_api/api/DXEndpoint.hpp +++ b/include/dxfeed_graal_cpp_api/api/DXEndpoint.hpp @@ -397,7 +397,7 @@ struct DXEndpoint : SharedEntity { LOCAL_HUB }; - static auto roleToString(Role role) { + static std::string roleToString(Role role) { switch (role) { case Role::FEED: return "FEED"; @@ -488,7 +488,7 @@ struct DXEndpoint : SharedEntity { public: virtual ~DXEndpoint() { if constexpr (Debugger::isDebug) { - Debugger::debug("DXEndpoint{{{}}}::~DXEndpoint()", handler_.toString()); + Debugger::debug("DXEndpoint{" + handler_.toString() + " }::~DXEndpoint()"); } } @@ -534,7 +534,7 @@ struct DXEndpoint : SharedEntity { */ static std::shared_ptr getInstance(Role role) { if constexpr (Debugger::isDebug) { - Debugger::debug("DXEndpoint::getInstance(role = {})", roleToString(role)); + Debugger::debug("DXEndpoint::getInstance(role = " + roleToString(role) + ")"); } std::lock_guard lock(MTX); @@ -573,7 +573,7 @@ struct DXEndpoint : SharedEntity { */ static std::shared_ptr create(Role role) { if constexpr (Debugger::isDebug) { - Debugger::debug("DXEndpoint::create(role = {})", roleToString(role)); + Debugger::debug("DXEndpoint::create(role = " + roleToString(role) + ")"); } return newBuilder()->withRole(role)->build(); @@ -749,7 +749,7 @@ struct DXEndpoint : SharedEntity { */ void close() { if constexpr (Debugger::isDebug) { - Debugger::debug("DXEndpoint{{{}}}::close()", handler_.toString()); + Debugger::debug("DXEndpoint{" + handler_.toString() + "}::close()"); } closeImpl(); @@ -838,7 +838,7 @@ struct DXEndpoint : SharedEntity { /// Releases the GraalVM handle virtual ~Builder() { if constexpr (Debugger::isDebug) { - Debugger::debug("DXEndpoint::Builder{{{}}}::~Builder()", handler_.toString()); + Debugger::debug("DXEndpoint::Builder{" + handler_.toString() + "}::~Builder()"); } } @@ -854,7 +854,7 @@ struct DXEndpoint : SharedEntity { std::shared_ptr withName(const std::string &name) { // TODO: check invalid utf-8 if constexpr (Debugger::isDebug) { - Debugger::debug("DXEndpoint::Builder{{{}}}::withName(name = {})", handler_.toString(), name); + Debugger::debug("DXEndpoint::Builder{" + handler_.toString() + "}::withName(name = " + name + ")"); } return withProperty(NAME_PROPERTY, name); @@ -892,8 +892,8 @@ struct DXEndpoint : SharedEntity { */ template std::shared_ptr withProperties(Properties &&properties) { if constexpr (Debugger::isDebug) { - Debugger::debug("DXEndpoint::Builder{{{}}}::withProperties(properties[{}])", handler_.toString(), - properties.size()); + Debugger::debug("DXEndpoint::Builder{" + handler_.toString() + "}::withProperties(properties[" + + std::to_string(properties.size()) + "])"); } for (auto &&[k, v] : properties) { diff --git a/include/dxfeed_graal_cpp_api/api/DXFeed.hpp b/include/dxfeed_graal_cpp_api/api/DXFeed.hpp index cc0d0d3b..2f458791 100644 --- a/include/dxfeed_graal_cpp_api/api/DXFeed.hpp +++ b/include/dxfeed_graal_cpp_api/api/DXFeed.hpp @@ -43,7 +43,7 @@ struct DXFeed : SharedEntity { public: virtual ~DXFeed() noexcept { if constexpr (Debugger::isDebug) { - Debugger::debug("DXFeed{{{}}}::~DXFeed()", handler_.toString()); + Debugger::debug("DXFeed{" + handler_.toString() + "}::~DXFeed()"); } } @@ -68,7 +68,7 @@ struct DXFeed : SharedEntity { template std::shared_ptr createSubscription(EventTypeIt begin, EventTypeIt end) noexcept { if constexpr (Debugger::isDebug) { - Debugger::debug("{}::createSubscription(eventTypes = {})", namesToString(begin, end)); + Debugger::debug("{}::createSubscription(eventTypes = " + namesToString(begin, end) + ")"); } auto sub = DXFeedSubscription::create(begin, end); @@ -87,8 +87,8 @@ struct DXFeed : SharedEntity { #endif { if constexpr (Debugger::isDebug) { - Debugger::debug("{}::createSubscription(eventTypes = {})", toString(), - namesToString(std::begin(eventTypes), std::end(eventTypes))); + Debugger::debug(toString() + "::createSubscription(eventTypes = " + + namesToString(std::begin(eventTypes), std::end(eventTypes)) + ")"); } auto sub = DXFeedSubscription::create(eventTypes); diff --git a/include/dxfeed_graal_cpp_api/api/DXFeedSubscription.hpp b/include/dxfeed_graal_cpp_api/api/DXFeedSubscription.hpp index ae18e4da..0cfd9984 100644 --- a/include/dxfeed_graal_cpp_api/api/DXFeedSubscription.hpp +++ b/include/dxfeed_graal_cpp_api/api/DXFeedSubscription.hpp @@ -33,7 +33,7 @@ class DXFeedSubscription : public SharedEntity { DXFeedSubscription(EventTypeIt begin, EventTypeIt end) noexcept : mtx_{}, handler_{}, eventListenerHandler_{}, onEvent_{} { if constexpr (Debugger::isDebug) { - Debugger::debug("DXFeedSubscription(eventTypes = {})", namesToString(begin, end)); + Debugger::debug("DXFeedSubscription(eventTypes = " + namesToString(begin, end) + ")"); } auto list = handler_utils::EventClassList::create(begin, end); @@ -72,7 +72,7 @@ class DXFeedSubscription : public SharedEntity { ~DXFeedSubscription() override { if constexpr (Debugger::isDebug) { - Debugger::debug("DXFeedSubscription{{{}}}::~DXFeedSubscription()", handler_.toString()); + Debugger::debug("DXFeedSubscription{" + handler_.toString() + "}::~DXFeedSubscription()"); } tryCallWithLock(mtx_, [this] { closeImpl(); }); @@ -85,7 +85,7 @@ class DXFeedSubscription : public SharedEntity { */ static std::shared_ptr create(const EventTypeEnum &eventType) noexcept { if constexpr (Debugger::isDebug) { - Debugger::debug("DXFeedSubscription::create(eventType = {})", eventType.getName()); + Debugger::debug("DXFeedSubscription::create(eventType = " + eventType.getName() + ")"); } auto sub = std::shared_ptr(new DXFeedSubscription(eventType)); @@ -107,7 +107,7 @@ class DXFeedSubscription : public SharedEntity { template static std::shared_ptr create(EventTypeIt begin, EventTypeIt end) noexcept { if constexpr (Debugger::isDebug) { - Debugger::debug("DXFeedSubscription::create(eventTypes = {})", namesToString(begin, end)); + Debugger::debug("DXFeedSubscription::create(eventTypes = " + namesToString(begin, end) + ")"); } auto sub = std::shared_ptr(new DXFeedSubscription(begin, end)); @@ -178,7 +178,7 @@ class DXFeedSubscription : public SharedEntity { */ void close() noexcept { if constexpr (Debugger::isDebug) { - Debugger::debug("{}::close()", toString()); + Debugger::debug(toString() + "::close()"); } std::lock_guard lock(mtx_); @@ -227,7 +227,7 @@ class DXFeedSubscription : public SharedEntity { template void addSymbol(Symbol &&symbol) noexcept { if constexpr (Debugger::isDebug) { - Debugger::debug("{}::addSymbol(symbol = {})", toString(), symbol); + Debugger::debug(toString() + "::addSymbol(symbol = " + std::string(symbol) + ")"); } if constexpr (std::is_same_v, std::string>) { @@ -245,7 +245,7 @@ class DXFeedSubscription : public SharedEntity { template void removeSymbol(Symbol &&symbol) noexcept { if constexpr (Debugger::isDebug) { - Debugger::debug("{}::removeSymbol(symbol = {})", toString(), symbol); + Debugger::debug(toString() + "::removeSymbol(symbol = " + symbol + ")"); } if constexpr (std::is_same_v, std::string>) { @@ -272,7 +272,7 @@ class DXFeedSubscription : public SharedEntity { */ void clear() noexcept { if constexpr (Debugger::isDebug) { - Debugger::debug("{}::clear()", toString()); + Debugger::debug(toString() + "::clear()"); } std::lock_guard lock(mtx_); @@ -289,7 +289,7 @@ class DXFeedSubscription : public SharedEntity { */ bool isClosed() noexcept { if constexpr (Debugger::isDebug) { - Debugger::debug("{}::isClosed()", toString()); + Debugger::debug(toString() + "::isClosed()"); } std::lock_guard lock(mtx_); diff --git a/include/dxfeed_graal_cpp_api/internal/Isolate.hpp b/include/dxfeed_graal_cpp_api/internal/Isolate.hpp index 1f2b0593..a227f789 100644 --- a/include/dxfeed_graal_cpp_api/internal/Isolate.hpp +++ b/include/dxfeed_graal_cpp_api/internal/Isolate.hpp @@ -37,20 +37,21 @@ class Isolate final { this->idx = idx++; if constexpr (Debugger::traceIsolates) { - Debugger::trace("IsolateThread{{{}, isMain = {}, tid = {}, idx = {}}}()", - dxfcpp::toString(bit_cast(handle)), isMain, dxfcpp::toString(tid), idx); + Debugger::trace("IsolateThread{" + dxfcpp::toString(bit_cast(handle)) + + ", isMain = " + dxfcpp::toString(isMain) + ", tid = " + dxfcpp::toString(tid) + + ", idx = " + std::to_string(idx) + "}()"); } } CEntryPointErrors detach() noexcept { if constexpr (Debugger::traceIsolates) { - Debugger::trace("{}::detach()", toString()); + Debugger::trace(toString() + "::detach()"); } // OK if nothing is attached. if (!handle) { if constexpr (Debugger::traceIsolates) { - Debugger::trace("\tNot attached"); + Debugger::trace(toString() + "::detach(): !handle => Not attached"); } return CEntryPointErrors::NO_ERROR; @@ -60,7 +61,7 @@ class Isolate final { if (result == CEntryPointErrors::NO_ERROR) { if constexpr (Debugger::traceIsolates) { - Debugger::trace("\tDetached"); + Debugger::trace(toString() + "::detach(): result == CEntryPointErrors::NO_ERROR => Detached"); } handle = nullptr; @@ -71,12 +72,12 @@ class Isolate final { CEntryPointErrors detachAllThreadsAndTearDownIsolate() noexcept { if constexpr (Debugger::traceIsolates) { - Debugger::trace("{}::detachAllThreadsAndTearDownIsolate()", toString()); + Debugger::trace(toString() + "::detachAllThreadsAndTearDownIsolate()"); } if (!handle) { if constexpr (Debugger::traceIsolates) { - Debugger::trace("\tNot attached"); + Debugger::trace(toString() + "::detachAllThreadsAndTearDownIsolate(): !handle => Not attached"); } return CEntryPointErrors::NO_ERROR; @@ -86,7 +87,9 @@ class Isolate final { if (result == CEntryPointErrors::NO_ERROR) { if constexpr (Debugger::traceIsolates) { - Debugger::trace("\tAll threads have been detached. The isolate has been teared down."); + Debugger::trace(toString() + + "::detachAllThreadsAndTearDownIsolate(): CEntryPointErrors::NO_ERROR => All " + "threads have been detached. The isolate has been teared down."); } handle = nullptr; @@ -97,12 +100,12 @@ class Isolate final { ~IsolateThread() noexcept { if constexpr (Debugger::traceIsolates) { - Debugger::trace("~{}()", toString()); + Debugger::trace(toString() + "::~()"); } if (isMain) { if constexpr (Debugger::traceIsolates) { - Debugger::trace("\tThis is the main thread"); + Debugger::trace(toString() + "::~(): isMain => This is the main thread"); } return; @@ -130,8 +133,8 @@ class Isolate final { currentIsolateThread_.isMain = true; if constexpr (Debugger::traceIsolates) { - Debugger::trace("Isolate{{{}, main = {}, current = {}}}()", bit_cast(handle), - mainIsolateThread_.toString(), currentIsolateThread_.toString()); + Debugger::trace("Isolate{" + dxfcpp::toString(bit_cast(handle)) + ", main = " + + mainIsolateThread_.toString() + ", current = " + currentIsolateThread_.toString() + "}()"); } } @@ -149,14 +152,14 @@ class Isolate final { auto result = std::shared_ptr{new Isolate{graalIsolateHandle, graalIsolateThreadHandle}}; if constexpr (Debugger::traceIsolates) { - Debugger::trace("Isolate::create() -> *{}", result->toString()); + Debugger::trace("Isolate::create() -> *" + result->toString()); } return result; } if constexpr (Debugger::traceIsolates) { - Debugger::trace("\t-> nullptr"); + Debugger::trace("Isolate::create() -> nullptr"); } return nullptr; @@ -164,13 +167,13 @@ class Isolate final { CEntryPointErrors attach() noexcept { if constexpr (Debugger::traceIsolates) { - Debugger::trace("{}::attach()", toString()); + Debugger::trace(toString() + "::attach()"); } // We will not re-attach. if (!currentIsolateThread_.handle) { if constexpr (Debugger::traceIsolates) { - Debugger::trace("\tNeeds to be attached."); + Debugger::trace(toString() + "::attach(): !currentIsolateThread_.handle => Needs to be attached."); } GraalIsolateThreadHandle newIsolateThreadHandle{}; @@ -179,7 +182,8 @@ class Isolate final { result != CEntryPointErrors::NO_ERROR) { if constexpr (Debugger::traceIsolates) { - Debugger::trace("\t-> {}", result.getDescription()); + Debugger::trace(toString() + "::attach(): result != CEntryPointErrors::NO_ERROR [" + + std::to_string(result.getCode()) + "] " + result.getDescription()); } return result; @@ -189,11 +193,11 @@ class Isolate final { currentIsolateThread_.isMain = mainIsolateThread_.handle == newIsolateThreadHandle; if constexpr (Debugger::traceIsolates) { - Debugger::trace("\tAttached: {}", currentIsolateThread_.toString()); + Debugger::trace(toString() + "::attach(): Attached: " + currentIsolateThread_.toString()); } } else { if constexpr (Debugger::traceIsolates) { - Debugger::trace("\tCached: {}", currentIsolateThread_.toString()); + Debugger::trace(toString() + "::attach(): Cached: " + currentIsolateThread_.toString()); } } @@ -202,7 +206,7 @@ class Isolate final { GraalIsolateThreadHandle get() noexcept { if constexpr (Debugger::traceIsolates) { - Debugger::trace("{}::get()", toString()); + Debugger::trace(toString() + "::get()"); } return graal_get_current_thread(handle_); @@ -221,7 +225,7 @@ class Isolate final { static std::shared_ptr instance = create(); if constexpr (Debugger::traceIsolates) { - Debugger::trace("Isolate::getInstance() -> *{}", instance->toString()); + Debugger::trace("Isolate::getInstance() -> *" + instance->toString()); } return instance; @@ -230,7 +234,7 @@ class Isolate final { template auto runIsolated(F &&f) -> std::variant> { if constexpr (Debugger::traceIsolates) { - Debugger::trace("{}::runIsolated({})", toString(), bit_cast(&f)); + Debugger::trace(toString() + "::runIsolated(" + typeid(f).name() + ")"); } // Perhaps the code is already running within the GraalVM thread (for example, we are in a listener) @@ -240,7 +244,8 @@ class Isolate final { if (auto result = attach(); result != CEntryPointErrors::NO_ERROR) { if constexpr (Debugger::traceIsolates) { - Debugger::trace("\t-> {}", result.getDescription()); + Debugger::trace(toString() + "::runIsolated(" + typeid(f).name() + + "): result != CEntryPointErrors::NO_ERROR -> " + result.getDescription()); } return result; diff --git a/include/dxfeed_graal_cpp_api/internal/managers/EntityManager.hpp b/include/dxfeed_graal_cpp_api/internal/managers/EntityManager.hpp index f36935fd..151abacf 100644 --- a/include/dxfeed_graal_cpp_api/internal/managers/EntityManager.hpp +++ b/include/dxfeed_graal_cpp_api/internal/managers/EntityManager.hpp @@ -14,9 +14,7 @@ namespace dxfcpp { template struct EntityManager : private NonCopyable> { #if DXFCPP_DEBUG == 1 - static auto getDebugName() { - return std::string("EntityManager<") + typeid(EntityType).name() + ">"; - } + static auto getDebugName() { return std::string("EntityManager<") + typeid(EntityType).name() + ">"; } #endif // TODO: Boost.Bimap @@ -26,14 +24,14 @@ template struct EntityManager : private NonCopyable registerEntity(std::shared_ptr entity) { if constexpr (Debugger::isDebug) { - Debugger::debug("{}::registerEntity({})", getDebugName(), entity->toString()); + Debugger::debug(getDebugName() + "::registerEntity(" + entity->toString() + ")"); } std::lock_guard lockGuard{mutex_}; @@ -52,7 +50,7 @@ template struct EntityManager : private NonCopyable entity) { if constexpr (Debugger::isDebug) { - Debugger::debug("{}::unregisterEntity({})", getDebugName(), entity->toString()); + Debugger::debug(getDebugName() + "::unregisterEntity(" + entity->toString() + ")"); } std::lock_guard lockGuard{mutex_}; @@ -69,7 +67,7 @@ template struct EntityManager : private NonCopyable id) { if constexpr (Debugger::isDebug) { - Debugger::debug("{}::unregisterEntity(id = {})", getDebugName(), id.getValue()); + Debugger::debug(getDebugName() + "::unregisterEntity(id = " + std::to_string(id.getValue()) + ")"); } std::lock_guard lockGuard{mutex_}; @@ -86,7 +84,7 @@ template struct EntityManager : private NonCopyable getEntity(Id id) { if constexpr (Debugger::isDebug) { - Debugger::debug("{}::getEntity(id = {})", getDebugName(), id.getValue()); + Debugger::debug(getDebugName() + "::getEntity(id = " + std::to_string(id.getValue()) + ")"); } std::lock_guard lockGuard{mutex_}; @@ -100,7 +98,7 @@ template struct EntityManager : private NonCopyable> getId(std::shared_ptr entity) { if constexpr (Debugger::isDebug) { - Debugger::debug("{}::getId({})", getDebugName(), entity->toString()); + Debugger::debug(getDebugName() + "::getId(" + entity->toString() + ")"); } std::lock_guard lockGuard{mutex_}; diff --git a/include/dxfeed_graal_cpp_api/internal/utils/debug/Debug.hpp b/include/dxfeed_graal_cpp_api/internal/utils/debug/Debug.hpp index 7ff611ee..3a9555ba 100644 --- a/include/dxfeed_graal_cpp_api/internal/utils/debug/Debug.hpp +++ b/include/dxfeed_graal_cpp_api/internal/utils/debug/Debug.hpp @@ -5,6 +5,7 @@ #define DXFCPP_DEBUG 1 #define DXFCPP_TRACE_LISTS 1 +#define DXFCPP_TRACE_ISOLATES 1 #ifndef DXFCPP_DEBUG # define DXFCPP_DEBUG 0 @@ -49,9 +50,13 @@ struct Debugger { # else static constexpr bool traceLists = false; # endif - template static void debug(std::string_view format, Args &&...args); + static std::string nowStr(); + static std::string nowStrWithTimeZone(); + static std::string debugPrefixStr(); + static void debug(std::string); # if DXFCPP_TRACE == 1 - template static void trace(std::string_view format, Args &&...args); + static std::string tracePrefixStr(); + static void trace(std::string); # else static void trace(...); # endif diff --git a/src/api/DXEndpoint.cpp b/src/api/DXEndpoint.cpp index fbb60196..71ab4e06 100644 --- a/src/api/DXEndpoint.cpp +++ b/src/api/DXEndpoint.cpp @@ -72,8 +72,8 @@ static DXEndpoint::State graalStateToState(dxfg_endpoint_state_t state) { std::shared_ptr DXEndpoint::create(void *endpointHandle, DXEndpoint::Role role, const std::unordered_map &properties) { if constexpr (Debugger::isDebug) { - Debugger::debug("DXEndpoint::create{{handle = {}, role = {}, properties[{}]}}()", endpointHandle, - roleToString(role), properties.size()); + Debugger::debug("DXEndpoint::create(handle = " + dxfcpp::toString(endpointHandle) + + ", role = " + roleToString(role) + ", properties[" + std::to_string(properties.size()) + "])"); } std::shared_ptr endpoint{new (std::nothrow) DXEndpoint{}}; @@ -96,8 +96,8 @@ std::shared_ptr DXEndpoint::create(void *endpointHandle, DXEndpoint: auto endpoint = ApiContext::getInstance()->getDxEndpointManager()->getEntity(id); if constexpr (Debugger::isDebug) { - Debugger::debug("onStateChange: id = {}, endpoint = {}", std::to_string(id.getValue()), - ((endpoint) ? endpoint->toString() : "nullptr")); + Debugger::debug("onStateChange: id = " + std::to_string(id.getValue()) + + ", endpoint = " + ((endpoint) ? endpoint->toString() : "nullptr")); } if (endpoint) { @@ -159,7 +159,7 @@ void DXEndpoint::closeImpl() { std::shared_ptr DXEndpoint::user(const std::string &user) { // TODO: check invalid utf-8 if constexpr (Debugger::isDebug) { - Debugger::debug("DXEndpoint{{{}}}::user(user = {})", handler_.toString(), user); + Debugger::debug("DXEndpoint{" + handler_.toString() + "}::user(user = " + user + ")"); } if (handler_) { @@ -176,7 +176,7 @@ std::shared_ptr DXEndpoint::user(const std::string &user) { std::shared_ptr DXEndpoint::password(const std::string &password) { // TODO: check invalid utf-8 if constexpr (Debugger::isDebug) { - Debugger::debug("DXEndpoint{{{}}}::password(password = {})", handler_.toString(), password); + Debugger::debug("DXEndpoint{" + handler_.toString() + "}::password(password = " + password + ")"); } if (handler_) { @@ -193,7 +193,7 @@ std::shared_ptr DXEndpoint::password(const std::string &password) { std::shared_ptr DXEndpoint::connect(const std::string &address) { // TODO: check invalid utf-8 if constexpr (Debugger::isDebug) { - Debugger::debug("DXEndpoint{{{}}}::connect(address = {})", handler_.toString(), address); + Debugger::debug("DXEndpoint{" + handler_.toString() + "}::connect(address = " + address + ")"); } if (handler_) { @@ -209,7 +209,7 @@ std::shared_ptr DXEndpoint::connect(const std::string &address) { void DXEndpoint::reconnect() { if constexpr (Debugger::isDebug) { - Debugger::debug("DXEndpoint{{{}}}::reconnect()", handler_.toString()); + Debugger::debug("DXEndpoint{" + handler_.toString() + "}::reconnect()"); } if (!handler_) { @@ -223,7 +223,7 @@ void DXEndpoint::reconnect() { void DXEndpoint::disconnect() { if constexpr (Debugger::isDebug) { - Debugger::debug("DXEndpoint{{{}}}::disconnect()", handler_.toString()); + Debugger::debug("DXEndpoint{" + handler_.toString() + "}::disconnect()"); } if (!handler_) { @@ -237,7 +237,7 @@ void DXEndpoint::disconnect() { void DXEndpoint::disconnectAndClear() { if constexpr (Debugger::isDebug) { - Debugger::debug("DXEndpoint{{{}}}::disconnectAndClear()", handler_.toString()); + Debugger::debug("DXEndpoint{" + handler_.toString() + "}::disconnectAndClear()"); } if (!handler_) { @@ -251,7 +251,7 @@ void DXEndpoint::disconnectAndClear() { void DXEndpoint::awaitNotConnected() { if constexpr (Debugger::isDebug) { - Debugger::debug("DXEndpoint{{{}}}::awaitNotConnected()", handler_.toString()); + Debugger::debug("DXEndpoint{" + handler_.toString() + "}::awaitNotConnected()"); } if (!handler_) { @@ -265,7 +265,7 @@ void DXEndpoint::awaitNotConnected() { void DXEndpoint::awaitProcessed() { if constexpr (Debugger::isDebug) { - Debugger::debug("DXEndpoint{{{}}}::awaitProcessed()", handler_.toString()); + Debugger::debug("DXEndpoint{" + handler_.toString() + "}::awaitProcessed()"); } if (!handler_) { @@ -279,7 +279,7 @@ void DXEndpoint::awaitProcessed() { void DXEndpoint::closeAndAwaitTermination() { if constexpr (Debugger::isDebug) { - Debugger::debug("DXEndpoint{{{}}}::closeAndAwaitTermination()", handler_.toString()); + Debugger::debug("DXEndpoint{" + handler_.toString() + "}::closeAndAwaitTermination()"); } if (!handler_) { @@ -297,7 +297,7 @@ void DXEndpoint::closeAndAwaitTermination() { std::shared_ptr DXEndpoint::getFeed() { if constexpr (Debugger::isDebug) { - Debugger::debug("DXEndpoint{{{}}}::getFeed()", handler_.toString()); + Debugger::debug("DXEndpoint{" + handler_.toString() + "}::getFeed()"); } if (!feed_) { @@ -377,7 +377,8 @@ void DXEndpoint::Builder::loadDefaultPropertiesImpl() { std::shared_ptr DXEndpoint::Builder::withRole(DXEndpoint::Role role) { if constexpr (Debugger::isDebug) { - Debugger::debug("DXEndpoint::Builder{{{}}}::withRole(role = {})", handler_.toString(), roleToString(role)); + Debugger::debug("DXEndpoint::Builder{" + handler_.toString() + "}::withRole(role = " + roleToString(role) + + ")"); } role_ = role; @@ -397,7 +398,8 @@ std::shared_ptr DXEndpoint::Builder::withProperty(const std const std::string &value) { // TODO: check invalid utf-8 if constexpr (Debugger::isDebug) { - Debugger::debug("DXEndpoint::Builder{{{}}}::withProperty(key = {}, value = {})", handler_.toString(), key, value); + Debugger::debug("DXEndpoint::Builder{" + handler_.toString() + "}::withProperty(key = " + key + + ", value = " + value + ")"); } properties_[key] = value; @@ -417,7 +419,7 @@ std::shared_ptr DXEndpoint::Builder::withProperty(const std bool DXEndpoint::Builder::supportsProperty(const std::string &key) { // TODO: check invalid utf-8 if constexpr (Debugger::isDebug) { - Debugger::debug("DXEndpoint::Builder{{{}}}::supportsProperty(key = {})", handler_.toString(), key); + Debugger::debug("DXEndpoint::Builder{" + handler_.toString() + "}::supportsProperty(key = " + key + ")"); } if (!handler_) { @@ -433,7 +435,7 @@ bool DXEndpoint::Builder::supportsProperty(const std::string &key) { std::shared_ptr DXEndpoint::Builder::build() { if constexpr (Debugger::isDebug) { - Debugger::debug("DXEndpoint::Builder{{{}}}::build()", handler_.toString()); + Debugger::debug("DXEndpoint::Builder{" + handler_.toString() + "}::build()"); } loadDefaultPropertiesImpl(); diff --git a/src/api/DXFeed.cpp b/src/api/DXFeed.cpp index a5a28a73..965cecdc 100644 --- a/src/api/DXFeed.cpp +++ b/src/api/DXFeed.cpp @@ -6,8 +6,8 @@ #include #include -#include #include +#include #include #include @@ -26,7 +26,7 @@ std::shared_ptr DXFeed::getInstance() noexcept { void DXFeed::attachSubscription(std::shared_ptr subscription) noexcept { if constexpr (Debugger::isDebug) { - Debugger::debug("{}::attachSubscription({})", toString(), subscription->toString()); + Debugger::debug(toString() + "::attachSubscription(" + subscription->toString() + ")"); } if (!handler_ || !subscription || !subscription->handler_) { @@ -46,7 +46,7 @@ void DXFeed::attachSubscription(std::shared_ptr subscription void DXFeed::detachSubscription(std::shared_ptr subscription) noexcept { if constexpr (Debugger::isDebug) { - Debugger::debug("{}::detachSubscription({})", toString(), subscription->toString()); + Debugger::debug(toString() + "::detachSubscription(" + subscription->toString() + ")"); } if (!handler_ || !subscription || !subscription->handler_) { @@ -66,7 +66,7 @@ void DXFeed::detachSubscription(std::shared_ptr subscription void DXFeed::detachSubscriptionAndClear(std::shared_ptr subscription) noexcept { if constexpr (Debugger::isDebug) { - Debugger::debug("{}::detachSubscriptionAndClear({})", toString(), subscription->toString()); + Debugger::debug(toString() + "::detachSubscriptionAndClear(" + subscription->toString() + ")"); } if (!handler_ || !subscription || !subscription->handler_) { @@ -86,7 +86,7 @@ void DXFeed::detachSubscriptionAndClear(std::shared_ptr subs std::shared_ptr DXFeed::createSubscription(const EventTypeEnum &eventType) noexcept { if constexpr (Debugger::isDebug) { - Debugger::debug("{}::createSubscription(eventType = {})", toString(), eventType.getName()); + Debugger::debug(toString() + "::createSubscription(eventType = " + eventType.getName() + ")"); } auto sub = DXFeedSubscription::create(eventType); @@ -99,8 +99,8 @@ std::shared_ptr DXFeed::createSubscription(const EventTypeEn std::shared_ptr DXFeed::createSubscription(std::initializer_list eventTypes) noexcept { if constexpr (Debugger::isDebug) { - Debugger::debug("{}::createSubscription(eventTypes = {})", toString(), - namesToString(eventTypes.begin(), eventTypes.end())); + Debugger::debug(toString() + "::createSubscription(eventTypes = " + + namesToString(eventTypes.begin(), eventTypes.end()) + ")"); } auto sub = DXFeedSubscription::create(eventTypes); @@ -112,7 +112,7 @@ DXFeed::createSubscription(std::initializer_list eventTypes) noex std::shared_ptr DXFeed::create(void *feedHandle) noexcept { if constexpr (Debugger::isDebug) { - Debugger::debug("DXFeed::create({})", feedHandle); + Debugger::debug("DXFeed::create(" + dxfcpp::toString(feedHandle) + ")"); } std::shared_ptr feed{new (std::nothrow) DXFeed{}}; @@ -124,4 +124,4 @@ std::shared_ptr DXFeed::create(void *feedHandle) noexcept { std::string DXFeed::toString() const noexcept { return fmt::format("DXFeed{{{}}}", handler_.toString()); } -} \ No newline at end of file +} // namespace dxfcpp \ No newline at end of file diff --git a/src/api/DXFeedSubscription.cpp b/src/api/DXFeedSubscription.cpp index 908ea629..28671e70 100644 --- a/src/api/DXFeedSubscription.cpp +++ b/src/api/DXFeedSubscription.cpp @@ -17,7 +17,7 @@ namespace dxfcpp { void DXFeedSubscription::attach(std::shared_ptr feed) noexcept { if constexpr (Debugger::isDebug) { - Debugger::debug("{}::attach(feed = {})", toString(), feed->toString()); + Debugger::debug(toString() + "::attach(feed = " + feed->toString() + ")"); } feed->attachSubscription(sharedAs()); @@ -25,7 +25,7 @@ void DXFeedSubscription::attach(std::shared_ptr feed) noexcept { void DXFeedSubscription::detach(std::shared_ptr feed) noexcept { if constexpr (Debugger::isDebug) { - Debugger::debug("{}::detach(feed = {})", toString(), feed->toString()); + Debugger::debug(toString() + "::detach(feed = " + feed->toString() + ")"); } feed->detachSubscription(sharedAs()); @@ -33,7 +33,7 @@ void DXFeedSubscription::detach(std::shared_ptr feed) noexcept { template auto symbolDataRetriever(Symbol &&s) { if constexpr (Debugger::isDebug) { - Debugger::debug("{}", typeid(decltype(s)).name()); + Debugger::debug(typeid(decltype(s)).name()); } } @@ -92,7 +92,7 @@ bool DXFeedSubscription::isClosedImpl() noexcept { DXFeedSubscription::DXFeedSubscription(const EventTypeEnum &eventType) noexcept : mtx_{}, handler_{}, eventListenerHandler_{}, onEvent_{} { if constexpr (Debugger::isDebug) { - Debugger::debug("DXFeedSubscription(eventType = {})", eventType.getName()); + Debugger::debug("DXFeedSubscription(eventType = " + eventType.getName() + ")"); } handler_ = handler_utils::JavaObjectHandler(runIsolatedOrElse( diff --git a/src/internal/Common.cpp b/src/internal/Common.cpp index 1751e6a7..2de7e4d0 100644 --- a/src/internal/Common.cpp +++ b/src/internal/Common.cpp @@ -46,8 +46,7 @@ template struct RawGraalListTraits { template struct RawListWrapper { #if DXFCPP_DEBUG == 1 static auto getDebugName() { - return fmt::format("RawListWrapper<{}, {}>", typeid(List).name(), - typeid(ElementSetter).name()); + return fmt::format("RawListWrapper<{}, {}>", typeid(List).name(), typeid(ElementSetter).name()); } #endif @@ -55,18 +54,19 @@ template struct RawListWrapper { RawListWrapper() noexcept : list_{0, nullptr} { if constexpr (Debugger::traceLists) { - Debugger::trace("{}::()", getDebugName()); + Debugger::trace(getDebugName() + "::()"); } } void set(std::size_t index, auto value) const noexcept { if constexpr (Debugger::traceLists) { - Debugger::trace("{}::set({}, {})", getDebugName(), index, value); + Debugger::trace(getDebugName() + "::set(" + std::to_string(index) + ", " + std::to_string(value) + ")"); } if (list_.size == 0) { if constexpr (Debugger::traceLists) { - Debugger::trace("{}::set({}, {}): list_.size == 0 ", getDebugName(), index, value); + Debugger::trace(getDebugName() + "::set(" + std::to_string(index) + ", " + std::to_string(value) + + "): list_.size == 0"); } return; @@ -74,7 +74,8 @@ template struct RawListWrapper { if (index < list_.size) { if constexpr (Debugger::traceLists) { - Debugger::trace("{}::set({}, {}): index < list_.size ", getDebugName(), index, value); + Debugger::trace(getDebugName() + "::set(" + std::to_string(index) + ", " + std::to_string(value) + + "): index < list_.size"); } ElementSetter(list_, index, value); @@ -83,7 +84,7 @@ template struct RawListWrapper { [[nodiscard]] bool isEmpty() const noexcept { if constexpr (Debugger::traceLists) { - Debugger::trace("{}::isEmpty() -> ", getDebugName(), (list_.size == 0)); + Debugger::trace(getDebugName() + "::isEmpty() -> " + dxfcpp::toString(list_.size == 0)); } return list_.size == 0; @@ -91,7 +92,7 @@ template struct RawListWrapper { [[nodiscard]] std::size_t size() const noexcept { if constexpr (Debugger::traceLists) { - Debugger::trace("{}::size() -> ", getDebugName(), (static_cast(list_.size))); + Debugger::trace(getDebugName() + "::size() -> " + std::to_string(static_cast(list_.size))); } return static_cast(list_.size); @@ -99,7 +100,7 @@ template struct RawListWrapper { void *getHandler() noexcept { if constexpr (Debugger::traceLists) { - Debugger::trace("{}::getHandler() -> ", getDebugName(), (bit_cast(&list_))); + Debugger::trace(getDebugName() + "::getHandler() -> " + dxfcpp::toString(bit_cast(&list_))); } return bit_cast(&list_); @@ -107,12 +108,12 @@ template struct RawListWrapper { void init(std::size_t size) noexcept { if constexpr (Debugger::traceLists) { - Debugger::trace("{}::init({})", getDebugName(), size); + Debugger::trace(getDebugName() + "::init(" + std::to_string(size) + ")"); } if (size <= 0) { if constexpr (Debugger::traceLists) { - Debugger::trace("{}::init({}): size <= 0", getDebugName()); + Debugger::trace(getDebugName() + "::init(" + std::to_string(size) + "): size <= 0"); } return; @@ -123,7 +124,7 @@ template struct RawListWrapper { if (!list_.elements) { if constexpr (Debugger::traceLists) { - Debugger::trace("{}::init({}): !list_.elements", getDebugName()); + Debugger::trace(getDebugName() + "::init(" + std::to_string(size) + "): !list_.elements"); } release(); @@ -143,7 +144,7 @@ template struct RawListWrapper { if (needToRelease) { if constexpr (Debugger::traceLists) { - Debugger::trace("{}::init({}): needToRelease", getDebugName()); + Debugger::trace(getDebugName() + "::init({}): needToRelease"); } release(); @@ -152,14 +153,12 @@ template struct RawListWrapper { void release() { if constexpr (Debugger::traceLists) { - Debugger::trace("{}::release()", getDebugName()); + Debugger::trace(getDebugName() + "::release()"); } if (list_.size == 0 || list_.elements == nullptr) { if constexpr (Debugger::traceLists) { - Debugger::trace( - "{}::release(): list_.size == 0 || list_.elements == nullptr", - getDebugName()); + Debugger::trace(getDebugName() + "::release(): list_.size == 0 || list_.elements == nullptr"); } return; @@ -176,18 +175,17 @@ template struct RawListWrapper { ~RawListWrapper() noexcept { if constexpr (Debugger::traceLists) { - Debugger::trace("{}::~()", getDebugName()); + Debugger::trace(getDebugName() + "::~()"); } release(); } }; -struct EventClassList::Impl - : public RawListWrapper(id); - }> {}; +struct EventClassList::Impl : public RawListWrapper(id); +}> {}; template struct handler_utils::JavaObjectHandler; template struct handler_utils::JavaObjectHandler; @@ -218,9 +216,7 @@ EventClassList::~EventClassList() noexcept = default; } // namespace handler_utils -std::string toString(bool b) { - return b ? "true" : "false"; -} +std::string toString(bool b) { return b ? "true" : "false"; } std::string toString(const char *chars) { if (chars == nullptr) { @@ -238,7 +234,7 @@ std::string toString(std::thread::id threadId) { return result.str(); } -std::string toString(void* ptr) { +std::string toString(void *ptr) { std::ostringstream result{}; result << ptr; diff --git a/src/internal/utils/debug/Debug.cpp b/src/internal/utils/debug/Debug.cpp index 9e280ffe..6b900856 100644 --- a/src/internal/utils/debug/Debug.cpp +++ b/src/internal/utils/debug/Debug.cpp @@ -16,22 +16,22 @@ namespace dxfcpp { #if DXFCPP_DEBUG == 0 #else -template static std::string vformat(std::string_view format, Args &&...args) { +template std::string vformat(std::string_view format, Args &&...args) { return fmt::vformat(format, fmt::make_format_args(args...)); } -template void static vprint(std::ostream &os, std::string_view format, Args &&...args) { +template void vprint(std::ostream &os, std::string_view format, Args &&...args) { fmt::vprint(os, format, fmt::make_format_args(args...)); } -static inline std::string nowStr() { +std::string Debugger::nowStr() { auto now = std::chrono::system_clock::now(); auto ms = std::chrono::duration_cast(now.time_since_epoch()).count() % 1000; return fmt::format("{:%y%m%d %H%M%S}.{:0>3}", std::chrono::floor(now), ms); } -static inline std::string nowStrWithTimeZone() { +std::string Debugger::nowStrWithTimeZone() { auto now = std::chrono::system_clock::now(); auto ms = std::chrono::duration_cast(now.time_since_epoch()).count() % 1000; @@ -39,21 +39,21 @@ static inline std::string nowStrWithTimeZone() { std::chrono::floor(now)); } -static inline std::string debugPrefixStr() { +std::string Debugger::debugPrefixStr() { return fmt::format("D {} [{}]", nowStr(), toString(std::this_thread::get_id())); } -static inline std::string tracePrefixStr() { - return fmt::format("T {} [{}]", nowStr(), toString(std::this_thread::get_id())); -} + void Debugger::debug(std::string str) { + vprint(std::cerr, "{} {}\n", debugPrefixStr(), std::move(str)); + } -template void Debugger::debug(std::string_view format, Args &&...args) { - vprint(std::cerr, "{} {}\n", debugPrefixStr(), vformat(format, std::forward(args)...)); +# if DXFCPP_TRACE == 1 +std::string Debugger::tracePrefixStr() { + return fmt::format("T {} [{}]", nowStr(), toString(std::this_thread::get_id())); } -# if DXFCPP_TRACE == 1 -template void Debugger::trace(std::string_view format, Args &&...args) { - vprint(std::cerr, "{} ~~ {}\n", tracePrefixStr(), vformat(format, std::forward(args)...)); +void Debugger::trace(std::string str) { + vprint(std::cerr, "{} ~~ {}\n", tracePrefixStr(), std::move(str)); } # else inline void Debugger::trace(...) {} @@ -62,42 +62,3 @@ inline void Debugger::trace(...) {} #endif } // namespace dxfcpp - -#if DXFCPP_DEBUG == 0 -#else -template void dxfcpp::Debugger::debug(std::string_view); -template void dxfcpp::Debugger::debug(std::string_view, std::string &&); -template void dxfcpp::Debugger::debug(std::string_view, const std::string &); -template void dxfcpp::Debugger::debug(std::string_view, const char *&&); -template void dxfcpp::Debugger::debug(std::string_view, std::string &&, const std::string &); -template void dxfcpp::Debugger::debug(std::string_view, std::string &&, std::string &&); -template void dxfcpp::Debugger::debug(std::string_view, const std::string &, const std::string &); -template void dxfcpp::Debugger::debug(std::string_view, const std::string &, std::string &); -template void dxfcpp::Debugger::debug(std::string_view, std::string &&, char const (&)[1]); -template void dxfcpp::Debugger::debug(std::string_view, std::string &&, char const (&)[2]); -template void dxfcpp::Debugger::debug(std::string_view, std::string &&, char const (&)[3]); -template void dxfcpp::Debugger::debug(std::string_view, std::string &&, char const (&)[4]); -template void dxfcpp::Debugger::debug(std::string_view, std::string &&, char const (&)[5]); -template void dxfcpp::Debugger::debug(std::string_view, std::string &&, std::string_view &); -template void dxfcpp::Debugger::debug(std::string_view, std::string &&, std::string &); -template void dxfcpp::Debugger::debug(std::string_view, std::string &&, std::size_t &&); -template void dxfcpp::Debugger::debug(std::string_view, void *&); -template void dxfcpp::Debugger::debug(std::string_view, void *&, char const *&&, std::size_t &&); -template void dxfcpp::Debugger::debug(std::string_view, std::string &&, char const *&&); -template void dxfcpp::Debugger::debug(std::string_view, std::string &&, std::string const &, std::string const &); -template void dxfcpp::Debugger::debug(std::string_view, std::string const &, std::string const &, bool &); - -# if DXFCPP_TRACE == 1 -template void dxfcpp::Debugger::trace(std::string_view); -template void dxfcpp::Debugger::trace(std::string_view, std::string &&); -template void dxfcpp::Debugger::trace(std::string_view, const std::string &); -template void dxfcpp::Debugger::trace(std::string_view, const char *&&); -template void dxfcpp::Debugger::trace(std::string_view, std::string &&, const std::string &); -template void dxfcpp::Debugger::trace(std::string_view, std::string &&, std::string &&); -template void dxfcpp::Debugger::trace(std::string_view, std::string &&, std::size_t &); -template void dxfcpp::Debugger::trace(std::string_view, std::string &&, void *&&); -template void dxfcpp::Debugger::trace(std::string_view, std::string &&, std::size_t &&); -template void dxfcpp::Debugger::trace(std::string_view, std::string &&, bool &&); -template void dxfcpp::Debugger::trace(std::string_view, std::string &&, std::size_t &, unsigned int &); -# endif -#endif \ No newline at end of file diff --git a/src/system/System.cpp b/src/system/System.cpp index ae06030d..73f2d5a1 100644 --- a/src/system/System.cpp +++ b/src/system/System.cpp @@ -16,9 +16,9 @@ namespace dxfcpp { bool System::setProperty(const std::string &key, const std::string &value) { - //TODO: check invalid utf-8 + // TODO: check invalid utf-8 if constexpr (Debugger::isDebug) { - Debugger::debug("System::setProperty(key = '{}', value = '{}')", key, value); + Debugger::debug("System::setProperty(key = '" + key + "', value = '" + value + "')"); } auto result = runIsolatedOrElse( @@ -29,16 +29,16 @@ bool System::setProperty(const std::string &key, const std::string &value) { false); if constexpr (Debugger::isDebug) { - Debugger::debug("System::setProperty(key = '{}', value = '{}') -> {}", key, value, result); + Debugger::debug("System::setProperty(key = '" + key + "', value = '" + value + "') -> " + toString(result)); } return result; } std::string System::getProperty(const std::string &key) { - //TODO: check invalid utf-8 + // TODO: check invalid utf-8 if constexpr (Debugger::isDebug) { - Debugger::debug("System::getProperty(key = {})", key); + Debugger::debug("System::getProperty(key = " + key + ")"); } auto result = runIsolatedOrElse( @@ -55,7 +55,7 @@ std::string System::getProperty(const std::string &key) { std::string{}); if constexpr (Debugger::isDebug) { - Debugger::debug("System::getProperty(key = '{}') -> '{}'", key, result); + Debugger::debug("System::getProperty(key = '" + key + "') -> '" + result + "'"); } return result; @@ -64,7 +64,7 @@ std::string System::getProperty(const std::string &key) { } // namespace dxfcpp dxfc_error_code_t dxfc_system_set_property(const char *key, const char *value) { - //TODO: check invalid utf-8 + // TODO: check invalid utf-8 return dxfcpp::System::setProperty(key, value) ? DXFC_EC_SUCCESS : DXFC_EC_ERROR; } diff --git a/tests/api/DXEndpointTest.cpp b/tests/api/DXEndpointTest.cpp index 5829fe48..0ea1c241 100644 --- a/tests/api/DXEndpointTest.cpp +++ b/tests/api/DXEndpointTest.cpp @@ -76,7 +76,7 @@ TEST_CASE("dxfc_dxendpoint_builder_t bug") { // // result = dxfc_dxendpoint_add_state_change_listener( // endpoint, [](dxfc_dxendpoint_state_t oldState, dxfc_dxendpoint_state_t newState, void *) { -// dxfcpp::debug("dxfc_dxendpoint_builder_t Test: {}", std::string("State changed: ") + +// Debugger::debug("dxfc_dxendpoint_builder_t Test: {}", std::string("State changed: ") + // cApiStateToString(oldState) + " -> " + // cApiStateToString(newState)); // });