SPARK 1731 - Simplify SecurityOracle impl
This commit is contained in:
1 parent
791b0fdbc1
commit
bf72122edc
5 files changed
+21
-37
No files matched your search
+10
-7
@@ -1,6 +1,7 @@
|
||||
#include "MDClient.h"
|
||||
#include "get_symbols.h"
|
||||
#include "SecurityCache.h"
|
||||
#include "SecurityOracle.h"
|
||||
#include <set>
|
||||
|
||||
namespace bts {
|
||||
@@ -14,14 +15,16 @@ struct MDClientImpl{
|
||||
utils::DispatcherTimer _recovery_timer;
|
||||
MDConsumer _consumer;
|
||||
utils::Event<MDConsumer> _event;
|
||||
SecurityOracle _oracle;
|
||||
|
||||
MDClientImpl(utils::Dispatcher& d, std::shared_ptr<api::ISyntheticSecurityService> s):
|
||||
MDClientImpl(utils::Dispatcher& d, std::shared_ptr<api::ISyntheticSecurityService> s, SecurityOracle o):
|
||||
_dispatcher(d),
|
||||
_ss(s),
|
||||
_security_timer(d, config::get<RelayOptions>().security_scan_interval(),[this]() { scan_securities(); }),
|
||||
_recovery_timer(d, config::get<RelayOptions>().recovery_interval(), [this]() { check_heartbeats(); }),
|
||||
_consumer(s, _cache),
|
||||
_event()
|
||||
_event(),
|
||||
_oracle(o)
|
||||
{
|
||||
_security_timer.start();
|
||||
_recovery_timer.start();
|
||||
@@ -57,8 +60,8 @@ struct MDClientImpl{
|
||||
};
|
||||
|
||||
|
||||
MDClient::MDClient(utils::Dispatcher& d, std::shared_ptr<api::ISyntheticSecurityService> s) : _self(new MDClientImpl(d,s)) {
|
||||
|
||||
MDClient::MDClient(utils::Dispatcher& d, std::shared_ptr<api::ISyntheticSecurityService> s) :
|
||||
_self(new MDClientImpl(d,s, SecurityOracle(*this))) {
|
||||
}
|
||||
MDClient::~MDClient() {
|
||||
}
|
||||
@@ -66,11 +69,11 @@ MDClient::~MDClient() {
|
||||
utils::EventSubscriber<MDConsumer>& MDClient::on_consumer() {
|
||||
return _self->_event;
|
||||
}
|
||||
MDConsumer MDClient::current_consumer() const {
|
||||
MDConsumer& MDClient::current_consumer() const {
|
||||
return _self->_consumer;
|
||||
}
|
||||
SecurityOracle MDClient::oracle() {
|
||||
return SecurityOracle(*this);
|
||||
SecurityOracle& MDClient::oracle() const {
|
||||
return _self->_oracle;
|
||||
}
|
||||
|
||||
}}//namespace
|
||||
@@ -3,12 +3,12 @@
|
||||
#include "lib/utils/Dispatcher.h"
|
||||
#include "lib/utils/Event.h"
|
||||
#include "ISyntheticSecurityService.h"
|
||||
#include "SecurityOracle.h"
|
||||
#include <memory>
|
||||
|
||||
namespace bts {
|
||||
namespace md {
|
||||
|
||||
class SecurityOracle;
|
||||
struct MDClientImpl;
|
||||
class MDClient {
|
||||
std::unique_ptr<MDClientImpl> _self;
|
||||
@@ -18,8 +18,8 @@ public:
|
||||
~MDClient();
|
||||
|
||||
utils::EventSubscriber<MDConsumer>& on_consumer();
|
||||
MDConsumer current_consumer() const;
|
||||
SecurityOracle oracle();
|
||||
MDConsumer& current_consumer() const;
|
||||
SecurityOracle& oracle() const;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "common.h"
|
||||
#include "UserSymbol.h"
|
||||
#include "MDConsumer.h"
|
||||
#include "SecurityCache.h"
|
||||
#include "get_symbols.h"
|
||||
#include "relay/RelayClient.h"
|
||||
#include "lib/utils/Dispatcher.h"
|
||||
@@ -27,15 +28,16 @@ struct BlitUserSymbol {
|
||||
|
||||
CAPI MDConsumer* create_md_consumer(BlitUserSymbol* usersymbols, uint32_t count, bool shared) {
|
||||
std::shared_ptr<api::ISyntheticSecurityService> pnull = nullptr;
|
||||
SecurityCache cache;
|
||||
if (usersymbols == nullptr || count == 0) {
|
||||
return new MDConsumer(pnull, shared);
|
||||
return new MDConsumer(pnull, cache, shared);
|
||||
}
|
||||
else {
|
||||
std::set<UserSymbol> symbols;
|
||||
for (size_t x = 0; x < count; ++x) {
|
||||
symbols.insert(UserSymbol(usersymbols[x].symbol, usersymbols[x].exchange, usersymbols[x].type));
|
||||
}
|
||||
return new MDConsumer(symbols, pnull, shared);
|
||||
return new MDConsumer(symbols, pnull, cache, shared);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,28 +4,10 @@
|
||||
namespace bts {
|
||||
namespace md {
|
||||
|
||||
struct SecurityOracleImpl {
|
||||
SecurityOracleImpl(MDClient& client):
|
||||
client(client),
|
||||
consumer(client.current_consumer())
|
||||
{
|
||||
sub = client.on_consumer().subscribe([this](const MDConsumer& c) {
|
||||
consumer = c;
|
||||
});
|
||||
}
|
||||
~SecurityOracleImpl() {
|
||||
client.on_consumer().unsubscribe(sub);
|
||||
}
|
||||
MDClient& client;
|
||||
MDConsumer consumer;
|
||||
int sub;
|
||||
|
||||
};
|
||||
|
||||
SecurityOracle::SecurityOracle(MDClient& client): _self(new SecurityOracleImpl(client)) { }
|
||||
SecurityOracle::SecurityOracle(const MDClient& client): _client(client) {}
|
||||
SecurityOracle::~SecurityOracle() { }
|
||||
const api::Security* SecurityOracle::get_security(SecurityKey key) const {
|
||||
return _self->consumer.get_security(key);
|
||||
return _client.current_consumer().get_security(key);
|
||||
}
|
||||
|
||||
}}//namespace
|
||||
@@ -4,14 +4,11 @@
|
||||
|
||||
namespace bts {
|
||||
namespace md {
|
||||
|
||||
class MDClient;
|
||||
|
||||
struct SecurityOracleImpl;
|
||||
class SecurityOracle {
|
||||
std::unique_ptr<SecurityOracleImpl> _self;
|
||||
const MDClient& _client;
|
||||
public:
|
||||
SecurityOracle(MDClient&);
|
||||
SecurityOracle(const MDClient&);
|
||||
~SecurityOracle();
|
||||
const api::Security* get_security(SecurityKey key) const;
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user