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

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 int 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
 

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
 
bool m_millisecondsInTimeStamp
 
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

typedef std::set< SessionID > FIX::Session::SessionIDs
private

Definition at line 219 of file Session.h.

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

Definition at line 218 of file Session.h.

Constructor & Destructor Documentation

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.

References addSession(), checkSessionTime(), FIX::MessageStoreFactory::create(), FIX::LogFactory::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(), FIX::SessionState::store(), and FIX::TYPE::UtcTimeStamp.

47 : m_application( application ),
48  m_sessionID( sessionID ),
49  m_sessionTime( sessionTime ),
50  m_logonTime( sessionTime ),
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 ),
64  m_dataDictionaryProvider( dataDictionaryProvider ),
65  m_messageStoreFactory( messageStoreFactory ),
66  m_pLogFactory( pLogFactory ),
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 MessageStore * create(const SessionID &)=0
virtual void onCreate(const SessionID &)=0
Notification of a session begin created.
DataDictionaryProvider m_dataDictionaryProvider
Definition: Session.h:321
virtual Log * create()=0
MessageStoreFactory & m_messageStoreFactory
Definition: Session.h:322
static bool addSession(Session &)
Definition: Session.cpp:1466
bool m_checkLatency
Definition: Session.h:310
SessionID m_sessionID
Definition: Session.h:302
void reset()
Definition: Session.h:66
bool m_checkCompId
Definition: Session.h:309
int m_maxLatency
Definition: Session.h:311
Application & m_application
Definition: Session.h:301
bool m_resetOnLogon
Definition: Session.h:312
std::string m_senderDefaultApplVerID
Definition: Session.h:306
LogFactory * m_pLogFactory
Definition: Session.h:323
bool initiate() const
Definition: SessionState.h:68
bool m_millisecondsInTimeStamp
Definition: Session.h:316
TimeRange m_logonTime
Definition: Session.h:304
SessionState m_state
Definition: Session.h:320
std::string m_targetDefaultApplVerID
Definition: Session.h:307
bool m_validateLengthAndChecksum
Definition: Session.h:318
bool checkSessionTime(const UtcTimeStamp &timeStamp)
Definition: Session.h:240
void onEvent(const std::string &string)
Definition: SessionState.h:204
bool m_resetOnDisconnect
Definition: Session.h:314
TimeRange m_sessionTime
Definition: Session.h:303
bool m_persistMessages
Definition: Session.h:317
bool m_sendRedundantResendRequests
Definition: Session.h:308
Responder * m_pResponder
Definition: Session.h:324
bool m_resetOnLogout
Definition: Session.h:313
MessageStore * store()
Definition: SessionState.h:89
bool m_refreshOnLogon
Definition: Session.h:315
void heartBtInt(const HeartBtInt &value)
Definition: SessionState.h:94
const char ApplVerID_FIX50[]
Definition: FixValues.h:810
FIX::Session::~Session ( )
virtual

Definition at line 83 of file Session.cpp.

References FIX::MessageStoreFactory::destroy(), FIX::LogFactory::destroy(), FIX::SessionState::log(), m_messageStoreFactory, m_pLogFactory, m_state, removeSession(), and FIX::SessionState::store().

84 {
85  removeSession( *this );
87  if ( m_pLogFactory && m_state.log() )
89 }
MessageStoreFactory & m_messageStoreFactory
Definition: Session.h:322
virtual void destroy(Log *)=0
LogFactory * m_pLogFactory
Definition: Session.h:323
SessionState m_state
Definition: Session.h:320
virtual void destroy(MessageStore *)=0
static void removeSession(Session &)
Definition: Session.cpp:1480
MessageStore * store()
Definition: SessionState.h:89

Member Function Documentation

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

Definition at line 1466 of file Session.cpp.

References m_sessionID, s_mutex, s_sessionIDs, and s_sessions.

Referenced by Session().

1467 {
1468  Locker locker( s_mutex );
1469  Sessions::iterator it = s_sessions.find( s.m_sessionID );
1470  if ( it == s_sessions.end() )
1471  {
1472  s_sessions[ s.m_sessionID ] = &s;
1473  s_sessionIDs.insert( s.m_sessionID );
1474  return true;
1475  }
1476  else
1477  return false;
1478 }
static Sessions s_sessions
Definition: Session.h:327
static SessionIDs s_sessionIDs
Definition: Session.h:328
static Mutex s_mutex
Definition: Session.h:330
bool FIX::Session::checkSessionTime ( const UtcTimeStamp timeStamp)
inlineprivate

Definition at line 240 of file Session.h.

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

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

241  {
242  UtcTimeStamp creationTime = m_state.getCreationTime();
243  return m_sessionTime.isInSameRange( timeStamp, creationTime );
244  }
UtcTimeStamp getCreationTime() const
Definition: SessionState.h:189
SessionState m_state
Definition: Session.h:320
TimeRange m_sessionTime
Definition: Session.h:303
static bool isInSameRange(const UtcTimeOnly &start, const UtcTimeOnly &end, const DateTime &time1, const DateTime &time2)
Definition: TimeRange.h:76
void FIX::Session::disconnect ( )

Definition at line 542 of file Session.cpp.

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(), and FIX::SessionState::sentReset().

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

543 {
544  Locker l(m_mutex);
545 
546  if ( m_pResponder )
547  {
548  m_state.onEvent( "Disconnecting" );
549 
551  m_pResponder = 0;
552  }
553 
554  if ( m_state.receivedLogon() || m_state.sentLogon() )
555  {
556  m_state.receivedLogon( false );
557  m_state.sentLogon( false );
559  }
560 
561  m_state.sentLogout( false );
562  m_state.receivedReset( false );
563  m_state.sentReset( false );
566  if ( m_resetOnDisconnect )
567  m_state.reset();
568 
569  m_state.resendRange( 0, 0 );
570 }
virtual void onLogout(const SessionID &)=0
Notification of a session logging off or disconnecting.
bool sentLogout() const
Definition: SessionState.h:56
bool receivedLogon() const
Definition: SessionState.h:53
bool sentLogon() const
Definition: SessionState.h:59
SessionID m_sessionID
Definition: Session.h:302
bool sentReset() const
Definition: SessionState.h:65
bool receivedReset() const
Definition: SessionState.h:62
Application & m_application
Definition: Session.h:301
SessionState m_state
Definition: Session.h:320
void onEvent(const std::string &string)
Definition: SessionState.h:204
virtual void disconnect()=0
Mutex m_mutex
Definition: Session.h:325
bool m_resetOnDisconnect
Definition: Session.h:314
Responder * m_pResponder
Definition: Session.h:324
std::string logoutReason() const
Definition: SessionState.h:150
ResendRange resendRange() const
Definition: SessionState.h:85
void FIX::Session::doBadCompID ( const Message msg)
private

Definition at line 1059 of file Session.cpp.

References generateLogout(), generateReject(), and FIX::SessionRejectReason_COMPID_PROBLEM.

Referenced by verify().

1060 {
1062  generateLogout();
1063 }
void generateReject(const Message &, int err, int field=0)
Definition: Session.cpp:720
void generateLogout(const std::string &text="")
Definition: Session.cpp:905
const int SessionRejectReason_COMPID_PROBLEM
Definition: FixValues.h:1864
void FIX::Session::doBadTime ( const Message msg)
private

Definition at line 1053 of file Session.cpp.

References generateLogout(), generateReject(), and FIX::SessionRejectReason_SENDINGTIME_ACCURACY_PROBLEM.

Referenced by verify().

1054 {
1056  generateLogout();
1057 }
const int SessionRejectReason_SENDINGTIME_ACCURACY_PROBLEM
Definition: FixValues.h:1881
void generateReject(const Message &, int err, int field=0)
Definition: Session.cpp:720
void generateLogout(const std::string &text="")
Definition: Session.cpp:905
bool FIX::Session::doesSessionExist ( const SessionID sessionID)
static

Definition at line 1397 of file Session.cpp.

References s_mutex, and s_sessions.

1398 {
1399  Locker locker( s_mutex );
1400  return s_sessions.end() != s_sessions.find( sessionID );
1401 }
static Sessions s_sessions
Definition: Session.h:327
static Mutex s_mutex
Definition: Session.h:330
bool FIX::Session::doPossDup ( const Message msg)
private

Definition at line 1065 of file Session.cpp.

References generateLogout(), generateReject(), FIX::FieldMap::getField(), FIX::FieldMap::getFieldIfSet(), FIX::Message::getHeader(), FIX::FIELD::MsgType, FIX::MsgType_SequenceReset, FIX::FIELD::OrigSendingTime, FIX::FIELD::SendingTime, FIX::SessionRejectReason_REQUIRED_TAG_MISSING, and FIX::SessionRejectReason_SENDINGTIME_ACCURACY_PROBLEM.

Referenced by doTargetTooLow().

1066 {
1067  const Header & header = msg.getHeader();
1068  OrigSendingTime origSendingTime;
1069  SendingTime sendingTime;
1070  MsgType msgType;
1071 
1072  header.getField( msgType );
1073  header.getField( sendingTime );
1074 
1075  if ( msgType != MsgType_SequenceReset )
1076  {
1077  if ( !header.getFieldIfSet( origSendingTime ) )
1078  {
1079  generateReject( msg, SessionRejectReason_REQUIRED_TAG_MISSING, origSendingTime.getField() );
1080  return false;
1081  }
1082 
1083  if ( origSendingTime > sendingTime )
1084  {
1086  generateLogout();
1087  return false;
1088  }
1089  }
1090  return true;
1091 }
const int OrigSendingTime
const char MsgType_SequenceReset[]
Definition: FixValues.h:646
const int SendingTime
const int SessionRejectReason_SENDINGTIME_ACCURACY_PROBLEM
Definition: FixValues.h:1881
void generateReject(const Message &, int err, int field=0)
Definition: Session.cpp:720
void generateLogout(const std::string &text="")
Definition: Session.cpp:905
const int SessionRejectReason_REQUIRED_TAG_MISSING
Definition: FixValues.h:1871
const int MsgType
void FIX::Session::doTargetTooHigh ( const Message msg)
private

Definition at line 1113 of file Session.cpp.

References FIX::FIELD::BeginString, FIX::IntConvertor::convert(), generateResendRequest(), getExpectedTargetNum(), FIX::FieldMap::getField(), FIX::Message::getHeader(), m_sendRedundantResendRequests, m_state, FIX::FIELD::MsgSeqNum, FIX::SessionState::onEvent(), FIX::SessionState::queue(), FIX::SessionState::resendRange(), and FIX::SessionState::resendRequested().

Referenced by nextLogon(), and verify().

1114 {
1115  const Header & header = msg.getHeader();
1116  BeginString beginString;
1117  MsgSeqNum msgSeqNum;
1118  header.getField( beginString );
1119  header.getField( msgSeqNum );
1120 
1121  m_state.onEvent( "MsgSeqNum too high, expecting "
1123  + " but received "
1124  + IntConvertor::convert( msgSeqNum ) );
1125 
1126  m_state.queue( msgSeqNum, msg );
1127 
1128  if( m_state.resendRequested() )
1129  {
1131 
1132  if( !m_sendRedundantResendRequests && msgSeqNum >= range.first )
1133  {
1134  m_state.onEvent ("Already sent ResendRequest FROM: " +
1135  IntConvertor::convert (range.first) + " TO: " +
1136  IntConvertor::convert (range.second) +
1137  ". Not sending another.");
1138  return;
1139  }
1140  }
1141 
1142  generateResendRequest( beginString, msgSeqNum );
1143 }
int getExpectedTargetNum()
Definition: Session.h:212
std::pair< int, int > ResendRange
Definition: SessionState.h:83
void generateResendRequest(const BeginString &, const MsgSeqNum &)
Definition: Session.cpp:643
void queue(int msgSeqNum, const Message &message)
Definition: SessionState.h:155
static std::string convert(signed_int value)
SessionState m_state
Definition: Session.h:320
bool resendRequested() const
Definition: SessionState.h:80
void onEvent(const std::string &string)
Definition: SessionState.h:204
const int BeginString
const int MsgSeqNum
bool m_sendRedundantResendRequests
Definition: Session.h:308
ResendRange resendRange() const
Definition: SessionState.h:85
bool FIX::Session::doTargetTooLow ( const Message msg)
private

Definition at line 1093 of file Session.cpp.

References doPossDup(), generateLogout(), getExpectedTargetNum(), FIX::FieldMap::getField(), FIX::FieldMap::getFieldIfSet(), FIX::Message::getHeader(), FIX::FIELD::MsgSeqNum, and FIX::FIELD::PossDupFlag.

Referenced by verify().

1094 {
1095  const Header & header = msg.getHeader();
1096  PossDupFlag possDupFlag(false);
1097  MsgSeqNum msgSeqNum;
1098  header.getFieldIfSet(possDupFlag);
1099  header.getField( msgSeqNum );
1100 
1101  if ( !possDupFlag )
1102  {
1103  std::stringstream stream;
1104  stream << "MsgSeqNum too low, expecting " << getExpectedTargetNum()
1105  << " but received " << msgSeqNum;
1106  generateLogout( stream.str() );
1107  throw std::logic_error( stream.str() );
1108  }
1109 
1110  return doPossDup( msg );
1111 }
int getExpectedTargetNum()
Definition: Session.h:212
void generateLogout(const std::string &text="")
Definition: Session.cpp:905
const int PossDupFlag
const int MsgSeqNum
bool doPossDup(const Message &msg)
Definition: Session.cpp:1065
void FIX::Session::fill ( Header header)
private

Definition at line 114 of file Session.cpp.

References FIX::SessionID::getBeginString(), getExpectedSenderNum(), FIX::SessionID::getSenderCompID(), FIX::SessionID::getTargetCompID(), insertSendingTime(), FIX::SessionState::lastSentTime(), m_sessionID, m_state, FIX::FIELD::MsgSeqNum, and FIX::FieldMap::setField().

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

115 {
116  UtcTimeStamp now;
117  m_state.lastSentTime( now );
118  header.setField( m_sessionID.getBeginString() );
119  header.setField( m_sessionID.getSenderCompID() );
120  header.setField( m_sessionID.getTargetCompID() );
121  header.setField( MsgSeqNum( getExpectedSenderNum() ) );
122  insertSendingTime( header );
123 }
int getExpectedSenderNum()
Definition: Session.h:211
SessionID m_sessionID
Definition: Session.h:302
void lastSentTime(const UtcTimeStamp &value)
Definition: SessionState.h:101
const SenderCompID & getSenderCompID() const
Definition: SessionID.h:55
SessionState m_state
Definition: Session.h:320
void insertSendingTime(Header &)
Definition: Session.cpp:91
const int MsgSeqNum
const BeginString & getBeginString() const
Definition: SessionID.h:53
const TargetCompID & getTargetCompID() const
Definition: SessionID.h:57
void FIX::Session::fromCallback ( const MsgType &  msgType,
const Message msg,
const SessionID sessionID 
)
private

Definition at line 1044 of file Session.cpp.

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

Referenced by verify().

