refactor: Change refs/raw ptrs to smart ptrs in md gateway

This commit is contained in:
John Colvin committed 2024-10-21 14:31:48 +00:00
1 parent 1f4fcdaabd
commit 7afb4bbcc1
4 files changed
+30 -26

No files matched your search

@@ -47,13 +47,15 @@ static bool validate(const MarketDataConfig &cfg, vector<string> &errs) {
struct MarketDataGateway::PImpl {
struct MdSink {
GeneralSecurityIndex sec_index;
MDProducer md_producer;
shared_ptr<GeneralSecurityIndex> sec_index;
shared_ptr<MDProducer> md_producer;
shared_ptr<IMarketDataListener> listener;
MdSink(api::Venue venue, IDGenerator *sec_id_store)
: sec_index(), listener(std::make_shared<GeneralMarketDataListener>(
sec_index, md_producer, venue, sec_id_store)) {}
: sec_index(std::make_shared<GeneralSecurityIndex>()),
md_producer(std::make_shared<MDProducer>()),
listener(std::make_shared<GeneralMarketDataListener>(
sec_index, md_producer, venue, sec_id_store)) {}
};
MarketDataConfig config;
@@ -40,13 +40,14 @@ static bool validate(
struct CCApiMarketDataProvider::PImpl {
struct VenueSink {
GeneralSecurityIndex sec_index;
MDProducer md_producer;
GeneralMarketDataListener listener;
std::shared_ptr<GeneralSecurityIndex> sec_index;
std::shared_ptr<MDProducer> md_producer;
std::shared_ptr<GeneralMarketDataListener> listener;
VenueSink(api::Venue venue, shared_ptr<IDGenerator> sec_id_store)
: sec_index(),
listener(sec_index, md_producer, venue, sec_id_store.get()) {}
: sec_index(), md_producer(std::make_shared<MDProducer>()),
listener(std::make_shared<GeneralMarketDataListener>(
sec_index, md_producer, venue, sec_id_store.get())) {}
};
MarketDataConfig config;
@@ -173,12 +173,12 @@ struct GeneralMarketDataListener::PImpl {
// if this is set to true, then the security key passed on in the
// on_securities function is used. If this is not set to true, then a new key
// is generated
const bool use_given_sec_key = true;
const bool use_given_sec_key = false;
const std::string cc_name_prefix = "cc_security";
size_t n_bk_updates = 0;
bts::persistence::IDGenerator *id_gen;
GeneralSecurityIndex &index;
MDProducer &md_producer;
std::shared_ptr<GeneralSecurityIndex> index;
std::shared_ptr<MDProducer> md_producer;
const std::shared_ptr<bts::orderman::SimExecutionGateway> sim_ex_gwy =
nullptr;
// map of logical key (venue + exchange key) to id
@@ -191,14 +191,15 @@ struct GeneralMarketDataListener::PImpl {
MDArray asks = {};
IncrementalBookData inc_book_data = {};
explicit PImpl(
GeneralSecurityIndex &index,
MDProducer &md_producer,
std::shared_ptr<GeneralSecurityIndex> index,
std::shared_ptr<MDProducer> md_producer,
std::shared_ptr<bts::orderman::SimExecutionGateway> sim_ex_gwy,
persistence::IDGenerator *sec_id_store)
: id_gen(sec_id_store), index(index), md_producer(md_producer),
sim_ex_gwy(sim_ex_gwy) {
if (sim_ex_gwy != nullptr) {
sim_ex_gwy->set_producers(&index);
: id_gen(sec_id_store), index(std::move(index)),
md_producer(std::move(md_producer)),
sim_ex_gwy(std::move(sim_ex_gwy)) {
if (this->sim_ex_gwy != nullptr) {
this->sim_ex_gwy->set_producers(this->index.get());
}
}
};
@@ -247,8 +248,8 @@ void copy_books(
// interface functions ////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
GeneralMarketDataListener::GeneralMarketDataListener(
GeneralSecurityIndex &index,
MDProducer &md_producer,
std::shared_ptr<GeneralSecurityIndex> index,
std::shared_ptr<MDProducer> md_producer,
api::Venue venue,
persistence::IDGenerator *sec_id_store)
: me(std::make_unique<PImpl>(
@@ -419,7 +420,7 @@ SecurityIndexData *GeneralMarketDataListener::_find_handle(
auto it = me->cc_sec_id_map.find(cc_id);
if (it != me->cc_sec_id_map.end()) {
auto id = it->second;
return me->index.get_security(id);
return me->index->get_security(id);
}
return nullptr;
}
@@ -513,15 +514,15 @@ void GeneralMarketDataListener::_add_spot(const bts::domain::Security &sec) {
void GeneralMarketDataListener::_commit_security(const FixedSecurity &sec) {
// Set up the shared memory for this security
bts_assert(sec.numeric_id != 0);
auto handle = me->md_producer.add_security(sec);
auto handle = me->md_producer->add_security(sec);
// Add it to the index so it can receive messages
auto kp = me->index.add_security(sec.numeric_id, handle);
auto kp = me->index->add_security(sec.numeric_id, handle);
LOG(md, Info,
"GeneralMarketDataListener::_add_security_to_shm added sec: {} id: "
"{} "
"num_id: {} n_secs: {}",
std::string(handle.security().security_desc()), kp->id,
handle.security().numeric_id, me->index.n_secs());
handle.security().numeric_id, me->index->n_secs());
}
void GeneralMarketDataListener::_copy_security_common(
@@ -17,8 +17,8 @@ namespace bts::md {
class GeneralMarketDataListener : public IMarketDataListener {
public:
GeneralMarketDataListener(
GeneralSecurityIndex &index,
MDProducer &md_producer,
std::shared_ptr<GeneralSecurityIndex> index,
std::shared_ptr<MDProducer> md_producer,
api::Venue venue,
persistence::IDGenerator *sec_id_store);
virtual ~GeneralMarketDataListener();