Initiator.h
Go to the documentation of this file.
/* -*- C++ -*- */
/****************************************************************************
** Copyright (c) 2001-2014
**
** This file is part of the QuickFIX FIX Engine
**
** This file may be distributed under the terms of the quickfixengine.org
** license as defined by quickfixengine.org and appearing in the file
** LICENSE included in the packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.quickfixengine.org/LICENSE for licensing information.
**
** Contact ask@quickfixengine.org if any conditions of this licensing are
** not clear to you.
**
****************************************************************************/
#ifndef FIX_INITIATOR_H
#define FIX_INITIATOR_H
#ifdef _MSC_VER
#pragma warning( disable : 4503 4355 4786 4290 )
#endif
#include "Application.h"
#include "MessageStore.h"
#include "Log.h"
#include "Responder.h"
#include "SessionSettings.h"
#include "Exceptions.h"
#include "Mutex.h"
#include "Session.h"
#include <set>
#include <map>
#include <string>
namespace FIX
{
class Client;
class Initiator
{
public:
Initiator( Application&, MessageStoreFactory&,
const SessionSettings& ) throw( ConfigError );
Initiator( Application&, MessageStoreFactory&,
const SessionSettings&, LogFactory& ) throw( ConfigError );
virtual ~Initiator();
void start() throw ( ConfigError, RuntimeError );
void block() throw ( ConfigError, RuntimeError );
bool poll( double timeout = 0.0 ) throw ( ConfigError, RuntimeError );
void stop( bool force = false );
bool isLoggedOn();
Session* getSession( const SessionID& sessionID, Responder& );
const std::set<SessionID>& getSessions() const { return m_sessionIDs; }
Session* getSession( const SessionID& sessionID ) const;
const Dictionary* const getSessionSettings( const SessionID& sessionID ) const;
bool has( const SessionID& id )
{ return m_sessions.find( id ) != m_sessions.end(); }
bool isStopped() { return m_stop; }
public:
Application& getApplication() { return m_application; }
MessageStoreFactory& getMessageStoreFactory()
{ return m_messageStoreFactory; }
Log* getLog()
{
if( m_pLog ) return m_pLog;
return &m_nullLog;
}
protected:
void setPending( const SessionID& );
void setConnected( const SessionID& );
void setDisconnected( const SessionID& );
bool isPending( const SessionID& );
bool isConnected( const SessionID& );
bool isDisconnected( const SessionID& );
void connect();
private:
void initialize() throw ( ConfigError );
virtual void onConfigure( const SessionSettings& ) throw ( ConfigError ) {};
virtual void onInitialize( const SessionSettings& ) throw ( RuntimeError ) {};
virtual void onStart() = 0;
virtual bool onPoll( double timeout ) = 0;
virtual void onStop() = 0;
virtual void doConnect( const SessionID&, const Dictionary& ) = 0;
static THREAD_PROC startThread( void* p );
typedef std::set < SessionID > SessionIDs;
typedef std::map < SessionID, int > SessionState;
typedef std::map < SessionID, Session* > Sessions;
Sessions m_sessions;
SessionIDs m_sessionIDs;
SessionIDs m_pending;
SessionIDs m_connected;
SessionIDs m_disconnected;
SessionState m_sessionState;
thread_id m_threadid;
Application& m_application;
MessageStoreFactory& m_messageStoreFactory;
protected:
SessionSettings m_settings;
private:
LogFactory* m_pLogFactory;
Log* m_pLog;
NullLog m_nullLog;
bool m_firstPoll;
bool m_stop;
Mutex m_mutex;
};
}
#endif // FIX_INITIATOR_H
Application.h
Exceptions.h
Log.h
MessageStore.h
Mutex.h
Responder.h
Session.h
SessionSettings.h
THREAD_PROC
#define THREAD_PROC
Definition Utility.h:184
FIX::Application
This interface must be implemented to define what your FIX application does.
Definition Application.h:44
FIX::Dictionary
For storage and retrieval of key/value pairs.
Definition Dictionary.h:37
FIX::Initiator
Base for classes which act as an initiator for establishing connections.
Definition Initiator.h:52
FIX::Initiator::getSessionSettings
const Dictionary *const getSessionSettings(const SessionID &sessionID) const
Definition Initiator.cpp:119
FIX::Initiator::onPoll
virtual bool onPoll(double timeout)=0
Implemented to connect and poll for events.
FIX::Initiator::onStart
virtual void onStart()=0
Implemented to start connecting to targets.
FIX::Initiator::m_threadid
thread_id m_threadid
Definition Initiator.h:135
FIX::Initiator::m_connected
SessionIDs m_connected
Definition Initiator.h:131
FIX::Initiator::isLoggedOn
bool isLoggedOn()
Check to see if any sessions are currently logged on.
Definition Initiator.cpp:275
FIX::Initiator::m_mutex
Mutex m_mutex
Definition Initiator.h:146
FIX::Initiator::setConnected
void setConnected(const SessionID &)
Definition Initiator.cpp:154
FIX::Initiator::getSessions
const std::set< SessionID > & getSessions() const
Definition Initiator.h:76
FIX::Initiator::m_pLog
Log * m_pLog
Definition Initiator.h:142
FIX::Initiator::SessionIDs
std::set< SessionID > SessionIDs
Definition Initiator.h:124
FIX::Initiator::setPending
void setPending(const SessionID &)
Definition Initiator.cpp:145
FIX::Initiator::startThread
static THREAD_PROC startThread(void *p)
Definition Initiator.cpp:289
FIX::Initiator::Sessions
std::map< SessionID, Session * > Sessions
Definition Initiator.h:126
FIX::Initiator::initialize
void initialize()
Definition Initiator.cpp:63
FIX::Initiator::stop
void stop(bool force=false)
Stop initiator.
Definition Initiator.cpp:226
FIX::Initiator::setDisconnected
void setDisconnected(const SessionID &)
Definition Initiator.cpp:163
FIX::Initiator::connect
void connect()
Definition Initiator.cpp:131
FIX::Initiator::m_pending
SessionIDs m_pending
Definition Initiator.h:130
FIX::Initiator::start
void start()
Start initiator.
Definition Initiator.cpp:190
FIX::Initiator::getMessageStoreFactory
MessageStoreFactory & getMessageStoreFactory()
Definition Initiator.h:87
FIX::Initiator::doConnect
virtual void doConnect(const SessionID &, const Dictionary &)=0
Implemented to connect a session to its target.
FIX::Initiator::getSession
Session * getSession(const SessionID &sessionID, Responder &)
Definition Initiator.cpp:98
FIX::Initiator::m_sessionState
SessionState m_sessionState
Definition Initiator.h:133
FIX::Initiator::m_sessions
Sessions m_sessions
Definition Initiator.h:128
FIX::Initiator::poll
bool poll(double timeout=0.0)
Poll the initiator.
Definition Initiator.cpp:212
FIX::Initiator::SessionState
std::map< SessionID, int > SessionState
Definition Initiator.h:125
FIX::Initiator::isDisconnected
bool isDisconnected(const SessionID &)
Definition Initiator.cpp:184
FIX::Initiator::m_disconnected
SessionIDs m_disconnected
Definition Initiator.h:132
FIX::Initiator::block
void block()
Block on the initiator.
Definition Initiator.cpp:203
FIX::Initiator::isConnected
bool isConnected(const SessionID &)
Definition Initiator.cpp:178
FIX::Initiator::onConfigure
virtual void onConfigure(const SessionSettings &)
Implemented to configure acceptor.
Definition Initiator.h:110
FIX::Initiator::m_firstPoll
bool m_firstPoll
Definition Initiator.h:144
FIX::Initiator::getLog
Log * getLog()
Definition Initiator.h:90
FIX::Initiator::m_pLogFactory
LogFactory * m_pLogFactory
Definition Initiator.h:141
FIX::Initiator::m_sessionIDs
SessionIDs m_sessionIDs
Definition Initiator.h:129
FIX::Initiator::onInitialize
virtual void onInitialize(const SessionSettings &)
Implemented to initialize initiator.
Definition Initiator.h:112
FIX::Initiator::m_settings
SessionSettings m_settings
Definition Initiator.h:139
FIX::Initiator::isStopped
bool isStopped()
Definition Initiator.h:83
FIX::Initiator::isPending
bool isPending(const SessionID &)
Definition Initiator.cpp:172
FIX::Initiator::~Initiator
virtual ~Initiator()
Definition Initiator.cpp:88
FIX::Initiator::m_nullLog
NullLog m_nullLog
Definition Initiator.h:143
FIX::Initiator::m_stop
bool m_stop
Definition Initiator.h:145
FIX::Initiator::has
bool has(const SessionID &id)
Definition Initiator.h:80
FIX::Initiator::m_application
Application & m_application
Definition Initiator.h:136
FIX::Initiator::m_messageStoreFactory
MessageStoreFactory & m_messageStoreFactory
Definition Initiator.h:137
FIX::Initiator::onStop
virtual void onStop()=0
Implemented to stop a running initiator.
FIX::Initiator::getApplication
Application & getApplication()
Definition Initiator.h:86
FIX::LogFactory
This interface must be implemented to create a Log.
Definition Log.h:43
FIX::Log
This interface must be implemented to log messages and events.
Definition Log.h:82
FIX::MessageStoreFactory
This interface must be implemented to create a MessageStore.
Definition MessageStore.h:42
FIX::Mutex
Portable implementation of a mutex.
Definition Mutex.h:31
FIX::NullLog
Null implementation of Log.
Definition Log.h:101
FIX::Responder
Interface implements sending on and disconnecting a transport.
Definition Responder.h:35
FIX::Session
Maintains the state and implements the logic of a FIX session.
Definition Session.h:46
FIX::SessionID
Unique session id consists of BeginString, SenderCompID and TargetCompID.
Definition SessionID.h:31
FIX::SessionSettings
Container for setting dictionaries mapped to sessions.
Definition SessionSettings.h:221
FIX
Definition Acceptor.cpp:35
FIX::thread_id
pthread_t thread_id
Definition Utility.h:190
FIX::ConfigError
Application is not configured correctly
Definition Exceptions.h:88
FIX::RuntimeError
Application encountered serious error during runtime
Definition Exceptions.h:95