FIX::Initiator Class Referenceabstract

Base for classes which act as an initiator for establishing connections. More...

`#include <Initiator.h>`

Inheritance diagram for FIX::Initiator:
[legend]
Collaboration diagram for FIX::Initiator:
[legend]

## Public Member Functions

| Initiator (Application &, MessageStoreFactory &, const SessionSettings &) throw ( ConfigError )
| Initiator (Application &, MessageStoreFactory &, const SessionSettings &, LogFactory &) throw ( ConfigError )
virtual | ~Initiator ()
void | start () throw ( ConfigError, RuntimeError )
| Start initiator. More...
void | block () throw ( ConfigError, RuntimeError )
| Block on the initiator. More...
bool | poll (double timeout=0.0) throw ( ConfigError, RuntimeError )
| Poll the initiator. More...
void | stop (bool force=false)
| Stop initiator. More...
bool | isLoggedOn ()
| Check to see if any sessions are currently logged on. More...
Session * | getSession (const SessionID &sessionID, Responder &)
const std::set< SessionID > & | getSessions () const
Session * | getSession (const SessionID &sessionID) const
const Dictionary *const | getSessionSettings (const SessionID &sessionID) const
bool | has (const SessionID &id)
bool | isStopped ()
Application & | getApplication ()
MessageStoreFactory & | getMessageStoreFactory ()
Log * | getLog ()

## Protected Member Functions

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 ()

## Protected Attributes

SessionSettings | m_settings

## Private Types

typedef std::set< SessionID > | SessionIDs
typedef std::map< SessionID, int > | SessionState
typedef std::map< SessionID, Session * > | Sessions

## Private Member Functions

void | initialize () throw ( ConfigError )
virtual void | onConfigure (const SessionSettings &) throw ( ConfigError )
| Implemented to configure acceptor. More...
virtual void | onInitialize (const SessionSettings &) throw ( RuntimeError )
| Implemented to initialize initiator. More...
virtual void | onStart ()=0
| Implemented to start connecting to targets. More...
virtual bool | onPoll (double timeout)=0
| Implemented to connect and poll for events. More...
virtual void | onStop ()=0
| Implemented to stop a running initiator. More...
virtual void | doConnect (const SessionID &, const Dictionary &)=0
| Implemented to connect a session to its target. More...

## Static Private Member Functions

static THREAD_PROC | startThread (void *p)

## Private Attributes

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
LogFactory * | m_pLogFactory
Log * | m_pLog
NullLog | m_nullLog
bool | m_firstPoll
bool | m_stop
Mutex | m_mutex

## Detailed Description

Base for classes which act as an initiator for establishing connections.

Most users will not need to implement one of these. The default SocketInitiator implementation will be used in most cases.

Definition at line 68 of file Initiator.h.

## Member Typedef Documentation

## SessionIDs

typedef std::set< SessionID > FIX::Initiator::SessionIDs

private

Definition at line 141 of file Initiator.h.

## Sessions

typedef std::map< SessionID, Session* > FIX::Initiator::Sessions

private

Definition at line 143 of file Initiator.h.

## SessionState

typedef std::map< SessionID, int > FIX::Initiator::SessionState

private

Definition at line 142 of file Initiator.h.

## Constructor & Destructor Documentation

## Initiator() [1/2]

FIX::Initiator::Initiator | ( | Application & | application,
|  | MessageStoreFactory & | messageStoreFactory,
|  | const SessionSettings & | settings
| ) |  |
throw | ( | ConfigError
| ) |  |

Definition at line 53 of file Initiator.cpp.

