Skip to content

Commit

Permalink
InstrumentProfileCollector
Browse files Browse the repository at this point in the history
  • Loading branch information
ttldtor committed Oct 13, 2023
1 parent 866e252 commit 22f5e10
Show file tree
Hide file tree
Showing 12 changed files with 141 additions and 13 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ set(dxFeedGraalCxxApi_Ipf_Sources
src/ipf/InstrumentProfile.cpp
src/ipf/InstrumentProfileField.cpp
src/ipf/InstrumentProfileReader.cpp
src/ipf/live/InstrumentProfileCollector.cpp
)

set(dxFeedGraalCxxApi_Symbols_Sources
Expand Down
6 changes: 6 additions & 0 deletions include/dxfeed_graal_cpp_api/api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,16 @@
#include "internal/SymbolList.hpp"
#include "internal/Timer.hpp"
#include "internal/context/ApiContext.hpp"

#include "internal/managers/DXEndpointManager.hpp"
#include "internal/managers/DXFeedManager.hpp"
#include "internal/managers/DXFeedSubscriptionManager.hpp"
#include "internal/managers/DXPublisherManager.hpp"
#include "internal/managers/InstrumentProfileReaderManager.hpp"
#include "internal/managers/InstrumentProfileCollectorManager.hpp"
#include "internal/managers/EntityManager.hpp"
#include "internal/managers/ErrorHandlingManager.hpp"

#include "internal/utils/CmdArgsUtils.hpp"
#include "internal/utils/EnumUtils.hpp"
#include "internal/utils/StringUtils.hpp"
Expand Down
7 changes: 5 additions & 2 deletions include/dxfeed_graal_cpp_api/internal/context/ApiContext.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@
#include "../managers/DXFeedManager.hpp"
#include "../managers/DXFeedSubscriptionManager.hpp"
#include "../managers/DXPublisherManager.hpp"
#include "../managers/InstrumentProfileCollectorManager.hpp"
#include "../managers/InstrumentProfileReaderManager.hpp"

namespace dxfcpp {

template <typename Manager> struct AddManagerMixin {
mutable std::shared_ptr<Manager> manager_;

AddManagerMixin() noexcept : manager_{std::make_shared<Manager>()} {}
AddManagerMixin() noexcept : manager_{std::make_shared<Manager>()} {
}

std::shared_ptr<Manager> getManager() const noexcept {
return manager_;
Expand All @@ -29,7 +31,8 @@ class DXFCPP_EXPORT ApiContext : AddManagerMixin<DXEndpointManager>,
AddManagerMixin<DXFeedSubscriptionManager>,
AddManagerMixin<DXFeedManager>,
AddManagerMixin<DXPublisherManager>,
AddManagerMixin<InstrumentProfileReaderManager> {
AddManagerMixin<InstrumentProfileReaderManager>,
AddManagerMixin<InstrumentProfileCollectorManager> {
ApiContext() noexcept = default;

public:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) 2023 Devexperts LLC.
// SPDX-License-Identifier: MPL-2.0

#pragma once

#include "../Conf.hpp"

#include <memory>
#include <unordered_map>
#include <unordered_set>

#include "../Common.hpp"
#include "EntityManager.hpp"

namespace dxfcpp {

class InstrumentProfileCollector;

using InstrumentProfileCollectorManager = EntityManager<InstrumentProfileCollector>;

} // namespace dxfcpp
17 changes: 10 additions & 7 deletions include/dxfeed_graal_cpp_api/ipf/InstrumentProfileReader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
#include "../internal/Conf.hpp"

#include "../internal/Common.hpp"
#include "../internal/Id.hpp"
#include "../internal/JavaObjectHandle.hpp"

#include "../entity/SharedEntity.hpp"

#include "InstrumentProfile.hpp"

Expand Down Expand Up @@ -48,13 +52,12 @@ class DXFCPP_EXPORT InstrumentProfileReader final : public SharedEntity {
/// The alias to a type of unique pointer to the InstrumentProfileReader object
using Unique = std::unique_ptr<InstrumentProfileReader>;

static Ptr create() noexcept {
auto reader = std::shared_ptr<InstrumentProfileReader>(new InstrumentProfileReader());

reader->id_ = ApiContext::getInstance()->getManager<InstrumentProfileReaderManager>()->registerEntity(reader);

return reader;
}
/**
* Creates the new InstrumentProfileReader
*
* @return The new InstrumentProfileReader
*/
static Ptr create() noexcept;

/**
* Returns last modification time (in milliseconds) from last InstrumentProfileReader::readFromFile() operation
Expand Down
4 changes: 3 additions & 1 deletion include/dxfeed_graal_cpp_api/ipf/IpfModule.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@

#include "InstrumentProfileField.hpp"
#include "InstrumentProfile.hpp"
#include "InstrumentProfileReader.hpp"
#include "InstrumentProfileReader.hpp"

#include "live/InstrumentProfileCollector.hpp"
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright (c) 2023 Devexperts LLC.
// SPDX-License-Identifier: MPL-2.0

#pragma once

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

#include "../../internal/Common.hpp"

namespace dxfcpp {

class DXFCPP_EXPORT InstrumentProfileCollector final : public SharedEntity {
Id<InstrumentProfileCollector> id_;
JavaObjectHandle<InstrumentProfileCollector> handle_;

InstrumentProfileCollector() noexcept;

public:

/// The alias to a type of shared pointer to the InstrumentProfileCollector object
using Ptr = std::shared_ptr<InstrumentProfileCollector>;

/// The alias to a type of unique pointer to the InstrumentProfileCollector object
using Unique = std::unique_ptr<InstrumentProfileCollector>;

/**
* Creates the new InstrumentProfileCollector
*
* @return The new InstrumentProfileCollector
*/
static Ptr create() noexcept;
};

}
4 changes: 4 additions & 0 deletions include/dxfeed_graal_cpp_api/isolated/Isolated.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ struct InstrumentProfileReader {
static std::string resolveSourceURL(const std::string & address) noexcept;
};

struct InstrumentProfileCollector {
static /* dxfg_ipf_collector_t* */ void *create() noexcept;
};

struct InstrumentProfileList {
static bool release(/* dxfg_instrument_profile_list * */ void *graalInstrumentProfileList) noexcept;
};
Expand Down
14 changes: 12 additions & 2 deletions src/internal/Isolate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ GraalIsolateThreadHandle Isolate::get() noexcept {

} // namespace dxfcpp

// see isolated/isolated.hpp

namespace dxfcpp::isolated {

namespace api {
Expand Down Expand Up @@ -232,11 +234,11 @@ dxfcpp::DXEndpoint::State DXEndpoint::getState(/* dxfg_endpoint_t* */ void *graa
namespace ipf {

/* dxfg_instrument_profile_reader_t* */ void *InstrumentProfileReader::create() noexcept {
return runIsolatedOrElse(
return dxfcpp::bit_cast<void *>(runIsolatedOrElse(
[](auto threadHandle) {
return dxfg_InstrumentProfileReader_new(dxfcpp::bit_cast<graal_isolatethread_t *>(threadHandle));
},
nullptr);
nullptr));
}

std::int64_t InstrumentProfileReader::getLastModified(
Expand Down Expand Up @@ -309,6 +311,14 @@ std::string InstrumentProfileReader::resolveSourceURL(const std::string &address
nullptr, address));
}

/* dxfg_ipf_collector_t* */ void *InstrumentProfileCollector::create() noexcept {
return dxfcpp::bit_cast<void *>(runIsolatedOrElse(
[](auto threadHandle) {
return dxfg_InstrumentProfileCollector_new(dxfcpp::bit_cast<graal_isolatethread_t *>(threadHandle));
},
nullptr));
}

bool InstrumentProfileList::release(/* dxfg_instrument_profile_list * */ void *graalInstrumentProfileList) noexcept {
if (!graalInstrumentProfileList) {
return false;
Expand Down
5 changes: 4 additions & 1 deletion src/internal/JavaObjectHandle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@ template <typename T> void JavaObjectHandle<T>::deleter(void *handle) noexcept {
}

template struct JavaObjectHandle<DXEndpoint>;
template struct JavaObjectHandle<DXEndpoint::Builder>;
template struct JavaObjectHandle<DXEndpointStateChangeListener>;

template struct JavaObjectHandle<DXFeed>;
template struct JavaObjectHandle<DXPublisher>;
template struct JavaObjectHandle<DXFeedSubscription>;
template struct JavaObjectHandle<DXFeedEventListener>;
template struct JavaObjectHandle<DXEndpoint::Builder>;

template struct JavaObjectHandle<InstrumentProfileReader>;
template struct JavaObjectHandle<InstrumentProfileCollector>;

} // namespace dxfcpp
8 changes: 8 additions & 0 deletions src/ipf/InstrumentProfileReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ InstrumentProfileReader::InstrumentProfileReader() noexcept : id_{Id<InstrumentP
handle_ = JavaObjectHandle<InstrumentProfileReader>(dxfcpp::isolated::ipf::InstrumentProfileReader::create());
}

InstrumentProfileReader::Ptr InstrumentProfileReader::create() noexcept {
auto reader = std::shared_ptr<InstrumentProfileReader>(new InstrumentProfileReader());

reader->id_ = ApiContext::getInstance()->getManager<InstrumentProfileReaderManager>()->registerEntity(reader);

return reader;
}

std::int64_t InstrumentProfileReader::getLastModified() const noexcept {
if (!handle_) {
return 0;
Expand Down
33 changes: 33 additions & 0 deletions src/ipf/live/InstrumentProfileCollector.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (c) 2023 Devexperts LLC.
// SPDX-License-Identifier: MPL-2.0

#include <dxfg_api.h>

#include <dxfeed_graal_c_api/api.h>
#include <dxfeed_graal_cpp_api/api.hpp>

#include <cstring>
#include <memory>
#include <utf8.h>
#include <utility>

#include <fmt/chrono.h>
#include <fmt/format.h>
#include <fmt/ostream.h>
#include <fmt/std.h>

namespace dxfcpp {

InstrumentProfileCollector::InstrumentProfileCollector() noexcept : id_{Id<InstrumentProfileCollector>::UNKNOWN}, handle_{} {
handle_ = JavaObjectHandle<InstrumentProfileCollector>(dxfcpp::isolated::ipf::InstrumentProfileCollector::create());
}

InstrumentProfileCollector::Ptr InstrumentProfileCollector::create() noexcept {
auto collector = std::shared_ptr<InstrumentProfileCollector>(new InstrumentProfileCollector());

collector->id_ = ApiContext::getInstance()->getManager<InstrumentProfileCollectorManager>()->registerEntity(collector);

return collector;
}

}

0 comments on commit 22f5e10

Please sign in to comment.