Session.h

Go to the documentation of this file.
00001 /*
00002 * (c) Onix Solutions.
00003 */
00004 
00005 #ifndef Session_h
00006 #define Session_h
00007 
00008 #include <string>
00009 
00010 #include "FIXEngineDefines.h"
00011 
00012 namespace FIXForge{
00013 namespace FIX{
00014 
00015 class FF_API Message;
00016 class FF_API ISessionListener;
00017 
00018 /// FIX Session - a bi-directional stream of ordered messages between two parties within a continuous sequence number series.
00019 class FF_API Session{
00020 public: 
00021     /// Constructor.
00022     Session(const std::string& senderCompID, const std::string& targetCompID, Version version, bool keepSequenceNumbersAfterLogout, ISessionListener* listener);
00023 
00024     /// Constructor.
00025     Session(const std::string& senderCompID, const std::string& targetCompID, Version version, ISessionListener* listener);
00026 
00027     /// Destructor.
00028     ~Session(); 
00029 
00030     /// Session state.
00031     enum State{DISCONNECTED, LOGON_IN_PROGRESS, LOGOUT_IN_PROGRESS, ACTIVE, RECONNECTING};
00032 
00033     /// Returns the session state.
00034     State getState();   
00035     
00036     /// Returns the session state as a string.
00037     static const char* state2string(State state);
00038 
00039     enum EncryptionMethod{
00040         NONE, ///< No encryption
00041         SSL ///< Secure Sockets Layer
00042     };
00043 
00044     /// Returns the current encryption method.
00045     EncryptionMethod getEncryptionMethod() const;
00046 
00047     /// Sets the encryption method.
00048     void setEncryptionMethod(EncryptionMethod newEncryptionMethod);
00049 
00050     /// Sets the SSL certificate file.
00051     /// 
00052     /// @note Only the (Privacy Enhanced Mail) Base 64 Encoded (.pem) SSL certificates are supported. 
00053     void setSslCertificateFile(const std::string& file);
00054 
00055     /// Sets the SSL private key file.
00056     /// 
00057     /// @note Only the (Privacy Enhanced Mail) Base 64 Encoded (.pem) SSL certificates are supported. 
00058     void setSslPrivateKeyFile(const std::string& file);
00059 
00060     /**
00061      * Establishes the FIX Connection as Acceptor. 
00062      *
00063      * Acceptor is the receiving party of the FIX session. 
00064      * It listens for the incoming connection on the pre-defined port. 
00065      * The acceptor has responsibility to perform first level authentication and formally declare 
00066      * the connection request "accepted" through transmission of an acknowledgment Logon message. 
00067      */
00068     void logonAsAcceptor();
00069     
00070     /**
00071      * Establishes FIX Connection as Initiator using the ResetSeqNumFlag(141) field.
00072      * 
00073      * Initiator establishes the telecommunications link and initiates the session via transmission
00074      * of the initial Logon message.    
00075      */ 
00076     void logonAsInitiator(const std::string& host, int port, bool setResetSeqNumFlag);
00077 
00078         /**
00079      * Establishes FIX Connection as Initiator. 
00080      * 
00081      * Initiator establishes the telecommunications link and initiates the session via transmission
00082      * of the initial Logon message.    
00083      */ 
00084     void logonAsInitiator(const std::string& host, int port);
00085 
00086     /// Establishes FIX Connection as Initiator using the given Heartbeat interval (seconds).
00087     void logonAsInitiator(const std::string& host, int port, int heartBtInt);
00088 
00089     /// Establishes FIX Connection as Initiator using the given Heartbeat interval (seconds) and the ResetSeqNumFlag(141) field.
00090     void logonAsInitiator(const std::string& host, int port, int heartBtInt, bool setResetSeqNumFlag);
00091 
00092     /// Establishes FIX Connection as Initiator using the custom Logon message. 
00093     void logonAsInitiator(const std::string& host, int port, int heartBtInt, Message* customLogonMsg);
00094 
00095     /// Establishes FIX Connection as Initiator using the custom Logon message and the ResetSeqNumFlag(141) field. 
00096     void logonAsInitiator(const std::string& host, int port, int heartBtInt, Message* customLogonMsg, bool setResetSeqNumFlag);
00097 
00098     /** 
00099      * Terminates the FIX Connection. 
00100      *
00101      * The initial Logout message is sent to the conterparty and the method blocks until the acknowledgement 
00102      * Logout message is received.  
00103      */
00104     void logout();
00105     
00106     /**
00107      * Terminates the FIX Connection. 
00108      *
00109      * @param text Free format text string that is sent to the counterparty in the Text(58) field of the initial 
00110      * Logout message.
00111      */
00112     void logout(const std::string& text);
00113 
00114     /**
00115      * Sends the message to the counterparty.
00116      *
00117      * As soon as a session is created it is possible to start sending messages via the session. 
00118      * If the session is not established, the messages will be sent when the connection is established with 
00119      * the counterparty.
00120      */
00121     void send(Message* msg);
00122 
00123     /**
00124      * Shutdowns the session.   
00125      */
00126     void shutdown();
00127     
00128     /// Returns the string descripton of the session.
00129     operator const std::string& ();
00130 
00131     /// Returns the counterparty host name or address.
00132     const std::string& getCounterpartyHost();
00133 
00134     /// Returns the counterparty port number.
00135     size_t getCounterpartyPort();
00136 
00137     /// Returns the Heartbeat interval (seconds).
00138     int getHeartBtInt();
00139 
00140     /// Returns the expected sequence number of the next incoming message.
00141     int getInSeqNum();
00142 
00143     /// Sets the expected sequence number of the next incoming message.
00144     void setInSeqNum(int seqNum);   
00145 
00146     /// Returns the sequence number of the next outgoing message.
00147     int getOutSeqNum();
00148 
00149     /// Sets the sequence number of the next outgoing message.
00150     void setOutSeqNum(int seqNum);
00151 
00152     /// Session role.
00153     enum Role{NA, INITIATOR, ACCEPTOR};
00154 
00155     /// Returns the session role.
00156     Role getRole();
00157     
00158     /// Returns the assigned value used to identify firm sending message (the SenderCompID (tag=49) field value in outgoing messages).
00159     const std::string& getSenderCompID();
00160 
00161     /// Returns the Assigned value used to identify receiving firm (the TargetCompID (tag=56) field value in outgoing messages).
00162     const std::string& getTargetCompID();
00163 
00164     /// Returns the session FIX Protocol version.
00165     Version getVersion();       
00166 
00167     /// Backups the current log files and resets the sequence numbers to 1. 
00168     ///
00169     /// @note This method can be called only when the session is disconnected.
00170     void reset();
00171 
00172     /// Sends a Logon message with the ResetSeqNumFlag set.
00173     void resetSeqNumViaLogonExchange();
00174 
00175     /// Sets the SenderSubID (tag=50) field values for all outgoing messages.
00176     void senderSubID(const std::string& value);
00177 
00178     /// Sets the TargetSubID (tag=57) field values for all outgoing messages.
00179     void targetSubID(const std::string& value);
00180 
00181     /// Sets the SenderLocationID (tag=142) field values for all outgoing messages.
00182     void senderLocationID(const std::string& value);
00183 
00184     /// Sets the TargetLocationID (tag=143) field values for all outgoing messages.
00185     void targetLocationID(const std::string& value);
00186 
00187     /// Sends the Test Request (MsgType=1) message.
00188     void sendTestRequest(const std::string& testReqID = "");
00189 
00190 private:    
00191     void init(const std::string& senderCompID, const std::string& targetCompID, Version version, 
00192                 bool keepSequenceNumbersAfterLogout, ISessionListener* listener);
00193 
00194  public:    
00195     struct Impl;    
00196 
00197  private:
00198     Impl* impl_;    
00199 };
00200 }};
00201 
00202 #endif

Generated on Thu Jul 31 12:55:03 2008 for FIXForge C++ FIX Engine by  doxygen 1.5.2