57 lines
1.3 KiB
C++
57 lines
1.3 KiB
C++
#pragma once
|
|
#ifndef WIN32
|
|
#include "common.h"
|
|
#include "MDProducerHandle.h"
|
|
|
|
#include <functional>
|
|
#include <memory>
|
|
#include <atomic>
|
|
#include <vector>
|
|
#include <tbb/concurrent_queue.h>
|
|
|
|
namespace bts {
|
|
namespace md {
|
|
|
|
/*
|
|
* Manages security to unique 32 bit id mapping across multiple processes
|
|
* Provides a callback when ids are safely persisted.
|
|
*/
|
|
|
|
struct SecurityIDRecorderState;
|
|
class SecurityIDRecorder
|
|
{
|
|
public:
|
|
SecurityIDRecorder();
|
|
// Automatically call do_work on this dispatcher
|
|
SecurityIDRecorder(utils::Dispatcher&);
|
|
~SecurityIDRecorder();
|
|
typedef std::function<void(const api::Security&)> Callback;
|
|
|
|
// Fast - for use by market data producers
|
|
void ensure_key(MDProducerHandle handle);
|
|
// Slow (copies security) - for use by services
|
|
void assign_key(const api::Security& security, const Callback& key_assigned);
|
|
|
|
// Someone must call work periodically to do lookups and flush the reserved ids to disk.
|
|
void do_work();
|
|
|
|
void bulk_insert(const std::vector<const api::Security*>&, const char* prefix);
|
|
|
|
private:
|
|
std::shared_ptr<SecurityIDRecorderState> _self;
|
|
|
|
void init();
|
|
};
|
|
|
|
}}//namespace
|
|
#else
|
|
#include "MDProducerHandle.h"
|
|
namespace bts {
|
|
namespace md {
|
|
class SecurityIDRecorder {
|
|
public:
|
|
void ensure_key(MDProducerHandle){};
|
|
};
|
|
}}
|
|
#endif
|