00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef FIX_ACCEPTOR_H
00023 #define FIX_ACCEPTOR_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 <map>
00036 #include <string>
00037
00038 namespace FIX
00039 {
00040 class Client;
00041 class Session;
00042
00049 class Acceptor
00050 {
00051 public:
00052 Acceptor( Application&, MessageStoreFactory&,
00053 const SessionSettings& ) throw( ConfigError );
00054 Acceptor( Application&, MessageStoreFactory&,
00055 const SessionSettings&, LogFactory& ) throw( ConfigError );
00056
00057 virtual ~Acceptor();
00058
00060 void start() throw ( ConfigError, RuntimeError );
00062 void block() throw ( ConfigError, RuntimeError );
00064 bool poll() throw ( ConfigError, RuntimeError );
00065
00067 void stop( bool force = false );
00068
00070 bool isLoggedOn();
00071
00072 Session* getSession( const std::string& msg, Responder& );
00073 const std::set<SessionID> getSessions() const { return m_sessionIDs; }
00074
00075 bool has( const SessionID& id )
00076 { return m_sessions.find( id ) != m_sessions.end(); }
00077
00078 bool isStopped() { return m_stop; }
00079
00080 Application& getApplication() { return m_application; }
00081 MessageStoreFactory& getMessageStoreFactory()
00082 { return m_messageStoreFactory; }
00083
00084 protected:
00085 void log( const std::string& text )
00086 { if( m_pLog ) m_pLog->onEvent( text ); }
00087
00088 private:
00089 void initialize() throw ( ConfigError );
00090
00092 virtual void onConfigure( const SessionSettings& ) throw ( ConfigError ) {};
00094 virtual void onInitialize( const SessionSettings& ) throw ( RuntimeError ) {};
00096 virtual void onStart() = 0;
00098 virtual bool onPoll() = 0;
00100 virtual void onStop() = 0;
00101
00102 static THREAD_PROC startThread( void* p );
00103
00104 typedef std::set < SessionID > SessionIDs;
00105 typedef std::map < SessionID, Session* > Sessions;
00106
00107 unsigned m_threadid;
00108 Sessions m_sessions;
00109 SessionIDs m_sessionIDs;
00110 Application& m_application;
00111 MessageStoreFactory& m_messageStoreFactory;
00112 SessionSettings m_settings;
00113 LogFactory* m_pLogFactory;
00114 Log* m_pLog;
00115 bool m_firstPoll;
00116 bool m_stop;
00117 };
00119 }
00120
00121 #endif // FIX_ACCEPTOR_H