Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
FIX::Session Class Reference

Maintains the state and implements the logic of a FIX session. More...

#include <Session.h>

Collaboration diagram for FIX::Session:
Collaboration graph
[legend]

Public Member Functions

 Session (Application &, MessageStoreFactory &, const SessionID &, const DataDictionaryProvider &, const TimeRange &, int heartBtInt, LogFactory *pLogFactory)
 
virtual ~Session ()
 
void logon ()
 
void logout (const std::string &reason="")
 
bool isEnabled ()
 
bool sentLogon ()
 
bool sentLogout ()
 
bool receivedLogon ()
 
bool isLoggedOn ()
 
void reset () throw ( IOException )
 
void refresh () throw ( IOException )
 
void setNextSenderMsgSeqNum (int num) throw ( IOException )
 
void setNextTargetMsgSeqNum (int num) throw ( IOException )
 
const SessionIDgetSessionID () const
 
void setDataDictionaryProvider (const DataDictionaryProvider &dataDictionaryProvider)
 
const DataDictionaryProvidergetDataDictionaryProvider () const
 
bool isSessionTime (const UtcTimeStamp &time)
 
bool isLogonTime (const UtcTimeStamp &time)
 
bool isInitiator ()
 
bool isAcceptor ()
 
const TimeRangegetLogonTime ()
 
void setLogonTime (const TimeRange &value)
 
const std::string & getSenderDefaultApplVerID ()
 
void setSenderDefaultApplVerID (const std::string &senderDefaultApplVerID)
 
const std::string & getTargetDefaultApplVerID ()
 
void setTargetDefaultApplVerID (const std::string &targetDefaultApplVerID)
 
bool getSendRedundantResendRequests ()
 
void setSendRedundantResendRequests (bool value)
 
bool getCheckCompId ()
 
void setCheckCompId (bool value)
 
bool getCheckLatency ()
 
void setCheckLatency (bool value)
 
int getMaxLatency ()
 
void setMaxLatency (int value)
 
int getLogonTimeout ()
 
void setLogonTimeout (int value)
 
int getLogoutTimeout ()
 
void setLogoutTimeout (int value)
 
bool getResetOnLogon ()
 
void setResetOnLogon (bool value)
 
bool getResetOnLogout ()
 
void setResetOnLogout (bool value)
 
bool getResetOnDisconnect ()
 
void setResetOnDisconnect (bool value)
 
bool getRefreshOnLogon ()
 
void setRefreshOnLogon (bool value)
 
bool getMillisecondsInTimeStamp ()
 
void setMillisecondsInTimeStamp (bool value)
 
int getTimestampPrecision ()
 
void setTimestampPrecision (int precision)
 
bool getPersistMessages ()
 
void setPersistMessages (bool value)
 
bool getValidateLengthAndChecksum ()
 
void setValidateLengthAndChecksum (bool value)
 
void setResponder (Responder *pR)
 
bool send (Message &)
 
void next ()
 
void next (const UtcTimeStamp &timeStamp)
 
void next (const std::string &, const UtcTimeStamp &timeStamp, bool queued=false)
 
void next (const Message &, const UtcTimeStamp &timeStamp, bool queued=false)
 
void disconnect ()
 
int getExpectedSenderNum ()
 
int getExpectedTargetNum ()
 
LoggetLog ()
 
const MessageStoregetStore ()
 
const HeartBtIntgetHeartBtInt () const
 

Static Public Member Functions

static bool sendToTarget (Message &message, const std::string &qualifier="") throw ( SessionNotFound )
 
static bool sendToTarget (Message &message, const SessionID &sessionID) throw ( SessionNotFound )
 
static bool sendToTarget (Message &, const SenderCompID &senderCompID, const TargetCompID &targetCompID, const std::string &qualifier="") throw ( SessionNotFound )
 
static bool sendToTarget (Message &message, const std::string &senderCompID, const std::string &targetCompID, const std::string &qualifier="") throw ( SessionNotFound )
 
static std::set< SessionIDgetSessions ()
 
static bool doesSessionExist (const SessionID &)
 
static SessionlookupSession (const SessionID &)
 
static SessionlookupSession (const std::string &, bool reverse=false)
 
static bool isSessionRegistered (const SessionID &)
 
static SessionregisterSession (const SessionID &)
 
static void unregisterSession (const SessionID &)
 
static size_t numSessions ()
 

Private Types

typedef std::map< SessionID, Session * > Sessions
 
typedef std::set< SessionIDSessionIDs
 

Private Member Functions

bool send (const std::string &)
 
bool sendRaw (Message &, int msgSeqNum=0)
 
bool resend (Message &message)
 
void persist (const Message &, const std::string &) throw ( IOException )
 
void insertSendingTime (Header &)
 
void insertOrigSendingTime (Header &, const UtcTimeStamp &when=UtcTimeStamp())
 
void fill (Header &)
 
bool isGoodTime (const SendingTime &sendingTime)
 
bool checkSessionTime (const UtcTimeStamp &timeStamp)
 
bool isTargetTooHigh (const MsgSeqNum &msgSeqNum)
 
bool isTargetTooLow (const MsgSeqNum &msgSeqNum)
 
bool isCorrectCompID (const SenderCompID &senderCompID, const TargetCompID &targetCompID)
 
bool shouldSendReset ()
 
bool validLogonState (const MsgType &msgType)
 
void fromCallback (const MsgType &msgType, const Message &msg, const SessionID &sessionID)
 
void doBadTime (const Message &msg)
 
void doBadCompID (const Message &msg)
 
bool doPossDup (const Message &msg)
 
bool doTargetTooLow (const Message &msg)
 
void doTargetTooHigh (const Message &msg)
 
void nextQueued (const UtcTimeStamp &timeStamp)
 
bool nextQueued (int num, const UtcTimeStamp &timeStamp)
 
void nextLogon (const Message &, const UtcTimeStamp &timeStamp)
 
void nextHeartbeat (const Message &, const UtcTimeStamp &timeStamp)
 
void nextTestRequest (const Message &, const UtcTimeStamp &timeStamp)
 
void nextLogout (const Message &, const UtcTimeStamp &timeStamp)
 
void nextReject (const Message &, const UtcTimeStamp &timeStamp)
 
void nextSequenceReset (const Message &, const UtcTimeStamp &timeStamp)
 
void nextResendRequest (const Message &, const UtcTimeStamp &timeStamp)
 
void generateLogon ()
 
void generateLogon (const Message &)
 
void generateResendRequest (const BeginString &, const MsgSeqNum &)
 
void generateSequenceReset (int, int)
 
void generateHeartbeat ()
 
void generateHeartbeat (const Message &)
 
void generateTestRequest (const std::string &)
 
void generateReject (const Message &, int err, int field=0)
 
void generateReject (const Message &, const std::string &)
 
void generateBusinessReject (const Message &, int err, int field=0)
 
void generateLogout (const std::string &text="")
 
void populateRejectReason (Message &, int field, const std::string &)
 
void populateRejectReason (Message &, const std::string &)
 
bool verify (const Message &msg, bool checkTooHigh=true, bool checkTooLow=true)
 
bool set (int s, const Message &m)
 
bool get (int s, Message &m) const
 
MessagenewMessage (const std::string &msgType) const
 

Static Private Member Functions

static bool addSession (Session &)
 
static void removeSession (Session &)
 

Private Attributes

Applicationm_application
 
SessionID m_sessionID
 
TimeRange m_sessionTime
 
TimeRange m_logonTime
 
std::string m_senderDefaultApplVerID
 
std::string m_targetDefaultApplVerID
 
bool m_sendRedundantResendRequests
 
bool m_checkCompId
 
bool m_checkLatency
 
int m_maxLatency
 
bool m_resetOnLogon
 
bool m_resetOnLogout
 
bool m_resetOnDisconnect
 
bool m_refreshOnLogon
 
int m_timestampPrecision
 
bool m_persistMessages
 
bool m_validateLengthAndChecksum
 
SessionState m_state
 
DataDictionaryProvider m_dataDictionaryProvider
 
MessageStoreFactorym_messageStoreFactory
 
LogFactorym_pLogFactory
 
Responderm_pResponder
 
Mutex m_mutex
 

Static Private Attributes

static Sessions s_sessions
 
static SessionIDs s_sessionIDs
 
static Sessions s_registered
 
static Mutex s_mutex
 

Detailed Description

Maintains the state and implements the logic of a FIX session.

Definition at line 45 of file Session.h.

Member Typedef Documentation

◆ SessionIDs

Definition at line 234 of file Session.h.

◆ Sessions

Definition at line 233 of file Session.h.

Constructor & Destructor Documentation

◆ Session()

FIX::Session::Session ( Application application,
MessageStoreFactory messageStoreFactory,
const SessionID sessionID,
const DataDictionaryProvider dataDictionaryProvider,
const TimeRange sessionTime,
int  heartBtInt,
LogFactory pLogFactory 
)

Definition at line 41 of file Session.cpp.

54 m_checkCompId( true ),
55 m_checkLatency( true ),
56 m_maxLatency( 120 ),
57 m_resetOnLogon( false ),
58 m_resetOnLogout( false ),
59 m_resetOnDisconnect( false ),
60 m_refreshOnLogon( false ),
62 m_persistMessages( true ),
67 m_pResponder( 0 )
68{
69 m_state.heartBtInt( heartBtInt );
70 m_state.initiate( heartBtInt != 0 );
72 if ( m_pLogFactory )
74
76 reset();
77
78 addSession( *this );
80 m_state.onEvent( "Created session" );
81}
virtual void onCreate(const SessionID &)=0
Notification of a session begin created.
virtual Log * create()=0
virtual MessageStore * create(const SessionID &)=0
MessageStoreFactory & m_messageStoreFactory
Definition Session.h:339
bool m_resetOnLogout
Definition Session.h:330
int m_maxLatency
Definition Session.h:328
LogFactory * m_pLogFactory
Definition Session.h:340
bool m_checkLatency
Definition Session.h:327
Application & m_application
Definition Session.h:318
SessionState m_state
Definition Session.h:337
bool m_refreshOnLogon
Definition Session.h:332
bool m_persistMessages
Definition Session.h:334
Responder * m_pResponder
Definition Session.h:341
DataDictionaryProvider m_dataDictionaryProvider
Definition Session.h:338
bool checkSessionTime(const UtcTimeStamp &timeStamp)
Definition Session.h:255
bool m_sendRedundantResendRequests
Definition Session.h:325
SessionID m_sessionID
Definition Session.h:319
void reset()
Definition Session.h:66
std::string m_targetDefaultApplVerID
Definition Session.h:324
std::string m_senderDefaultApplVerID
Definition Session.h:323
int m_timestampPrecision
Definition Session.h:333
static bool addSession(Session &)
Definition Session.cpp:1559
bool m_resetOnDisconnect
Definition Session.h:331
bool m_validateLengthAndChecksum
Definition Session.h:335
bool m_resetOnLogon
Definition Session.h:329
TimeRange m_sessionTime
Definition Session.h:320
bool m_checkCompId
Definition Session.h:326
bool set(int s, const Message &m)
TimeRange m_logonTime
Definition Session.h:321
MessageStore * store()
bool initiate() const
void onEvent(const std::string &string)
void heartBtInt(const HeartBtInt &value)

References addSession(), checkSessionTime(), FIX::LogFactory::create(), FIX::MessageStoreFactory::create(), FIX::SessionState::heartBtInt(), FIX::SessionState::initiate(), FIX::SessionState::log(), m_application, m_messageStoreFactory, m_pLogFactory, m_sessionID, m_state, FIX::Application::onCreate(), FIX::SessionState::onEvent(), reset(), and FIX::SessionState::store().

◆ ~Session()

FIX::Session::~Session ( )
virtual

Member Function Documentation

◆ addSession()

bool FIX::Session::addSession ( Session s)
staticprivate

Definition at line 1559 of file Session.cpp.

