Acceptor.h
Go to the documentation of this file.
1 /* -*- C++ -*- */
2 
3 /****************************************************************************
4 ** Copyright (c) 2001-2014
5 **
6 ** This file is part of the QuickFIX FIX Engine
7 **
8 ** This file may be distributed under the terms of the quickfixengine.org
9 ** license as defined by quickfixengine.org and appearing in the file
10 ** LICENSE included in the packaging of this file.
11 **
12 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
13 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
14 **
15 ** See http://www.quickfixengine.org/LICENSE for licensing information.
16 **
17 ** Contact ask@quickfixengine.org if any conditions of this licensing are
18 ** not clear to you.
19 **
20 ****************************************************************************/
21 
22 #ifndef FIX_ACCEPTOR_H
23 #define FIX_ACCEPTOR_H
24 
25 #ifdef _MSC_VER
26 #pragma warning( disable : 4503 4355 4786 4290 )
27 #endif
28 
29 #include "Application.h"
30 #include "MessageStore.h"
31 #include "Log.h"
32 #include "Responder.h"
33 #include "SessionSettings.h"
34 #include "Exceptions.h"
35 #include <map>
36 #include <string>
37 
38 namespace FIX
39 {
40 class Client;
41 class Session;
42 
49 class Acceptor
50 {
51 public:
52  Acceptor( Application&, MessageStoreFactory&,
53  const SessionSettings& ) throw( ConfigError );
54  Acceptor( Application&, MessageStoreFactory&,
55  const SessionSettings&, LogFactory& ) throw( ConfigError );
56 
57  virtual ~Acceptor();
58 
59  Log* getLog()
60  {
61  if( m_pLog ) return m_pLog;
62  return &m_nullLog;
63  }
64 
66  void start() throw ( ConfigError, RuntimeError );
68  void block() throw ( ConfigError, RuntimeError );
70  bool poll( double timeout = 0.0 ) throw ( ConfigError, RuntimeError );
71 
73  void stop( bool force = false );
74 
76  bool isLoggedOn();
77 
78  Session* getSession( const std::string& msg, Responder& );
79 
80  const std::set<SessionID>& getSessions() const { return m_sessionIDs; }
81  Session* getSession( const SessionID& sessionID ) const;
82  const Dictionary* const getSessionSettings( const SessionID& sessionID ) const;
83 
84  bool has( const SessionID& id )
85  { return m_sessions.find( id ) != m_sessions.end(); }
86 
87  bool isStopped() { return m_stop; }
88 
89  Application& getApplication() { return m_application; }
90  MessageStoreFactory& getMessageStoreFactory()
91  { return m_messageStoreFactory; }
92 
93 private:
94  void initialize() throw ( ConfigError );
95 
97  virtual void onConfigure( const SessionSettings& ) throw ( ConfigError ) {};
99  virtual void onInitialize( const SessionSettings& ) throw ( RuntimeError ) {};
101  virtual void onStart() = 0;
103  virtual bool onPoll( double second ) = 0;
105  virtual void onStop() = 0;
106 
107  static THREAD_PROC startThread( void* p );
108 
109  typedef std::set < SessionID > SessionIDs;
110  typedef std::map < SessionID, Session* > Sessions;
111 
117 protected:
119 private:
121  Log* m_pLog;
123  bool m_firstPoll;
124  bool m_stop;
125 };
127 }
128 
129 #endif // FIX_ACCEPTOR_H
FIX::thread_id
pthread_t thread_id
Definition: Utility.h:190
FIX::Acceptor::SessionIDs
std::set< SessionID > SessionIDs
Definition: Acceptor.h:126
FIX::Acceptor::getSession
Session * getSession(const std::string &msg, Responder &)
Definition: Acceptor.cpp:121
FIX::Acceptor::getLog
Log * getLog()
Definition: Acceptor.h:76
FIX::Acceptor::onInitialize
virtual void onInitialize(const SessionSettings &)
Implemented to initialize acceptor.
Definition: Acceptor.h:116
SessionSettings.h
FIX::MessageStoreFactory
This interface must be implemented to create a MessageStore.
Definition: MessageStore.h:58
FIX::Acceptor::getSessionSettings
const Dictionary *const getSessionSettings(const SessionID &sessionID) const
Definition: Acceptor.cpp:163
FIX::Acceptor::getMessageStoreFactory
MessageStoreFactory & getMessageStoreFactory()
Definition: Acceptor.h:107
FIX::Acceptor::m_messageStoreFactory
MessageStoreFactory & m_messageStoreFactory
Definition: Acceptor.h:133
FIX::Acceptor::m_pLogFactory
LogFactory * m_pLogFactory
Definition: Acceptor.h:137
FIX::Acceptor::m_firstPoll
bool m_firstPoll
Definition: Acceptor.h:140
FIX::Acceptor::Acceptor
Acceptor(Application &, MessageStoreFactory &, const SessionSettings &)
Definition: Acceptor.cpp:53
FIX::Acceptor::start
void start()
Start acceptor.
Definition: Acceptor.cpp:175
FIX::Application
This interface must be implemented to define what your FIX application does.
Definition: Application.h:60
FIX::ConfigError
Application is not configured correctly
Definition: Exceptions.h:104
FIX::RuntimeError
Application encountered serious error during runtime
Definition: Exceptions.h:111
FIX::SessionID
Unique session id consists of BeginString, SenderCompID and TargetCompID.
Definition: SessionID.h:47
FIX::Acceptor::~Acceptor
virtual ~Acceptor()
Definition: Acceptor.cpp:110
FIX::SessionSettings
Container for setting dictionaries mapped to sessions.
Definition: SessionSettings.h:237
FIX::Acceptor::startThread
static THREAD_PROC startThread(void *p)
Definition: Acceptor.cpp:259
THREAD_PROC
#define THREAD_PROC
Definition: Utility.h:184
FIX::Acceptor::isLoggedOn
bool isLoggedOn()
Check to see if any sessions are currently logged on.
Definition: Acceptor.cpp:247
FIX::Acceptor::getApplication
Application & getApplication()
Definition: Acceptor.h:106
FIX::Acceptor::Sessions
std::map< SessionID, Session * > Sessions
Definition: Acceptor.h:127
FIX::Acceptor::block
void block()
Block on the acceptor.
Definition: Acceptor.cpp:187
FIX::Acceptor::m_pLog
Log * m_pLog
Definition: Acceptor.h:138
FIX::Acceptor::getSessions
const std::set< SessionID > & getSessions() const
Definition: Acceptor.h:97
FIX::Acceptor::m_nullLog
NullLog m_nullLog
Definition: Acceptor.h:139
FIX::Acceptor::m_sessionIDs
SessionIDs m_sessionIDs
Definition: Acceptor.h:131
Application.h
FIX::Acceptor::onStop
virtual void onStop()=0
Implemented to stop a running acceptor.
FIX::Acceptor::onPoll
virtual bool onPoll(double second)=0
Implemented to connect and poll for events.
FIX::Responder
Interface implements sending on and disconnecting a transport.
Definition: Responder.h:51
FIX::Acceptor::has
bool has(const SessionID &id)
Definition: Acceptor.h:101
FIX
Definition: Acceptor.cpp:34
FIX::Acceptor::m_stop
bool m_stop
Definition: Acceptor.h:141
FIX::Acceptor::stop
void stop(bool force=false)
Stop acceptor.
Definition: Acceptor.cpp:209
FIX::Acceptor::initialize
void initialize()
Definition: Acceptor.cpp:86
FIX::NullLog
Null implementation of Log.
Definition: Log.h:117
Responder.h
Exceptions.h
FIX::Acceptor::onConfigure
virtual void onConfigure(const SessionSettings &)
Implemented to configure acceptor.
Definition: Acceptor.h:114
FIX::LogFactory
This interface must be implemented to create a Log.
Definition: Log.h:59
FIX::Acceptor::poll
bool poll(double timeout=0.0)
Poll the acceptor.
Definition: Acceptor.cpp:196
FIX::Acceptor::m_settings
SessionSettings m_settings
Definition: Acceptor.h:135
FIX::Acceptor::isStopped
bool isStopped()
Definition: Acceptor.h:104
FIX::Dictionary
For storage and retrieval of key/value pairs.
Definition: Dictionary.h:53
FIX::Log
This interface must be implemented to log messages and events.
Definition: Log.h:98
FIX::Acceptor::m_application
Application & m_application
Definition: Acceptor.h:132
FIX::Acceptor::m_sessions
Sessions m_sessions
Definition: Acceptor.h:130
Log.h
FIX::Acceptor::m_threadid
thread_id m_threadid
Definition: Acceptor.h:129
FIX::Acceptor::onStart
virtual void onStart()=0
Implemented to start listening for connections.
MessageStore.h
FIX::Session
Maintains the state and implements the logic of a FIX session.
Definition: Session.h:62

Generated on Wed Apr 29 2020 19:41:30 for QuickFIX by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2001