Index  Source Files  Annotated Class List  Alphabetical Class List  Class Hierarchy  Graphical Class Hierarchy 

Initiator.h

Go to the documentation of this file.
00001 /* -*- C++ -*- */
00002 
00003 /****************************************************************************
00004 ** Copyright (c) quickfixengine.org  All rights reserved.
00005 **
00006 ** This file is part of the QuickFIX FIX Engine
00007 **
00008 ** This file may be distributed under the terms of the quickfixengine.org
00009 ** license as defined by quickfixengine.org and appearing in the file
00010 ** LICENSE included in the packaging of this file.
00011 **
00012 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00013 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00014 **
00015 ** See http://www.quickfixengine.org/LICENSE for licensing information.
00016 **
00017 ** Contact ask@quickfixengine.org if any conditions of this licensing are
00018 ** not clear to you.
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( double timeout = 0.0 ) throw ( ConfigError, RuntimeError );
00067 
00069   void stop( bool force = false );
00070 
00072   bool isLoggedOn();
00073 
00074   Session* getSession( const SessionID& sessionID, Responder& );
00075 
00076   const std::set<SessionID>& getSessions() const { return m_sessionIDs; }
00077   Session* getSession( const SessionID& sessionID ) const;
00078   const Dictionary* const getSessionSettings( const SessionID& sessionID ) const;
00079 
00080   bool has( const SessionID& id )
00081   { return m_sessions.find( id ) != m_sessions.end(); }
00082 
00083   bool isStopped() { return m_stop; }
00084 
00085 public:
00086   Application& getApplication() { return m_application; }
00087   MessageStoreFactory& getMessageStoreFactory()
00088   { return m_messageStoreFactory; }
00089 
00090   Log* getLog() 
00091   { 
00092     if( m_pLog ) return m_pLog; 
00093     return &m_nullLog;
00094   }
00095 
00096 protected:
00097   void setPending( const SessionID& );
00098   void setConnected( const SessionID& );
00099   void setDisconnected( const SessionID& );
00100 
00101   bool isPending( const SessionID& );
00102   bool isConnected( const SessionID& );
00103   bool isDisconnected( const SessionID& );
00104   void connect();
00105 
00106 private:
00107   void initialize() throw ( ConfigError );
00108 
00110   virtual void onConfigure( const SessionSettings& ) throw ( ConfigError ) {};
00112   virtual void onInitialize( const SessionSettings& ) throw ( RuntimeError ) {};
00114   virtual void onStart() = 0;
00116   virtual bool onPoll( double timeout ) = 0;
00118   virtual void onStop() = 0;
00120   virtual void doConnect( const SessionID&, const Dictionary& ) = 0;
00121 
00122   static THREAD_PROC startThread( void* p );
00123 
00124   typedef std::set < SessionID > SessionIDs;
00125   typedef std::map < SessionID, int > SessionState;
00126   typedef std::map < SessionID, Session* > Sessions;
00127 
00128   Sessions m_sessions;
00129   SessionIDs m_sessionIDs;
00130   SessionIDs m_pending;
00131   SessionIDs m_connected;
00132   SessionIDs m_disconnected;
00133   SessionState m_sessionState;
00134 
00135   thread_id m_threadid;
00136   Application& m_application;
00137   MessageStoreFactory& m_messageStoreFactory;
00138   SessionSettings m_settings;
00139   LogFactory* m_pLogFactory;
00140   Log* m_pLog;
00141   NullLog m_nullLog;
00142   bool m_firstPoll;
00143   bool m_stop;
00144   Mutex m_mutex;
00145 };
00147 }
00148 
00149 #endif // FIX_INITIATOR_H

Generated on Mon Apr 5 20:59:50 2010 for QuickFIX by doxygen 1.6.1 written by Dimitri van Heesch, © 1997-2001