OnixS C++ SGX Titan OUCH Trading Handler  1.2.0
API documentation
ListenerHolder.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 #include <OnixS/HandlerCore/HandlerLogger.h>
20 #include <OnixS/HandlerCore/Compiler.h>
21 
27 
28 #include "Utils.h"
29 #include "ListenerHolder.h"
30 
31 using namespace OnixS::SgxTitan::Trading::Ouch;
33 
34 /*
35 ListenerHolder
36 */
37 
38 ListenerHolder::ListenerHolder (const OnixS::Logging::LogFacility* parent,
39  OnixS::HandlerCore::Common::HandlerLogger& logger)
40  : base("ListenerHolder", parent, OnixS::Logging::LOG_LEVEL_DEBUG)
41  , logger_ (logger)
42  , errorListener_ (nullptr)
43  , warningListener_ (nullptr)
44  , handlerStateListener_(nullptr)
45  , sessionListener_(nullptr)
46  , messageListener_(nullptr)
47 {
48 }
49 
50 /*
51 User callback's
52 */
53 
55 {
56  if (ErrorListener* listener = errorListener_)
57  {
58  ONIXS_EXCEPTION_TRACED_CALLBACK(listener->onError(code, description), "onError");
59  }
60 }
61 
62 void ListenerHolder::invokeWarning (const std::string& description)
63 {
64  if (WarningListener* listener = warningListener_)
65  {
66  ONIXS_EXCEPTION_TRACED_CALLBACK(listener->onWarning(description), "onWarning");
67  }
68 }
69 
71 {
72  if (HandlerStateListener* listener = handlerStateListener_)
73  {
74  ONIXS_EXCEPTION_TRACED_CALLBACK(listener->onStateChanged(newState), "onStateChanged");
75  }
76 }
77 
78 void ListenerHolder::invokeReceivedBytes(const char* bytes, size_t size)
79 {
80  if (SessionListener* listener = sessionListener_)
81  {
82  ONIXS_EXCEPTION_TRACED_CALLBACK(listener->onReceivedBytes(bytes, size), "onReceivedBytes");
83  }
84 }
85 
86 
87 #define DEFINE_MESSAGE_CALLBACK(MsgType) \
88 void ListenerHolder::invoke(const MsgType& msg)\
89 {\
90  if (MessageListener* listener = messageListener_)\
91  {\
92  ONIXS_EXCEPTION_TRACED_CALLBACK(listener->on##MsgType(msg), "on"#MsgType);\
93  }\
94 }\
95 
#define DEFINE_MESSAGE_CALLBACK(MsgType)
Enum
Defines the state that the handler is in.
ListenerHolder(const Logging::LogFacility *parent, OnixS::HandlerCore::Common::HandlerLogger &logger)
#define ONIXS_EXCEPTION_TRACED_CALLBACK(callback, contextName)
Definition: Utils.h:65
void invokeError(ErrorCode::Enum code, const std::string &description)
Enum
Known (selected) error codes.
Definition: ErrorListener.h:33