00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #if !defined(__ONIXS_SESSION_H__)
00021 #define __ONIXS_SESSION_H__
00022
00023 #include <string>
00024
00025 #include "OnixS/FIX/ABI.h"
00026 #include "OnixS/FIX/Definitions.h"
00027 #include "OnixS/FIX/Engine.h"
00028
00029 namespace OnixS
00030 {
00031 namespace FIX
00032 {
00033 ONIXS_FIXENGINE_API_DECL(class, Message);
00034 ONIXS_FIXENGINE_API_DECL(class, Dialect);
00035 ONIXS_FIXENGINE_API_DECL(class, Engine);
00036 ONIXS_FIXENGINE_API_DECL(class, ISessionListener);
00037 ONIXS_FIXENGINE_API_DECL(class, ISessionStorage);
00038
00041 class ONIXS_FIXENGINE_API Session
00042 {
00043 public:
00045 enum SessionStorageType
00046 {
00047 FileBasedStorage,
00048 MemoryBasedStorage,
00049 PluggableStorage
00050 };
00051
00053 static const char* storageType2String(SessionStorageType value);
00054
00064 Session(const std::string& senderCompId, const std::string& targetCompId, Version version, bool keepSequenceNumbersAfterLogout,
00065 OnixS::FIX::ISessionListener* listener, SessionStorageType storageType = FileBasedStorage, ISessionStorage* storage = NULL);
00066
00075 Session(const std::string& senderCompId, const std::string& targetCompId, Version version, ISessionListener* listener,
00076 SessionStorageType storageType = FileBasedStorage, ISessionStorage* storage = NULL);
00077
00086 Session(const std::string& senderCompId, const std::string& targetCompId, const Dialect& dialect, ISessionListener* listener,
00087 SessionStorageType storageType = FileBasedStorage, ISessionStorage* storage = NULL);
00088
00098 Session(const std::string& senderCompId, const std::string& targetCompId, const Dialect& dialect, bool keepSequenceNumbersAfterLogout,
00099 OnixS::FIX::ISessionListener* listener, SessionStorageType storageType = FileBasedStorage, ISessionStorage* storage = NULL);
00100
00111 Session(const std::string& senderCompId, const std::string& targetCompId, Version version, bool keepSequenceNumbersAfterLogout,
00112 OnixS::FIX::ISessionListener* listener, const std::string& customSessionKey, SessionStorageType storageType = FileBasedStorage,
00113 ISessionStorage* storage = NULL);
00114
00125 Session(const std::string& senderCompId, const std::string& targetCompId, const Dialect& dialect, bool keepSequenceNumbersAfterLogout,
00126 OnixS::FIX::ISessionListener* listener, const std::string& customSessionKey, SessionStorageType storageType = FileBasedStorage,
00127 ISessionStorage* storage = NULL);
00128
00129
00131 ~Session();
00132
00134 enum State{DISCONNECTED, LOGON_IN_PROGRESS, LOGOUT_IN_PROGRESS, ACTIVE, RECONNECTING};
00135
00137 void clearOutboundQueue();
00138
00140 State getState();
00141
00143 static const char* state2string(State state);
00144
00145 enum EncryptionMethod{
00146 NONE,
00147 SSL
00148 };
00149
00151 EncryptionMethod getEncryptionMethod() const;
00152
00154 void setEncryptionMethod(EncryptionMethod newEncryptionMethod);
00155
00157 int getListenPort() const;
00158
00160 void setListenPort(int listenPort);
00161
00163 void setLocalNetworkInterface(const std::string& localNetworkInterface);
00164
00166 const std::string& getLocalNetworkInterface();
00167
00169 void setTcpNoDelayOption(bool value = true);
00170
00172 bool getTcpNoDelayOption() const;
00173
00177 void setSslCertificateFile(const std::string& file);
00178
00182 void setSslPrivateKeyFile(const std::string& file);
00183
00185 void setSslPrivateKeyPassword(const std::string& password);
00186
00195 void logonAsAcceptor();
00196
00203 void logonAsInitiator(const std::string& host, int port, bool setResetSeqNumFlag);
00204
00211 void logonAsInitiator(const std::string& host, int port);
00212
00214 void logonAsInitiator(const std::string& host, int port, int heartBtInt);
00215
00217 void logonAsInitiator(const std::string& host, int port, int heartBtInt, bool setResetSeqNumFlag);
00218
00220 void logonAsInitiator(const std::string& host, int port, int heartBtInt, Message* customLogonMsg);
00221
00223 void logonAsInitiator(const std::string& host, int port, int heartBtInt, Message* customLogonMsg, bool setResetSeqNumFlag);
00224
00231 void logout();
00232
00239 void logout(const std::string& text);
00240
00246 void logout(Message * customLogoutMessage);
00247
00251 void breakConnection();
00252
00262 void send(Message* message);
00263
00267 void shutdown();
00268
00270 operator const std::string& ();
00271
00273 const std::string& getStorageID();
00274
00276 std::string getCounterpartyHost();
00277
00279 std::string getCounterpartyIpAddress();
00280
00282 size_t getCounterpartyPort();
00283
00285 const std::string& getCustomKey() const;
00286
00288 size_t getOutboundQueueBytes();
00289
00291 size_t getOutboundQueueCount();
00292
00294 int getHeartBtInt();
00295
00297 bool getLogInboundMessages() const;
00298
00300 void setLogInboundMessages(bool value);
00301
00303 bool getLogOutboundMessages() const;
00304
00306 void setLogOutboundMessages(bool value);
00307
00309 int getInSeqNum();
00310
00312 void setInSeqNum(int seqNum);
00313
00315 int getOutSeqNum();
00316
00318 void setOutSeqNum(int seqNum);
00319
00321 System::ThreadId getReceivingThreadId() const;
00322
00324 enum Role{NA, INITIATOR, ACCEPTOR};
00325
00327 Role getRole();
00328
00330 const std::string& getSenderCompID();
00331
00333 System::ThreadId getSendingThreadId() const;
00334
00336 const std::string& getTargetCompID();
00337
00339 Version getVersion();
00340
00343 const Dialect& dialect();
00344
00346 Message* findSentMessage(int messageSequenceNumber);
00347
00350 void registerListener(ISessionListener* listener);
00351
00353 void unregisterListener();
00354
00358 void reset();
00359
00361 void resetSeqNumViaLogonExchange();
00362
00364 void senderSubID(const std::string& value);
00365
00367 void targetSubID(const std::string& value);
00368
00370 void senderLocationID(const std::string& value);
00371
00373 void targetLocationID(const std::string& value);
00374
00376 void sendTestRequest(const std::string& testReqID = "");
00377
00378 struct Impl;
00379
00380 private:
00381 void init(const std::string& senderCompId, const std::string& targetCompId, Version version, ISessionListener* listener,
00382 bool keepSequenceNumbersAfterLogout, SessionStorageType storageType, ISessionStorage* storage, const std::string& customSessionKey);
00383
00384 void init(const std::string& senderCompId, const std::string& targetCompId, const std::string& dialectId, ISessionListener* listener,
00385 bool keepSequenceNumbersAfterLogout, SessionStorageType storageType, ISessionStorage* storage, const std::string& customSessionKey);
00386
00387 Session(void* native);
00388
00389 Impl* impl_;
00390
00391 friend struct Engine::Impl;
00392 };
00393 }
00394 }
00395
00396 #endif // __ONIXS_SESSION_H__