1560{
1561 Locker locker( s_mutex );
1562 Sessions::iterator it = s_sessions.find( s.m_sessionID );
1563 if ( it == s_sessions.end() )
1564 {
1565 s_sessions[ s.m_sessionID ] = &s;
1566 s_sessionIDs.insert( s.m_sessionID );
1567 return true;
1568 }
1569 else
1570 return false;
1571}
static Mutex s_mutex
Definition Session.h:347
static SessionIDs s_sessionIDs
Definition Session.h:345
static Sessions s_sessions
Definition Session.h:344

References s_mutex, s_sessionIDs, s_sessions, and set().

Referenced by Session().

◆ checkSessionTime()

bool FIX::Session::checkSessionTime ( const UtcTimeStamp timeStamp)
inlineprivate

Definition at line 255 of file Session.h.

256 {
259 }
UtcTimeStamp getCreationTime() const
static bool isInSameRange(const UtcTimeOnly &start, const UtcTimeOnly &end, const DateTime &time1, const DateTime &time2)
Definition TimeRange.h:76

References FIX::SessionState::getCreationTime(), FIX::TimeRange::isInSameRange(), m_sessionTime, m_state, and set().

Referenced by next(), next(), Session(), and setResponder().

◆ disconnect()

void FIX::Session::disconnect ( )

Definition at line 613 of file Session.cpp.

614{
615 Locker l(m_mutex);
616
617 if ( m_pResponder )
618 {
619 m_state.onEvent( "Disconnecting" );
620
622 m_pResponder = 0;
623 }
624
626 {
627 m_state.receivedLogon( false );
628 m_state.sentLogon( false );
630 }
631
632 m_state.sentLogout( false );
633 m_state.receivedReset( false );
634 m_state.sentReset( false );
638 m_state.reset();
639
640 m_state.resendRange( 0, 0 );
641}
virtual void onLogout(const SessionID &)=0
Notification of a session logging off or disconnecting.
virtual void disconnect()=0
Mutex m_mutex
Definition Session.h:342
bool sentLogon() const
bool sentReset() const
bool sentLogout() const
bool receivedLogon() const
std::string logoutReason() const
bool receivedReset() const
ResendRange resendRange() const

References FIX::SessionState::clearQueue(), FIX::Responder::disconnect(), FIX::SessionState::logoutReason(), m_application, m_mutex, m_pResponder, m_resetOnDisconnect, m_sessionID, m_state, FIX::SessionState::onEvent(), FIX::Application::onLogout(), FIX::SessionState::receivedLogon(), FIX::SessionState::receivedReset(), FIX::SessionState::resendRange(), FIX::SessionState::reset(), FIX::SessionState::sentLogon(), FIX::SessionState::sentLogout(), FIX::SessionState::sentReset(), and set().

Referenced by next(), next(), next(), nextLogon(), nextLogout(), FIX::SocketInitiator::onDisconnect(), FIX::SocketAcceptor::onDisconnect(), FIX::ThreadedSocketConnection::read(), reset(), and verify().

◆ doBadCompID()

void FIX::Session::doBadCompID ( const Message msg)
private

Definition at line 1152 of file Session.cpp.

1153{
1156}
void generateLogout(const std::string &text="")
Definition Session.cpp:996
void generateReject(const Message &, int err, int field=0)
Definition Session.cpp:805

References generateLogout(), generateReject(), and set().

Referenced by verify().

◆ doBadTime()

void FIX::Session::doBadTime ( const Message msg)
private

Definition at line 1146 of file Session.cpp.

References generateLogout(), generateReject(), and set().

Referenced by verify().

◆ doesSessionExist()

bool FIX::Session::doesSessionExist ( const SessionID sessionID)
static

Definition at line 1490 of file Session.cpp.

1491{
1492 Locker locker( s_mutex );
1493 return s_sessions.end() != s_sessions.find( sessionID );
1494}

References s_mutex, s_sessions, and set().

◆ doPossDup()

bool FIX::Session::doPossDup ( const Message msg)
private

Definition at line 1158 of file Session.cpp.

1159{
1160 const Header & header = msg.getHeader();
1164
1165 header.getField( msgType );
1166 header.getField( sendingTime );
1167
1169 {
1170 if ( !header.getFieldIfSet( origSendingTime ) )
1171 {
1173 return false;
1174 }
1175
1177 {
1180 return false;
1181 }
1182 }
1183 return true;
1184}

References generateLogout(), generateReject(), FIX::FieldMap::getField(), FIX::FieldMap::getFieldIfSet(), and set().

Referenced by doTargetTooLow().

◆ doTargetTooHigh()

void FIX::Session::doTargetTooHigh ( const Message msg)
private

Definition at line 1206 of file Session.cpp.