1046 {
1047  if ( Message::isAdminMsgType( msgType ) )
1049  else
1051 }
static bool isAdminMsgType(const MsgType &msgType)
Definition: Message.h:250
SessionID m_sessionID
Definition: Session.h:302
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.
Application & m_application
Definition: Session.h:301
void FIX::Session::generateBusinessReject ( const Message message,
int  err,
int  field = 0 
)
private

Definition at line 842 of file Session.cpp.

References FIX::FIELD::BusinessRejectReason, FIX::BusinessRejectReason_APPLICATION_NOT_AVAILABLE, FIX::BusinessRejectReason_APPLICATION_NOT_AVAILABLE_TEXT, FIX::BusinessRejectReason_CONDITIONALLY_REQUIRED_FIELD_MISSING, FIX::BusinessRejectReason_CONDITIONALLY_REQUIRED_FIELD_MISSING_TEXT, FIX::BusinessRejectReason_DELIVERTO_FIRM_NOT_AVAILABLE_AT_THIS_TIME, FIX::BusinessRejectReason_DELIVERTO_FIRM_NOT_AVAILABLE_AT_THIS_TIME_TEXT, FIX::BusinessRejectReason_NOT_AUTHORIZED, FIX::BusinessRejectReason_NOT_AUTHORIZED_TEXT, FIX::BusinessRejectReason_OTHER, FIX::BusinessRejectReason_OTHER_TEXT, FIX::BusinessRejectReason_UNKNOWN_ID, FIX::BusinessRejectReason_UNKNOWN_ID_TEXT, FIX::BusinessRejectReason_UNKNOWN_MESSAGE_TYPE, FIX::BusinessRejectReason_UNKNOWN_SECURITY, FIX::BusinessRejectReason_UNKNOWN_SECURITY_TEXT, FIX::BusinessRejectReason_UNSUPPORTED_MESSAGE_TYPE_TEXT, FIX::IntConvertor::convert(), FIX::FIELD::DefaultApplVerID, fill(), FIX::FieldMap::getField(), FIX::Message::getHeader(), FIX::SessionState::incrNextTargetMsgSeqNum(), FIX::SessionID::isFIXT(), m_senderDefaultApplVerID, m_sessionID, m_state, FIX::FIELD::MsgSeqNum, FIX::FIELD::MsgType, FIX::MsgType_BusinessMessageReject, FIX::SessionState::onEvent(), populateRejectReason(), FIX::FIELD::RefMsgType, FIX::FIELD::RefSeqNum, sendRaw(), and FIX::FieldMap::setField().

Referenced by next().

843 {
844  Message reject;
845  reject.getHeader().setField( MsgType( MsgType_BusinessMessageReject ) );
846  if( m_sessionID.isFIXT() )
847  reject.setField( DefaultApplVerID(m_senderDefaultApplVerID) );
848  fill( reject.getHeader() );
849  MsgType msgType;
850  MsgSeqNum msgSeqNum;
851  message.getHeader().getField( msgType );
852  message.getHeader().getField( msgSeqNum );
853  reject.setField( RefMsgType( msgType ) );
854  reject.setField( RefSeqNum( msgSeqNum ) );
855  reject.setField( BusinessRejectReason( err ) );
857 
858  const char* reason = 0;
859  switch ( err )
860  {
863  break;
866  break;
869  break;
872  break;
875  break;
878  break;
881  break;
884  break;
885  };
886 
887  if ( reason && field )
888  {
889  populateRejectReason( reject, field, reason );
890  m_state.onEvent( "Message " + msgSeqNum.getString() + " Rejected: "
891  + reason + ":" + IntConvertor::convert( field ) );
892  }
893  else if ( reason )
894  {
895  populateRejectReason( reject, reason );
896  m_state.onEvent( "Message " + msgSeqNum.getString()
897  + " Rejected: " + reason );
898  }
899  else
900  m_state.onEvent( "Message " + msgSeqNum.getString() + " Rejected" );
901 
902  sendRaw( reject );
903 }
const int BusinessRejectReason_UNKNOWN_ID
Definition: FixValues.h:3271
void populateRejectReason(Message &, int field, const std::string &)
Definition: Session.cpp:916
const int RefMsgType
const int BusinessRejectReason_OTHER
Definition: FixValues.h:3272
const char BusinessRejectReason_NOT_AUTHORIZED_TEXT[]
Definition: Values.h:59
const int BusinessRejectReason_APPLICATION_NOT_AVAILABLE
Definition: FixValues.h:3267
void incrNextTargetMsgSeqNum()
Definition: SessionState.h:187
const int BusinessRejectReason_NOT_AUTHORIZED
Definition: FixValues.h:3275
bool sendRaw(Message &, int msgSeqNum=0)
Definition: Session.cpp:459
SessionID m_sessionID
Definition: Session.h:302
const char BusinessRejectReason_CONDITIONALLY_REQUIRED_FIELD_MISSING_TEXT[]
Definition: Values.h:58
static std::string convert(signed_int value)
const int BusinessRejectReason_UNKNOWN_MESSAGE_TYPE
Definition: FixValues.h:3274
const char BusinessRejectReason_UNKNOWN_ID_TEXT[]
Definition: Values.h:54
const int BusinessRejectReason_CONDITIONALLY_REQUIRED_FIELD_MISSING
Definition: FixValues.h:3270
std::string m_senderDefaultApplVerID
Definition: Session.h:306
const char BusinessRejectReason_APPLICATION_NOT_AVAILABLE_TEXT[]
Definition: Values.h:57
const char BusinessRejectReason_UNSUPPORTED_MESSAGE_TYPE_TEXT[]
Definition: Values.h:56
const int BusinessRejectReason_UNKNOWN_SECURITY
Definition: FixValues.h:3266
const bool isFIXT() const
Definition: SessionID.h:61
const int BusinessRejectReason_DELIVERTO_FIRM_NOT_AVAILABLE_AT_THIS_TIME
Definition: FixValues.h:3269
SessionState m_state
Definition: Session.h:320
const char BusinessRejectReason_OTHER_TEXT[]
Definition: Values.h:53
void onEvent(const std::string &string)
Definition: SessionState.h:204
const char MsgType_BusinessMessageReject[]
Definition: FixValues.h:626
const int DefaultApplVerID
void fill(Header &)
Definition: Session.cpp:114
const int MsgSeqNum
const int RefSeqNum
const char BusinessRejectReason_UNKNOWN_SECURITY_TEXT[]
Definition: Values.h:55
const char BusinessRejectReason_DELIVERTO_FIRM_NOT_AVAILABLE_AT_THIS_TIME_TEXT[]
Definition: Values.h:60
const int BusinessRejectReason
const int MsgType
void FIX::Session::generateHeartbeat ( )
private

Definition at line 685 of file Session.cpp.

References fill(), FIX::Message::getHeader(), FIX::FIELD::MsgType, sendRaw(), and FIX::FieldMap::setField().

Referenced by next(), and nextTestRequest().

686 {
687  Message heartbeat;
688  heartbeat.getHeader().setField( MsgType( "0" ) );
689  fill( heartbeat.getHeader() );
690  sendRaw( heartbeat );
691 }
bool sendRaw(Message &, int msgSeqNum=0)
Definition: Session.cpp:459
void fill(Header &)
Definition: Session.cpp:114
const int MsgType
void FIX::Session::generateHeartbeat ( const Message testRequest)
private

Definition at line 693 of file Session.cpp.

References fill(), FIX::FieldMap::getField(), FIX::Message::getHeader(), FIX::FIELD::MsgType, sendRaw(), FIX::FieldMap::setField(), and FIX::FIELD::TestReqID.

694 {
695  Message heartbeat;
696  heartbeat.getHeader().setField( MsgType( "0" ) );
697  fill( heartbeat.getHeader() );
698  try
699  {
700  TestReqID testReqID;
701  testRequest.getField( testReqID );
702  heartbeat.setField( testReqID );
703  }
704  catch ( FieldNotFound& ) {}
705 
706  sendRaw( heartbeat );
707 }
bool sendRaw(Message &, int msgSeqNum=0)
Definition: Session.cpp:459
void fill(Header &)
Definition: Session.cpp:114
const int TestReqID
const int MsgType
void FIX::Session::generateLogon ( )
private

Definition at line 602 of file Session.cpp.

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

Referenced by next(), and nextLogon().

603 {
604  Message logon;
605  logon.getHeader().setField( MsgType( "A" ) );
606  logon.setField( EncryptMethod( 0 ) );
607  logon.setField( m_state.heartBtInt() );
608  if( m_sessionID.isFIXT() )
609  logon.setField( DefaultApplVerID(m_senderDefaultApplVerID) );
610  if( m_refreshOnLogon )
611  refresh();
612  if( m_resetOnLogon )
613  m_state.reset();
614  if( shouldSendReset() )
615  logon.setField( ResetSeqNumFlag(true) );
616 
617  fill( logon.getHeader() );
618  UtcTimeStamp now;
619  m_state.lastReceivedTime( now );
620  m_state.testRequest( 0 );
621  m_state.sentLogon( true );
622  sendRaw( logon );
623 }
void lastReceivedTime(const UtcTimeStamp &value)
Definition: SessionState.h:108
bool sentLogon() const
Definition: SessionState.h:59
bool sendRaw(Message &, int msgSeqNum=0)
Definition: Session.cpp:459
SessionID m_sessionID
Definition: Session.h:302
void refresh()
Definition: Session.h:68
bool m_resetOnLogon
Definition: Session.h:312
std::string m_senderDefaultApplVerID
Definition: Session.h:306
const int EncryptMethod
const bool isFIXT() const
Definition: SessionID.h:61
SessionState m_state
Definition: Session.h:320
bool shouldSendReset()
Definition: Session.cpp:1013
const int DefaultApplVerID
void fill(Header &)
Definition: Session.cpp:114
const int ResetSeqNumFlag
int testRequest() const
Definition: SessionState.h:77
bool m_refreshOnLogon
Definition: Session.h:315
const int MsgType
void heartBtInt(const HeartBtInt &value)
Definition: SessionState.h:94
void logon()
Definition: Session.h:55
void FIX::Session::generateLogon ( const Message aLogon)
private

Definition at line 625 of file Session.cpp.

References FIX::FIELD::DefaultApplVerID, FIX::FIELD::EncryptMethod, fill(), FIX::FieldMap::getField(), FIX::Message::getHeader(), FIX::FIELD::HeartBtInt, FIX::SessionID::isFIXT(), logon(), m_senderDefaultApplVerID, m_sessionID, m_state, FIX::FIELD::MsgType, FIX::SessionState::receivedReset(), FIX::FIELD::ResetSeqNumFlag, sendRaw(), FIX::SessionState::sentLogon(), and FIX::FieldMap::setField().

626 {
627  Message logon;
628  EncryptMethod encryptMethod;
629  HeartBtInt heartBtInt;
630  logon.setField( EncryptMethod( 0 ) );
631  if( m_sessionID.isFIXT() )
632  logon.setField( DefaultApplVerID(m_senderDefaultApplVerID) );
633  if( m_state.receivedReset() )
634  logon.setField( ResetSeqNumFlag(true) );
635  aLogon.getField( heartBtInt );
636  logon.getHeader().setField( MsgType( "A" ) );
637  logon.setField( heartBtInt );
638  fill( logon.getHeader() );
639  sendRaw( logon );
640  m_state.sentLogon( true );
641 }
const int HeartBtInt
bool sentLogon() const
Definition: SessionState.h:59
bool sendRaw(Message &, int msgSeqNum=0)
Definition: Session.cpp:459
SessionID m_sessionID
Definition: Session.h:302
bool receivedReset() const
Definition: SessionState.h:62
std::string m_senderDefaultApplVerID
Definition: Session.h:306
const int EncryptMethod
const bool isFIXT() const
Definition: SessionID.h:61
SessionState m_state
Definition: Session.h:320
const int DefaultApplVerID
void fill(Header &)
Definition: Session.cpp:114
const int ResetSeqNumFlag
const int MsgType
void logon()
Definition: Session.h:55
void FIX::Session::generateLogout ( const std::string &  text = "")
private

Definition at line 905 of file Session.cpp.

References fill(), FIX::Message::getHeader(), logout(), m_state, FIX::FIELD::MsgType, FIX::MsgType_Logout, sendRaw(), FIX::SessionState::sentLogout(), FIX::FieldMap::setField(), and FIX::FIELD::Text.

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

906 {
907  Message logout;
908  logout.getHeader().setField( MsgType( MsgType_Logout ) );
909  fill( logout.getHeader() );
910  if ( text.length() )
911  logout.setField( Text( text ) );
912  sendRaw( logout );
913  m_state.sentLogout( true );
914 }
bool sentLogout() const
Definition: SessionState.h:56
bool sendRaw(Message &, int msgSeqNum=0)
Definition: Session.cpp:459
SessionState m_state
Definition: Session.h:320
const int Text
void logout(const std::string &reason="")
Definition: Session.h:57
void fill(Header &)
Definition: Session.cpp:114
const char MsgType_Logout[]
Definition: FixValues.h:622
const int MsgType
void FIX::Session::generateReject ( const Message message,
int  err,
int  field = 0 
)
private

Definition at line 720 of file Session.cpp.

References FIX::BeginString_FIX42, FIX::IntConvertor::convert(), fill(), FIX::SessionID::getBeginString(), getExpectedTargetNum(), FIX::FieldMap::getField(), FIX::FieldMap::getFieldIfSet(), FIX::Message::getHeader(), FIX::SessionState::incrNextTargetMsgSeqNum(), m_sessionID, m_state, FIX::FIELD::MsgSeqNum, FIX::FIELD::MsgType, FIX::MsgType_Logon, FIX::MsgType_SequenceReset, FIX::SessionState::onEvent(), populateRejectReason(), FIX::SessionState::receivedLogon(), FIX::FIELD::RefMsgType, FIX::FIELD::RefSeqNum, FIX::Message::reverseRoute(), sendRaw(), FIX::FIELD::SessionRejectReason, FIX::SessionRejectReason_COMPID_PROBLEM, FIX::SessionRejectReason_COMPID_PROBLEM_TEXT, FIX::SessionRejectReason_INCORRECT_DATA_FORMAT_FOR_VALUE, FIX::SessionRejectReason_INCORRECT_DATA_FORMAT_FOR_VALUE_TEXT, FIX::SessionRejectReason_INCORRECT_NUMINGROUP_COUNT_FOR_REPEATING_GROUP, FIX::SessionRejectReason_INCORRECT_NUMINGROUP_COUNT_FOR_REPEATING_GROUP_TEXT, FIX::SessionRejectReason_INVALID_MSGTYPE, FIX::SessionRejectReason_INVALID_MSGTYPE_TEXT, FIX::SessionRejectReason_INVALID_TAG_NUMBER, FIX::SessionRejectReason_INVALID_TAG_NUMBER_TEXT, FIX::SessionRejectReason_REQUIRED_TAG_MISSING, FIX::SessionRejectReason_REQUIRED_TAG_MISSING_TEXT, FIX::SessionRejectReason_SENDINGTIME_ACCURACY_PROBLEM, FIX::SessionRejectReason_SENDINGTIME_ACCURACY_PROBLEM_TEXT, FIX::SessionRejectReason_TAG_APPEARS_MORE_THAN_ONCE, FIX::SessionRejectReason_TAG_APPEARS_MORE_THAN_ONCE_TEXT, FIX::SessionRejectReason_TAG_NOT_DEFINED_FOR_THIS_MESSAGE_TYPE, FIX::SessionRejectReason_TAG_NOT_DEFINED_FOR_THIS_MESSAGE_TYPE_TEXT, FIX::SessionRejectReason_TAG_SPECIFIED_OUT_OF_REQUIRED_ORDER, FIX::SessionRejectReason_TAG_SPECIFIED_OUT_OF_REQUIRED_ORDER_TEXT, FIX::SessionRejectReason_TAG_SPECIFIED_WITHOUT_A_VALUE, FIX::SessionRejectReason_TAG_SPECIFIED_WITHOUT_A_VALUE_TEXT, FIX::SessionRejectReason_VALUE_IS_INCORRECT, FIX::SessionRejectReason_VALUE_IS_INCORRECT_TEXT, and FIX::FieldMap::setField().

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

