175 lines
8.3 KiB
C++
175 lines
8.3 KiB
C++
/*
|
|
* Copyright Onix Solutions Limited [OnixS]. All rights reserved.
|
|
*
|
|
* This software owned by Onix Solutions Limited [OnixS] and is protected by copyright law
|
|
* and international copyright treaties.
|
|
*
|
|
* Access to and use of the software is governed by the terms of the applicable OnixS Software
|
|
* Services Agreement (the Agreement) and Customer end user license agreements granting
|
|
* a non-assignable, non-transferable and non-exclusive license to use the software
|
|
* for it's own data processing purposes under the terms defined in the Agreement.
|
|
*
|
|
* Except as otherwise granted within the terms of the Agreement, copying or reproduction of any part
|
|
* of this source code or associated reference material to any other location for further reproduction
|
|
* or redistribution, and any amendments to this copyright notice, are expressly prohibited.
|
|
*
|
|
* Any reproduction or redistribution for sale or hiring of the Software not in accordance with
|
|
* the terms of the Agreement is a violation of copyright law.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include <OnixS/FIXEngine/Compiler.h>
|
|
#include <OnixS/FIXEngine/FIX/Timestamp.h>
|
|
#include <OnixS/FIXEngine/FIX/Message.h>
|
|
#include <OnixS/FIXEngine/FIX/FlatMessage.h>
|
|
|
|
namespace OnixS {
|
|
namespace FIX {
|
|
/// The session's pluggable storage.
|
|
class ONIXS_FIXENGINE_API ISessionStorage
|
|
{
|
|
public:
|
|
/// The destructor.
|
|
virtual ~ISessionStorage() ONIXS_FIXENGINE_DEFAULT;
|
|
|
|
/// Clears the storage.
|
|
virtual void clear() = 0;
|
|
|
|
/// Closes the storage.
|
|
///
|
|
/// @param keepSequenceNumbers The flag to indicate if it needs to clear sequence numbers on close or not. It corresponds to the same parameter in the Session's constructor.
|
|
/// @param doBackup The flag to indicate if it needs to back up the stored data. It is true, when the Session::resetLocalSequenceNumbers() method is called.
|
|
virtual void close(bool keepSequenceNumbers, bool doBackup) = 0;
|
|
|
|
/// The pointer to the native (tag=value) FIX Message.
|
|
struct ONIXS_FIXENGINE_API RawMessagePointer {
|
|
RawMessagePointer();
|
|
|
|
RawMessagePointer(const char * buffer, size_t length);
|
|
|
|
/// @note The buffer is NOT owned by the RawMessagePointer.
|
|
const char * buffer_;
|
|
|
|
size_t length_;
|
|
};
|
|
|
|
/// The Session Storage listener that is used to replay messages.
|
|
class ISessionStorageListener
|
|
{
|
|
public:
|
|
/// @note The FIX Engine/Session Storage does NOT manage the lifetime of this listener.
|
|
virtual ~ISessionStorageListener() ONIXS_FIXENGINE_DEFAULT;
|
|
|
|
/// The Implementation should pass required messages one by one to this method.
|
|
virtual void onReplayedMessage(const RawMessagePointer & pointer) = 0;
|
|
};
|
|
|
|
/// Gets the messages that have been sent earlier.
|
|
/// The implementation should pass required messages one by one to the ISessionStorageListener::onReplayedMessage(const RawMessagePointer& pointer) method.
|
|
/// It is possible to omit some or even all messages in the requested range, in this case the Engine will automatically
|
|
/// generate appropriate \a SequenceReset-GapFill messages to replace omitted ones.
|
|
///
|
|
/// @param beginSequenceNumber The sequence number of first message to resend.
|
|
/// @param endSequenceNumber the sequence number of last message to resend.
|
|
/// @param listener Requested messages have to be passed to the interface using the ISessionStorageListener::onReplayedMessage method.
|
|
/// @note The FIX Engine/Session Storage does NOT manage the lifetime of this listener.
|
|
virtual void getOutbound(SequenceNumber beginSequenceNumber, SequenceNumber endSequenceNumber, ISessionStorageListener * listener) = 0;
|
|
|
|
/// Returns the last inbound sequence number.
|
|
virtual SequenceNumber inSeqNum() = 0;
|
|
|
|
/// Sets the last inbound sequence number.
|
|
virtual void inSeqNum(SequenceNumber messageSequenceNumber) = 0;
|
|
|
|
/// Stores the given inbound message.
|
|
///
|
|
/// @param message The incoming message.
|
|
/// @param sequenceNumber The sequence number of the inbound message.
|
|
/// @param pointer The raw buffer of the inbound message.
|
|
/// @param logMessage The flag to indicate whether it needs to store the content of the message in the session storage or not.
|
|
/// This parameter depends on the Session::logInboundMessages() and Session::inboundMessageLogFilter() settings.
|
|
virtual void storeInbound(const Message & message, SequenceNumber sequenceNumber, const RawMessagePointer & pointer, bool logMessage) = 0;
|
|
|
|
/// Stores the given inbound message.
|
|
///
|
|
/// @param message The incoming message.
|
|
/// @param sequenceNumber The sequence number of the inbound message.
|
|
/// @param pointer The raw buffer of the inbound message.
|
|
/// @param logMessage The flag to indicate whether it needs to store the content of the message in the session storage or not.
|
|
/// This parameter depends on the Session::logInboundMessages() and Session::inboundMessageLogFilter() settings.
|
|
virtual void storeInbound(const FlatMessage & message, SequenceNumber sequenceNumber, const RawMessagePointer & pointer, bool logMessage) = 0;
|
|
|
|
/// Stores the given outgoing message.
|
|
/// It is called when the `messageMode` is set to `Message`.
|
|
///
|
|
/// @param message The outgoing message.
|
|
/// @param pointer The raw buffer of the outgoing message.
|
|
/// @param logMessage The flag to indicate whether it needs to store the content of the message in the session storage or not.
|
|
/// This parameter depends on the Session::logOutboundMessages() and Session::outboundMessageLogFilter() settings.
|
|
virtual void storeOutbound(const Message & message, const RawMessagePointer & pointer, bool logMessage) = 0;
|
|
|
|
/// Stores the given outgoing message.
|
|
/// It is called when the `messageMode` is set to `FlatMessage`.
|
|
///
|
|
/// @param message The outgoing message.
|
|
/// @param sequenceNumber The sequence number of the outgoing message.
|
|
/// @param pointer The raw buffer of the outgoing message.
|
|
/// @param logMessage The flag to indicate whether it needs to store the content of the message in the session storage or not.
|
|
/// This parameter depends on the Session::logOutboundMessages() and Session::outboundMessageLogFilter() settings.
|
|
virtual void storeOutbound(const FlatMessage & message, SequenceNumber sequenceNumber, const RawMessagePointer & pointer, bool logMessage) = 0;
|
|
|
|
/// Sets the session termination flag.
|
|
///
|
|
/// @param terminated If 'true' then the session is terminated and its state information is not needed any more.
|
|
/// It happens when the session is disconnected gracefully, and the `keepSequenceNumbers` parameter is false.
|
|
virtual void setSessionTerminationFlag(bool terminated) = 0;
|
|
|
|
/// Returns the last outgoing sequence number.
|
|
virtual SequenceNumber outSeqNum() = 0;
|
|
|
|
/// Sets the last outgoing sequence number.
|
|
virtual void outSeqNum(SequenceNumber messageSequenceNumber) = 0;
|
|
|
|
/// Sets the session creation time.
|
|
/// The implementation should store the \a timestamp value. This value have to be returned without changes
|
|
/// by subsequent ISessionStorage::sessionCreationTime() calls.
|
|
///
|
|
/// @param timestamp The timestamp to store in the storage.
|
|
virtual void sessionCreationTime(Timestamp timestamp) = 0;
|
|
|
|
/// Returns a value stored by the ISessionStorage::sessionCreationTime(Timestamp) call.
|
|
/// If the timestamp was never updated the method should return an instance
|
|
/// of the OnixS::FIX::Timestamp class created by the default constructor.
|
|
///
|
|
/// The code snippet below illustrate this approach:
|
|
///
|
|
/// virtual Timestamp sessionCreationTime() {
|
|
///
|
|
/// if (!creationTimeUpdated_)
|
|
/// return Timestamp();
|
|
///
|
|
/// /* Return previously stored value. */
|
|
///
|
|
/// }
|
|
///
|
|
virtual Timestamp sessionCreationTime() = 0;
|
|
|
|
/// Flushes all internal buffers
|
|
virtual void flush() = 0;
|
|
|
|
/// Returns the number of sent messages that are available for resending on counterparty's Resend Request <2> message
|
|
virtual size_t resendingQueueSize() const = 0;
|
|
|
|
/// Sets the number of sent messages that are available for resending on counterparty's Resend Request <2> message
|
|
virtual void resendingQueueSize(size_t value) = 0;
|
|
|
|
/// Warm ups the storage
|
|
virtual void warmup(size_t /*messageSize*/) {}
|
|
};
|
|
}
|
|
}
|