Initiator.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_INITIATOR_H
23#define FIX_INITIATOR_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 "Mutex.h"
36#include "Session.h"
37#include <set>
38#include <map>
39#include <string>
40
41namespace FIX
42{
43class Client;
44
52{
53public:
55 const SessionSettings& ) throw( ConfigError );
57 const SessionSettings&, LogFactory& ) throw( ConfigError );
58
59 virtual ~Initiator();
60
62 void start() throw ( ConfigError, RuntimeError );
64 void block() throw ( ConfigError, RuntimeError );
66 bool poll( double timeout = 0.0 ) throw ( ConfigError, RuntimeError );
67
69 void stop( bool force = false );
70
72 bool isLoggedOn();
73
74 Session* getSession( const SessionID& sessionID, Responder& );
75
76 const std::set<SessionID>& getSessions() const { return m_sessionIDs; }
77 Session* getSession( const SessionID& sessionID ) const;
78 const Dictionary* const getSessionSettings( const SessionID& sessionID ) const;
79
80 bool has( const SessionID& id )
81 { return m_sessions.find( id ) != m_sessions.end(); }
82
83 bool isStopped() { return m_stop; }
84
85public:
89
91 {
92 if( m_pLog ) return m_pLog;
93 return &m_nullLog;
94 }
95
96protected:
97 void setPending( const SessionID& );
98 void setConnected( const SessionID& );
99 void setDisconnected( const SessionID& );
100
101 bool isPending( const SessionID& );
102 bool isConnected( const SessionID& );
103 bool isDisconnected( const SessionID& );
104 void connect();
105
106private:
107 void initialize() throw ( ConfigError );
108
110 virtual void onConfigure( const SessionSettings& ) throw ( ConfigError ) {};
112 virtual void onInitialize( const SessionSettings& ) throw ( RuntimeError ) {};
114 virtual void onStart() = 0;
116 virtual bool onPoll( double timeout ) = 0;
118 virtual void onStop() = 0;
120 virtual void doConnect( const SessionID&, const Dictionary& ) = 0;
121
122 static THREAD_PROC startThread( void* p );
123
124 typedef std::set < SessionID > SessionIDs;
125 typedef std::map < SessionID, int > SessionState;
126 typedef std::map < SessionID, Session* > Sessions;
127
134
138protected:
140private:
145 bool m_stop;
147};
149}
150
151#endif // FIX_INITIATOR_H
#define THREAD_PROC
Definition Utility.h:184
This interface must be implemented to define what your FIX application does.
Definition Application.h:44
For storage and retrieval of key/value pairs.
Definition Dictionary.h:37
Base for classes which act as an initiator for establishing connections.
Definition Initiator.h:52
const Dictionary *const getSessionSettings(const SessionID &sessionID) const
virtual bool onPoll(double timeout)=0
Implemented to connect and poll for events.
virtual void onStart()=0
Implemented to start connecting to targets.
thread_id m_threadid
Definition Initiator.h:135
SessionIDs m_connected
Definition Initiator.h:131
bool isLoggedOn()
Check to see if any sessions are currently logged on.
void setConnected(const SessionID &)
const std::set< SessionID > & getSessions() const
Definition Initiator.h:76
std::set< SessionID > SessionIDs
Definition Initiator.h:124
void setPending(const SessionID &)
static THREAD_PROC startThread(void *p)
std::map< SessionID, Session * > Sessions
Definition Initiator.h:126
void initialize()
Definition Initiator.cpp:63
void stop(bool force=false)
Stop initiator.
void setDisconnected(const SessionID &)
SessionIDs m_pending
Definition Initiator.h:130
void start()
Start initiator.
MessageStoreFactory & getMessageStoreFactory()
Definition Initiator.h:87
virtual void doConnect(const SessionID &, const Dictionary &)=0
Implemented to connect a session to its target.
Session * getSession(const SessionID &sessionID, Responder &)
Definition Initiator.cpp:98
SessionState m_sessionState
Definition Initiator.h:133
Sessions m_sessions
Definition Initiator.h:128
bool poll(double timeout=0.0)
Poll the initiator.
std::map< SessionID, int > SessionState
Definition Initiator.h:125
bool isDisconnected(const SessionID &)
SessionIDs m_disconnected
Definition Initiator.h:132
void block()
Block on the initiator.
bool isConnected(const SessionID &)
virtual void onConfigure(const SessionSettings &)
Implemented to configure acceptor.
Definition Initiator.h:110
Log * getLog()
Definition Initiator.h:90
LogFactory * m_pLogFactory
Definition Initiator.h:141
SessionIDs m_sessionIDs
Definition Initiator.h:129
virtual void onInitialize(const SessionSettings &)
Implemented to initialize initiator.
Definition Initiator.h:112
SessionSettings m_settings
Definition Initiator.h:139
bool isStopped()
Definition Initiator.h:83
bool isPending(const SessionID &)
virtual ~Initiator()
Definition Initiator.cpp:88
NullLog m_nullLog
Definition Initiator.h:143
bool has(const SessionID &id)
Definition Initiator.h:80
Application & m_application
Definition Initiator.h:136
MessageStoreFactory & m_messageStoreFactory
Definition Initiator.h:137
virtual void onStop()=0
Implemented to stop a running initiator.
Application & getApplication()
Definition Initiator.h:86
This interface must be implemented to create a Log.
Definition Log.h:43
This interface must be implemented to log messages and events.
Definition Log.h:82
This interface must be implemented to create a MessageStore.
Portable implementation of a mutex.
Definition Mutex.h:31
Null implementation of Log.
Definition Log.h:101
Interface implements sending on and disconnecting a transport.
Definition Responder.h:35
Maintains the state and implements the logic of a FIX session.
Definition Session.h:46
Unique session id consists of BeginString, SenderCompID and TargetCompID.
Definition SessionID.h:31
Container for setting dictionaries mapped to sessions.
pthread_t thread_id
Definition Utility.h:190
Application is not configured correctly
Definition Exceptions.h:88
Application encountered serious error during runtime
Definition Exceptions.h:95

Generated on Fri Sep 27 2024 13:45:21 for QuickFIX by doxygen 1.9.8 written by Dimitri van Heesch, © 1997-2001