: m_threadid( 0 ),
m_application( application ),
m_messageStoreFactory( messageStoreFactory ),
m_settings( settings ),
m_pLogFactory( &logFactory ),
m_pLog( logFactory.create() ),
m_firstPoll( true ),
m_stop( true )
{ initialize(); }
void Initiator::initialize() throw ( ConfigError )
{

## Initiator() [2/2]

FIX::Initiator::Initiator | ( | Application & | application,
|  | MessageStoreFactory & | messageStoreFactory,
|  | const SessionSettings & | settings,
|  | LogFactory & | logFactory
| ) |  |
throw | ( | ConfigError
| ) |  |

Definition at line 66 of file Initiator.cpp.

{
if ( m_settings.get( *i ).getString( "ConnectionType" ) == "initiator" )
{
m_sessionIDs.insert( *i );

## ~Initiator()

FIX::Initiator::~Initiator | ( |  | ) |

virtual

Definition at line 105 of file Initiator.cpp.

{
Sessions::const_iterator i = m_sessions.find( sessionID );
if( i != m_sessions.end() )

## Member Function Documentation

## block()

void FIX::Initiator::block | ( |  | ) |
throw | ( | ConfigError,
|  | RuntimeError
| ) |  |

Block on the initiator.

Definition at line 220 of file Initiator.cpp.

{

## connect()

void FIX::Initiator::connect | ( |  | ) |

protected

Definition at line 148 of file Initiator.cpp.

{
Locker l(m_mutex);
m_pending.erase( sessionID );
m_connected.insert( sessionID );
m_disconnected.erase( sessionID );

## doConnect()

virtual void FIX::Initiator::doConnect | ( | const SessionID & | ,
|  | const Dictionary & |
| ) |  |

private pure virtual

Implemented to connect a session to its target.

Implemented in FIX::ThreadedSocketInitiator, and FIX::SocketInitiator.

Referenced by getSessionSettings().

## getApplication()

Application& FIX::Initiator::getApplication | ( |  | ) |

inline

Definition at line 103 of file Initiator.h.

:
void initialize() throw ( ConfigError );

## getLog()

Log* FIX::Initiator::getLog | ( |  | ) |

inline

Definition at line 107 of file Initiator.h.

{};

## getMessageStoreFactory()

MessageStoreFactory& FIX::Initiator::getMessageStoreFactory | ( |  | ) |

inline

Definition at line 104 of file Initiator.h.

:
void initialize() throw ( ConfigError );

## getSession() [1/2]

Session * FIX::Initiator::getSession | ( | const SessionID & | sessionID | ) | const

Definition at line 127 of file Initiator.cpp.

{
Locker l(m_mutex);

## getSession() [2/2]

Session * FIX::Initiator::getSession | ( | const SessionID & | sessionID,
|  | Responder & | responder
| ) |  |

Definition at line 115 of file Initiator.cpp.

{
try
{
return &m_settings.get( sessionID );
}
catch( ConfigError& )

## getSessions()

const std::set<SessionID>& FIX::Initiator::getSessions | ( |  | ) | const

inline

Definition at line 93 of file Initiator.h.

:
void setPending( const SessionID& );

## getSessionSettings()

const Dictionary *const FIX::Initiator::getSessionSettings | ( | const SessionID & | sessionID | ) | const

Definition at line 136 of file Initiator.cpp.

{
Session* pSession = Session::lookupSession( *i );
if ( pSession->isEnabled() && pSession->isSessionTime(UtcTimeStamp()) )
doConnect( *i, m_settings.get( *i ));
}
}
void Initiator::setPending( const SessionID& sessionID )
{

References doConnect(), FIX::SessionSettings::get(), FIX::Session::isEnabled(), FIX::Session::isSessionTime(), FIX::Session::lookupSession(), and m_settings.

## has()

bool FIX::Initiator::has | ( | const SessionID & | id | ) |

inline

Definition at line 97 of file Initiator.h.

:
void initialize() throw ( ConfigError );

## initialize()

void FIX::Initiator::initialize | ( |  | ) |
throw | ( | ConfigError
| ) |  |

private

Definition at line 80 of file Initiator.cpp.

{
Sessions::iterator i;
for ( i = m_sessions.begin(); i != m_sessions.end(); ++i )
delete i->second;
if( m_pLogFactory && m_pLog )
m_pLogFactory->destroy( m_pLog );
}
Session* Initiator::getSession( const SessionID& sessionID,
Responder& responder )
{
Sessions::iterator i = m_sessions.find( sessionID );
if ( i != m_sessions.end() )
{

## isConnected()

bool FIX::Initiator::isConnected | ( | const SessionID & | sessionID | ) |

protected

Definition at line 195 of file Initiator.cpp.

## isDisconnected()

bool FIX::Initiator::isDisconnected | ( | const SessionID & | sessionID | ) |

protected

Definition at line 201 of file Initiator.cpp.

{
m_stop = false;

References m_settings, m_stop, and onConfigure().

## isLoggedOn()

bool FIX::Initiator::isLoggedOn | ( |  | ) |

Check to see if any sessions are currently logged on.

Definition at line 292 of file Initiator.cpp.

## isPending()

bool FIX::Initiator::isPending | ( | const SessionID & | sessionID | ) |

protected

Definition at line 189 of file Initiator.cpp.

{
m_stop = false;
onConfigure( m_settings );

References m_settings, m_stop, onConfigure(), and onInitialize().

## isStopped()

bool FIX::Initiator::isStopped | ( |  | ) |

inline

Definition at line 100 of file Initiator.h.

:
void initialize() throw ( ConfigError );

## onConfigure()

virtual void FIX::Initiator::onConfigure | ( | const SessionSettings & |  | ) |
throw | ( | ConfigError
| ) |  |

inline private virtual

Implemented to configure acceptor.

Reimplemented in FIX::SocketInitiator, and FIX::ThreadedSocketInitiator.

Definition at line 127 of file Initiator.h.

:
SessionSettings m_settings;

Referenced by isDisconnected(), and isPending().

## onInitialize()

virtual void FIX::Initiator::onInitialize | ( | const SessionSettings & |  | ) |
throw | ( | RuntimeError
| ) |  |

inline private virtual

Implemented to initialize initiator.

Reimplemented in FIX::SocketInitiator, and FIX::ThreadedSocketInitiator.

Definition at line 129 of file Initiator.h.

:
SessionSettings m_settings;

Referenced by isPending().

## onPoll()

virtual bool FIX::Initiator::onPoll | ( | double | timeout | ) |

private pure virtual

Implemented to connect and poll for events.

Implemented in FIX::SocketInitiator, and FIX::ThreadedSocketInitiator.

## onStart()

virtual void FIX::Initiator::onStart | ( |  | ) |

private pure virtual

Implemented to start connecting to targets.

Implemented in FIX::SocketInitiator, and FIX::ThreadedSocketInitiator.

## onStop()

virtual void FIX::Initiator::onStop | ( |  | ) |

private pure virtual

Implemented to stop a running initiator.

Implemented in FIX::SocketInitiator, and FIX::ThreadedSocketInitiator.

## poll()

bool FIX::Initiator::poll | ( | double | timeout = `0.0` | ) |
throw | ( | ConfigError,
|  | RuntimeError
| ) |  |

Poll the initiator.

Definition at line 229 of file Initiator.cpp.

{
Locker l(m_mutex);
connected = m_connected;
}
SessionIDs::iterator i = connected.begin();

## setConnected()

void FIX::Initiator::setConnected | ( | const SessionID & | sessionID | ) |

protected

Definition at line 171 of file Initiator.cpp.

{
Locker l(m_mutex);
return m_pending.find( sessionID ) != m_pending.end();
}
bool Initiator::isConnected( const SessionID& sessionID )

References m_mutex, and m_pending.

## setDisconnected()

void FIX::Initiator::setDisconnected | ( | const SessionID & | sessionID | ) |

protected

Definition at line 180 of file Initiator.cpp.

{
Locker l(m_mutex);
return m_disconnected.find( sessionID ) != m_disconnected.end();

Referenced by FIX::SocketInitiator::onDisconnect().

## setPending()

void FIX::Initiator::setPending | ( | const SessionID & | sessionID | ) |

protected

Definition at line 162 of file Initiator.cpp.

{
Locker l(m_mutex);
m_pending.erase( sessionID );
m_connected.erase( sessionID );
m_disconnected.insert( sessionID );

References m_connected, m_disconnected, m_mutex, and m_pending.

## start()

void FIX::Initiator::start | ( |  | ) |
throw | ( | ConfigError,
|  | RuntimeError
| ) |  |

Start initiator.

Definition at line 207 of file Initiator.cpp.

{
if( m_firstPoll )
{
m_stop = false;
onConfigure( m_settings );

Referenced by FIX::ThreadedSocketInitiator::onPoll().

## startThread()

THREAD_PROC FIX::Initiator::startThread | ( | void * | p | ) |

static private

Definition at line 306 of file Initiator.cpp.

## stop()

void FIX::Initiator::stop | ( | bool | force = `false` | ) |

Stop initiator.

Definition at line 243 of file Initiator.cpp.

{
Session* pSession = Session::lookupSession(*i);
if( pSession && pSession->isEnabled() )
{
enabledSessions.push_back( pSession );
pSession->logout();
}
}
if( !force )
{
for ( int second = 1; second <= 10 && isLoggedOn(); ++second )
process_sleep( 1 );
}
{
Locker l(m_mutex);
for ( i = connected.begin(); i != connected.end(); ++i )
setDisconnected( Session::lookupSession(*i)->getSessionID() );
}
m_stop = true;
onStop();
if( m_threadid )
thread_join( m_threadid );
m_threadid = 0;
std::vector<Session*>::iterator session = enabledSessions.begin();
for( ; session != enabledSessions.end(); ++session )
(*session)->logon();
}
bool Initiator::isLoggedOn()
{
Locker l(m_mutex);
SessionIDs connected = m_connected;
SessionIDs::iterator i = connected.begin();
for ( ; i != connected.end(); ++i )
{
if( Session::lookupSession(*i)->isLoggedOn() )
return true;
}
return false;
}
THREAD_PROC Initiator::startThread( void* p )
{

References FIX::Session::isEnabled(), FIX::Session::logout(), and FIX::Session::lookupSession().

## Member Data Documentation

## m_application

Application& FIX::Initiator::m_application

private

Definition at line 153 of file Initiator.h.

## m_connected

SessionIDs FIX::Initiator::m_connected

private

Definition at line 148 of file Initiator.h.

Referenced by setPending().

## m_disconnected

SessionIDs FIX::Initiator::m_disconnected

private

Definition at line 149 of file Initiator.h.

Referenced by setPending().

## m_firstPoll

bool FIX::Initiator::m_firstPoll

private

Definition at line 161 of file Initiator.h.

## m_messageStoreFactory

MessageStoreFactory& FIX::Initiator::m_messageStoreFactory

private

Definition at line 154 of file Initiator.h.

## m_mutex

Mutex FIX::Initiator::m_mutex

private

Definition at line 163 of file Initiator.h.

Referenced by setConnected(), and setPending().

## m_nullLog

NullLog FIX::Initiator::m_nullLog

private

Definition at line 160 of file Initiator.h.

## m_pending

SessionIDs FIX::Initiator::m_pending

private

Definition at line 147 of file Initiator.h.

Referenced by setConnected(), and setPending().

## m_pLog

Log* FIX::Initiator::m_pLog

private

Definition at line 159 of file Initiator.h.

## m_pLogFactory

LogFactory* FIX::Initiator::m_pLogFactory

private

Definition at line 158 of file Initiator.h.

## m_sessionIDs

SessionIDs FIX::Initiator::m_sessionIDs

private

Definition at line 146 of file Initiator.h.

## m_sessions

Sessions FIX::Initiator::m_sessions

private

Definition at line 145 of file Initiator.h.

## m_sessionState

SessionState FIX::Initiator::m_sessionState

private

Definition at line 150 of file Initiator.h.

## m_settings

SessionSettings FIX::Initiator::m_settings

protected

Definition at line 156 of file Initiator.h.

Referenced by getSessionSettings(), isDisconnected(), and isPending().

## m_stop

bool FIX::Initiator::m_stop

private

Definition at line 162 of file Initiator.h.

Referenced by isDisconnected(), and isPending().

## m_threadid

thread_id FIX::Initiator::m_threadid

private

Definition at line 152 of file Initiator.h.

The documentation for this class was generated from the following files:

- Initiator.h
- Initiator.cpp

FIX::Initiator::SessionIDs
std::set< SessionID > SessionIDs
Definition: Initiator.h:141
FIX::Initiator::m_stop
bool m_stop
Definition: Initiator.h:162
FIX::Initiator::m_disconnected
SessionIDs m_disconnected
Definition: Initiator.h:149
FIX::Session::lookupSession
static Session * lookupSession(const SessionID &)
Definition: Session.cpp:1513
FIX::Initiator::m_pLogFactory
LogFactory * m_pLogFactory
Definition: Initiator.h:158
FIX::Dictionary::getString
std::string getString(const std::string &, bool capitalize=false) const
Get a value as a string.
Definition: Dictionary.cpp:49
FIX::Initiator::getSession
Session * getSession(const SessionID &sessionID, Responder &)
Definition: Initiator.cpp:115
FIX::Initiator::m_sessions
Sessions m_sessions
Definition: Initiator.h:145
FIX::Session::getSessionID
const SessionID & getSessionID() const
Definition: Session.h:109
FIX::Initiator::m_firstPoll
bool m_firstPoll
Definition: Initiator.h:161
FIX::Initiator::m_pLog
Log * m_pLog
Definition: Initiator.h:159
FIX::Initiator::isLoggedOn
bool isLoggedOn()
Check to see if any sessions are currently logged on.
Definition: Initiator.cpp:292
FIX::Initiator::onStop
virtual void onStop()=0
Implemented to stop a running initiator.
FIX::Initiator::m_mutex
Mutex m_mutex
Definition: Initiator.h:163
FIX::Initiator::m_settings
SessionSettings m_settings
Definition: Initiator.h:156
FIX::TYPE::UtcTimeStamp
@ UtcTimeStamp
Definition: FieldTypes.h:940
THREAD_PROC
#define THREAD_PROC
Definition: Utility.h:184
FIX::LogFactory::destroy
virtual void destroy(Log *)=0
FIX::Initiator::setDisconnected
void setDisconnected(const SessionID &)
Definition: Initiator.cpp:180
FIX::Initiator::m_messageStoreFactory
MessageStoreFactory & m_messageStoreFactory
Definition: Initiator.h:154
FIX::Initiator::m_sessionIDs
SessionIDs m_sessionIDs
Definition: Initiator.h:146
FIX::Session::isLoggedOn
bool isLoggedOn()
Definition: Session.h:99
FIX::Initiator::m_application
Application & m_application
Definition: Initiator.h:153
FIX::process_sleep
void process_sleep(double s)
Definition: Utility.cpp:483
FIX::Initiator::setPending
void setPending(const SessionID &)
Definition: Initiator.cpp:162
FIX::Initiator::initialize
void initialize()
Definition: Initiator.cpp:80
FIX::Initiator::m_threadid
thread_id m_threadid
Definition: Initiator.h:152
FIX::thread_join
void thread_join(thread_id thread)
Definition: Utility.cpp:454
FIX::Initiator::doConnect
virtual void doConnect(const SessionID &, const Dictionary &)=0
Implemented to connect a session to its target.
FIX::Initiator::m_pending
SessionIDs m_pending
Definition: Initiator.h:147
FIX::Initiator::startThread
static THREAD_PROC startThread(void *p)
Definition: Initiator.cpp:306
FIX::Initiator::m_connected
SessionIDs m_connected
Definition: Initiator.h:148
FIX::SessionSettings::get
const Dictionary & get(const SessionID &) const
Get a dictionary for a session.
Definition: SessionSettings.cpp:144
FIX::Initiator::onConfigure
virtual void onConfigure(const SessionSettings &)
Implemented to configure acceptor.
Definition: Initiator.h:127
FIX::Initiator::isConnected
bool isConnected(const SessionID &)
Definition: Initiator.cpp:195