00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef FIX_INITIATOR_H
00023 #define FIX_INITIATOR_H
00024
00025 #ifdef _MSC_VER
00026 #pragma warning( disable : 4503 4355 4786 4290 )
00027 #endif
00028
00029 #include "Application.h"
00030 #include "MessageStore.h"
00031 #include "Log.h"
00032 #include "Responder.h"
00033 #include "SessionSettings.h"
00034 #include "Exceptions.h"
00035 #include "Mutex.h"
00036 #include "Session.h"
00037 #include <set>
00038 #include <map>
00039 #include <string>
00040
00041 namespace FIX
00042 {
00043 class Client;
00044
00051 class Initiator
00052 {
00053 public:
00054 Initiator( Application&, MessageStoreFactory&,
00055 const SessionSettings& ) throw( ConfigError );
00056 Initiator( Application&, MessageStoreFactory&,
00057 const SessionSettings&, LogFactory& ) throw( ConfigError );
00058
00059 virtual ~Initiator();
00060
00062 void start() throw ( ConfigError, RuntimeError );
00064 void block() throw ( ConfigError, RuntimeError );
00066 bool poll() throw ( ConfigError, RuntimeError );
00067
00069 void stop( bool force = false );
00070
00072 bool isLoggedOn();
00073
00074 Session* getSession( const SessionID& sessionID, Responder& );
00075 const std::set<SessionID> getSessions() const { return m_sessionIDs; }
00076
00077 bool has( const SessionID& id )
00078 { return m_sessions.find( id ) != m_sessions.end(); }
00079
00080 bool isStopped() { return m_stop; }
00081
00082 public:
00083 Application& getApplication() { return m_application; }
00084 MessageStoreFactory& getMessageStoreFactory()
00085 { return m_messageStoreFactory; }
00086
00087 protected:
00088 void setPending( const SessionID& );
00089 void setConnected( const SessionID& );
00090 void setDisconnected( const SessionID& );
00091
00092 bool isPending( const SessionID& );
00093 bool isConnected( const SessionID& );
00094 bool isDisconnected( const SessionID& );
00095 void connect();
00096
00097 private:
00098 void initialize() throw ( ConfigError );
00099
00101 virtual void onConfigure( const SessionSettings& ) throw ( ConfigError ) {};
00103 virtual void onInitialize( const SessionSettings& ) throw ( RuntimeError ) {};
00105 virtual void onStart() = 0;
00107 virtual bool onPoll() = 0;
00109 virtual void onStop() = 0;
00111 virtual bool doConnect( const SessionID&, const Dictionary& ) = 0;
00112
00113 static THREAD_PROC startThread( void* p );
00114
00115 typedef std::set < SessionID > SessionIDs;
00116 typedef std::map < SessionID, int > SessionState;
00117 typedef std::map < SessionID, Session* > Sessions;
00118
00119 Sessions m_sessions;
00120 SessionIDs m_sessionIDs;
00121 SessionIDs m_pending;
00122 SessionIDs m_connected;
00123 SessionIDs m_disconnected;
00124 SessionState m_sessionState;
00125
00126 unsigned m_threadid;
00127 Application& m_application;
00128 MessageStoreFactory& m_messageStoreFactory;
00129 SessionSettings m_settings;
00130 LogFactory* m_pLogFactory;
00131 bool m_firstPoll;
00132 bool m_stop;
00133 Mutex m_mutex;
00134 };
00136 }
00137
00138 #endif // FIX_INITIATOR_H