OnixS C++ SGX Titan OUCH Trading Handler  1.2.0
API documentation
AuditTrailDumper.cpp
Go to the documentation of this file.
1 /*
2 * Copyright Onix Solutions Limited [OnixS]. All rights reserved.
3 *
4 * This software owned by Onix Solutions Limited [OnixS] and is protected by copyright law
5 * and international copyright treaties.
6 *
7 * Access to and use of the software is governed by the terms of the applicable OnixS Software
8 * Services Agreement(the Agreement) and Customer end user license agreements granting
9 * a non-assignable, non-transferable and non-exclusive license to use the software
10 * for it's own data processing purposes under the terms defined in the Agreement.
11 *
12 * Except as otherwise granted within the terms of the Agreement, copying or reproduction of any part
13 * of this source code or associated reference material to any other location for further reproduction
14 * or redistribution, and any amendments to this copyright notice, are expressly prohibited.
15 *
16 * Any reproduction or redistribution for sale or hiring of the Software not in accordance with
17 * the terms of the Agreement is a violation of copyright law.
18 */
19 
23 
24 #include "ProtocolFormatting.h"
25 #include "Utils.h"
26 #include "AuditTrailDumper.h"
27 
28 
30 namespace Implementation {
31 
32 namespace
33 {
34  struct OutputMessageHelper : public OutgoingMessage
35  {
36  OutputMessageHelper(void* data, MessageSize size)
37  : OutgoingMessage(data, size)
38  {
39  }
40  };
41 }
42 
44  const std::string& path,
45  const Logging::LogFacility* parent,
46  OnixS::HandlerCore::Common::HandlerLogger& logger,
47  const OnixS::System::Thread::CpuIndexes& affinity,
48  size_t auditTrailFileMaxSize)
49 
50  : AuditTrailDumperBase(path, parent, &logger, affinity, auditTrailFileMaxSize)
51 {
52 }
53 
55 {
56 }
57 
58 void AuditTrailDumper::serialize(const Record& record, OnixS::Util::TextBuilder& tb)
59 {
60  BOOST_ASSERT(record.buffer);
61  BOOST_ASSERT(record.bufferSize > 0);
62 
63  tb <<(record.direction == Record::In ? " IN " : "OUT ")
64  << OnixS::Time::YYYYMMDDHHMMSSnsecFormatter()(record.timestamp) << ' ';
65 
66  const void* const dataPtr = record.buffer;
67 
68  BOOST_ASSERT(record.bufferSize <= std::numeric_limits<Binary2>::max());
69  const Binary2 messageLength = static_cast<Binary2>(record.bufferSize);
70 
71  if(record.direction == Record::In)
72  {
73  const IncomingMessage message(dataPtr, messageLength);
74  const InboundMessageTypes::Enum messageType = message.type();
75 
76  if(InboundMessageTypes::OrderAccepted == messageType)
77  {
78  OrderAccepted::validateSize(messageLength);
79  tb << static_cast<const OrderAccepted&>(message) << '\n';
80  }
81  else if(InboundMessageTypes::OrderRejected == messageType)
82  {
83  OrderRejected::validateSize(messageLength);
84  tb << static_cast<const OrderRejected&>(message) << '\n';
85  }
86  else if(InboundMessageTypes::OrderReplaced == messageType)
87  {
88  OrderReplaced::validateSize(messageLength);
89  tb << static_cast<const OrderReplaced&>(message) << '\n';
90  }
91  else if(InboundMessageTypes::OrderCancelled == messageType)
92  {
93  OrderCancelled::validateSize(messageLength);
94  tb << static_cast<const OrderCancelled&>(message) << '\n';
95  }
96  else if(InboundMessageTypes::OrderExecuted == messageType)
97  {
98  OrderExecuted::validateSize(messageLength);
99  tb << static_cast<const OrderExecuted&>(message) << '\n';
100  }
101  else
102  log(ONIXS_LOG_WARN[this] << "Received unknown message, type = " << static_cast<Binary1>(message.type()));
103  }
104  else if(record.direction == Record::Out)
105  {
106  const OutgoingMessage& message =
107  OutputMessageHelper(const_cast<void*>(dataPtr), messageLength);
108 
109  const OutboundMessageTypes::Enum type = message.type();
110 
111  if(type == OutboundMessageTypes::EnterOrder)
112  {
113  tb << static_cast<const EnterOrder&>(message) << '\n';
114  }
115  else if(type == OutboundMessageTypes::ReplaceOrder)
116  {
117  tb << static_cast<const ReplaceOrder&>(message) << '\n';
118  }
119  else if(type == OutboundMessageTypes::CancelOrder)
120  {
121  tb << static_cast<const CancelOrder&>(message) << '\n';
122  }
123  else if(type == OutboundMessageTypes::CancelByOrderId)
124  {
125  tb << static_cast<const CancelByOrderId&>(message) << '\n';
126  }
127  else
128  log(ONIXS_LOG_WARN[this] << "Sent unknown message, type = " << static_cast<Binary1>(message.type()));
129  }
130  else
131  return;
132 }
133 
134 void AuditTrailDumper::onOutboundMessage(const OutgoingMessage& msg, bool warmup)
135 {
136  AuditTrailDumperBase::onOutboundMessage(static_cast <const char*>(msg.binary()), msg.binarySize(), warmup);
137 }
138 
139 void AuditTrailDumper::onInboundMessage(const IncomingMessage& msg, bool warmup)
140 {
141  AuditTrailDumperBase::onInboundMessage(static_cast <const char*>(msg.binary()), msg.binarySize(), warmup);
142 }
143 
144 }}}}}
void serialize(const Record &record, OnixS::Util::TextBuilder &tb) final
OnixS::HandlerCore::Common::AuditTrailDumperBase< MaxMessageBinarySize > AuditTrailDumperBase
Binary2 MessageSize
Aliases message length type.
Definition: Defines.h:47
AuditTrailDumper(const std::string &path, const Logging::LogFacility *parent, OnixS::HandlerCore::Common::HandlerLogger &logger, const OnixS::System::Thread::CpuIndexes &affinity, size_t auditTrailFileMaxSize)
void onOutboundMessage(const OutgoingMessage &msg, bool warmup)
#define ONIXS_SGXTITAN_OUCH_NAMESPACE_BEGIN
Definition: Bootstrap.h:27
void onInboundMessage(const IncomingMessage &msg, bool warmup)