82 lines
2.3 KiB
C++
82 lines
2.3 KiB
C++
#pragma once
|
|
|
|
#include "lib/utils/bts_export.h"
|
|
#include "lib/utils/bts_no_copy.h"
|
|
|
|
#include "MDProducerChannel.h"
|
|
#include "MDProducerHandle.h"
|
|
#include "SecurityMapper.h"
|
|
#include "Shm/FixedSecurity.h"
|
|
#include "common.h"
|
|
#include <memory>
|
|
#include <mutex>
|
|
#include <vector>
|
|
|
|
namespace bts {
|
|
namespace md {
|
|
|
|
class MDProducerImpl;
|
|
class SecurityIDRecorder;
|
|
|
|
enum class MDProducerFlags {
|
|
None = 0x0,
|
|
Shared = 0x1,
|
|
SecurityMapper = 0x2,
|
|
};
|
|
|
|
constexpr MDProducerFlags operator+(MDProducerFlags a, MDProducerFlags b) {
|
|
return (MDProducerFlags)((uint32_t)a | (uint32_t)b);
|
|
}
|
|
constexpr MDProducerFlags operator-(MDProducerFlags a, MDProducerFlags b) {
|
|
return (MDProducerFlags)((uint32_t)a | (uint32_t)b);
|
|
}
|
|
constexpr bool operator&(const MDProducerFlags a, const MDProducerFlags b) {
|
|
return ((uint32_t)a & (uint32_t)b) == (uint32_t)b;
|
|
}
|
|
|
|
constexpr MDProducerFlags DefaultMDProducerFlags =
|
|
MDProducerFlags::Shared + MDProducerFlags::SecurityMapper;
|
|
|
|
// All updates to a single security go through here. Assumes a single writer
|
|
// thread. MDP3Main constructs it and passes it to MDPListener (and subsquently
|
|
// the same for he other venue))
|
|
class BTS_EXPORT MDProducer {
|
|
public:
|
|
MDProducer(
|
|
Platform platform, MDProducerFlags flags = DefaultMDProducerFlags);
|
|
MDProducer(
|
|
Platform platform,
|
|
SecurityIDRecorder recorder,
|
|
MDProducerFlags flags = DefaultMDProducerFlags);
|
|
MDProducer(MDProducer &&other);
|
|
~MDProducer();
|
|
|
|
// A single MDProducer owns a given symbol+type.
|
|
// Attempting to add the same Symbol+type to a second
|
|
// producer (even in a different process) is a crash-worthy error
|
|
MDProducerHandle add_security(const FixedSecurity &security);
|
|
|
|
// A Producer Channel holds data shared between the
|
|
MDProducerChannel get_channel(
|
|
const char *symbol, SecurityType type, Venue exchange);
|
|
|
|
// Heartbeat all channels
|
|
void heartbeat();
|
|
|
|
private:
|
|
BTS_NO_COPY(MDProducer);
|
|
|
|
MDProducerImpl &get_producer(
|
|
const char *symbol, SecurityType type, Venue exchange);
|
|
|
|
std::unique_ptr<std::mutex> _mutex;
|
|
std::vector<std::unique_ptr<MDProducerImpl>> _producers;
|
|
std::unique_ptr<SecurityIDRecorder> _id_recorder;
|
|
Platform _platform;
|
|
MDProducerFlags _flags;
|
|
SecurityMapper _smapper;
|
|
};
|
|
|
|
} // namespace md
|
|
} // namespace bts
|