721 {
722  std::string beginString = m_sessionID.getBeginString();
723 
724  Message reject;
725  reject.getHeader().setField( MsgType( "3" ) );
726  reject.reverseRoute( message.getHeader() );
727  fill( reject.getHeader() );
728 
729  MsgSeqNum msgSeqNum;
730  MsgType msgType;
731 
732  message.getHeader().getField( msgType );
733  if( message.getHeader().getFieldIfSet( msgSeqNum ) )
734  {
735  if( msgSeqNum.getString() != "" )
736  reject.setField( RefSeqNum( msgSeqNum ) );
737  }
738 
739  if ( beginString >= FIX::BeginString_FIX42 )
740  {
741  if( msgType.getString() != "" )
742  reject.setField( RefMsgType( msgType ) );
743  if ( (beginString == FIX::BeginString_FIX42
745  || beginString > FIX::BeginString_FIX42 )
746  {
747  reject.setField( SessionRejectReason( err ) );
748  }
749  }
750  if ( msgType != MsgType_Logon && msgType != MsgType_SequenceReset
751  && msgSeqNum == getExpectedTargetNum() )
753 
754  const char* reason = 0;
755  switch ( err )
756  {
759  break;
762  break;
765  break;
768  break;
771  break;
774  break;
777  break;
780  break;
783  break;
786  break;
789  break;
792  };
793 
794  if ( reason && ( field || err == SessionRejectReason_INVALID_TAG_NUMBER ) )
795  {
796  populateRejectReason( reject, field, reason );
797  m_state.onEvent( "Message " + msgSeqNum.getString() + " Rejected: "
798  + reason + ":" + IntConvertor::convert( field ) );
799  }
800  else if ( reason )
801  {
802  populateRejectReason( reject, reason );
803  m_state.onEvent( "Message " + msgSeqNum.getString()
804  + " Rejected: " + reason );
805  }
806  else
807  m_state.onEvent( "Message " + msgSeqNum.getString() + " Rejected" );
808 
809  if ( !m_state.receivedLogon() )
810  throw std::runtime_error( "Tried to send a reject while not logged on" );
811 
812  sendRaw( reject );
813 }
int getExpectedTargetNum()
Definition: Session.h:212
const char SessionRejectReason_COMPID_PROBLEM_TEXT[]
Definition: Values.h:47
void populateRejectReason(Message &, int field, const std::string &)
Definition: Session.cpp:916
const int RefMsgType
const char BeginString_FIX42[]
Definition: Values.h:34
void incrNextTargetMsgSeqNum()
Definition: SessionState.h:187
const char SessionRejectReason_INCORRECT_DATA_FORMAT_FOR_VALUE_TEXT[]
Definition: Values.h:44
const char SessionRejectReason_TAG_APPEARS_MORE_THAN_ONCE_TEXT[]
Definition: Values.h:50
const char SessionRejectReason_INVALID_TAG_NUMBER_TEXT[]
Definition: Values.h:38
bool receivedLogon() const
Definition: SessionState.h:53
bool sendRaw(Message &, int msgSeqNum=0)
Definition: Session.cpp:459
SessionID m_sessionID
Definition: Session.h:302
const int SessionRejectReason_TAG_APPEARS_MORE_THAN_ONCE
Definition: FixValues.h:1874
const int SessionRejectReason_TAG_SPECIFIED_OUT_OF_REQUIRED_ORDER
Definition: FixValues.h:1875
const char SessionRejectReason_VALUE_IS_INCORRECT_TEXT[]
Definition: Values.h:43
const char MsgType_SequenceReset[]
Definition: FixValues.h:646
static std::string convert(signed_int value)
const int SessionRejectReason_INVALID_MSGTYPE
Definition: FixValues.h:1880
const char SessionRejectReason_SENDINGTIME_ACCURACY_PROBLEM_TEXT[]
Definition: Values.h:48
const int SessionRejectReason
const char SessionRejectReason_INVALID_MSGTYPE_TEXT[]
Definition: Values.h:49
const char SessionRejectReason_REQUIRED_TAG_MISSING_TEXT[]
Definition: Values.h:39
const int SessionRejectReason_SENDINGTIME_ACCURACY_PROBLEM
Definition: FixValues.h:1881
const char SessionRejectReason_TAG_SPECIFIED_WITHOUT_A_VALUE_TEXT[]
Definition: Values.h:42
const int SessionRejectReason_INCORRECT_NUMINGROUP_COUNT_FOR_REPEATING_GROUP
Definition: FixValues.h:1873
const char SessionRejectReason_INCORRECT_NUMINGROUP_COUNT_FOR_REPEATING_GROUP_TEXT[]
Definition: Values.h:52
SessionState m_state
Definition: Session.h:320
const int SessionRejectReason_INCORRECT_DATA_FORMAT_FOR_VALUE
Definition: FixValues.h:1869
const int SessionRejectReason_TAG_NOT_DEFINED_FOR_THIS_MESSAGE_TYPE
Definition: FixValues.h:1866
void onEvent(const std::string &string)
Definition: SessionState.h:204
const char MsgType_Logon[]
Definition: FixValues.h:614
const char SessionRejectReason_TAG_SPECIFIED_OUT_OF_REQUIRED_ORDER_TEXT[]
Definition: Values.h:51
void fill(Header &)
Definition: Session.cpp:114
const int SessionRejectReason_COMPID_PROBLEM
Definition: FixValues.h:1864
const int MsgSeqNum
const char SessionRejectReason_TAG_NOT_DEFINED_FOR_THIS_MESSAGE_TYPE_TEXT[]
Definition: Values.h:40
const int SessionRejectReason_INVALID_TAG_NUMBER
Definition: FixValues.h:1877
const int RefSeqNum
const int SessionRejectReason_REQUIRED_TAG_MISSING
Definition: FixValues.h:1871
const BeginString & getBeginString() const
Definition: SessionID.h:53
const int MsgType
const int SessionRejectReason_TAG_SPECIFIED_WITHOUT_A_VALUE
Definition: FixValues.h:1879
const int SessionRejectReason_VALUE_IS_INCORRECT
Definition: FixValues.h:1878
void FIX::Session::generateReject ( const Message message,
const std::string &  str 
)
private

Definition at line 815 of file Session.cpp.

References FIX::BeginString_FIX42, fill(), FIX::SessionID::getBeginString(), FIX::FieldMap::getField(), FIX::Message::getHeader(), FIX::SessionState::incrNextTargetMsgSeqNum(), m_sessionID, m_state, FIX::FIELD::MsgSeqNum, FIX::FIELD::MsgType, FIX::MsgType_Logon, FIX::MsgType_SequenceReset, FIX::SessionState::onEvent(), FIX::FIELD::RefMsgType, FIX::FIELD::RefSeqNum, FIX::Message::reverseRoute(), sendRaw(), FIX::FieldMap::setField(), and FIX::FIELD::Text.

816 {
817  std::string beginString = m_sessionID.getBeginString();
818 
819  Message reject;
820  reject.getHeader().setField( MsgType( "3" ) );
821  reject.reverseRoute( message.getHeader() );
822  fill( reject.getHeader() );
823 
824  MsgType msgType;
825  MsgSeqNum msgSeqNum;
826 
827  message.getHeader().getField( msgType );
828  message.getHeader().getField( msgSeqNum );
829  if ( beginString >= FIX::BeginString_FIX42 )
830  reject.setField( RefMsgType( msgType ) );
831  reject.setField( RefSeqNum( msgSeqNum ) );
832 
833  if ( msgType != MsgType_Logon && msgType != MsgType_SequenceReset )
835 
836  reject.setField( Text( str ) );
837  sendRaw( reject );
838  m_state.onEvent( "Message " + msgSeqNum.getString()
839  + " Rejected: " + str );
840 }
const int RefMsgType
const char BeginString_FIX42[]
Definition: Values.h:34
void incrNextTargetMsgSeqNum()
Definition: SessionState.h:187
bool sendRaw(Message &, int msgSeqNum=0)
Definition: Session.cpp:459
SessionID m_sessionID
Definition: Session.h:302
const char MsgType_SequenceReset[]
Definition: FixValues.h:646
SessionState m_state
Definition: Session.h:320
const int Text
void onEvent(const std::string &string)
Definition: SessionState.h:204
const char MsgType_Logon[]
Definition: FixValues.h:614
void fill(Header &)
Definition: Session.cpp:114
const int MsgSeqNum
const int RefSeqNum
const BeginString & getBeginString() const
Definition: SessionID.h:53
const int MsgType
void FIX::Session::generateResendRequest ( const BeginString &  beginString,
const MsgSeqNum &  msgSeqNum 
)
private

Definition at line 643 of file Session.cpp.

References FIX::FIELD::BeginSeqNo, FIX::BeginString_FIX41, FIX::BeginString_FIX42, FIX::IntConvertor::convert(), FIX::FIELD::EndSeqNo, fill(), getExpectedTargetNum(), FIX::Message::getHeader(), m_state, FIX::FIELD::MsgType, FIX::SessionState::onEvent(), FIX::SessionState::resendRange(), sendRaw(), and FIX::FieldMap::setField().

Referenced by doTargetTooHigh().

644 {
645  Message resendRequest;
646  BeginSeqNo beginSeqNo( ( int ) getExpectedTargetNum() );
647  EndSeqNo endSeqNo( msgSeqNum - 1 );
648  if ( beginString >= FIX::BeginString_FIX42 )
649  endSeqNo = 0;
650  else if( beginString <= FIX::BeginString_FIX41 )
651  endSeqNo = 999999;
652  resendRequest.getHeader().setField( MsgType( "2" ) );
653  resendRequest.setField( beginSeqNo );
654  resendRequest.setField( endSeqNo );
655  fill( resendRequest.getHeader() );
656  sendRaw( resendRequest );
657 
658  m_state.onEvent( "Sent ResendRequest FROM: "
659  + IntConvertor::convert( beginSeqNo ) +
660  " TO: " + IntConvertor::convert( endSeqNo ) );
661 
662  m_state.resendRange( beginSeqNo, msgSeqNum - 1 );
663 }
int getExpectedTargetNum()
Definition: Session.h:212
const int BeginSeqNo
const char BeginString_FIX42[]
Definition: Values.h:34
const int EndSeqNo
bool sendRaw(Message &, int msgSeqNum=0)
Definition: Session.cpp:459
static std::string convert(signed_int value)
SessionState m_state
Definition: Session.h:320
const char BeginString_FIX41[]
Definition: Values.h:35
void onEvent(const std::string &string)
Definition: SessionState.h:204
void fill(Header &)
Definition: Session.cpp:114
ResendRange resendRange() const
Definition: SessionState.h:85
const int MsgType
void FIX::Session::generateSequenceReset ( int  beginSeqNo,
int  endSeqNo 
)
private

Definition at line 666 of file Session.cpp.

References FIX::IntConvertor::convert(), FIX::FIELD::GapFillFlag, FIX::FieldMap::getField(), FIX::Message::getHeader(), FIX::FIELD::MsgSeqNum, FIX::FIELD::MsgType, FIX::FIELD::NewSeqNo, FIX::FIELD::PossDupFlag, FIX::FIELD::SendingTime, and FIX::FieldMap::setField().

Referenced by nextResendRequest().

667 {
668  Message sequenceReset;
669  NewSeqNo newSeqNo( endSeqNo );
670  sequenceReset.getHeader().setField( MsgType( "4" ) );
671  sequenceReset.getHeader().setField( PossDupFlag( true ) );
672  sequenceReset.setField( newSeqNo );
673  fill( sequenceReset.getHeader() );
674 
675  SendingTime sendingTime;
676  sequenceReset.getHeader().getField( sendingTime );
677  insertOrigSendingTime( sequenceReset.getHeader(), sendingTime );
678  sequenceReset.getHeader().setField( MsgSeqNum( beginSeqNo ) );
679  sequenceReset.setField( GapFillFlag( true ) );
680  sendRaw( sequenceReset, beginSeqNo );
681  m_state.onEvent( "Sent SequenceReset TO: "
682  + IntConvertor::convert( newSeqNo ) );
683 }
bool sendRaw(Message &, int msgSeqNum=0)
Definition: Session.cpp:459
const int NewSeqNo
static std::string convert(signed_int value)
const int SendingTime
const int GapFillFlag
SessionState m_state
Definition: Session.h:320
void onEvent(const std::string &string)
Definition: SessionState.h:204
void fill(Header &)
Definition: Session.cpp:114
const int PossDupFlag
const int MsgSeqNum
void insertOrigSendingTime(Header &, const UtcTimeStamp &when=UtcTimeStamp())
Definition: Session.cpp:103
const int MsgType
void FIX::Session::generateTestRequest ( const std::string &  id)
private

Definition at line 709 of file Session.cpp.

References fill(), FIX::Message::getHeader(), FIX::FIELD::MsgType, sendRaw(), FIX::FieldMap::setField(), and FIX::FIELD::TestReqID.

Referenced by next().

710 {
711  Message testRequest;
712  testRequest.getHeader().setField( MsgType( "1" ) );
713  fill( testRequest.getHeader() );
714  TestReqID testReqID( id );
715  testRequest.setField( testReqID );
716 
717  sendRaw( testRequest );
718 }
bool sendRaw(Message &, int msgSeqNum=0)
Definition: Session.cpp:459
void fill(Header &)
Definition: Session.cpp:114
const int TestReqID
const int MsgType
bool FIX::Session::get ( int  s,
Message m 
) const
private
bool FIX::Session::getCheckCompId ( )
inline

Definition at line 137 of file Session.h.

References m_checkCompId.

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

138  { return m_checkCompId; }
bool m_checkCompId
Definition: Session.h:309
bool FIX::Session::getCheckLatency ( )
inline

Definition at line 142 of file Session.h.

References m_checkLatency.

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

143  { return m_checkLatency; }
bool m_checkLatency
Definition: Session.h:310
const DataDictionaryProvider& FIX::Session::getDataDictionaryProvider ( ) const
inline

Definition at line 79 of file Session.h.

References m_dataDictionaryProvider.

80  { return m_dataDictionaryProvider; }
DataDictionaryProvider m_dataDictionaryProvider
Definition: Session.h:321
int FIX::Session::getExpectedSenderNum ( )
inline
int FIX::Session::getExpectedTargetNum ( )
inline
Log* FIX::Session::getLog ( )
inline
const TimeRange& FIX::Session::getLogonTime ( )
inline

Definition at line 117 of file Session.h.

References m_logonTime.

118  { return m_logonTime; }
TimeRange m_logonTime
Definition: Session.h:304
int FIX::Session::getLogonTimeout ( )
inline

Definition at line 152 of file Session.h.

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

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

153  { return m_state.logonTimeout(); }
int logonTimeout() const
Definition: SessionState.h:71
SessionState m_state
Definition: Session.h:320
int FIX::Session::getLogoutTimeout ( )
inline

Definition at line 157 of file Session.h.

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

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

158  { return m_state.logoutTimeout(); }
int logoutTimeout() const
Definition: SessionState.h:74
SessionState m_state
Definition: Session.h:320
int FIX::Session::getMaxLatency ( )
inline

Definition at line 147 of file Session.h.

References m_maxLatency.

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

148  { return m_maxLatency; }
int m_maxLatency
Definition: Session.h:311
bool FIX::Session::getMillisecondsInTimeStamp ( )
inline

Definition at line 182 of file Session.h.

References m_millisecondsInTimeStamp.

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

183  { return m_millisecondsInTimeStamp; }
bool m_millisecondsInTimeStamp
Definition: Session.h:316
bool FIX::Session::getPersistMessages ( )
inline

Definition at line 187 of file Session.h.

References m_persistMessages.

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

188  { return m_persistMessages; }
bool m_persistMessages
Definition: Session.h:317
bool FIX::Session::getRefreshOnLogon ( )
inline

Definition at line 177 of file Session.h.

References m_refreshOnLogon.

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

178  { return m_refreshOnLogon; }
bool m_refreshOnLogon
Definition: Session.h:315
bool FIX::Session::getResetOnDisconnect ( )
inline

Definition at line 172 of file Session.h.

References m_resetOnDisconnect.

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

173  { return m_resetOnDisconnect; }
bool m_resetOnDisconnect
Definition: Session.h:314
bool FIX::Session::getResetOnLogon ( )
inline

Definition at line 162 of file Session.h.

References m_resetOnLogon.

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

163  { return m_resetOnLogon; }
bool m_resetOnLogon
Definition: Session.h:312
bool FIX::Session::getResetOnLogout ( )
inline

Definition at line 167 of file Session.h.

References m_resetOnLogout.

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

168  { return m_resetOnLogout; }
bool m_resetOnLogout
Definition: Session.h:313
const std::string& FIX::Session::getSenderDefaultApplVerID ( )
inline

Definition at line 122 of file Session.h.

References m_senderDefaultApplVerID.

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

123  { return m_senderDefaultApplVerID; }
std::string m_senderDefaultApplVerID
Definition: Session.h:306
bool FIX::Session::getSendRedundantResendRequests ( )
inline

Definition at line 132 of file Session.h.

References m_sendRedundantResendRequests.

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

bool m_sendRedundantResendRequests
Definition: Session.h:308
const SessionID& FIX::Session::getSessionID ( ) const
inline
std::set< SessionID > FIX::Session::getSessions ( )
static
const MessageStore* FIX::Session::getStore ( )
inline

Definition at line 215 of file Session.h.

References m_state.

215 { return &m_state; }
SessionState m_state
Definition: Session.h:320
const std::string& FIX::Session::getTargetDefaultApplVerID ( )
inline

Definition at line 127 of file Session.h.

References m_targetDefaultApplVerID.

128  { return m_targetDefaultApplVerID; }
std::string m_targetDefaultApplVerID
Definition: Session.h:307
bool FIX::Session::getValidateLengthAndChecksum ( )
inline

Definition at line 192 of file Session.h.

References m_validateLengthAndChecksum.

193  { return m_validateLengthAndChecksum; }
bool m_validateLengthAndChecksum
Definition: Session.h:318
void FIX::Session::insertOrigSendingTime ( Header header,
const UtcTimeStamp when = UtcTimeStamp () 
)
private

Definition at line 103 of file Session.cpp.

References FIX::BeginString_FIX42, FIX::BeginString_FIXT11, FIX::SessionID::getBeginString(), m_millisecondsInTimeStamp, m_sessionID, FIX::FIELD::OrigSendingTime, and FIX::FieldMap::setField().

Referenced by resend().

104 {
105  bool showMilliseconds = false;
107  showMilliseconds = true;
108  else
109  showMilliseconds = m_sessionID.getBeginString() >= BeginString_FIX42;
110 
111  header.setField( OrigSendingTime(when, showMilliseconds && m_millisecondsInTimeStamp) );
112 }
const int OrigSendingTime
const char BeginString_FIX42[]
Definition: Values.h:34
const char BeginString_FIXT11[]
Definition: Values.h:30
SessionID m_sessionID
Definition: Session.h:302
bool m_millisecondsInTimeStamp
Definition: Session.h:316
const BeginString & getBeginString() const
Definition: SessionID.h:53
void FIX::Session::insertSendingTime ( Header header)
private

Definition at line 91 of file Session.cpp.

References FIX::BeginString_FIX42, FIX::BeginString_FIXT11, FIX::SessionID::getBeginString(), m_millisecondsInTimeStamp, m_sessionID, FIX::FIELD::SendingTime, and FIX::FieldMap::setField().

Referenced by fill(), and resend().

92 {
93  UtcTimeStamp now;
94  bool showMilliseconds = false;
96  showMilliseconds = true;
97  else
98  showMilliseconds = m_sessionID.getBeginString() >= BeginString_FIX42;
99 
100  header.setField( SendingTime(now, showMilliseconds && m_millisecondsInTimeStamp) );
101 }
const char BeginString_FIX42[]
Definition: Values.h:34
const char BeginString_FIXT11[]
Definition: Values.h:30
SessionID m_sessionID
Definition: Session.h:302
const int SendingTime
bool m_millisecondsInTimeStamp
Definition: Session.h:316
const BeginString & getBeginString() const
Definition: SessionID.h:53
bool FIX::Session::isAcceptor ( )
inline

Definition at line 114 of file Session.h.

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

115  { return !m_state.initiate(); }
bool initiate() const
Definition: SessionState.h:68
SessionState m_state
Definition: Session.h:320
bool FIX::Session::isCorrectCompID ( const SenderCompID &  senderCompID,
const TargetCompID &  targetCompID 
)
inlineprivate

Definition at line 249 of file Session.h.

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

Referenced by verify().

251  {
252  if( !m_checkCompId ) return true;
253 
254  return
255  m_sessionID.getSenderCompID().getValue() == targetCompID.getValue()
256  && m_sessionID.getTargetCompID().getValue() == senderCompID.getValue();
257  }
SessionID m_sessionID
Definition: Session.h:302
bool m_checkCompId
Definition: Session.h:309
const SenderCompID & getSenderCompID() const
Definition: SessionID.h:55
const TargetCompID & getTargetCompID() const
Definition: SessionID.h:57
bool FIX::Session::isEnabled ( )
inline
bool FIX::Session::isGoodTime ( const SendingTime &  sendingTime)
inlineprivate

Definition at line 234 of file Session.h.

References m_checkLatency, and m_maxLatency.

Referenced by verify().

235  {
236  if ( !m_checkLatency ) return true;
237  UtcTimeStamp now;
238  return labs( now - sendingTime ) <= m_maxLatency;
239  }
bool m_checkLatency
Definition: Session.h:310
int m_maxLatency
Definition: Session.h:311
bool FIX::Session::isInitiator ( )
inline

Definition at line 112 of file Session.h.

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

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

113  { return m_state.initiate(); }
bool initiate() const
Definition: SessionState.h:68
SessionState m_state
Definition: Session.h:320
bool FIX::Session::isLoggedOn ( )
inline
bool FIX::Session::isLogonTime ( const UtcTimeStamp time)
inline

Definition at line 110 of file Session.h.

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

Referenced by next(), and nextLogon().

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

Definition at line 1438 of file Session.cpp.

References s_mutex, and s_registered.

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

1439 {
1440  Locker locker( s_mutex );
1441  return s_registered.end() != s_registered.find( sessionID );
1442 }
static Mutex s_mutex
Definition: Session.h:330
static Sessions s_registered
Definition: Session.h:329
bool FIX::Session::isSessionTime ( const UtcTimeStamp time)
inline

Definition at line 108 of file Session.h.

References FIX::TimeRange::isInRange(), and m_sessionTime.

Referenced by FIX::Initiator::connect(), FIX::SocketInitiator::doConnect(), FIX::ThreadedSocketInitiator::doConnect(), FIX::HttpConnection::processRoot(), and FIX::HttpConnection::processSession().

109  { return m_sessionTime.isInRange(time); }
static bool isInRange(const UtcTimeOnly &start, const UtcTimeOnly &end, const DateTime &time)
Definition: TimeRange.h:43
TimeRange m_sessionTime
Definition: Session.h:303
bool FIX::Session::isTargetTooHigh ( const MsgSeqNum &  msgSeqNum)
inlineprivate

Definition at line 245 of file Session.h.

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

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

246  { return msgSeqNum > ( m_state.getNextTargetMsgSeqNum() ); }
int getNextTargetMsgSeqNum() const
Definition: SessionState.h:179
SessionState m_state
Definition: Session.h:320
bool FIX::Session::isTargetTooLow ( const MsgSeqNum &  msgSeqNum)
inlineprivate

Definition at line 247 of file Session.h.

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

Referenced by nextResendRequest(), and verify().

248  { return msgSeqNum < ( m_state.getNextTargetMsgSeqNum() ); }
int getNextTargetMsgSeqNum() const
Definition: SessionState.h:179
SessionState m_state
Definition: Session.h:320
void FIX::Session::logon ( )
inline
void FIX::Session::logout ( const std::string &  reason = "")
inline
Session * FIX::Session::lookupSession ( const SessionID sessionID)
static
Session * FIX::Session::lookupSession ( const std::string &  string,
bool  reverse = false 
)
static

Definition at line 1413 of file Session.cpp.

References FIX::FIELD::BeginString, FIELD_GET_REF, FIX::Message::getHeader(), lookupSession(), FIX::FIELD::SenderCompID, FIX::Message::setStringHeader(), and FIX::FIELD::TargetCompID.

1414 {
1415  Message message;
1416  if ( !message.setStringHeader( string ) )
1417  return 0;
1418 
1419  try
1420  {
1421  const Header& header = message.getHeader();
1422  const BeginString& beginString = FIELD_GET_REF( header, BeginString );
1423  const SenderCompID& senderCompID = FIELD_GET_REF( header, SenderCompID );
1424  const TargetCompID& targetCompID = FIELD_GET_REF( header, TargetCompID );
1425 
1426  if ( reverse )
1427  {
1428  return lookupSession( SessionID( beginString, SenderCompID( targetCompID ),
1429  TargetCompID( senderCompID ) ) );
1430  }
1431 
1432  return lookupSession( SessionID( beginString, senderCompID,
1433  targetCompID ) );
1434  }
1435  catch ( FieldNotFound& ) { return 0; }
1436 }
static Session * lookupSession(const SessionID &)
Definition: Session.cpp:1403
const int TargetCompID
const int SenderCompID
const int BeginString
#define FIELD_GET_REF(MAP, FLD)
Definition: FieldMap.h:236
void FIX::Session::next ( )
void FIX::Session::next ( const UtcTimeStamp timeStamp)

Definition at line 130 of file Session.cpp.

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(), FIX::SessionState::shouldSendLogon(), FIX::SessionState::testRequest(), FIX::SessionState::timedOut(), and FIX::SessionState::withinHeartBeat().

131 {
132  try
133  {
134  if ( !checkSessionTime(timeStamp) )
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  {
153  if ( m_state.shouldSendLogon() && isLogonTime(timeStamp) )
154  {
155  generateLogon();
156  m_state.onEvent( "Initiated logon request" );
157  }
158  else if ( m_state.alreadySentLogon() && m_state.logonTimedOut() )
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 
174  if ( m_state.withinHeartBeat() ) return ;
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 }
bool isEnabled()
Definition: Session.h:59
void generateHeartbeat()
Definition: Session.cpp:685
bool sentLogout() const
Definition: SessionState.h:56
bool withinHeartBeat() const
Definition: SessionState.h:127
bool receivedLogon() const
Definition: SessionState.h:53
void reset()
Definition: Session.h:66
bool isLogonTime(const UtcTimeStamp &time)
Definition: Session.h:110
void generateLogon()
Definition: Session.cpp:602
void disconnect()
Definition: Session.cpp:542
SessionState m_state
Definition: Session.h:320
bool logoutTimedOut() const
Definition: SessionState.h:122
bool checkSessionTime(const UtcTimeStamp &timeStamp)
Definition: Session.h:240
void generateTestRequest(const std::string &)
Definition: Session.cpp:709
void onEvent(const std::string &string)
Definition: SessionState.h:204
bool alreadySentLogon() const
Definition: SessionState.h:116
void generateLogout(const std::string &text="")
Definition: Session.cpp:905
bool logonTimedOut() const
Definition: SessionState.h:117
int testRequest() const
Definition: SessionState.h:77
bool needHeartbeat() const
Definition: SessionState.h:138
bool needTestRequest() const
Definition: SessionState.h:143
std::string logoutReason() const
Definition: SessionState.h:150
bool timedOut() const
Definition: SessionState.h:133
IO Error.
Definition: Exceptions.h:238
void heartBtInt(const HeartBtInt &value)
Definition: SessionState.h:94
bool shouldSendLogon() const
Definition: SessionState.h:115
bool isLoggedOn()
Definition: Session.h:65
void FIX::Session::next ( const std::string &  msg,
const UtcTimeStamp timeStamp,
bool  queued = false 
)

Definition at line 1174 of file Session.cpp.

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, FIX::MsgType_Logon, next(), FIX::SessionState::onEvent(), and FIX::SessionState::onIncoming().

1175 {
1176  try
1177  {
1178  m_state.onIncoming( msg );
1179  const DataDictionary& sessionDD =
1181  if( m_sessionID.isFIXT() )
1182  {
1183  const DataDictionary& applicationDD =
1185  next( Message( msg, sessionDD, applicationDD, m_validateLengthAndChecksum ), timeStamp, queued );
1186  }
1187  else
1188  {
1189  next( Message( msg, sessionDD, m_validateLengthAndChecksum ), timeStamp, queued );
1190  }
1191  }
1192  catch( InvalidMessage& e )
1193  {
1194  m_state.onEvent( e.what() );
1195 
1196  try
1197  {
1198  if( identifyType(msg) == MsgType_Logon )
1199  {
1200  m_state.onEvent( "Logon message is not valid" );
1201  disconnect();
1202  }
1203  } catch( MessageParseError& ) {}
1204  throw e;
1205  }
1206 }
DataDictionaryProvider m_dataDictionaryProvider
Definition: Session.h:321
void next()
Definition: Session.cpp:125
const DataDictionary & getApplicationDataDictionary(const ApplVerID &applVerID) const
SessionID m_sessionID
Definition: Session.h:302
const DataDictionary & getSessionDataDictionary(const BeginString &beginString) const
std::string m_senderDefaultApplVerID
Definition: Session.h:306
void disconnect()
Definition: Session.cpp:542
const bool isFIXT() const
Definition: SessionID.h:61
SessionState m_state
Definition: Session.h:320
bool m_validateLengthAndChecksum
Definition: Session.h:318
void onIncoming(const std::string &string)
Definition: SessionState.h:200
void onEvent(const std::string &string)
Definition: SessionState.h:204
const char MsgType_Logon[]
Definition: FixValues.h:614
MsgType identifyType(const std::string &message)
Parse the type of a message from a string.
Definition: Message.h:355
const BeginString & getBeginString() const
Definition: SessionID.h:53
void FIX::Session::next ( const Message message,
const UtcTimeStamp timeStamp,
bool  queued = false 
)

Definition at line 1208 of file Session.cpp.

References FIX::FIELD::ApplVerID, FIX::FIELD::BeginString, FIX::BeginString_FIX42, FIX::BusinessRejectReason_CONDITIONALLY_REQUIRED_FIELD_MISSING, FIX::BusinessRejectReason_UNKNOWN_MESSAGE_TYPE, checkSessionTime(), FIX::FIELD::DefaultApplVerID, disconnect(), FIX::FieldNotFound::field, FIX::InvalidTagNumber::field, FIX::RequiredTagMissing::field, FIX::TagNotDefinedForMessage::field, FIX::NoTagValue::field, FIX::IncorrectTagValue::field, FIX::IncorrectDataFormat::field, FIX::TagOutOfOrder::field, FIX::RepeatedTag::field, FIX::RepeatingGroupCountMismatch::field, FIELD_GET_REF, FIELD_THROW_IF_NOT_FOUND, generateBusinessReject(), generateLogout(), generateReject(), FIX::DataDictionaryProvider::getApplicationDataDictionary(), FIX::SessionID::getBeginString(), FIX::FieldMap::getField(), FIX::FieldMap::getFieldIfSet(), FIX::Message::getHeader(), FIX::DataDictionaryProvider::getSessionDataDictionary(), FIX::SessionState::incrNextTargetMsgSeqNum(), FIX::Message::isApp(), FIX::SessionID::isFIXT(), isLoggedOn(), LOGEX, m_dataDictionaryProvider, m_sessionID, m_state, m_targetDefaultApplVerID, FIX::FIELD::MsgType, FIX::MsgType_Heartbeat, FIX::MsgType_Logon, FIX::MsgType_Logout, FIX::MsgType_Reject, FIX::MsgType_ResendRequest, FIX::MsgType_SequenceReset, FIX::MsgType_TestRequest, next(), nextHeartbeat(), nextLogon(), nextLogout(), nextQueued(), nextReject(), nextResendRequest(), nextSequenceReset(), nextTestRequest(), FIX::SessionState::onEvent(), reset(), FIX::FIELD::SenderCompID, FIX::SessionRejectReason_INCORRECT_DATA_FORMAT_FOR_VALUE, FIX::SessionRejectReason_INCORRECT_NUMINGROUP_COUNT_FOR_REPEATING_GROUP, FIX::SessionRejectReason_INVALID_MSGTYPE, FIX::SessionRejectReason_INVALID_TAG_NUMBER, FIX::SessionRejectReason_REQUIRED_TAG_MISSING, FIX::SessionRejectReason_TAG_APPEARS_MORE_THAN_ONCE, FIX::SessionRejectReason_TAG_NOT_DEFINED_FOR_THIS_MESSAGE_TYPE, FIX::SessionRejectReason_TAG_SPECIFIED_OUT_OF_REQUIRED_ORDER, FIX::SessionRejectReason_TAG_SPECIFIED_WITHOUT_A_VALUE, FIX::SessionRejectReason_VALUE_IS_INCORRECT, setTargetDefaultApplVerID(), FIX::FIELD::TargetCompID, FIX::Message::toApplVerID(), FIX::DataDictionary::validate(), and verify().

1209 {
1210  const Header& header = message.getHeader();
1211 
1212  try
1213  {
1214  if ( !checkSessionTime(timeStamp) )
1215  { reset(); return; }
1216 
1217  const MsgType& msgType = FIELD_GET_REF( header, MsgType );
1218  const BeginString& beginString = FIELD_GET_REF( header, BeginString );
1219  // make sure these fields are present
1222 
1223  if ( beginString != m_sessionID.getBeginString() )
1224  throw UnsupportedVersion();
1225 
1226  if( msgType == MsgType_Logon )
1227  {
1228  if( m_sessionID.isFIXT() )
1229  {
1230  const DefaultApplVerID& applVerID = FIELD_GET_REF( message, DefaultApplVerID );
1231  setTargetDefaultApplVerID(applVerID);
1232  }
1233  else
1234  {
1236  }
1237  }
1238 
1239  const DataDictionary& sessionDataDictionary =
1241 
1242  if( m_sessionID.isFIXT() && message.isApp() )
1243  {
1244  ApplVerID applVerID = m_targetDefaultApplVerID;
1245  header.getFieldIfSet(applVerID);
1246  const DataDictionary& applicationDataDictionary =
1248  DataDictionary::validate( message, &sessionDataDictionary, &applicationDataDictionary );
1249  }
1250  else
1251  {
1252  sessionDataDictionary.validate( message );
1253  }
1254 
1255  if ( msgType == MsgType_Logon )
1256  nextLogon( message, timeStamp );
1257  else if ( msgType == MsgType_Heartbeat )
1258  nextHeartbeat( message, timeStamp );
1259  else if ( msgType == MsgType_TestRequest )
1260  nextTestRequest( message, timeStamp );
1261  else if ( msgType == MsgType_SequenceReset )
1262  nextSequenceReset( message, timeStamp );
1263  else if ( msgType == MsgType_Logout )
1264  nextLogout( message, timeStamp );
1265  else if ( msgType == MsgType_ResendRequest )
1266  nextResendRequest( message,timeStamp );
1267  else if ( msgType == MsgType_Reject )
1268  nextReject( message, timeStamp );
1269  else
1270  {
1271  if ( !verify( message ) ) return ;
1273  }
1274  }
1275  catch ( MessageParseError& e )
1276  { m_state.onEvent( e.what() ); }
1277  catch ( RequiredTagMissing & e )
1279  catch ( FieldNotFound & e )
1280  {
1281  if( header.getField(FIELD::BeginString) >= FIX::BeginString_FIX42 && message.isApp() )
1282  {
1284  }
1285  else
1286  {
1288  if ( header.getField(FIELD::MsgType) == MsgType_Logon )
1289  {
1290  m_state.onEvent( "Required field missing from logon" );
1291  disconnect();
1292  }
1293  }
1294  }
1295  catch ( InvalidTagNumber & e )
1296  { LOGEX( generateReject( message, SessionRejectReason_INVALID_TAG_NUMBER, e.field ) ); }
1297  catch ( NoTagValue & e )
1299  catch ( TagNotDefinedForMessage & e )
1301  catch ( InvalidMessageType& )
1303  catch ( UnsupportedMessageType& )
1304  {
1305  if ( header.getField(FIELD::BeginString) >= FIX::BeginString_FIX42 )
1307  else
1308  { LOGEX( generateReject( message, "Unsupported message type" ) ); }
1309  }
1310  catch ( TagOutOfOrder & e )
1312  catch ( IncorrectDataFormat & e )
1314  catch ( IncorrectTagValue & e )
1315  { LOGEX( generateReject( message, SessionRejectReason_VALUE_IS_INCORRECT, e.field ) ); }
1316  catch ( RepeatedTag & e )
1318  catch ( RepeatingGroupCountMismatch & e )
1320  catch ( InvalidMessage& e )
1321  { m_state.onEvent( e.what() ); }
1322  catch ( RejectLogon& e )
1323  {
1324  m_state.onEvent( e.what() );
1325  generateLogout( e.what() );
1326  disconnect();
1327  }
1328  catch ( UnsupportedVersion& )
1329  {
1330  if ( header.getField(FIELD::MsgType) == MsgType_Logout )
1331  nextLogout( message, timeStamp );
1332  else
1333  {
1334  generateLogout( "Incorrect BeginString" );
1336  }
1337  }
1338  catch ( IOException& e )
1339  {
1340  m_state.onEvent( e.what() );
1341  disconnect();
1342  }
1343 
1344  if( !queued )
1345  nextQueued( timeStamp );
1346 
1347  if( isLoggedOn() )
1348  next();
1349 }
const int ApplVerID
bool verify(const Message &msg, bool checkTooHigh=true, bool checkTooLow=true)
Definition: Session.cpp:941
#define FIELD_THROW_IF_NOT_FOUND(MAP, FLD)
Definition: FieldMap.h:238
DataDictionaryProvider m_dataDictionaryProvider
Definition: Session.h:321
const char BeginString_FIX42[]
Definition: Values.h:34
void nextReject(const Message &, const UtcTimeStamp &timeStamp)
Definition: Session.cpp:312
void incrNextTargetMsgSeqNum()
Definition: SessionState.h:187
void next()
Definition: Session.cpp:125
static ApplVerID toApplVerID(const BeginString &value)
Definition: Message.h:257
const DataDictionary & getApplicationDataDictionary(const ApplVerID &applVerID) const
const char MsgType_ResendRequest[]
Definition: FixValues.h:666
SessionID m_sessionID
Definition: Session.h:302
const int SessionRejectReason_TAG_APPEARS_MORE_THAN_ONCE
Definition: FixValues.h:1874
void nextTestRequest(const Message &, const UtcTimeStamp &timeStamp)
Definition: Session.cpp:287
void reset()
Definition: Session.h:66
const int SessionRejectReason_TAG_SPECIFIED_OUT_OF_REQUIRED_ORDER
Definition: FixValues.h:1875
void nextResendRequest(const Message &, const UtcTimeStamp &timeStamp)
Definition: Session.cpp:344
const char MsgType_SequenceReset[]
Definition: FixValues.h:646
const int SessionRejectReason_INVALID_MSGTYPE
Definition: FixValues.h:1880
static void validate(const Message &message, const DataDictionary *const pSessionDD, const DataDictionary *const pAppID)
Validate a message.
const int BusinessRejectReason_UNKNOWN_MESSAGE_TYPE
Definition: FixValues.h:3274
const DataDictionary & getSessionDataDictionary(const BeginString &beginString) const
const int BusinessRejectReason_CONDITIONALLY_REQUIRED_FIELD_MISSING
Definition: FixValues.h:3270
void disconnect()
Definition: Session.cpp:542
const int TargetCompID
const bool isFIXT() const
Definition: SessionID.h:61
const int SessionRejectReason_INCORRECT_NUMINGROUP_COUNT_FOR_REPEATING_GROUP
Definition: FixValues.h:1873
void generateReject(const Message &, int err, int field=0)
Definition: Session.cpp:720
SessionState m_state
Definition: Session.h:320
std::string m_targetDefaultApplVerID
Definition: Session.h:307
#define LOGEX(method)
Definition: Session.cpp:38
const int SessionRejectReason_INCORRECT_DATA_FORMAT_FOR_VALUE
Definition: FixValues.h:1869
bool checkSessionTime(const UtcTimeStamp &timeStamp)
Definition: Session.h:240
const int SessionRejectReason_TAG_NOT_DEFINED_FOR_THIS_MESSAGE_TYPE
Definition: FixValues.h:1866
void nextHeartbeat(const Message &, const UtcTimeStamp &timeStamp)
Definition: Session.cpp:280
const char MsgType_TestRequest[]
Definition: FixValues.h:629
const int SenderCompID
void onEvent(const std::string &string)
Definition: SessionState.h:204
void nextLogon(const Message &, const UtcTimeStamp &timeStamp)
Definition: Session.cpp:202
const char MsgType_Logon[]
Definition: FixValues.h:614
const int DefaultApplVerID
void generateLogout(const std::string &text="")
Definition: Session.cpp:905
void generateBusinessReject(const Message &, int err, int field=0)
Definition: Session.cpp:842
const int BeginString
const int SessionRejectReason_INVALID_TAG_NUMBER
Definition: FixValues.h:1877
const char MsgType_Logout[]
Definition: FixValues.h:622
void nextQueued(const UtcTimeStamp &timeStamp)
Definition: Session.cpp:1145
const char MsgType_Heartbeat[]
Definition: FixValues.h:634
const int SessionRejectReason_REQUIRED_TAG_MISSING
Definition: FixValues.h:1871
const BeginString & getBeginString() const
Definition: SessionID.h:53
void nextLogout(const Message &, const UtcTimeStamp &timeStamp)
Definition: Session.cpp:295
#define FIELD_GET_REF(MAP, FLD)
Definition: FieldMap.h:236
void setTargetDefaultApplVerID(const std::string &targetDefaultApplVerID)
Definition: Session.h:129
const int MsgType
const int SessionRejectReason_TAG_SPECIFIED_WITHOUT_A_VALUE
Definition: FixValues.h:1879
void nextSequenceReset(const Message &, const UtcTimeStamp &timeStamp)
Definition: Session.cpp:319
const char MsgType_Reject[]
Definition: FixValues.h:682
const int SessionRejectReason_VALUE_IS_INCORRECT
Definition: FixValues.h:1878
bool isLoggedOn()
Definition: Session.h:65
void FIX::Session::nextHeartbeat ( const Message heartbeat,
const UtcTimeStamp timeStamp 
)
private

Definition at line 280 of file Session.cpp.

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

Referenced by next().

281 {
282  if ( !verify( heartbeat ) ) return ;
284  nextQueued( timeStamp );
285 }
bool verify(const Message &msg, bool checkTooHigh=true, bool checkTooLow=true)
Definition: Session.cpp:941
void incrNextTargetMsgSeqNum()
Definition: SessionState.h:187
SessionState m_state
Definition: Session.h:320
void nextQueued(const UtcTimeStamp &timeStamp)
Definition: Session.cpp:1145
void FIX::Session::nextLogon ( const Message logon,
const UtcTimeStamp timeStamp 
)
private

Definition at line 202 of file Session.cpp.

References disconnect(), doTargetTooHigh(), generateLogon(), FIX::FieldMap::getField(), FIX::FieldMap::getFieldIfSet(), FIX::Message::getHeader(), FIX::SessionState::heartBtInt(), FIX::SessionState::incrNextTargetMsgSeqNum(), FIX::SessionState::initiate(), isEnabled(), isLoggedOn(), isLogonTime(), isTargetTooHigh(), m_application, m_refreshOnLogon, m_resetOnLogon, m_sessionID, m_state, FIX::FIELD::MsgSeqNum, nextQueued(), FIX::SessionState::onEvent(), FIX::Application::onLogon(), FIX::SessionState::receivedLogon(), FIX::SessionState::receivedReset(), refresh(), FIX::SessionState::reset(), FIX::FIELD::ResetSeqNumFlag, FIX::FIELD::SenderCompID, FIX::SessionState::sentReset(), FIX::SessionState::shouldSendLogon(), FIX::FIELD::TargetCompID, and verify().

Referenced by next().

203 {
204  SenderCompID senderCompID;
205  TargetCompID targetCompID;
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 
226  ResetSeqNumFlag resetSeqNumFlag(false);
227  logon.getFieldIfSet(resetSeqNumFlag);
228  m_state.receivedReset( 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 
243  if( !m_state.initiate() && m_resetOnLogon )
244  m_state.reset();
245 
246  if( !verify( logon, false, true ) )
247  return;
248  m_state.receivedLogon( true );
249 
250  if ( !m_state.initiate()
251  || (m_state.receivedReset() && !m_state.sentReset()) )
252  {
253  logon.getFieldIfSet(m_state.heartBtInt());
254  m_state.onEvent( "Received logon request" );
255  generateLogon( logon );
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 
264  MsgSeqNum msgSeqNum;
265  logon.getHeader().getField( msgSeqNum );
266  if ( isTargetTooHigh( msgSeqNum ) && !resetSeqNumFlag )
267  {
269  }
270  else
271  {
273  nextQueued( timeStamp );
274  }
275 
276  if ( isLoggedOn() )
278 }
bool isEnabled()
Definition: Session.h:59
bool verify(const Message &msg, bool checkTooHigh=true, bool checkTooLow=true)
Definition: Session.cpp:941
void incrNextTargetMsgSeqNum()
Definition: SessionState.h:187
bool receivedLogon() const
Definition: SessionState.h:53
virtual void onLogon(const SessionID &)=0
Notification of a session successfully logging on.
SessionID m_sessionID
Definition: Session.h:302
bool sentReset() const
Definition: SessionState.h:65
bool receivedReset() const
Definition: SessionState.h:62
void refresh()
Definition: Session.h:68
bool isLogonTime(const UtcTimeStamp &time)
Definition: Session.h:110
void doTargetTooHigh(const Message &msg)
Definition: Session.cpp:1113
void generateLogon()
Definition: Session.cpp:602
Application & m_application
Definition: Session.h:301
bool m_resetOnLogon
Definition: Session.h:312
void disconnect()
Definition: Session.cpp:542
bool initiate() const
Definition: SessionState.h:68
bool isTargetTooHigh(const MsgSeqNum &msgSeqNum)
Definition: Session.h:245
const int TargetCompID
SessionState m_state
Definition: Session.h:320
const int SenderCompID
void onEvent(const std::string &string)
Definition: SessionState.h:204
const int ResetSeqNumFlag
const int MsgSeqNum
void nextQueued(const UtcTimeStamp &timeStamp)
Definition: Session.cpp:1145
bool m_refreshOnLogon
Definition: Session.h:315
void heartBtInt(const HeartBtInt &value)
Definition: SessionState.h:94
void logon()
Definition: Session.h:55
bool shouldSendLogon() const
Definition: SessionState.h:115
bool isLoggedOn()
Definition: Session.h:65
void FIX::Session::nextLogout ( const Message logout,
const UtcTimeStamp timeStamp 
)
private

Definition at line 295 of file Session.cpp.

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

Referenced by next().

296 {
297  if ( !verify( logout, false, false ) ) return ;
298  if ( !m_state.sentLogout() )
299  {
300  m_state.onEvent( "Received logout request" );
301  generateLogout();
302  m_state.onEvent( "Sending logout response" );
303  }
304  else
305  m_state.onEvent( "Received logout response" );
306 
308  if ( m_resetOnLogout ) m_state.reset();
309  disconnect();
310 }
bool verify(const Message &msg, bool checkTooHigh=true, bool checkTooLow=true)
Definition: Session.cpp:941
void incrNextTargetMsgSeqNum()
Definition: SessionState.h:187
bool sentLogout() const
Definition: SessionState.h:56
void disconnect()
Definition: Session.cpp:542
SessionState m_state
Definition: Session.h:320
void onEvent(const std::string &string)
Definition: SessionState.h:204
void generateLogout(const std::string &text="")
Definition: Session.cpp:905
void logout(const std::string &reason="")
Definition: Session.h:57
bool m_resetOnLogout
Definition: Session.h:313
void FIX::Session::nextQueued ( const UtcTimeStamp timeStamp)
private

Definition at line 1145 of file Session.cpp.

References getExpectedTargetNum().

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

1146 {
1147  while ( nextQueued( getExpectedTargetNum(), timeStamp ) ) {}
1148 }
int getExpectedTargetNum()
Definition: Session.h:212
void nextQueued(const UtcTimeStamp &timeStamp)
Definition: Session.cpp:1145
bool FIX::Session::nextQueued ( int  num,
const UtcTimeStamp timeStamp 
)
private

Definition at line 1150 of file Session.cpp.

References FIX::IntConvertor::convert(), FIX::FieldMap::getField(), FIX::Message::getHeader(), FIX::SessionState::incrNextTargetMsgSeqNum(), m_state, FIX::FIELD::MsgType, FIX::MsgType_Logon, FIX::MsgType_ResendRequest, next(), FIX::SessionState::onEvent(), and FIX::SessionState::retrieve().

1151 {
1152  Message msg;
1153  MsgType msgType;
1154 
1155  if( m_state.retrieve( num, msg ) )
1156  {
1157  m_state.onEvent( "Processing QUEUED message: "
1158  + IntConvertor::convert( num ) );
1159  msg.getHeader().getField( msgType );
1160  if( msgType == MsgType_Logon
1161  || msgType == MsgType_ResendRequest )
1162  {
1164  }
1165  else
1166  {
1167  next( msg, timeStamp, true );
1168  }
1169  return true;
1170  }
1171  return false;
1172 }
void incrNextTargetMsgSeqNum()
Definition: SessionState.h:187
void next()
Definition: Session.cpp:125
bool retrieve(int msgSeqNum, Message &message)
Definition: SessionState.h:157
const char MsgType_ResendRequest[]
Definition: FixValues.h:666
static std::string convert(signed_int value)
SessionState m_state
Definition: Session.h:320
void onEvent(const std::string &string)
Definition: SessionState.h:204
const char MsgType_Logon[]
Definition: FixValues.h:614
const int MsgType
void FIX::Session::nextReject ( const Message reject,
const UtcTimeStamp timeStamp 
)
private

Definition at line 312 of file Session.cpp.

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

Referenced by next().

313 {
314  if ( !verify( reject, false, true ) ) return ;
316  nextQueued( timeStamp );
317 }
bool verify(const Message &msg, bool checkTooHigh=true, bool checkTooLow=true)
Definition: Session.cpp:941
void incrNextTargetMsgSeqNum()
Definition: SessionState.h:187
SessionState m_state
Definition: Session.h:320
void nextQueued(const UtcTimeStamp &timeStamp)
Definition: Session.cpp:1145
void FIX::Session::nextResendRequest ( const Message resendRequest,
const UtcTimeStamp timeStamp 
)
private

Definition at line 344 of file Session.cpp.

References FIX::FIELD::ApplVerID, FIX::FIELD::BeginSeqNo, FIX::BeginString_FIX42, FIX::IntConvertor::convert(), FIX::FIELD::EndSeqNo, generateSequenceReset(), FIX::SessionState::get(), FIX::DataDictionaryProvider::getApplicationDataDictionary(), FIX::SessionID::getBeginString(), getExpectedSenderNum(), FIX::FieldMap::getField(), FIX::FieldMap::getFieldIfSet(), 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, FIX::FIELD::MsgSeqNum, FIX::FIELD::MsgType, next(), FIX::SessionState::onEvent(), resend(), send(), FIX::Message::setStringHeader(), FIX::Message::toString(), and verify().

Referenced by next().

345 {
346  if ( !verify( resendRequest, false, false ) ) return ;
347 
348  Locker l( m_mutex );
349 
350  BeginSeqNo beginSeqNo;
351  EndSeqNo endSeqNo;
352  resendRequest.getField( beginSeqNo );
353  resendRequest.getField( endSeqNo );
354 
355  m_state.onEvent( "Received ResendRequest FROM: "
356  + IntConvertor::convert( beginSeqNo ) +
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) ||
362  (endSeqNo >= getExpectedSenderNum()) )
363  { endSeqNo = getExpectedSenderNum() - 1; }
364 
365  if ( !m_persistMessages )
366  {
367  endSeqNo = EndSeqNo(endSeqNo + 1);
369  if( endSeqNo > next )
370  endSeqNo = EndSeqNo(next);
371  generateSequenceReset( beginSeqNo, endSeqNo );
372  return;
373  }
374 
375  std::vector < std::string > messages;
376  m_state.get( beginSeqNo, endSeqNo, messages );
377 
378  std::vector < std::string > ::iterator i;
379  MsgSeqNum msgSeqNum(0);
380  MsgType msgType;
381  int begin = 0;
382  int current = beginSeqNo;
383  std::string messageString;
384  Message msg;
385 
386  for ( i = messages.begin(); i != messages.end(); ++i )
387  {
388  const DataDictionary& sessionDD =
390 
391  if( m_sessionID.isFIXT() )
392  {
393  msg.setStringHeader(*i);
394  ApplVerID applVerID;
395  if( !msg.getHeader().getFieldIfSet(applVerID) )
396  applVerID = m_senderDefaultApplVerID;
397 
398  const DataDictionary& applicationDD =
400  msg = Message( *i, sessionDD, applicationDD, m_validateLengthAndChecksum );
401  }
402  else
403  {
404  msg = Message( *i, sessionDD, m_validateLengthAndChecksum );
405  }
406 
407 
408  msg.getHeader().getField( msgSeqNum );
409  msg.getHeader().getField( msgType );
410 
411  if( (current != msgSeqNum) && !begin )
412  begin = current;
413 
414  if ( Message::isAdminMsgType( msgType ) )
415  {
416  if ( !begin ) begin = msgSeqNum;
417  }
418  else
419  {
420  if ( resend( msg ) )
421  {
422  if ( begin ) generateSequenceReset( begin, msgSeqNum );
423  send( msg.toString(messageString) );
424  m_state.onEvent( "Resending Message: "
425  + IntConvertor::convert( msgSeqNum ) );
426  begin = 0;
427  }
428  else
429  { if ( !begin ) begin = msgSeqNum; }
430  }
431  current = msgSeqNum + 1;
432  }
433  if ( begin )
434  {
435  generateSequenceReset( begin, msgSeqNum + 1 );
436  }
437 
438  if ( endSeqNo > msgSeqNum )
439  {
440  endSeqNo = EndSeqNo(endSeqNo + 1);
441  int next = m_state.getNextSenderMsgSeqNum();
442  if( endSeqNo > next )
443  endSeqNo = EndSeqNo(next);
444  generateSequenceReset( beginSeqNo, endSeqNo );
445  }
446 
447  resendRequest.getHeader().getField( msgSeqNum );
448  if( !isTargetTooHigh(msgSeqNum) && !isTargetTooLow(msgSeqNum) )
450 }
const int ApplVerID
const int BeginSeqNo
bool send(Message &)
Definition: Session.cpp:452
static bool isAdminMsgType(const MsgType &msgType)
Definition: Message.h:250
bool verify(const Message &msg, bool checkTooHigh=true, bool checkTooLow=true)
Definition: Session.cpp:941
int getExpectedSenderNum()
Definition: Session.h:211
DataDictionaryProvider m_dataDictionaryProvider
Definition: Session.h:321
int getNextSenderMsgSeqNum() const
Definition: SessionState.h:177
const char BeginString_FIX42[]
Definition: Values.h:34
void incrNextTargetMsgSeqNum()
Definition: SessionState.h:187
const int EndSeqNo
void next()
Definition: Session.cpp:125
const DataDictionary & getApplicationDataDictionary(const ApplVerID &applVerID) const
SessionID m_sessionID
Definition: Session.h:302
void get(int b, int e, std::vector< std::string > &m) const
Definition: SessionState.h:174
static std::string convert(signed_int value)
bool isTargetTooLow(const MsgSeqNum &msgSeqNum)
Definition: Session.h:247
void generateSequenceReset(int, int)
Definition: Session.cpp:666
const DataDictionary & getSessionDataDictionary(const BeginString &beginString) const
std::string m_senderDefaultApplVerID
Definition: Session.h:306
bool isTargetTooHigh(const MsgSeqNum &msgSeqNum)
Definition: Session.h:245
const bool isFIXT() const
Definition: SessionID.h:61
SessionState m_state
Definition: Session.h:320
bool m_validateLengthAndChecksum
Definition: Session.h:318
void onEvent(const std::string &string)
Definition: SessionState.h:204
Mutex m_mutex
Definition: Session.h:325
bool m_persistMessages
Definition: Session.h:317
const int MsgSeqNum
bool resend(Message &message)
Definition: Session.cpp:572
const BeginString & getBeginString() const
Definition: SessionID.h:53
const int MsgType
void FIX::Session::nextSequenceReset ( const Message sequenceReset,
const UtcTimeStamp timeStamp 
)
private

Definition at line 319 of file Session.cpp.

References FIX::IntConvertor::convert(), FIX::FIELD::GapFillFlag, generateReject(), getExpectedTargetNum(), FIX::FieldMap::getFieldIfSet(), m_state, FIX::FIELD::MsgSeqNum, FIX::FIELD::NewSeqNo, FIX::SessionState::onEvent(), FIX::SessionRejectReason_VALUE_IS_INCORRECT, FIX::SessionState::setNextTargetMsgSeqNum(), and verify().

Referenced by next().

320 {
321  bool isGapFill = false;
322  GapFillFlag gapFillFlag;
323  if ( sequenceReset.getFieldIfSet( gapFillFlag ) )
324  {
325  isGapFill = gapFillFlag;
326  }
327 
328  if ( !verify( sequenceReset, isGapFill, isGapFill ) ) return ;
329 
330  NewSeqNo newSeqNo;
331  if ( sequenceReset.getFieldIfSet( newSeqNo ) )
332  {
333  m_state.onEvent( "Received SequenceReset FROM: "
335  " TO: " + IntConvertor::convert( newSeqNo ) );
336 
337  if ( newSeqNo > getExpectedTargetNum() )
339  else if ( newSeqNo < getExpectedTargetNum() )
341  }
342 }
int getExpectedTargetNum()
Definition: Session.h:212
bool verify(const Message &msg, bool checkTooHigh=true, bool checkTooLow=true)
Definition: Session.cpp:941
void setNextTargetMsgSeqNum(int n)
Definition: SessionState.h:183
const int NewSeqNo
static std::string convert(signed_int value)
const int GapFillFlag
void generateReject(const Message &, int err, int field=0)
Definition: Session.cpp:720
SessionState m_state
Definition: Session.h:320
void onEvent(const std::string &string)
Definition: SessionState.h:204
const int MsgSeqNum
const int SessionRejectReason_VALUE_IS_INCORRECT
Definition: FixValues.h:1878
void FIX::Session::nextTestRequest ( const Message testRequest,
const UtcTimeStamp timeStamp 
)
private

Definition at line 287 of file Session.cpp.

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

Referenced by next().

288 {
289  if ( !verify( testRequest ) ) return ;
290  generateHeartbeat( testRequest );
292  nextQueued( timeStamp );
293 }
bool verify(const Message &msg, bool checkTooHigh=true, bool checkTooLow=true)
Definition: Session.cpp:941
void generateHeartbeat()
Definition: Session.cpp:685
void incrNextTargetMsgSeqNum()
Definition: SessionState.h:187
SessionState m_state
Definition: Session.h:320
void nextQueued(const UtcTimeStamp &timeStamp)
Definition: Session.cpp:1145
int FIX::Session::numSessions ( )
static

Definition at line 1460 of file Session.cpp.

References s_mutex, and s_sessions.

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

1461 {
1462  Locker locker( s_mutex );
1463  return s_sessions.size();
1464 }
static Sessions s_sessions
Definition: Session.h:327
static Mutex s_mutex
Definition: Session.h:330
void FIX::Session::persist ( const Message message,
const std::string &  messageString 
)
throw (IOException
)
private

Definition at line 592 of file Session.cpp.

References FIX::FIELD::MsgSeqNum.

Referenced by sendRaw().

594 {
595  MsgSeqNum msgSeqNum;
596  message.getHeader().getField( msgSeqNum );
597  if( m_persistMessages )
598  m_state.set( msgSeqNum, messageString );
600 }
bool set(int s, const std::string &m)
Definition: SessionState.h:172
SessionState m_state
Definition: Session.h:320
void incrNextSenderMsgSeqNum()
Definition: SessionState.h:185
bool m_persistMessages
Definition: Session.h:317
const int MsgSeqNum
void FIX::Session::populateRejectReason ( Message reject,
int  field,
const std::string &  text 
)
private

Definition at line 916 of file Session.cpp.

References FIX::BeginString_FIX42, FIX::SessionID::getBeginString(), FIX::FieldMap::getField(), FIX::Message::getHeader(), m_sessionID, FIX::FIELD::MsgType, FIX::MsgType_Reject, FIX::FIELD::RefTagID, FIX::FieldMap::setField(), and FIX::FIELD::Text.

Referenced by generateBusinessReject(), and generateReject().

918 {
919  MsgType msgType;
920  reject.getHeader().getField( msgType );
921 
922  if ( msgType == MsgType_Reject
924  {
925  reject.setField( RefTagID( field ) );
926  reject.setField( Text( text ) );
927  }
928  else
929  {
930  std::stringstream stream;
931  stream << text << " (" << field << ")";
932  reject.setField( Text( stream.str() ) );
933  }
934 }
const char BeginString_FIX42[]
Definition: Values.h:34
SessionID m_sessionID
Definition: Session.h:302
const int Text
const int RefTagID
const BeginString & getBeginString() const
Definition: SessionID.h:53
const int MsgType
const char MsgType_Reject[]
Definition: FixValues.h:682
void FIX::Session::populateRejectReason ( Message reject,
const std::string &  text 
)
private

Definition at line 936 of file Session.cpp.

References FIX::FieldMap::setField(), and FIX::FIELD::Text.

937 {
938  reject.setField( Text( text ) );
939 }
const int Text
bool FIX::Session::receivedLogon ( )
inline

Definition at line 64 of file Session.h.

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

Referenced by isLoggedOn().

64 { return m_state.receivedLogon(); }
bool receivedLogon() const
Definition: SessionState.h:53
SessionState m_state
Definition: Session.h:320
void FIX::Session::refresh ( )
throw (IOException
)
inline
Session * FIX::Session::registerSession ( const SessionID sessionID)
static

Definition at line 1444 of file Session.cpp.

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

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

1445 {
1446  Locker locker( s_mutex );
1447  Session* pSession = lookupSession( sessionID );
1448  if ( pSession == 0 ) return 0;
1449  if ( isSessionRegistered( sessionID ) ) return 0;
1450  s_registered[ sessionID ] = pSession;
1451  return pSession;
1452 }
static Session * lookupSession(const SessionID &)
Definition: Session.cpp:1403
static bool isSessionRegistered(const SessionID &)
Definition: Session.cpp:1438
Session(Application &, MessageStoreFactory &, const SessionID &, const DataDictionaryProvider &, const TimeRange &, int heartBtInt, LogFactory *pLogFactory)
Definition: Session.cpp:41
static Mutex s_mutex
Definition: Session.h:330
static Sessions s_registered
Definition: Session.h:329
void FIX::Session::removeSession ( Session s)
staticprivate

Definition at line 1480 of file Session.cpp.

References m_sessionID, s_mutex, s_registered, s_sessionIDs, and s_sessions.

Referenced by ~Session().

1481 {
1482  Locker locker( s_mutex );
1483  s_sessions.erase( s.m_sessionID );
1484  s_sessionIDs.erase( s.m_sessionID );
1485  s_registered.erase( s.m_sessionID );
1486 }
static Sessions s_sessions
Definition: Session.h:327
static SessionIDs s_sessionIDs
Definition: Session.h:328
static Mutex s_mutex
Definition: Session.h:330
static Sessions s_registered
Definition: Session.h:329
bool FIX::Session::resend ( Message message)
private

Definition at line 572 of file Session.cpp.

References FIX::FieldMap::getField(), FIX::Message::getHeader(), insertOrigSendingTime(), insertSendingTime(), m_application, m_sessionID, FIX::FIELD::MsgSeqNum, FIX::FIELD::PossDupFlag, FIX::FIELD::SendingTime, FIX::FieldMap::setField(), and FIX::Application::toApp().

Referenced by nextResendRequest().

573 {
574  SendingTime sendingTime;
575  MsgSeqNum msgSeqNum;
576  Header& header = message.getHeader();
577  header.getField( sendingTime );
578  header.getField( msgSeqNum );
579  insertOrigSendingTime( header, sendingTime );
580  header.setField( PossDupFlag( true ) );
581  insertSendingTime( header );
582 
583  try
584  {
585  m_application.toApp( message, m_sessionID );
586  return true;
587  }
588  catch ( DoNotSend& )
589  { return false; }
590 }
SessionID m_sessionID
Definition: Session.h:302
const int SendingTime
virtual void toApp(Message &, const SessionID &)=0
Notification of app message being sent to target.
Application & m_application
Definition: Session.h:301
void insertSendingTime(Header &)
Definition: Session.cpp:91
const int PossDupFlag
const int MsgSeqNum
void insertOrigSendingTime(Header &, const UtcTimeStamp &when=UtcTimeStamp())
Definition: Session.cpp:103
void FIX::Session::reset ( )
throw (IOException
)
inline
bool FIX::Session::send ( Message message)

Definition at line 452 of file Session.cpp.

References FIX::Message::getHeader(), FIX::FIELD::OrigSendingTime, FIX::FIELD::PossDupFlag, FIX::FieldMap::removeField(), and sendRaw().

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

453 {
454  message.getHeader().removeField( FIELD::PossDupFlag );
455  message.getHeader().removeField( FIELD::OrigSendingTime );
456  return sendRaw( message );
457 }
const int OrigSendingTime
bool sendRaw(Message &, int msgSeqNum=0)
Definition: Session.cpp:459
const int PossDupFlag
bool FIX::Session::send ( const std::string &  string)
private

Definition at line 535 of file Session.cpp.

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

536 {
537  if ( !m_pResponder ) return false;
538  m_state.onOutgoing( string );
539  return m_pResponder->send( string );
540 }
void onOutgoing(const std::string &string)
Definition: SessionState.h:202
virtual bool send(const std::string &)=0
SessionState m_state
Definition: Session.h:320
Responder * m_pResponder
Definition: Session.h:324
bool FIX::Session::sendRaw ( Message message,
int  msgSeqNum = 0 
)
private

Definition at line 459 of file Session.cpp.

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

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

460 {
461  Locker l( m_mutex );
462 
463  try
464  {
465  Header& header = message.getHeader();
466 
467  MsgType msgType;
468  header.getFieldIfSet(msgType);
469 
470  fill( header );
471  std::string messageString;
472 
473  if ( num )
474  header.setField( MsgSeqNum( num ) );
475 
476  if ( Message::isAdminMsgType( msgType ) )
477  {
478  m_application.toAdmin( message, m_sessionID );
479 
480  if( msgType == "A" && !m_state.receivedReset() )
481  {
482  ResetSeqNumFlag resetSeqNumFlag( false );
483  message.getFieldIfSet(resetSeqNumFlag);
484 
485  if( resetSeqNumFlag )
486  {
487  m_state.reset();
488  message.getHeader().setField( MsgSeqNum(getExpectedSenderNum()) );
489  }
490  m_state.sentReset( resetSeqNumFlag );
491  }
492 
493  message.toString( messageString );
494 
495  if( !num )
496  persist( message, messageString );
497 
498  if (
499  msgType == "A" || msgType == "5"
500  || msgType == "2" || msgType == "4"
501  || isLoggedOn() )
502  {
503  send( messageString );
504  }
505  }
506  else
507  {
508  // do not send application messages if they will just be cleared
509  if( !isLoggedOn() && shouldSendReset() )
510  return false;
511 
512  try
513  {
514  m_application.toApp( message, m_sessionID );
515  message.toString( messageString );
516 
517  if( !num )
518  persist( message, messageString );
519 
520  if ( isLoggedOn() )
521  send( messageString );
522  }
523  catch ( DoNotSend& ) { return false; }
524  }
525 
526  return true;
527  }
528  catch ( IOException& e )
529  {
530  m_state.onEvent( e.what() );
531  return false;
532  }
533 }
bool send(Message &)
Definition: Session.cpp:452
static bool isAdminMsgType(const MsgType &msgType)
Definition: Message.h:250
int getExpectedSenderNum()
Definition: Session.h:211
SessionID m_sessionID
Definition: Session.h:302
bool sentReset() const
Definition: SessionState.h:65
bool receivedReset() const
Definition: SessionState.h:62
virtual void toApp(Message &, const SessionID &)=0
Notification of app message being sent to target.
Application & m_application
Definition: Session.h:301
void persist(const Message &, const std::string &)
Definition: Session.cpp:592
SessionState m_state
Definition: Session.h:320
virtual void toAdmin(Message &, const SessionID &)=0
Notification of admin message being sent to target.
bool shouldSendReset()
Definition: Session.cpp:1013
void onEvent(const std::string &string)
Definition: SessionState.h:204
Mutex m_mutex
Definition: Session.h:325
void fill(Header &)
Definition: Session.cpp:114
const int ResetSeqNumFlag
const int MsgSeqNum
const int MsgType
bool isLoggedOn()
Definition: Session.h:65
bool FIX::Session::sendToTarget ( Message message,
const std::string &  qualifier = "" 
)
throw (SessionNotFound
)
static

Definition at line 1351 of file Session.cpp.

1353 {
1354  try
1355  {
1356  SessionID sessionID = message.getSessionID( qualifier );
1357  return sendToTarget( message, sessionID );
1358  }
1359  catch ( FieldNotFound& ) { throw SessionNotFound(); }
1360 }
static bool sendToTarget(Message &message, const std::string &qualifier="")
Definition: Session.cpp:1351
bool FIX::Session::sendToTarget ( Message message,
const SessionID sessionID 
)
throw (SessionNotFound
)
static

Definition at line 1362 of file Session.cpp.

References send().

1364 {
1365  message.setSessionID( sessionID );
1366  Session* pSession = lookupSession( sessionID );
1367  if ( !pSession ) throw SessionNotFound();
1368  return pSession->send( message );
1369 }
static Session * lookupSession(const SessionID &)
Definition: Session.cpp:1403
Session(Application &, MessageStoreFactory &, const SessionID &, const DataDictionaryProvider &, const TimeRange &, int heartBtInt, LogFactory *pLogFactory)
Definition: Session.cpp:41
bool FIX::Session::sendToTarget ( Message message,
const SenderCompID &  senderCompID,
const TargetCompID &  targetCompID,
const std::string &  qualifier = "" 
)
throw (SessionNotFound
)
static

Definition at line 1372 of file Session.cpp.

References FIX::Message::getHeader(), and FIX::FieldMap::setField().

1377 {
1378  message.getHeader().setField( senderCompID );
1379  message.getHeader().setField( targetCompID );
1380  return sendToTarget( message, qualifier );
1381 }
static bool sendToTarget(Message &message, const std::string &qualifier="")
Definition: Session.cpp:1351
bool FIX::Session::sendToTarget ( Message message,
const std::string &  senderCompID,
const std::string &  targetCompID,
const std::string &  qualifier = "" 
)
throw (SessionNotFound
)
static

Definition at line 1384 of file Session.cpp.

References FIX::FIELD::SenderCompID, and FIX::FIELD::TargetCompID.

1387 {
1388  return sendToTarget( message, SenderCompID( sender ),
1389  TargetCompID( target ), qualifier );
1390 }
static bool sendToTarget(Message &message, const std::string &qualifier="")
Definition: Session.cpp:1351
const int TargetCompID
const int SenderCompID
bool FIX::Session::sentLogon ( )
inline

Definition at line 62 of file Session.h.

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

Referenced by isLoggedOn().

62 { return m_state.sentLogon(); }
bool sentLogon() const
Definition: SessionState.h:59
SessionState m_state
Definition: Session.h:320
bool FIX::Session::sentLogout ( )
inline

Definition at line 63 of file Session.h.

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

63 { return m_state.sentLogout(); }
bool sentLogout() const
Definition: SessionState.h:56
SessionState m_state
Definition: Session.h:320
bool FIX::Session::set ( int  s,
const Message m 
)
private
void FIX::Session::setCheckCompId ( bool  value)
inline

Definition at line 139 of file Session.h.

References m_checkCompId.

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

140  { m_checkCompId = value; }
bool m_checkCompId
Definition: Session.h:309
void FIX::Session::setCheckLatency ( bool  value)
inline

Definition at line 144 of file Session.h.

References m_checkLatency.

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

145  { m_checkLatency = value; }
bool m_checkLatency
Definition: Session.h:310
void FIX::Session::setDataDictionaryProvider ( const DataDictionaryProvider dataDictionaryProvider)
inline

Definition at line 77 of file Session.h.

References m_dataDictionaryProvider.

78  { m_dataDictionaryProvider = dataDictionaryProvider; }
DataDictionaryProvider m_dataDictionaryProvider
Definition: Session.h:321
void FIX::Session::setLogonTime ( const TimeRange value)
inline

Definition at line 119 of file Session.h.

References m_logonTime.

120  { m_logonTime = value; }
TimeRange m_logonTime
Definition: Session.h:304
void FIX::Session::setLogonTimeout ( int  value)
inline

Definition at line 154 of file Session.h.

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

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

155  { m_state.logonTimeout( value ); }
int logonTimeout() const
Definition: SessionState.h:71
SessionState m_state
Definition: Session.h:320
void FIX::Session::setLogoutTimeout ( int  value)
inline

Definition at line 159 of file Session.h.

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

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

160  { m_state.logoutTimeout( value ); }
int logoutTimeout() const
Definition: SessionState.h:74
SessionState m_state
Definition: Session.h:320
void FIX::Session::setMaxLatency ( int  value)
inline

Definition at line 149 of file Session.h.

References m_maxLatency.

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

150  { m_maxLatency = value; }
int m_maxLatency
Definition: Session.h:311
void FIX::Session::setMillisecondsInTimeStamp ( bool  value)
inline

Definition at line 184 of file Session.h.

References m_millisecondsInTimeStamp.

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

185  { m_millisecondsInTimeStamp = value; }
bool m_millisecondsInTimeStamp
Definition: Session.h:316
void FIX::Session::setNextSenderMsgSeqNum ( int  num)
throw (IOException
)
inline

Definition at line 70 of file Session.h.

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

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

SessionState m_state
Definition: Session.h:320
void setNextSenderMsgSeqNum(int n)
Definition: SessionState.h:181
void FIX::Session::setNextTargetMsgSeqNum ( int  num)
throw (IOException
)
inline

Definition at line 72 of file Session.h.

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

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

void setNextTargetMsgSeqNum(int n)
Definition: SessionState.h:183
SessionState m_state
Definition: Session.h:320
void FIX::Session::setPersistMessages ( bool  value)
inline

Definition at line 189 of file Session.h.

References m_persistMessages.

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

190  { m_persistMessages = value; }
bool m_persistMessages
Definition: Session.h:317
void FIX::Session::setRefreshOnLogon ( bool  value)
inline

Definition at line 179 of file Session.h.

References m_refreshOnLogon.

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

180  { m_refreshOnLogon = value; }
bool m_refreshOnLogon
Definition: Session.h:315
void FIX::Session::setResetOnDisconnect ( bool  value)
inline

Definition at line 174 of file Session.h.

References m_resetOnDisconnect.

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

175  { m_resetOnDisconnect = value; }
bool m_resetOnDisconnect
Definition: Session.h:314
void FIX::Session::setResetOnLogon ( bool  value)
inline

Definition at line 164 of file Session.h.

References m_resetOnLogon.

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

165  { m_resetOnLogon = value; }
bool m_resetOnLogon
Definition: Session.h:312
void FIX::Session::setResetOnLogout ( bool  value)
inline

Definition at line 169 of file Session.h.

References m_resetOnLogout.

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

170  { m_resetOnLogout = value; }
bool m_resetOnLogout
Definition: Session.h:313
void FIX::Session::setResponder ( Responder pR)
inline

Definition at line 197 of file Session.h.

References checkSessionTime(), m_pResponder, reset(), and FIX::TYPE::UtcTimeStamp.

Referenced by FIX::ThreadedSocketConnection::setSession(), and FIX::ThreadedSocketConnection::~ThreadedSocketConnection().

198  {
200  reset();
201  m_pResponder = pR;
202  }
void reset()
Definition: Session.h:66
bool checkSessionTime(const UtcTimeStamp &timeStamp)
Definition: Session.h:240
Responder * m_pResponder
Definition: Session.h:324
void FIX::Session::setSenderDefaultApplVerID ( const std::string &  senderDefaultApplVerID)
inline

Definition at line 124 of file Session.h.

References m_senderDefaultApplVerID.

125  { m_senderDefaultApplVerID = senderDefaultApplVerID; }
std::string m_senderDefaultApplVerID
Definition: Session.h:306
void FIX::Session::setSendRedundantResendRequests ( bool  value)
inline

Definition at line 134 of file Session.h.

References m_sendRedundantResendRequests.

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

135  { m_sendRedundantResendRequests = value; }
bool m_sendRedundantResendRequests
Definition: Session.h:308
void FIX::Session::setTargetDefaultApplVerID ( const std::string &  targetDefaultApplVerID)
inline

Definition at line 129 of file Session.h.

References m_targetDefaultApplVerID.

Referenced by next().

130  { m_targetDefaultApplVerID = targetDefaultApplVerID; }
std::string m_targetDefaultApplVerID
Definition: Session.h:307
void FIX::Session::setValidateLengthAndChecksum ( bool  value)
inline

Definition at line 194 of file Session.h.

References m_validateLengthAndChecksum.

195  { m_validateLengthAndChecksum = value; }
bool m_validateLengthAndChecksum
Definition: Session.h:318
bool FIX::Session::shouldSendReset ( )
private

Definition at line 1013 of file Session.cpp.

References FIX::BeginString_FIX41, FIX::SessionID::getBeginString(), getExpectedSenderNum(), getExpectedTargetNum(), m_resetOnDisconnect, m_resetOnLogon, m_resetOnLogout, and m_sessionID.

Referenced by generateLogon(), and sendRaw().

1014 {
1015  std::string beginString = m_sessionID.getBeginString();
1016  return beginString >= FIX::BeginString_FIX41
1017  && ( m_resetOnLogon ||
1018  m_resetOnLogout ||
1020  && ( getExpectedSenderNum() == 1 )
1021  && ( getExpectedTargetNum() == 1 );
1022 }
int getExpectedTargetNum()
Definition: Session.h:212
int getExpectedSenderNum()
Definition: Session.h:211
SessionID m_sessionID
Definition: Session.h:302
bool m_resetOnLogon
Definition: Session.h:312
const char BeginString_FIX41[]
Definition: Values.h:35
bool m_resetOnDisconnect
Definition: Session.h:314
bool m_resetOnLogout
Definition: Session.h:313
const BeginString & getBeginString() const
Definition: SessionID.h:53
void FIX::Session::unregisterSession ( const SessionID sessionID)
static

Definition at line 1454 of file Session.cpp.

References s_mutex, and s_registered.

Referenced by FIX::Acceptor::stop(), FIX::SocketConnection::~SocketConnection(), and FIX::ThreadedSocketConnection::~ThreadedSocketConnection().

1455 {
1456  Locker locker( s_mutex );
1457  s_registered.erase( sessionID );
1458 }
static Mutex s_mutex
Definition: Session.h:330
static Sessions s_registered
Definition: Session.h:329
bool FIX::Session::validLogonState ( const MsgType &  msgType)
private

Definition at line 1024 of file Session.cpp.

References m_state, FIX::MsgType_Logon, FIX::MsgType_Logout, FIX::MsgType_Reject, FIX::MsgType_SequenceReset, FIX::SessionState::receivedLogon(), FIX::SessionState::receivedReset(), FIX::SessionState::sentLogon(), FIX::SessionState::sentLogout(), and FIX::SessionState::sentReset().

Referenced by verify().

1025 {
1026  if ( (msgType == MsgType_Logon && m_state.sentReset())
1027  || (m_state.receivedReset()) )
1028  return true;
1029  if ( (msgType == MsgType_Logon && !m_state.receivedLogon())
1030  || (msgType != MsgType_Logon && m_state.receivedLogon()) )
1031  return true;
1032  if ( msgType == MsgType_Logout && m_state.sentLogon() )
1033  return true;
1034  if ( msgType != MsgType_Logout && m_state.sentLogout() )
1035  return true;
1036  if ( msgType == MsgType_SequenceReset )
1037  return true;
1038  if ( msgType == MsgType_Reject )
1039  return true;
1040 
1041  return false;
1042 }
bool sentLogout() const
Definition: SessionState.h:56
bool receivedLogon() const
Definition: SessionState.h:53
bool sentLogon() const
Definition: SessionState.h:59
bool sentReset() const
Definition: SessionState.h:65
bool receivedReset() const
Definition: SessionState.h:62
const char MsgType_SequenceReset[]
Definition: FixValues.h:646
SessionState m_state
Definition: Session.h:320
const char MsgType_Logon[]
Definition: FixValues.h:614
const char MsgType_Logout[]
Definition: FixValues.h:622
const char MsgType_Reject[]
Definition: FixValues.h:682
bool FIX::Session::verify ( const Message msg,
bool  checkTooHigh = true,
bool  checkTooLow = true 
)
private

Definition at line 941 of file Session.cpp.

References FIX::IntConvertor::convert(), disconnect(), doBadCompID(), doBadTime(), doTargetTooHigh(), doTargetTooLow(), FIELD_GET_PTR, FIELD_GET_REF, fromCallback(), FIX::Message::getHeader(), isCorrectCompID(), isGoodTime(), isTargetTooHigh(), isTargetTooLow(), FIX::SessionState::lastReceivedTime(), m_sessionID, m_state, FIX::FIELD::MsgSeqNum, FIX::FIELD::MsgType, FIX::SessionState::onEvent(), FIX::SessionState::resendRange(), FIX::SessionState::resendRequested(), FIX::FIELD::SenderCompID, FIX::FIELD::SendingTime, FIX::FIELD::TargetCompID, FIX::SessionState::testRequest(), and validLogonState().

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

943 {
944  const MsgType* pMsgType = 0;
945  const MsgSeqNum* pMsgSeqNum = 0;
946 
947  try
948  {
949  const Header& header = msg.getHeader();
950 
951  pMsgType = FIELD_GET_PTR( header, MsgType );
952  const SenderCompID& senderCompID = FIELD_GET_REF( header, SenderCompID );
953  const TargetCompID& targetCompID = FIELD_GET_REF( header, TargetCompID );
954  const SendingTime& sendingTime = FIELD_GET_REF( header, SendingTime );
955 
956  if( checkTooHigh || checkTooLow )
957  pMsgSeqNum = FIELD_GET_PTR( header, MsgSeqNum );
958 
959  if ( !validLogonState( *pMsgType ) )
960  throw std::logic_error( "Logon state is not valid for message" );
961 
962  if ( !isGoodTime( sendingTime ) )
963  {
964  doBadTime( msg );
965  return false;
966  }
967  if ( !isCorrectCompID( senderCompID, targetCompID ) )
968  {
969  doBadCompID( msg );
970  return false;
971  }
972 
973  if ( checkTooHigh && isTargetTooHigh( *pMsgSeqNum ) )
974  {
975  doTargetTooHigh( msg );
976  return false;
977  }
978  else if ( checkTooLow && isTargetTooLow( *pMsgSeqNum ) )
979  {
980  doTargetTooLow( msg );
981  return false;
982  }
983 
984  if ( (checkTooHigh || checkTooLow) && m_state.resendRequested() )
985  {
987 
988  if ( *pMsgSeqNum >= range.second )
989  {
990  m_state.onEvent ("ResendRequest for messages FROM: " +
991  IntConvertor::convert (range.first) + " TO: " +
992  IntConvertor::convert (range.second) +
993  " has been satisfied.");
994  m_state.resendRange (0, 0);
995  }
996  }
997  }
998  catch ( std::exception& e )
999  {
1000  m_state.onEvent( e.what() );
1001  disconnect();
1002  return false;
1003  }
1004 
1005  UtcTimeStamp now;
1006  m_state.lastReceivedTime( now );
1007  m_state.testRequest( 0 );
1008 
1009  fromCallback( pMsgType ? *pMsgType : MsgType(), msg, m_sessionID );
1010  return true;
1011 }
void lastReceivedTime(const UtcTimeStamp &value)
Definition: SessionState.h:108
bool isGoodTime(const SendingTime &sendingTime)
Definition: Session.h:234
std::pair< int, int > ResendRange
Definition: SessionState.h:83
void doBadTime(const Message &msg)
Definition: Session.cpp:1053
SessionID m_sessionID
Definition: Session.h:302
bool validLogonState(const MsgType &msgType)
Definition: Session.cpp:1024
static std::string convert(signed_int value)
bool isTargetTooLow(const MsgSeqNum &msgSeqNum)
Definition: Session.h:247
const int SendingTime
void doTargetTooHigh(const Message &msg)
Definition: Session.cpp:1113
void disconnect()
Definition: Session.cpp:542
bool isTargetTooHigh(const MsgSeqNum &msgSeqNum)
Definition: Session.h:245
const int TargetCompID
SessionState m_state
Definition: Session.h:320
bool resendRequested() const
Definition: SessionState.h:80
void fromCallback(const MsgType &msgType, const Message &msg, const SessionID &sessionID)
Definition: Session.cpp:1044
bool isCorrectCompID(const SenderCompID &senderCompID, const TargetCompID &targetCompID)
Definition: Session.h:249
const int SenderCompID
void onEvent(const std::string &string)
Definition: SessionState.h:204
void doBadCompID(const Message &msg)
Definition: Session.cpp:1059
bool doTargetTooLow(const Message &msg)
Definition: Session.cpp:1093
const int MsgSeqNum
#define FIELD_GET_PTR(MAP, FLD)
Definition: FieldMap.h:234
int testRequest() const
Definition: SessionState.h:77
#define FIELD_GET_REF(MAP, FLD)
Definition: FieldMap.h:236
ResendRange resendRange() const
Definition: SessionState.h:85
const int MsgType

Member Data Documentation

Application& FIX::Session::m_application
private

Definition at line 301 of file Session.h.

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

bool FIX::Session::m_checkCompId
private

Definition at line 309 of file Session.h.

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

bool FIX::Session::m_checkLatency
private

Definition at line 310 of file Session.h.

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

DataDictionaryProvider FIX::Session::m_dataDictionaryProvider
private
TimeRange FIX::Session::m_logonTime
private

Definition at line 304 of file Session.h.

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

int FIX::Session::m_maxLatency
private

Definition at line 311 of file Session.h.

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

MessageStoreFactory& FIX::Session::m_messageStoreFactory
private

Definition at line 322 of file Session.h.

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

bool FIX::Session::m_millisecondsInTimeStamp
private
Mutex FIX::Session::m_mutex
private

Definition at line 325 of file Session.h.

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

bool FIX::Session::m_persistMessages
private

Definition at line 317 of file Session.h.

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

LogFactory* FIX::Session::m_pLogFactory
private

Definition at line 323 of file Session.h.

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

Responder* FIX::Session::m_pResponder
private

Definition at line 324 of file Session.h.

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

bool FIX::Session::m_refreshOnLogon
private

Definition at line 315 of file Session.h.

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

bool FIX::Session::m_resetOnDisconnect
private

Definition at line 314 of file Session.h.

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

bool FIX::Session::m_resetOnLogon
private
bool FIX::Session::m_resetOnLogout
private

Definition at line 313 of file Session.h.

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

std::string FIX::Session::m_senderDefaultApplVerID
private
bool FIX::Session::m_sendRedundantResendRequests
private
SessionID FIX::Session::m_sessionID
private
TimeRange FIX::Session::m_sessionTime
private

Definition at line 303 of file Session.h.

Referenced by checkSessionTime(), and isSessionTime().

SessionState FIX::Session::m_state
private
std::string FIX::Session::m_targetDefaultApplVerID
private

Definition at line 307 of file Session.h.

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

bool FIX::Session::m_validateLengthAndChecksum
private
Mutex FIX::Session::s_mutex
staticprivate
Session::Sessions FIX::Session::s_registered
staticprivate

Definition at line 329 of file Session.h.

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

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

Definition at line 328 of file Session.h.

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

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

Definition at line 327 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 Sat Mar 29 2014 15:13:35 for QuickFIX by doxygen 1.8.5 written by Dimitri van Heesch, © 1997-2001