1207{
1208 const Header & header = msg.getHeader();
1211 header.getField( beginString );
1212 header.getField( msgSeqNum );
1213
1214 m_state.onEvent( "MsgSeqNum too high, expecting "
1216 + " but received "
1218
1220
1221 if( m_state.resendRequested() )
1222 {
1224
1226 {
1227 m_state.onEvent ("Already sent ResendRequest FROM: " +
1228 IntConvertor::convert (range.first) + " TO: " +
1229 IntConvertor::convert (range.second) +
1230 ". Not sending another.");
1231 return;
1232 }
1233 }
1234
1236}
void generateResendRequest(const BeginString &, const MsgSeqNum &)
Definition Session.cpp:718
int getExpectedTargetNum()
Definition Session.h:225
bool resendRequested() const
std::pair< int, int > ResendRange
void queue(int msgSeqNum, const Message &message)
static std::string convert(signed_int value)

References FIX::IntConvertor::convert(), generateResendRequest(), getExpectedTargetNum(), FIX::FieldMap::getField(), m_sendRedundantResendRequests, m_state, FIX::SessionState::onEvent(), FIX::SessionState::queue(), FIX::SessionState::resendRange(), FIX::SessionState::resendRequested(), and set().

Referenced by nextLogon(), and verify().

◆ doTargetTooLow()

bool FIX::Session::doTargetTooLow ( const Message msg)
private

Definition at line 1186 of file Session.cpp.

1187{
1188 const Header & header = msg.getHeader();
1189 PossDupFlag possDupFlag(false);
1191 header.getFieldIfSet(possDupFlag);
1192 header.getField( msgSeqNum );
1193
1194 if ( !possDupFlag )
1195 {
1196 std::stringstream stream;
1197 stream << "MsgSeqNum too low, expecting " << getExpectedTargetNum()
1198 << " but received " << msgSeqNum;
1199 generateLogout( stream.str() );
1200 throw std::logic_error( stream.str() );
1201 }
1202
1203 return doPossDup( msg );
1204}
bool doPossDup(const Message &msg)
Definition Session.cpp:1158

References doPossDup(), generateLogout(), getExpectedTargetNum(), FIX::FieldMap::getField(), FIX::FieldMap::getFieldIfSet(), and set().

Referenced by verify().

◆ fill()

void FIX::Session::fill ( Header header)
private

◆ fromCallback()

void FIX::Session::fromCallback ( const MsgType msgType,
const Message msg,
const SessionID sessionID 
)
private

Definition at line 1137 of file Session.cpp.

1139{
1142 else
1144}
virtual void fromApp(const Message &, const SessionID &)=0
Notification of app message being received from target.
virtual void fromAdmin(const Message &, const SessionID &)=0
Notification of admin message being received from target.
static bool isAdminMsgType(const MsgType &msgType)
Definition Message.h:300

References FIX::Application::fromAdmin(), FIX::Application::fromApp(), FIX::Message::isAdminMsgType(), m_application, m_sessionID, and set().

Referenced by verify().

◆ generateBusinessReject()

void FIX::Session::generateBusinessReject ( const Message message,
int  err,
int  field = 0 
)
private

Definition at line 931 of file Session.cpp.

932{
934 Message & reject = *pMsg;
935
936 reject.getHeader().setField( MsgType( MsgType_BusinessMessageReject ) );
937 if( m_sessionID.isFIXT() )
939 fill( reject.getHeader() );
942 message.getHeader().getField( msgType );
943 message.getHeader().getField( msgSeqNum );
944 reject.setField( RefMsgType( msgType ) );
945 reject.setField( RefSeqNum( msgSeqNum ) );
946 reject.setField( BusinessRejectReason( err ) );
948
949 const char* reason = 0;
950 switch ( err )
951 {
954 break;
957 break;
960 break;
963 break;
966 break;
969 break;
972 break;
975 break;
976 };
977
978 if ( reason && field )
979 {
981 m_state.onEvent( "Message " + msgSeqNum.getString() + " Rejected: "
982 + reason + ":" + IntConvertor::convert( field ) );
983 }
984 else if ( reason )
985 {
987 m_state.onEvent( "Message " + msgSeqNum.getString()
988 + " Rejected: " + reason );
989 }
990 else
991 m_state.onEvent( "Message " + msgSeqNum.getString() + " Rejected" );
992
993 sendRaw( reject );
994}
void populateRejectReason(Message &, int field, const std::string &)
Definition Session.cpp:1009
void fill(Header &)
Definition Session.cpp:114
bool sendRaw(Message &, int msgSeqNum=0)
Definition Session.cpp:530
Message * newMessage(const std::string &msgType) const
Definition Session.cpp:492
const bool isFIXT() const
Definition SessionID.h:61
void incrNextTargetMsgSeqNum()
const char BusinessRejectReason_CONDITIONALLY_REQUIRED_FIELD_MISSING_TEXT[]
Definition Values.h:58
const char BusinessRejectReason_NOT_AUTHORIZED_TEXT[]
Definition Values.h:59
const char BusinessRejectReason_APPLICATION_NOT_AVAILABLE_TEXT[]
Definition Values.h:57
const char BusinessRejectReason_UNSUPPORTED_MESSAGE_TYPE_TEXT[]
Definition Values.h:56
const char BusinessRejectReason_DELIVERTO_FIRM_NOT_AVAILABLE_AT_THIS_TIME_TEXT[]
Definition Values.h:60
const char BusinessRejectReason_UNKNOWN_ID_TEXT[]
Definition Values.h:54
const char BusinessRejectReason_OTHER_TEXT[]
Definition Values.h:53
const char BusinessRejectReason_UNKNOWN_SECURITY_TEXT[]
Definition Values.h:55

References FIX::BusinessRejectReason_APPLICATION_NOT_AVAILABLE_TEXT, FIX::BusinessRejectReason_CONDITIONALLY_REQUIRED_FIELD_MISSING_TEXT, FIX::BusinessRejectReason_DELIVERTO_FIRM_NOT_AVAILABLE_AT_THIS_TIME_TEXT, FIX::BusinessRejectReason_NOT_AUTHORIZED_TEXT, FIX::BusinessRejectReason_OTHER_TEXT, FIX::BusinessRejectReason_UNKNOWN_ID_TEXT, FIX::BusinessRejectReason_UNKNOWN_SECURITY_TEXT, FIX::BusinessRejectReason_UNSUPPORTED_MESSAGE_TYPE_TEXT, FIX::IntConvertor::convert(), fill(), FIX::Message::getHeader(), FIX::SessionState::incrNextTargetMsgSeqNum(), FIX::SessionID::isFIXT(), m_senderDefaultApplVerID, m_sessionID, m_state, newMessage(), FIX::SessionState::onEvent(), populateRejectReason(), sendRaw(), set(), and FIX::FieldMap::setField().

Referenced by next().

◆ generateHeartbeat() [1/2]

void FIX::Session::generateHeartbeat ( )
private

Definition at line 764 of file Session.cpp.

765{
767 Message & heartbeat = *pMsg;
768
769 heartbeat.getHeader().setField( MsgType( "0" ) );
770 fill( heartbeat.getHeader() );
772}

References fill(), FIX::Message::getHeader(), newMessage(), sendRaw(), set(), and FIX::FieldMap::setField().

Referenced by next(), and nextTestRequest().

◆ generateHeartbeat() [2/2]

void FIX::Session::generateHeartbeat ( const Message testRequest)
private

Definition at line 774 of file Session.cpp.

775{
777 Message & heartbeat = *pMsg;
778
779 heartbeat.getHeader().setField( MsgType( "0" ) );
780 fill( heartbeat.getHeader() );
781 try
782 {
784 testRequest.getField( testReqID );
785 heartbeat.setField( testReqID );
786 }
787 catch ( FieldNotFound& ) {}
788
790}

References fill(), FIX::FieldMap::getField(), FIX::Message::getHeader(), newMessage(), sendRaw(), set(), FIX::FieldMap::setField(), and FIX::FieldBase::setField().

◆ generateLogon() [1/2]

void FIX::Session::generateLogon ( )
private

Definition at line 673 of file Session.cpp.

674{
676 Message & logon = *pMsg;
677
678 logon.getHeader().setField( MsgType( "A" ) );
679 logon.setField( EncryptMethod( 0 ) );
680 logon.setField( m_state.heartBtInt() );
681 if( m_sessionID.isFIXT() )
683 if( m_refreshOnLogon )
684 refresh();
685 if( m_resetOnLogon )
686 m_state.reset();
687 if( shouldSendReset() )
688 logon.setField( ResetSeqNumFlag(true) );
689
690 fill( logon.getHeader() );
693 m_state.testRequest( 0 );
694 m_state.sentLogon( true );
695 sendRaw( logon );
696}
bool shouldSendReset()
Definition Session.cpp:1106
void refresh()
Definition Session.h:68
void logon()
Definition Session.h:55
int testRequest() const
void lastReceivedTime(const UtcTimeStamp &value)

References fill(), FIX::Message::getHeader(), FIX::SessionState::heartBtInt(), FIX::SessionID::isFIXT(), FIX::SessionState::lastReceivedTime(), logon(), m_refreshOnLogon, m_resetOnLogon, m_senderDefaultApplVerID, m_sessionID, m_state, newMessage(), refresh(), FIX::SessionState::reset(), sendRaw(), FIX::SessionState::sentLogon(), set(), FIX::FieldMap::setField(), shouldSendReset(), and FIX::SessionState::testRequest().

Referenced by next(), and nextLogon().

◆ generateLogon() [2/2]

void FIX::Session::generateLogon ( const Message aLogon)
private

Definition at line 698 of file Session.cpp.

699{
701 Message & logon = *pMsg;
702
704 HeartBtInt heartBtInt;
705 logon.setField( EncryptMethod( 0 ) );
706 if( m_sessionID.isFIXT() )
708 if( m_state.receivedReset() )
709 logon.setField( ResetSeqNumFlag(true) );
710 aLogon.getField( heartBtInt );
711 logon.getHeader().setField( MsgType( "A" ) );
712 logon.setField( heartBtInt );
713 fill( logon.getHeader() );
714 sendRaw( logon );
715 m_state.sentLogon( true );
716}

References fill(), FIX::SessionID::isFIXT(), logon(), m_senderDefaultApplVerID, m_sessionID, m_state, newMessage(), FIX::SessionState::receivedReset(), sendRaw(), FIX::SessionState::sentLogon(), set(), and FIX::FieldMap::setField().

◆ generateLogout()

void FIX::Session::generateLogout ( const std::string &  text = "")
private

Definition at line 996 of file Session.cpp.

997{
999 Message & logout = *pMsg;
1000
1001 logout.getHeader().setField( MsgType( MsgType_Logout ) );
1002 fill( logout.getHeader() );
1003 if ( text.length() )
1004 logout.setField( Text( text ) );
1005 sendRaw( logout );
1006 m_state.sentLogout( true );
1007}
void logout(const std::string &reason="")
Definition Session.h:57

References fill(), FIX::Message::getHeader(), logout(), m_state, newMessage(), sendRaw(), FIX::SessionState::sentLogout(), set(), and FIX::FieldMap::setField().

Referenced by doBadCompID(), doBadTime(), doPossDup(), doTargetTooLow(), next(), next(), nextLogout(), and reset().

◆ generateReject() [1/2]

void FIX::Session::generateReject ( const Message message,
const std::string &  str 
)
private

Definition at line 902 of file Session.cpp.

903{
904 std::string beginString = m_sessionID.getBeginString();
905
907 Message & reject = *pMsg;
908
909 reject.getHeader().setField( MsgType( "3" ) );
910 reject.reverseRoute( message.getHeader() );
911 fill( reject.getHeader() );
912
915
916 message.getHeader().getField( msgType );
917 message.getHeader().getField( msgSeqNum );
919 reject.setField( RefMsgType( msgType ) );
920 reject.setField( RefSeqNum( msgSeqNum ) );
921
924
925 reject.setField( Text( str ) );
926 sendRaw( reject );
927 m_state.onEvent( "Message " + msgSeqNum.getString()
928 + " Rejected: " + str );
929}
const char BeginString_FIX42[]
Definition Values.h:34

References FIX::BeginString_FIX42, fill(), FIX::SessionID::getBeginString(), FIX::Message::getHeader(), FIX::SessionState::incrNextTargetMsgSeqNum(), m_sessionID, m_state, newMessage(), FIX::SessionState::onEvent(), sendRaw(), set(), and FIX::FieldMap::setField().

◆ generateReject() [2/2]

void FIX::Session::generateReject ( const Message message,
int  err,
int  field = 0 
)
private

Definition at line 805 of file Session.cpp.

806{
807 std::string beginString = m_sessionID.getBeginString();
808
810 Message & reject = *pMsg;
811
812 reject.getHeader().setField( MsgType( "3" ) );
813 reject.reverseRoute( message.getHeader() );
814 fill( reject.getHeader() );
815
818
819 message.getHeader().getField( msgType );
820 if( message.getHeader().getFieldIfSet( msgSeqNum ) )
821 {
822 if( msgSeqNum.getString() != "" )
823 reject.setField( RefSeqNum( msgSeqNum ) );
824 }
825
827 {
828 if( msgType.getString() != "" )
829 reject.setField( RefMsgType( msgType ) );
833 {
834 reject.setField( SessionRejectReason( err ) );
835 }
836 }
840
841 const char* reason = 0;
842 switch ( err )
843 {
846 break;
849 break;
852 break;
855 break;
858 break;
861 break;
864 break;
867 break;
870 break;
873 break;
876 break;
879 };
880
881 if ( reason && ( field || err == SessionRejectReason_INVALID_TAG_NUMBER ) )
882 {
884 m_state.onEvent( "Message " + msgSeqNum.getString() + " Rejected: "
885 + reason + ":" + IntConvertor::convert( field ) );
886 }
887 else if ( reason )
888 {
890 m_state.onEvent( "Message " + msgSeqNum.getString()
891 + " Rejected: " + reason );
892 }
893 else
894 m_state.onEvent( "Message " + msgSeqNum.getString() + " Rejected" );
895
896 if ( !m_state.receivedLogon() )
897 throw std::runtime_error( "Tried to send a reject while not logged on" );
898
899 sendRaw( reject );
900}
const char SessionRejectReason_INCORRECT_DATA_FORMAT_FOR_VALUE_TEXT[]
Definition Values.h:44
const char SessionRejectReason_COMPID_PROBLEM_TEXT[]
Definition Values.h:47
const char SessionRejectReason_INCORRECT_NUMINGROUP_COUNT_FOR_REPEATING_GROUP_TEXT[]
Definition Values.h:52
const char SessionRejectReason_TAG_SPECIFIED_WITHOUT_A_VALUE_TEXT[]
Definition Values.h:42
const char SessionRejectReason_REQUIRED_TAG_MISSING_TEXT[]
Definition Values.h:39
const char SessionRejectReason_INVALID_TAG_NUMBER_TEXT[]
Definition Values.h:38
const char SessionRejectReason_TAG_SPECIFIED_OUT_OF_REQUIRED_ORDER_TEXT[]
Definition Values.h:51
const char SessionRejectReason_INVALID_MSGTYPE_TEXT[]
Definition Values.h:49
const char SessionRejectReason_VALUE_IS_INCORRECT_TEXT[]
Definition Values.h:43
const char SessionRejectReason_TAG_APPEARS_MORE_THAN_ONCE_TEXT[]
Definition Values.h:50
const char SessionRejectReason_TAG_NOT_DEFINED_FOR_THIS_MESSAGE_TYPE_TEXT[]
Definition Values.h:40
const char SessionRejectReason_SENDINGTIME_ACCURACY_PROBLEM_TEXT[]
Definition Values.h:48

References FIX::BeginString_FIX42, FIX::IntConvertor::convert(), fill(), FIX::SessionID::getBeginString(), getExpectedTargetNum(), FIX::Message::getHeader(), FIX::SessionState::incrNextTargetMsgSeqNum(), m_sessionID, m_state, newMessage(), FIX::SessionState::onEvent(), populateRejectReason(), FIX::SessionState::receivedLogon(), sendRaw(), FIX::SessionRejectReason_COMPID_PROBLEM_TEXT, FIX::SessionRejectReason_INCORRECT_DATA_FORMAT_FOR_VALUE_TEXT, FIX::SessionRejectReason_INCORRECT_NUMINGROUP_COUNT_FOR_REPEATING_GROUP_TEXT, FIX::SessionRejectReason_INVALID_MSGTYPE_TEXT, FIX::SessionRejectReason_INVALID_TAG_NUMBER_TEXT, FIX::SessionRejectReason_REQUIRED_TAG_MISSING_TEXT, FIX::SessionRejectReason_SENDINGTIME_ACCURACY_PROBLEM_TEXT, FIX::SessionRejectReason_TAG_APPEARS_MORE_THAN_ONCE_TEXT, FIX::SessionRejectReason_TAG_NOT_DEFINED_FOR_THIS_MESSAGE_TYPE_TEXT, FIX::SessionRejectReason_TAG_SPECIFIED_OUT_OF_REQUIRED_ORDER_TEXT, FIX::SessionRejectReason_TAG_SPECIFIED_WITHOUT_A_VALUE_TEXT, FIX::SessionRejectReason_VALUE_IS_INCORRECT_TEXT, set(), and FIX::FieldMap::setField().

Referenced by doBadCompID(), doBadTime(), doPossDup(), next(), and nextSequenceReset().

◆ generateResendRequest()

void FIX::Session::generateResendRequest ( const BeginString beginString,
const MsgSeqNum msgSeqNum 
)
private

Definition at line 718 of file Session.cpp.

719{
721 Message & resendRequest = *pMsg;
722
726 endSeqNo = 0;
728 endSeqNo = 999999;
729 resendRequest.getHeader().setField( MsgType( "2" ) );
730 resendRequest.setField( beginSeqNo );
731 resendRequest.setField( endSeqNo );
732 fill( resendRequest.getHeader() );
734
735 m_state.onEvent( "Sent ResendRequest FROM: "
737 " TO: " + IntConvertor::convert( endSeqNo ) );
738
740}
const char BeginString_FIX41[]
Definition Values.h:35

References FIX::BeginString_FIX41, FIX::BeginString_FIX42, FIX::IntConvertor::convert(), fill(), getExpectedTargetNum(), m_state, newMessage(), FIX::SessionState::onEvent(), FIX::SessionState::resendRange(), sendRaw(), and set().

Referenced by doTargetTooHigh().

◆ generateSequenceReset()

void FIX::Session::generateSequenceReset ( int  beginSeqNo,
int  endSeqNo 
)
private

Definition at line 742 of file Session.cpp.

744{
746 Message & sequenceReset = *pMsg;
747
749 sequenceReset.getHeader().setField( MsgType( "4" ) );
750 sequenceReset.getHeader().setField( PossDupFlag( true ) );
751 sequenceReset.setField( newSeqNo );
752 fill( sequenceReset.getHeader() );
753
755 sequenceReset.getHeader().getField( sendingTime );
757 sequenceReset.getHeader().setField( MsgSeqNum( beginSeqNo ) );
758 sequenceReset.setField( GapFillFlag( true ) );
760 m_state.onEvent( "Sent SequenceReset TO: "
762}
void insertOrigSendingTime(Header &, const UtcTimeStamp &when=UtcTimeStamp())
Definition Session.cpp:103

References FIX::IntConvertor::convert(), fill(), insertOrigSendingTime(), m_state, newMessage(), FIX::SessionState::onEvent(), sendRaw(), and set().

Referenced by nextResendRequest().

◆ generateTestRequest()

void FIX::Session::generateTestRequest ( const std::string &  id)
private

Definition at line 792 of file Session.cpp.

793{
795 Message & testRequest = *pMsg;
796
797 testRequest.getHeader().setField( MsgType( "1" ) );
798 fill( testRequest.getHeader() );
799 TestReqID testReqID( id );
800 testRequest.setField( testReqID );
801
802 sendRaw( testRequest );
803}

References fill(), FIX::Message::getHeader(), newMessage(), sendRaw(), set(), and FIX::FieldMap::setField().

Referenced by next().

◆ get()

bool FIX::Session::get ( int  s,
Message m 
) const
private

◆ getCheckCompId()

bool FIX::Session::getCheckCompId ( )
inline

Definition at line 137 of file Session.h.

138 { return m_checkCompId; }

References m_checkCompId.

Referenced by FIX::HttpConnection::processSession().

◆ getCheckLatency()

bool FIX::Session::getCheckLatency ( )
inline

Definition at line 142 of file Session.h.

143 { return m_checkLatency; }

References m_checkLatency.

Referenced by FIX::HttpConnection::processSession().

◆ getDataDictionaryProvider()

const DataDictionaryProvider & FIX::Session::getDataDictionaryProvider ( ) const
inline

Definition at line 79 of file Session.h.

80 { return m_dataDictionaryProvider; }

References m_dataDictionaryProvider.

◆ getExpectedSenderNum()

int FIX::Session::getExpectedSenderNum ( )
inline

◆ getExpectedTargetNum()

int FIX::Session::getExpectedTargetNum ( )
inline

◆ getHeartBtInt()

const HeartBtInt & FIX::Session::getHeartBtInt ( ) const
inline

Definition at line 230 of file Session.h.

230{ return m_state.heartBtInt(); }

References FIX::SessionState::heartBtInt(), and m_state.

◆ getLog()

Log * FIX::Session::getLog ( )
inline

◆ getLogonTime()

const TimeRange & FIX::Session::getLogonTime ( )
inline

Definition at line 117 of file Session.h.

118 { return m_logonTime; }

References m_logonTime.

◆ getLogonTimeout()

int FIX::Session::getLogonTimeout ( )
inline

Definition at line 152 of file Session.h.

153 { return m_state.logonTimeout(); }
int logonTimeout() const

References FIX::SessionState::logonTimeout(), and m_state.

Referenced by FIX::HttpConnection::processSession().

◆ getLogoutTimeout()

int FIX::Session::getLogoutTimeout ( )
inline

Definition at line 157 of file Session.h.

158 { return m_state.logoutTimeout(); }
int logoutTimeout() const

References FIX::SessionState::logoutTimeout(), and m_state.

Referenced by FIX::HttpConnection::processSession().

◆ getMaxLatency()

int FIX::Session::getMaxLatency ( )
inline

Definition at line 147 of file Session.h.

148 { return m_maxLatency; }

References m_maxLatency.

Referenced by FIX::HttpConnection::processSession().

◆ getMillisecondsInTimeStamp()

bool FIX::Session::getMillisecondsInTimeStamp ( )
inline

Definition at line 182 of file Session.h.

183 { return (m_timestampPrecision == 3); }

References m_timestampPrecision.

Referenced by FIX::HttpConnection::processSession().

◆ getPersistMessages()

bool FIX::Session::getPersistMessages ( )
inline

Definition at line 200 of file Session.h.

201 { return m_persistMessages; }

References m_persistMessages.

Referenced by FIX::HttpConnection::processSession().

◆ getRefreshOnLogon()

bool FIX::Session::getRefreshOnLogon ( )
inline

Definition at line 177 of file Session.h.

178 { return m_refreshOnLogon; }

References m_refreshOnLogon.

Referenced by FIX::HttpConnection::processSession().

◆ getResetOnDisconnect()

bool FIX::Session::getResetOnDisconnect ( )
inline

Definition at line 172 of file Session.h.

173 { return m_resetOnDisconnect; }

References m_resetOnDisconnect.

Referenced by FIX::HttpConnection::processSession().

◆ getResetOnLogon()

bool FIX::Session::getResetOnLogon ( )
inline

Definition at line 162 of file Session.h.

163 { return m_resetOnLogon; }

References m_resetOnLogon.

Referenced by FIX::HttpConnection::processSession().

◆ getResetOnLogout()

bool FIX::Session::getResetOnLogout ( )
inline

Definition at line 167 of file Session.h.

168 { return m_resetOnLogout; }

References m_resetOnLogout.

Referenced by FIX::HttpConnection::processSession().

◆ getSenderDefaultApplVerID()

const std::string & FIX::Session::getSenderDefaultApplVerID ( )
inline

Definition at line 122 of file Session.h.

123 { return m_senderDefaultApplVerID; }

References m_senderDefaultApplVerID.

Referenced by FIX::MessageCracker::crack(), and FIX::MessageCracker::crack().

◆ getSendRedundantResendRequests()

bool FIX::Session::getSendRedundantResendRequests ( )
inline

Definition at line 132 of file Session.h.

References m_sendRedundantResendRequests.

Referenced by FIX::HttpConnection::processSession().

◆ getSessionID()

const SessionID & FIX::Session::getSessionID ( ) const
inline

◆ getSessions()

std::set< SessionID > FIX::Session::getSessions ( )
static

◆ getStore()

const MessageStore * FIX::Session::getStore ( )
inline

Definition at line 228 of file Session.h.

228{ return &m_state; }

References m_state.

◆ getTargetDefaultApplVerID()

const std::string & FIX::Session::getTargetDefaultApplVerID ( )
inline

Definition at line 127 of file Session.h.

128 { return m_targetDefaultApplVerID; }

References m_targetDefaultApplVerID.

◆ getTimestampPrecision()

int FIX::Session::getTimestampPrecision ( )
inline

Definition at line 190 of file Session.h.

191 { return m_timestampPrecision; }

References m_timestampPrecision.

◆ getValidateLengthAndChecksum()

bool FIX::Session::getValidateLengthAndChecksum ( )
inline

Definition at line 205 of file Session.h.

References m_validateLengthAndChecksum.

◆ insertOrigSendingTime()

void FIX::Session::insertOrigSendingTime ( Header header,
const UtcTimeStamp when = UtcTimeStamp () 
)
private

◆ insertSendingTime()

void FIX::Session::insertSendingTime ( Header header)
private

◆ isAcceptor()

bool FIX::Session::isAcceptor ( )
inline

Definition at line 114 of file Session.h.

115 { return !m_state.initiate(); }

References FIX::SessionState::initiate(), and m_state.

◆ isCorrectCompID()

bool FIX::Session::isCorrectCompID ( const SenderCompID senderCompID,
const TargetCompID targetCompID 
)
inlineprivate

Definition at line 264 of file Session.h.

266 {
267 if( !m_checkCompId ) return true;
268
269 return
270 m_sessionID.getSenderCompID().getValue() == targetCompID.getValue()
271 && m_sessionID.getTargetCompID().getValue() == senderCompID.getValue();
272 }

References FIX::SessionID::getSenderCompID(), FIX::SessionID::getTargetCompID(), m_checkCompId, m_sessionID, and set().

Referenced by verify().

◆ isEnabled()

bool FIX::Session::isEnabled ( )
inline

◆ isGoodTime()

bool FIX::Session::isGoodTime ( const SendingTime sendingTime)
inlineprivate

Definition at line 249 of file Session.h.

250 {
251 if ( !m_checkLatency ) return true;
253 return labs( now - sendingTime ) <= m_maxLatency;
254 }

References m_checkLatency, m_maxLatency, and set().

Referenced by verify().

◆ isInitiator()

bool FIX::Session::isInitiator ( )
inline

Definition at line 112 of file Session.h.

113 { return m_state.initiate(); }

References FIX::SessionState::initiate(), and m_state.

Referenced by FIX::HttpConnection::processRoot(), and FIX::HttpConnection::processSession().

◆ isLoggedOn()

bool FIX::Session::isLoggedOn ( )
inline

◆ isLogonTime()

bool FIX::Session::isLogonTime ( const UtcTimeStamp time)
inline

Definition at line 110 of file Session.h.

111 { return m_logonTime.isInRange(time); }
static bool isInRange(const UtcTimeOnly &start, const UtcTimeOnly &end, const DateTime &time)
Definition TimeRange.h:43

References FIX::TimeRange::isInRange(), m_logonTime, and set().

Referenced by next(), and nextLogon().

◆ isSessionRegistered()

bool FIX::Session::isSessionRegistered ( const SessionID sessionID)
static

Definition at line 1531 of file Session.cpp.

1532{
1533 Locker locker( s_mutex );
1534 return s_registered.end() != s_registered.find( sessionID );
1535}
static Sessions s_registered
Definition Session.h:346

References s_mutex, s_registered, and set().

Referenced by FIX::SocketConnection::isValidSession(), registerSession(), and FIX::ThreadedSocketConnection::setSession().

◆ isSessionTime()

bool FIX::Session::isSessionTime ( const UtcTimeStamp time)
inline

◆ isTargetTooHigh()

bool FIX::Session::isTargetTooHigh ( const MsgSeqNum msgSeqNum)
inlineprivate

Definition at line 260 of file Session.h.

261 { return msgSeqNum > ( m_state.getNextTargetMsgSeqNum() ); }

References FIX::SessionState::getNextTargetMsgSeqNum(), m_state, and set().

Referenced by nextLogon(), nextResendRequest(), and verify().

◆ isTargetTooLow()

bool FIX::Session::isTargetTooLow ( const MsgSeqNum msgSeqNum)
inlineprivate

Definition at line 262 of file Session.h.

263 { return msgSeqNum < ( m_state.getNextTargetMsgSeqNum() ); }

References FIX::SessionState::getNextTargetMsgSeqNum(), m_state, and set().

Referenced by nextResendRequest(), and verify().

◆ logon()

void FIX::Session::logon ( )
inline

◆ logout()

void FIX::Session::logout ( const std::string &  reason = "")
inline

◆ lookupSession() [1/2]

Session * FIX::Session::lookupSession ( const SessionID sessionID)
static

◆ lookupSession() [2/2]

Session * FIX::Session::lookupSession ( const std::string &  string,
bool  reverse = false 
)
static

Definition at line 1506 of file Session.cpp.

1507{
1508 Message message;
1509 if ( !message.setStringHeader( string ) )
1510 return 0;
1511
1512 try
1513 {
1514 const Header& header = message.getHeader();
1518
1519 if ( reverse )
1520 {
1521 return lookupSession( SessionID( beginString, SenderCompID( targetCompID ),
1523 }
1524
1525 return lookupSession( SessionID( beginString, senderCompID,
1526 targetCompID ) );
1527 }
1528 catch ( FieldNotFound& ) { return 0; }
1529}
#define FIELD_GET_REF(MAP, FLD)
Definition FieldMap.h:376
static Session * lookupSession(const SessionID &)
Definition Session.cpp:1496
void reverse(I begin, I end)
Definition pugixml.cpp:6009

References FIELD_GET_REF, lookupSession(), reverse(), and set().

◆ newMessage()

Message * FIX::Session::newMessage ( const std::string &  msgType) const
private

Definition at line 492 of file Session.cpp.

493{
494 Message * msg = 0;
495
496 const DataDictionary& sessionDD =
498 if (!sessionDD.isMessageFieldsOrderPreserved())
499 {
500 msg = new Message();
501 }
502 else
503 {
504 const message_order & hdrOrder = sessionDD.getHeaderOrderedFields();
505 const message_order & trlOrder = sessionDD.getTrailerOrderedFields();
507 {
508 const message_order & msgOrder = sessionDD.getMessageOrderedFields(msgType);
509 msg = new Message(hdrOrder, trlOrder, msgOrder);
510 }
511 else
512 {
513 const DataDictionary& applicationDD =
515 const message_order & msgOrder = applicationDD.getMessageOrderedFields(msgType);
516 msg = new Message(hdrOrder, trlOrder, msgOrder);
517 }
518 }
519
520 return msg;
521}
message_order const & getMessageOrderedFields(const std::string &msgType) const
const DataDictionary & getApplicationDataDictionary(const ApplVerID &applVerID) const
const DataDictionary & getSessionDataDictionary(const BeginString &beginString) const

References FIX::DataDictionaryProvider::getApplicationDataDictionary(), FIX::SessionID::getBeginString(), FIX::DataDictionaryProvider::getSessionDataDictionary(), FIX::Message::isAdminMsgType(), FIX::SessionID::isFIXT(), m_dataDictionaryProvider, m_senderDefaultApplVerID, m_sessionID, and set().

Referenced by generateBusinessReject(), generateHeartbeat(), generateHeartbeat(), generateLogon(), generateLogon(), generateLogout(), generateReject(), generateReject(), generateResendRequest(), generateSequenceReset(), and generateTestRequest().

◆ next() [1/4]

void FIX::Session::next ( )

◆ next() [2/4]

void FIX::Session::next ( const Message message,
const UtcTimeStamp timeStamp,
bool  queued = false 
)

Definition at line 1301 of file Session.cpp.

1302{
1303 const Header& header = message.getHeader();
1304
1305 try
1306 {
1308 { reset(); return; }
1309
1310 const MsgType& msgType = FIELD_GET_REF( header, MsgType );
1312 // make sure these fields are present
1315
1317 throw UnsupportedVersion();
1318
1319 if( msgType == MsgType_Logon )
1320 {
1321 if( m_sessionID.isFIXT() )
1322 {
1325 }
1326 else
1327 {
1329 }
1330 }
1331
1332 const DataDictionary& sessionDataDictionary =
1334
1335 if( m_sessionID.isFIXT() && message.isApp() )
1336 {
1338 header.getFieldIfSet(applVerID);
1339 const DataDictionary& applicationDataDictionary =
1342 }
1343 else
1344 {
1345 sessionDataDictionary.validate( message );
1346 }
1347
1348 if ( msgType == MsgType_Logon )
1350 else if ( msgType == MsgType_Heartbeat )
1352 else if ( msgType == MsgType_TestRequest )
1354 else if ( msgType == MsgType_SequenceReset )
1356 else if ( msgType == MsgType_Logout )
1358 else if ( msgType == MsgType_ResendRequest )
1360 else if ( msgType == MsgType_Reject )
1362 else
1363 {
1364 if ( !verify( message ) ) return ;
1366 }
1367 }
1368 catch ( MessageParseError& e )
1369 { m_state.onEvent( e.what() ); }
1370 catch ( RequiredTagMissing & e )
1372 catch ( FieldNotFound & e )
1373 {
1374 if( header.getField(FIELD::BeginString) >= FIX::BeginString_FIX42 && message.isApp() )
1375 {
1377 }
1378 else
1379 {
1381 if ( header.getField(FIELD::MsgType) == MsgType_Logon )
1382 {
1383 m_state.onEvent( "Required field missing from logon" );
1384 disconnect();
1385 }
1386 }
1387 }
1388 catch ( InvalidTagNumber & e )
1390 catch ( NoTagValue & e )
1392 catch ( TagNotDefinedForMessage & e )
1394 catch ( InvalidMessageType& )
1396 catch ( UnsupportedMessageType& )
1397 {
1398 if ( header.getField(FIELD::BeginString) >= FIX::BeginString_FIX42 )
1400 else
1401 { LOGEX( generateReject( message, "Unsupported message type" ) ); }
1402 }
1403 catch ( TagOutOfOrder & e )
1405 catch ( IncorrectDataFormat & e )
1407 catch ( IncorrectTagValue & e )
1409 catch ( RepeatedTag & e )
1411 catch ( RepeatingGroupCountMismatch & e )
1413 catch ( InvalidMessage& e )
1414 { m_state.onEvent( e.what() ); }
1415 catch ( RejectLogon& e )
1416 {
1417 m_state.onEvent( e.what() );
1418 generateLogout( e.what() );
1419 disconnect();
1420 }
1421 catch ( UnsupportedVersion& )
1422 {
1423 if ( header.getField(FIELD::MsgType) == MsgType_Logout )
1425 else
1426 {
1427 generateLogout( "Incorrect BeginString" );
1429 }
1430 }
1431 catch ( IOException& e )
1432 {
1433 m_state.onEvent( e.what() );
1434 disconnect();
1435 }
1436
1437 if( !queued )
1439
1440 if( isLoggedOn() )
1441 next();
1442}
#define FIELD_THROW_IF_NOT_FOUND(MAP, FLD)
Definition FieldMap.h:378
#define LOGEX(method)
Definition Session.cpp:38
static void validate(const Message &message, const DataDictionary *const pSessionDD, const DataDictionary *const pAppID)
Validate a message.
static ApplVerID toApplVerID(const BeginString &value)
Definition Message.h:307
void nextQueued(const UtcTimeStamp &timeStamp)
Definition Session.cpp:1238
void nextHeartbeat(const Message &, const UtcTimeStamp &timeStamp)
Definition Session.cpp:280
void nextSequenceReset(const Message &, const UtcTimeStamp &timeStamp)
Definition Session.cpp:319
void nextLogout(const Message &, const UtcTimeStamp &timeStamp)
Definition Session.cpp:295
void setTargetDefaultApplVerID(const std::string &targetDefaultApplVerID)
Definition Session.h:129
bool verify(const Message &msg, bool checkTooHigh=true, bool checkTooLow=true)
Definition Session.cpp:1034
void nextReject(const Message &, const UtcTimeStamp &timeStamp)
Definition Session.cpp:312
void generateBusinessReject(const Message &, int err, int field=0)
Definition Session.cpp:931
void nextTestRequest(const Message &, const UtcTimeStamp &timeStamp)
Definition Session.cpp:287
void nextLogon(const Message &, const UtcTimeStamp &timeStamp)
Definition Session.cpp:202
void nextResendRequest(const Message &, const UtcTimeStamp &timeStamp)
Definition Session.cpp:344
void disconnect()
Definition Session.cpp:613
bool isLoggedOn()
Definition Session.h:65

References FIX::BeginString_FIX42, checkSessionTime(), disconnect(), FIELD_GET_REF, FIELD_THROW_IF_NOT_FOUND, generateBusinessReject(), generateLogout(), generateReject(), FIX::DataDictionaryProvider::getApplicationDataDictionary(), FIX::SessionID::getBeginString(), FIX::FieldMap::getField(), FIX::FieldMap::getFieldIfSet(), FIX::DataDictionaryProvider::getSessionDataDictionary(), FIX::SessionState::incrNextTargetMsgSeqNum(), FIX::SessionID::isFIXT(), isLoggedOn(), LOGEX, m_dataDictionaryProvider, m_sessionID, m_state, m_targetDefaultApplVerID, next(), nextHeartbeat(), nextLogon(), nextLogout(), nextQueued(), nextReject(), nextResendRequest(), nextSequenceReset(), nextTestRequest(), FIX::SessionState::onEvent(), reset(), set(), setTargetDefaultApplVerID(), FIX::Message::toApplVerID(), FIX::DataDictionary::validate(), and verify().

◆ next() [3/4]

void FIX::Session::next ( const std::string &  msg,
const UtcTimeStamp timeStamp,
bool  queued = false 
)

Definition at line 1267 of file Session.cpp.

1268{
1269 try
1270 {
1272 const DataDictionary& sessionDD =
1274 if( m_sessionID.isFIXT() )
1275 {
1276 const DataDictionary& applicationDD =
1279 }
1280 else
1281 {
1283 }
1284 }
1285 catch( InvalidMessage& e )
1286 {
1287 m_state.onEvent( e.what() );
1288
1289 try
1290 {
1292 {
1293 m_state.onEvent( "Logon message is not valid" );
1294 disconnect();
1295 }
1296 } catch( MessageParseError& ) {}
1297 throw e;
1298 }
1299}
void onIncoming(const std::string &string)
MsgType identifyType(const std::string &message)
Parse the type of a message from a string.
Definition Message.h:417

References disconnect(), FIX::DataDictionaryProvider::getApplicationDataDictionary(), FIX::SessionID::getBeginString(), FIX::DataDictionaryProvider::getSessionDataDictionary(), FIX::identifyType(), FIX::SessionID::isFIXT(), m_dataDictionaryProvider, m_senderDefaultApplVerID, m_sessionID, m_state, m_validateLengthAndChecksum, next(), FIX::SessionState::onEvent(), FIX::SessionState::onIncoming(), and set().

◆ next() [4/4]

void FIX::Session::next ( const UtcTimeStamp timeStamp)

Definition at line 130 of file Session.cpp.

131{
132 try
133 {
135 { reset(); return; }
136
137 if( !isEnabled() || !isLogonTime(timeStamp) )
138 {
139 if( isLoggedOn() )
140 {
141 if( !m_state.sentLogout() )
142 {
143 m_state.onEvent( "Initiated logout request" );
145 }
146 }
147 else
148 return;
149 }
150
151 if ( !m_state.receivedLogon() )
152 {
154 {
156 m_state.onEvent( "Initiated logon request" );
157 }
159 {
160 m_state.onEvent( "Timed out waiting for logon response" );
161 disconnect();
162 }
163 return ;
164 }
165
166 if ( m_state.heartBtInt() == 0 ) return ;
167
168 if ( m_state.logoutTimedOut() )
169 {
170 m_state.onEvent( "Timed out waiting for logout response" );
171 disconnect();
172 }
173
175
176 if ( m_state.timedOut() )
177 {
178 m_state.onEvent( "Timed out waiting for heartbeat" );
179 disconnect();
180 }
181 else
182 {
183 if ( m_state.needTestRequest() )
184 {
185 generateTestRequest( "TEST" );
187 m_state.onEvent( "Sent test request TEST" );
188 }
189 else if ( m_state.needHeartbeat() )
190 {
192 }
193 }
194 }
195 catch ( FIX::IOException& e )
196 {
197 m_state.onEvent( e.what() );
198 disconnect();
199 }
200}
void generateHeartbeat()
Definition Session.cpp:764
void generateLogon()
Definition Session.cpp:673
bool isEnabled()
Definition Session.h:59
void generateTestRequest(const std::string &)
Definition Session.cpp:792
bool isLogonTime(const UtcTimeStamp &time)
Definition Session.h:110
bool logoutTimedOut() const
bool shouldSendLogon() const
bool logonTimedOut() const
bool withinHeartBeat() const
bool needTestRequest() const
bool timedOut() const
bool needHeartbeat() const
bool alreadySentLogon() const

References FIX::SessionState::alreadySentLogon(), checkSessionTime(), disconnect(), generateHeartbeat(), generateLogon(), generateLogout(), generateTestRequest(), FIX::SessionState::heartBtInt(), isEnabled(), isLoggedOn(), isLogonTime(), FIX::SessionState::logonTimedOut(), FIX::SessionState::logoutReason(), FIX::SessionState::logoutTimedOut(), m_state, FIX::SessionState::needHeartbeat(), FIX::SessionState::needTestRequest(), FIX::SessionState::onEvent(), FIX::SessionState::receivedLogon(), reset(), FIX::SessionState::sentLogout(), set(), FIX::SessionState::shouldSendLogon(), FIX::SessionState::testRequest(), FIX::SessionState::timedOut(), and FIX::SessionState::withinHeartBeat().

◆ nextHeartbeat()

void FIX::Session::nextHeartbeat ( const Message heartbeat,
const UtcTimeStamp timeStamp 
)
private

Definition at line 280 of file Session.cpp.

281{
282 if ( !verify( heartbeat ) ) return ;
285}

References FIX::SessionState::incrNextTargetMsgSeqNum(), m_state, nextQueued(), set(), and verify().

Referenced by next().

◆ nextLogon()

void FIX::Session::nextLogon ( const Message logon,
const UtcTimeStamp timeStamp 
)
private

Definition at line 202 of file Session.cpp.

203{
206 logon.getHeader().getField( senderCompID );
207 logon.getHeader().getField( targetCompID );
208
209 if( m_refreshOnLogon )
210 refresh();
211
212 if( !isEnabled() )
213 {
214 m_state.onEvent( "Session is not enabled for logon" );
215 disconnect();
216 return;
217 }
218
219 if( !isLogonTime(timeStamp) )
220 {
221 m_state.onEvent( "Received logon outside of valid logon time" );
222 disconnect();
223 return;
224 }
225
227 logon.getFieldIfSet(resetSeqNumFlag);
229
230 if( m_state.receivedReset() )
231 {
232 m_state.onEvent( "Logon contains ResetSeqNumFlag=Y, reseting sequence numbers to 1" );
233 if( !m_state.sentReset() ) m_state.reset();
234 }
235
237 {
238 m_state.onEvent( "Received logon response before sending request" );
239 disconnect();
240 return;
241 }
242
244 m_state.reset();
245
246 if( !verify( logon, false, true ) )
247 return;
248 m_state.receivedLogon( true );
249
250 if ( !m_state.initiate()
252 {
253 logon.getFieldIfSet(m_state.heartBtInt());
254 m_state.onEvent( "Received logon request" );
256 m_state.onEvent( "Responding to logon request" );
257 }
258 else
259 m_state.onEvent( "Received logon response" );
260
261 m_state.sentReset( false );
262 m_state.receivedReset( false );
263
265 logon.getHeader().getField( msgSeqNum );
267 {
269 }
270 else
271 {
274 }
275
276 if ( isLoggedOn() )
278}
virtual void onLogon(const SessionID &)=0
Notification of a session successfully logging on.
bool isTargetTooHigh(const MsgSeqNum &msgSeqNum)
Definition Session.h:260
void doTargetTooHigh(const Message &msg)
Definition Session.cpp:1206

References disconnect(), doTargetTooHigh(), generateLogon(), FIX::SessionState::heartBtInt(), FIX::SessionState::incrNextTargetMsgSeqNum(), FIX::SessionState::initiate(), isEnabled(), isLoggedOn(), isLogonTime(), isTargetTooHigh(), logon(), m_application, m_refreshOnLogon, m_resetOnLogon, m_sessionID, m_state, nextQueued(), FIX::SessionState::onEvent(), FIX::Application::onLogon(), FIX::SessionState::receivedLogon(), FIX::SessionState::receivedReset(), refresh(), FIX::SessionState::reset(), FIX::SessionState::sentReset(), set(), FIX::SessionState::shouldSendLogon(), and verify().

Referenced by next().

◆ nextLogout()

void FIX::Session::nextLogout ( const Message logout,
const UtcTimeStamp timeStamp 
)
private

Definition at line 295 of file Session.cpp.

296{
297 if ( !verify( logout, false, false ) ) return ;
298 if ( !m_state.sentLogout() )
299 {
300 m_state.onEvent( "Received logout request" );
302 m_state.onEvent( "Sending logout response" );
303 }
304 else
305 m_state.onEvent( "Received logout response" );
306
309 disconnect();
310}

References disconnect(), generateLogout(), FIX::SessionState::incrNextTargetMsgSeqNum(), logout(), m_resetOnLogout, m_state, FIX::SessionState::onEvent(), FIX::SessionState::reset(), FIX::SessionState::sentLogout(), set(), and verify().

Referenced by next().

◆ nextQueued() [1/2]

void FIX::Session::nextQueued ( const UtcTimeStamp timeStamp)
private

Definition at line 1238 of file Session.cpp.

1239{
1240 while ( nextQueued( getExpectedTargetNum(), timeStamp ) ) {}
1241}

References getExpectedTargetNum(), nextQueued(), and set().

Referenced by next(), nextHeartbeat(), nextLogon(), nextQueued(), nextReject(), and nextTestRequest().

◆ nextQueued() [2/2]

bool FIX::Session::nextQueued ( int  num,
const UtcTimeStamp timeStamp 
)
private

Definition at line 1243 of file Session.cpp.

1244{
1245 Message msg;
1247
1248 if( m_state.retrieve( num, msg ) )
1249 {
1250 m_state.onEvent( "Processing QUEUED message: "
1252 msg.getHeader().getField( msgType );
1253 if( msgType == MsgType_Logon
1255 {
1257 }
1258 else
1259 {
1260 next( msg, timeStamp, true );
1261 }
1262 return true;
1263 }
1264 return false;
1265}
bool retrieve(int msgSeqNum, Message &message)

References FIX::IntConvertor::convert(), FIX::SessionState::incrNextTargetMsgSeqNum(), m_state, next(), FIX::SessionState::onEvent(), FIX::SessionState::retrieve(), and set().

◆ nextReject()

void FIX::Session::nextReject ( const Message reject,
const UtcTimeStamp timeStamp 
)
private

Definition at line 312 of file Session.cpp.

313{
314 if ( !verify( reject, false, true ) ) return ;
317}

References FIX::SessionState::incrNextTargetMsgSeqNum(), m_state, nextQueued(), set(), and verify().

Referenced by next().

◆ nextResendRequest()

void FIX::Session::nextResendRequest ( const Message resendRequest,
const UtcTimeStamp timeStamp 
)
private

Definition at line 344 of file Session.cpp.

345{
346 if ( !verify( resendRequest, false, false ) ) return ;
347
348 Locker l( m_mutex );
349
352 resendRequest.getField( beginSeqNo );
353 resendRequest.getField( endSeqNo );
354
355 m_state.onEvent( "Received ResendRequest FROM: "
357 " TO: " + IntConvertor::convert( endSeqNo ) );
358
359 std::string beginString = m_sessionID.getBeginString();
360 if ( (beginString >= FIX::BeginString_FIX42 && endSeqNo == 0) ||
361 (beginString <= FIX::BeginString_FIX42 && endSeqNo == 999999) ||
363 { endSeqNo = getExpectedSenderNum() - 1; }
364
365 if ( !m_persistMessages )
366 {
369 if( endSeqNo > next )
372 return;
373 }
374
375 std::vector < std::string > messages;
377
378 std::vector < std::string > ::iterator i;
381 int begin = 0;
382 int current = beginSeqNo;
383 std::string messageString;
384
385 for ( i = messages.begin(); i != messages.end(); ++i )
386 {
388 std::string strMsgType;
389 const DataDictionary& sessionDD =
391 if (sessionDD.isMessageFieldsOrderPreserved())
392 {
393 std::string::size_type equalSign = (*i).find("\00135=");
394 equalSign += 4;
395 std::string::size_type soh = (*i).find_first_of('\001', equalSign);
396 strMsgType = (*i).substr(equalSign, soh - equalSign);
397#ifdef HAVE_EMX
399 {
400 equalSign = (*i).find("\0019426=", soh);
401 if (equalSign == std::string::npos)
402 throw FIX::IOException("EMX message type (9426) not found");
403
404 equalSign += 6;
405 soh = (*i).find_first_of('\001', equalSign);
406 if (soh == std::string::npos)
407 throw FIX::IOException("EMX message type (9426) soh char not found");
408 strMsgType.assign((*i).substr(equalSign, soh - equalSign));
409 }
410#endif
411 }
412
413 if( m_sessionID.isFIXT() )
414 {
415 Message msg;
416 msg.setStringHeader(*i);
418 if( !msg.getHeader().getFieldIfSet(applVerID) )
420
421 const DataDictionary& applicationDD =
423 if (strMsgType.empty())
424 pMsg.reset( new Message( *i, sessionDD, applicationDD, m_validateLengthAndChecksum ));
425 else
426 {
427 const message_order & hdrOrder = sessionDD.getHeaderOrderedFields();
428 const message_order & trlOrder = sessionDD.getTrailerOrderedFields();
429 const message_order & msgOrder = applicationDD.getMessageOrderedFields(strMsgType);
431 }
432 }
433 else
434 {
435 if (strMsgType.empty())
436 pMsg.reset( new Message( *i, sessionDD, m_validateLengthAndChecksum ));
437 else
438 {
439 const message_order & hdrOrder = sessionDD.getHeaderOrderedFields();
440 const message_order & trlOrder = sessionDD.getTrailerOrderedFields();
441 const message_order & msgOrder = sessionDD.getMessageOrderedFields(strMsgType);
443 }
444 }
445
446 Message & msg = *pMsg;
447
448 msg.getHeader().getField( msgSeqNum );
449 msg.getHeader().getField( msgType );
450
451 if( (current != msgSeqNum) && !begin )
452 begin = current;
453
455 {
456 if ( !begin ) begin = msgSeqNum;
457 }
458 else
459 {
460 if ( resend( msg ) )
461 {
462 if ( begin ) generateSequenceReset( begin, msgSeqNum );
463 send( msg.toString(messageString) );
464 m_state.onEvent( "Resending Message: "
466 begin = 0;
467 }
468 else
469 { if ( !begin ) begin = msgSeqNum; }
470 }
471 current = msgSeqNum + 1;
472 }
473 if ( begin )
474 {
475 generateSequenceReset( begin, msgSeqNum + 1 );
476 }
477
478 if ( endSeqNo > msgSeqNum )
479 {
482 if( endSeqNo > next )
485 }
486
487 resendRequest.getHeader().getField( msgSeqNum );
490}
message_order const & getHeaderOrderedFields() const
bool isTargetTooLow(const MsgSeqNum &msgSeqNum)
Definition Session.h:262
bool send(Message &)
Definition Session.cpp:523
bool resend(Message &message)
Definition Session.cpp:643
void generateSequenceReset(int, int)
Definition Session.cpp:743
void get(int b, int e, std::vector< std::string > &m) const

References FIX::BeginString_FIX42, FIX::IntConvertor::convert(), generateSequenceReset(), FIX::SessionState::get(), FIX::DataDictionaryProvider::getApplicationDataDictionary(), FIX::SessionID::getBeginString(), getExpectedSenderNum(), FIX::FieldBase::getField(), FIX::FieldMap::getField(), FIX::Message::getHeader(), FIX::SessionState::getNextSenderMsgSeqNum(), FIX::DataDictionaryProvider::getSessionDataDictionary(), FIX::SessionState::incrNextTargetMsgSeqNum(), FIX::Message::isAdminMsgType(), FIX::SessionID::isFIXT(), isTargetTooHigh(), isTargetTooLow(), m_dataDictionaryProvider, m_mutex, m_persistMessages, m_senderDefaultApplVerID, m_sessionID, m_state, m_validateLengthAndChecksum, next(), FIX::SessionState::onEvent(), resend(), send(), set(), FIX::Message::setStringHeader(), and verify().

Referenced by next().

◆ nextSequenceReset()

void FIX::Session::nextSequenceReset ( const Message sequenceReset,
const UtcTimeStamp timeStamp 
)
private

Definition at line 319 of file Session.cpp.

320{
321 bool isGapFill = false;
323 if ( sequenceReset.getFieldIfSet( gapFillFlag ) )
324 {
326 }
327
329
331 if ( sequenceReset.getFieldIfSet( newSeqNo ) )
332 {
333 m_state.onEvent( "Received SequenceReset FROM: "
335 " TO: " + IntConvertor::convert( newSeqNo ) );
336
339 else if ( newSeqNo < getExpectedTargetNum() )
341 }
342}
void setNextTargetMsgSeqNum(int n)

References FIX::IntConvertor::convert(), generateReject(), getExpectedTargetNum(), m_state, FIX::SessionState::onEvent(), set(), FIX::SessionState::setNextTargetMsgSeqNum(), and verify().

Referenced by next().

◆ nextTestRequest()

void FIX::Session::nextTestRequest ( const Message testRequest,
const UtcTimeStamp timeStamp 
)
private

Definition at line 287 of file Session.cpp.

288{
289 if ( !verify( testRequest ) ) return ;
290 generateHeartbeat( testRequest );
293}

References generateHeartbeat(), FIX::SessionState::incrNextTargetMsgSeqNum(), m_state, nextQueued(), set(), and verify().

Referenced by next().

◆ numSessions()

size_t FIX::Session::numSessions ( )
static

Definition at line 1553 of file Session.cpp.

1554{
1555 Locker locker( s_mutex );
1556 return s_sessions.size();
1557}

References s_mutex, s_sessions, and set().

Referenced by FIX::HttpConnection::processRoot().

◆ persist()

void FIX::Session::persist ( const Message message,
const std::string &  messageString 
)
throw (IOException
)
private

Definition at line 663 of file Session.cpp.

665{
667 message.getHeader().getField( msgSeqNum );
671}
void incrNextSenderMsgSeqNum()
bool set(int s, const std::string &m)

Referenced by sendRaw().

◆ populateRejectReason() [1/2]

void FIX::Session::populateRejectReason ( Message reject,
const std::string &  text 
)
private

Definition at line 1029 of file Session.cpp.

1030{
1031 reject.setField( Text( text ) );
1032}

References set().

◆ populateRejectReason() [2/2]

void FIX::Session::populateRejectReason ( Message reject,
int  field,
const std::string &  text 
)
private

Definition at line 1009 of file Session.cpp.

1011{
1013 reject.getHeader().getField( msgType );
1014
1015 if ( msgType == MsgType_Reject
1017 {
1018 reject.setField( RefTagID( field ) );
1019 reject.setField( Text( text ) );
1020 }
1021 else
1022 {
1023 std::stringstream stream;
1024 stream << text << " (" << field << ")";
1025 reject.setField( Text( stream.str() ) );
1026 }
1027}

References FIX::BeginString_FIX42, FIX::SessionID::getBeginString(), m_sessionID, and set().

Referenced by generateBusinessReject(), and generateReject().

◆ receivedLogon()

bool FIX::Session::receivedLogon ( )
inline

Definition at line 64 of file Session.h.

64{ return m_state.receivedLogon(); }

References m_state, and FIX::SessionState::receivedLogon().

Referenced by isLoggedOn().

◆ refresh()

void FIX::Session::refresh ( )
throw (IOException
)
inline

◆ registerSession()

Session * FIX::Session::registerSession ( const SessionID sessionID)
static

Definition at line 1537 of file Session.cpp.

1538{
1539 Locker locker( s_mutex );
1541 if ( pSession == 0 ) return 0;
1542 if ( isSessionRegistered( sessionID ) ) return 0;
1544 return pSession;
1545}
static bool isSessionRegistered(const SessionID &)
Definition Session.cpp:1531
Session(Application &, MessageStoreFactory &, const SessionID &, const DataDictionaryProvider &, const TimeRange &, int heartBtInt, LogFactory *pLogFactory)
Definition Session.cpp:41

References isSessionRegistered(), lookupSession(), s_mutex, s_registered, and set().

Referenced by FIX::SocketConnection::read(), and FIX::ThreadedSocketConnection::setSession().

◆ removeSession()

void FIX::Session::removeSession ( Session s)
staticprivate

Definition at line 1573 of file Session.cpp.

1574{
1575 Locker locker( s_mutex );
1576 s_sessions.erase( s.m_sessionID );
1577 s_sessionIDs.erase( s.m_sessionID );
1578 s_registered.erase( s.m_sessionID );
1579}

References s_mutex, s_registered, s_sessionIDs, s_sessions, and set().

Referenced by ~Session().

◆ resend()

bool FIX::Session::resend ( Message message)
private

Definition at line 643 of file Session.cpp.

644{
647 Header& header = message.getHeader();
648 header.getField( sendingTime );
649 header.getField( msgSeqNum );
651 header.setField( PossDupFlag( true ) );
652 insertSendingTime( header );
653
654 try
655 {
657 return true;
658 }
659 catch ( DoNotSend& )
660 { return false; }
661}
virtual void toApp(Message &, const SessionID &)=0
Notification of app message being sent to target.

References FIX::FieldMap::getField(), insertOrigSendingTime(), insertSendingTime(), m_application, m_sessionID, set(), FIX::FieldMap::setField(), and FIX::Application::toApp().

Referenced by nextResendRequest().

◆ reset()

void FIX::Session::reset ( )
throw (IOException
)
inline

◆ send() [1/2]

bool FIX::Session::send ( const std::string &  string)
private

Definition at line 606 of file Session.cpp.

607{
608 if ( !m_pResponder ) return false;
609 m_state.onOutgoing( string );
610 return m_pResponder->send( string );
611}
virtual bool send(const std::string &)=0
void onOutgoing(const std::string &string)

References m_pResponder, m_state, FIX::SessionState::onOutgoing(), and FIX::Responder::send().

◆ send() [2/2]

bool FIX::Session::send ( Message message)

Definition at line 523 of file Session.cpp.

524{
525 message.getHeader().removeField( FIELD::PossDupFlag );
526 message.getHeader().removeField( FIELD::OrigSendingTime );
527 return sendRaw( message );
528}

References sendRaw(), and set().

Referenced by nextResendRequest(), sendRaw(), and sendToTarget().

◆ sendRaw()

bool FIX::Session::sendRaw ( Message message,
int  msgSeqNum = 0 
)
private

Definition at line 530 of file Session.cpp.

531{
532 Locker l( m_mutex );
533
534 try
535 {
536 Header& header = message.getHeader();
537
539 header.getFieldIfSet(msgType);
540
541 fill( header );
542 std::string messageString;
543
544 if ( num )
545 header.setField( MsgSeqNum( num ) );
546
548 {
550
551 if( msgType == "A" && !m_state.receivedReset() )
552 {
554 message.getFieldIfSet(resetSeqNumFlag);
555
556 if( resetSeqNumFlag )
557 {
558 m_state.reset();
559 message.getHeader().setField( MsgSeqNum(getExpectedSenderNum()) );
560 }
562 }
563
564 message.toString( messageString );
565
566 if( !num )
568
569 if (
570 msgType == "A" || msgType == "5"
571 || msgType == "2" || msgType == "4"
572 || isLoggedOn() )
573 {
575 }
576 }
577 else
578 {
579 // do not send application messages if they will just be cleared
580 if( !isLoggedOn() && shouldSendReset() )
581 return false;
582
583 try
584 {
586 message.toString( messageString );
587
588 if( !num )
590
591 if ( isLoggedOn() )
593 }
594 catch ( DoNotSend& ) { return false; }
595 }
596
597 return true;
598 }
599 catch ( IOException& e )
600 {
601 m_state.onEvent( e.what() );
602 return false;
603 }
604}
virtual void toAdmin(Message &, const SessionID &)=0
Notification of admin message being sent to target.
void persist(const Message &, const std::string &)
Definition Session.cpp:663

References fill(), getExpectedSenderNum(), FIX::FieldMap::getFieldIfSet(), FIX::Message::isAdminMsgType(), isLoggedOn(), m_application, m_mutex, m_sessionID, m_state, FIX::SessionState::onEvent(), persist(), FIX::SessionState::receivedReset(), FIX::SessionState::reset(), send(), FIX::SessionState::sentReset(), set(), FIX::FieldMap::setField(), shouldSendReset(), FIX::Application::toAdmin(), and FIX::Application::toApp().

Referenced by generateBusinessReject(), generateHeartbeat(), generateHeartbeat(), generateLogon(), generateLogon(), generateLogout(), generateReject(), generateReject(), generateResendRequest(), generateSequenceReset(), generateTestRequest(), and send().

◆ sendToTarget() [1/4]

bool FIX::Session::sendToTarget ( Message message,
const SenderCompID senderCompID,
const TargetCompID targetCompID,
const std::string &  qualifier = "" 
)
throw (SessionNotFound
)
static

Definition at line 1464 of file Session.cpp.

1470{
1471 message.getHeader().setField( senderCompID );
1472 message.getHeader().setField( targetCompID );
1473 return sendToTarget( message, qualifier );
1474}
static bool sendToTarget(Message &message, const std::string &qualifier="")
Definition Session.cpp:1444

◆ sendToTarget() [2/4]

bool FIX::Session::sendToTarget ( Message message,
const SessionID sessionID 
)
throw (SessionNotFound
)
static

Definition at line 1455 of file Session.cpp.

1457{
1458 message.setSessionID( sessionID );
1460 if ( !pSession ) throw SessionNotFound();
1461 return pSession->send( message );
1462}

References send().

◆ sendToTarget() [3/4]

bool FIX::Session::sendToTarget ( Message message,
const std::string &  qualifier = "" 
)
throw (SessionNotFound
)
static

Definition at line 1444 of file Session.cpp.

1446{
1447 try
1448 {
1449 SessionID sessionID = message.getSessionID( qualifier );
1450 return sendToTarget( message, sessionID );
1451 }
1452 catch ( FieldNotFound& ) { throw SessionNotFound(); }
1453}

◆ sendToTarget() [4/4]

bool FIX::Session::sendToTarget ( Message message,
const std::string &  senderCompID,
const std::string &  targetCompID,
const std::string &  qualifier = "" 
)
throw (SessionNotFound
)
static

Definition at line 1476 of file Session.cpp.

1480{
1483}

◆ sentLogon()

bool FIX::Session::sentLogon ( )
inline

Definition at line 62 of file Session.h.

62{ return m_state.sentLogon(); }

References m_state, and FIX::SessionState::sentLogon().

Referenced by isLoggedOn().

◆ sentLogout()

bool FIX::Session::sentLogout ( )
inline

Definition at line 63 of file Session.h.

63{ return m_state.sentLogout(); }

References m_state, and FIX::SessionState::sentLogout().

◆ set()

bool FIX::Session::set ( int  s,
const Message m 
)
private

◆ setCheckCompId()

void FIX::Session::setCheckCompId ( bool  value)
inline

Definition at line 139 of file Session.h.

140 { m_checkCompId = value; }

References m_checkCompId.

Referenced by FIX::HttpConnection::processSession().

◆ setCheckLatency()

void FIX::Session::setCheckLatency ( bool  value)
inline

Definition at line 144 of file Session.h.

145 { m_checkLatency = value; }

References m_checkLatency.

Referenced by FIX::HttpConnection::processSession().

◆ setDataDictionaryProvider()

void FIX::Session::setDataDictionaryProvider ( const DataDictionaryProvider dataDictionaryProvider)
inline

Definition at line 77 of file Session.h.

References m_dataDictionaryProvider, and set().

◆ setLogonTime()

void FIX::Session::setLogonTime ( const TimeRange value)
inline

Definition at line 119 of file Session.h.

120 { m_logonTime = value; }

References m_logonTime.

◆ setLogonTimeout()

void FIX::Session::setLogonTimeout ( int  value)
inline

Definition at line 154 of file Session.h.

155 { m_state.logonTimeout( value ); }

References FIX::SessionState::logonTimeout(), and m_state.

Referenced by FIX::HttpConnection::processSession().

◆ setLogoutTimeout()

void FIX::Session::setLogoutTimeout ( int  value)
inline

Definition at line 159 of file Session.h.

160 { m_state.logoutTimeout( value ); }

References FIX::SessionState::logoutTimeout(), and m_state.

Referenced by FIX::HttpConnection::processSession().

◆ setMaxLatency()

void FIX::Session::setMaxLatency ( int  value)
inline

Definition at line 149 of file Session.h.

150 { m_maxLatency = value; }

References m_maxLatency.

Referenced by FIX::HttpConnection::processSession().

◆ setMillisecondsInTimeStamp()

void FIX::Session::setMillisecondsInTimeStamp ( bool  value)
inline

Definition at line 184 of file Session.h.

185 { if (value)
187 else
189 }

References m_timestampPrecision.

Referenced by FIX::HttpConnection::processSession().

◆ setNextSenderMsgSeqNum()

void FIX::Session::setNextSenderMsgSeqNum ( int  num)
throw (IOException
)
inline

◆ setNextTargetMsgSeqNum()

void FIX::Session::setNextTargetMsgSeqNum ( int  num)
throw (IOException
)
inline

◆ setPersistMessages()

void FIX::Session::setPersistMessages ( bool  value)
inline

Definition at line 202 of file Session.h.

203 { m_persistMessages = value; }

References m_persistMessages.

Referenced by FIX::HttpConnection::processSession().

◆ setRefreshOnLogon()

void FIX::Session::setRefreshOnLogon ( bool  value)
inline

Definition at line 179 of file Session.h.

180 { m_refreshOnLogon = value; }

References m_refreshOnLogon.

Referenced by FIX::HttpConnection::processSession().

◆ setResetOnDisconnect()

void FIX::Session::setResetOnDisconnect ( bool  value)
inline

Definition at line 174 of file Session.h.

175 { m_resetOnDisconnect = value; }

References m_resetOnDisconnect.

Referenced by FIX::HttpConnection::processSession().

◆ setResetOnLogon()

void FIX::Session::setResetOnLogon ( bool  value)
inline

Definition at line 164 of file Session.h.

165 { m_resetOnLogon = value; }

References m_resetOnLogon.

Referenced by FIX::HttpConnection::processSession().

◆ setResetOnLogout()

void FIX::Session::setResetOnLogout ( bool  value)
inline

Definition at line 169 of file Session.h.

170 { m_resetOnLogout = value; }

References m_resetOnLogout.

Referenced by FIX::HttpConnection::processSession().

◆ setResponder()

void FIX::Session::setResponder ( Responder pR)
inline

◆ setSenderDefaultApplVerID()

void FIX::Session::setSenderDefaultApplVerID ( const std::string &  senderDefaultApplVerID)
inline

Definition at line 124 of file Session.h.

References m_senderDefaultApplVerID, and set().

◆ setSendRedundantResendRequests()

void FIX::Session::setSendRedundantResendRequests ( bool  value)
inline

Definition at line 134 of file Session.h.

References m_sendRedundantResendRequests.

Referenced by FIX::HttpConnection::processSession().

◆ setTargetDefaultApplVerID()

void FIX::Session::setTargetDefaultApplVerID ( const std::string &  targetDefaultApplVerID)
inline

Definition at line 129 of file Session.h.

References m_targetDefaultApplVerID, and set().

Referenced by next().

◆ setTimestampPrecision()

void FIX::Session::setTimestampPrecision ( int  precision)
inline

Definition at line 192 of file Session.h.

193 {
195 return;
196
198 }

References m_timestampPrecision, and set().

◆ setValidateLengthAndChecksum()

void FIX::Session::setValidateLengthAndChecksum ( bool  value)
inline

Definition at line 207 of file Session.h.

208 { m_validateLengthAndChecksum = value; }

References m_validateLengthAndChecksum.

◆ shouldSendReset()

bool FIX::Session::shouldSendReset ( )
private

◆ unregisterSession()

void FIX::Session::unregisterSession ( const SessionID sessionID)
static

◆ validLogonState()

bool FIX::Session::validLogonState ( const MsgType msgType)
private

Definition at line 1117 of file Session.cpp.

1118{
1119 if ( (msgType == MsgType_Logon && m_state.sentReset())
1120 || (m_state.receivedReset()) )
1121 return true;
1124 return true;
1126 return true;
1128 return true;
1130 return true;
1131 if ( msgType == MsgType_Reject )
1132 return true;
1133
1134 return false;
1135}

References m_state, FIX::SessionState::receivedLogon(), FIX::SessionState::receivedReset(), FIX::SessionState::sentLogon(), FIX::SessionState::sentLogout(), FIX::SessionState::sentReset(), and set().

Referenced by verify().

◆ verify()

bool FIX::Session::verify ( const Message msg,
bool  checkTooHigh = true,
bool  checkTooLow = true 
)
private

Definition at line 1034 of file Session.cpp.

1036{
1037 const MsgType* pMsgType = 0;
1038 const MsgSeqNum* pMsgSeqNum = 0;
1039
1040 try
1041 {
1042 const Header& header = msg.getHeader();
1043
1044 pMsgType = FIELD_GET_PTR( header, MsgType );
1048
1049 if( checkTooHigh || checkTooLow )
1050 pMsgSeqNum = FIELD_GET_PTR( header, MsgSeqNum );
1051
1052 if ( !validLogonState( *pMsgType ) )
1053 throw std::logic_error( "Logon state is not valid for message" );
1054
1055 if ( !isGoodTime( sendingTime ) )
1056 {
1057 doBadTime( msg );
1058 return false;
1059 }
1061 {
1062 doBadCompID( msg );
1063 return false;
1064 }
1065
1067 {
1069 return false;
1070 }
1071 else if ( checkTooLow && isTargetTooLow( *pMsgSeqNum ) )
1072 {
1074 return false;
1075 }
1076
1078 {
1080
1081 if ( *pMsgSeqNum >= range.second )
1082 {
1083 m_state.onEvent ("ResendRequest for messages FROM: " +
1084 IntConvertor::convert (range.first) + " TO: " +
1085 IntConvertor::convert (range.second) +
1086 " has been satisfied.");
1087 m_state.resendRange (0, 0);
1088 }
1089 }
1090 }
1091 catch ( std::exception& e )
1092 {
1093 m_state.onEvent( e.what() );
1094 disconnect();
1095 return false;
1096 }
1097
1100 m_state.testRequest( 0 );
1101
1103 return true;
1104}
#define FIELD_GET_PTR(MAP, FLD)
Definition FieldMap.h:374
void fromCallback(const MsgType &msgType, const Message &msg, const SessionID &sessionID)
Definition Session.cpp:1137
bool isGoodTime(const SendingTime &sendingTime)
Definition Session.h:249
bool isCorrectCompID(const SenderCompID &senderCompID, const TargetCompID &targetCompID)
Definition Session.h:264
bool validLogonState(const MsgType &msgType)
Definition Session.cpp:1117
bool doTargetTooLow(const Message &msg)
Definition Session.cpp:1186
void doBadTime(const Message &msg)
Definition Session.cpp:1146
void doBadCompID(const Message &msg)
Definition Session.cpp:1152

References FIX::IntConvertor::convert(), disconnect(), doBadCompID(), doBadTime(), doTargetTooHigh(), doTargetTooLow(), FIELD_GET_PTR, FIELD_GET_REF, fromCallback(), isCorrectCompID(), isGoodTime(), isTargetTooHigh(), isTargetTooLow(), FIX::SessionState::lastReceivedTime(), m_sessionID, m_state, FIX::SessionState::onEvent(), FIX::SessionState::resendRange(), FIX::SessionState::resendRequested(), set(), FIX::SessionState::testRequest(), and validLogonState().

Referenced by next(), nextHeartbeat(), nextLogon(), nextLogout(), nextReject(), nextResendRequest(), nextSequenceReset(), and nextTestRequest().

Member Data Documentation

◆ m_application

Application& FIX::Session::m_application
private

Definition at line 318 of file Session.h.

Referenced by disconnect(), fromCallback(), nextLogon(), resend(), sendRaw(), and Session().

◆ m_checkCompId

bool FIX::Session::m_checkCompId
private

Definition at line 326 of file Session.h.

Referenced by getCheckCompId(), isCorrectCompID(), and setCheckCompId().

◆ m_checkLatency

bool FIX::Session::m_checkLatency
private

Definition at line 327 of file Session.h.

Referenced by getCheckLatency(), isGoodTime(), and setCheckLatency().

◆ m_dataDictionaryProvider

DataDictionaryProvider FIX::Session::m_dataDictionaryProvider
private

◆ m_logonTime

TimeRange FIX::Session::m_logonTime
private

Definition at line 321 of file Session.h.

Referenced by getLogonTime(), isLogonTime(), and setLogonTime().

◆ m_maxLatency

int FIX::Session::m_maxLatency
private

Definition at line 328 of file Session.h.

Referenced by getMaxLatency(), isGoodTime(), and setMaxLatency().

◆ m_messageStoreFactory

MessageStoreFactory& FIX::Session::m_messageStoreFactory
private

Definition at line 339 of file Session.h.

Referenced by Session(), and ~Session().

◆ m_mutex

Mutex FIX::Session::m_mutex
private

Definition at line 342 of file Session.h.

Referenced by disconnect(), nextResendRequest(), and sendRaw().

◆ m_persistMessages

bool FIX::Session::m_persistMessages
private

Definition at line 334 of file Session.h.

Referenced by getPersistMessages(), nextResendRequest(), and setPersistMessages().

◆ m_pLogFactory

LogFactory* FIX::Session::m_pLogFactory
private

Definition at line 340 of file Session.h.

Referenced by Session(), and ~Session().

◆ m_pResponder

Responder* FIX::Session::m_pResponder
private

Definition at line 341 of file Session.h.

Referenced by disconnect(), send(), and setResponder().

◆ m_refreshOnLogon

bool FIX::Session::m_refreshOnLogon
private

Definition at line 332 of file Session.h.

Referenced by generateLogon(), getRefreshOnLogon(), nextLogon(), and setRefreshOnLogon().

◆ m_resetOnDisconnect

bool FIX::Session::m_resetOnDisconnect
private

Definition at line 331 of file Session.h.

Referenced by disconnect(), getResetOnDisconnect(), setResetOnDisconnect(), and shouldSendReset().

◆ m_resetOnLogon

bool FIX::Session::m_resetOnLogon
private

◆ m_resetOnLogout

bool FIX::Session::m_resetOnLogout
private

Definition at line 330 of file Session.h.

Referenced by getResetOnLogout(), nextLogout(), setResetOnLogout(), and shouldSendReset().

◆ m_senderDefaultApplVerID

std::string FIX::Session::m_senderDefaultApplVerID
private

◆ m_sendRedundantResendRequests

bool FIX::Session::m_sendRedundantResendRequests
private

◆ m_sessionID

SessionID FIX::Session::m_sessionID
private

◆ m_sessionTime

TimeRange FIX::Session::m_sessionTime
private

Definition at line 320 of file Session.h.

Referenced by checkSessionTime(), and isSessionTime().

◆ m_state

SessionState FIX::Session::m_state
private

◆ m_targetDefaultApplVerID

std::string FIX::Session::m_targetDefaultApplVerID
private

Definition at line 324 of file Session.h.

Referenced by getTargetDefaultApplVerID(), next(), and setTargetDefaultApplVerID().

◆ m_timestampPrecision

int FIX::Session::m_timestampPrecision
private

◆ m_validateLengthAndChecksum

bool FIX::Session::m_validateLengthAndChecksum
private

◆ s_mutex

Mutex FIX::Session::s_mutex
staticprivate

◆ s_registered

Session::Sessions FIX::Session::s_registered
staticprivate

Definition at line 346 of file Session.h.

Referenced by isSessionRegistered(), registerSession(), removeSession(), and unregisterSession().

◆ s_sessionIDs

Session::SessionIDs FIX::Session::s_sessionIDs
staticprivate

Definition at line 345 of file Session.h.

Referenced by addSession(), getSessions(), and removeSession().

◆ s_sessions

Session::Sessions FIX::Session::s_sessions
staticprivate

Definition at line 344 of file Session.h.

Referenced by addSession(), doesSessionExist(), lookupSession(), numSessions(), and removeSession().


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

Generated on Fri Sep 27 2024 13:45:21 for QuickFIX by doxygen 1.9.8 written by Dimitri van Heesch, © 1997-2001