#include "SimExecutionGatewayFactory.h" #include "SimExecutionGateway.h" #include "lib/domain_model/Security.pb.h" #include "lib/logging/logging.h" #include "lib/md/common.h" #include "lib/utils/LockBox.h" #include "lib/utils/bts_assert.h" #include #include #include namespace bts::orderman { SimExecutionGatewayFactory *SimExecutionGatewayFactory::instance = nullptr; std::once_flag SimExecutionGatewayFactory::flag; SimExecutionGatewayFactory::SimExecutionGatewayFactory() : gateway_map() { LOG(OrderMan, Info, "SimExecutionGatewayFactory::SimExecutionGatewayFactory"); } std::shared_ptr SimExecutionGatewayFactory::get_getayeway( api::Venue venue) { LOG(OrderMan, Info, "SimExecutionGatewayFactory::get_getayeway venue: {}", bts::api::Venue_Name(venue)); if (!is_sim_execution_on(venue)) { LOG(OrderMan, Info, "SimExecutionGatewayFactory::get_getayeway venue: {}, sim is turned " "off", bts::api::Venue_Name(venue)); return nullptr; } std::shared_ptr rv = nullptr; gateway_map.lock( [&, venue](std::map> &data) { auto it = data.find(venue); if (it == data.end()) { data.insert({venue, std::make_shared(venue)}); it = data.find(venue); } rv = it->second; }); bts_assert(rv != nullptr); return rv; } SimExecutionGatewayFactory::~SimExecutionGatewayFactory() {} // singleton getter /////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// SimExecutionGatewayFactory *SimExecutionGatewayFactory::get() { std::call_once(flag, [&]() { LOG(OrderMan, Info, "SimExecutionGatewayFactory::init_once, initializing instance"); instance = new SimExecutionGatewayFactory(); }); bts_assert(instance != nullptr); return instance; } bool SimExecutionGatewayFactory::is_sim_execution_on(api::Venue venue) { // TODO: Arham, fix this ! return true; const auto &sim_exec = config::get(); for (const auto &e : sim_exec.entries()) { if (e.venue() == venue) { return true; } } return false; } } // namespace bts::orderman