Files
2024-09-23 12:00:04 -04:00

113 lines
3.6 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 <OnixS/FIXEngine/FIX/ISessionReactor.h>
#include <OnixS/FIXEngine/Threading/Thread.h>
#include <cassert>
namespace OnixS {
namespace FIX {
class ReactorOperator;
namespace TCPStandard {
/**
* A high-level wrapper over the TCP standard stack.
*/
class ONIXS_FIXENGINE_API Stack : public ISessionReactor
{
public:
/**
* Allocates a TCP stack.
*/
Stack();
#ifdef ONIXS_FIXENGINE_CXX11
Stack(const Stack &) = delete;
Stack(Stack &&) = delete;
Stack & operator=(const Stack &) = delete;
Stack & operator=(Stack &&) = delete;
#endif
~Stack();
/**
* Processes events on a stack and performs the necessary handling.
*
* These events include transmit and receive events raised by the hardware,
* and also software events such as TCP and FIX protocol timers.
*
* \warning The event dispatching should be performed from the same thread that created the stack.
*/
void dispatchEvents() ONIXS_FIXENGINE_OVERRIDE {
// The TCPStandard middleware is NOT thread-safe.
// Therefore, the event dispatching should be performed from the same thread that created the stack.
assert(threadId() == Threading::ThisThread::id() && "should be performed from the same thread that created the stack");
dispatchEventsImpl();
}
/**
* \return a boolean value indicating whether a stack is quiescent.
*
* This can be used to ensure that all connections have been closed gracefully before the destroying of a stack
* (or exiting the application). The destroying of a stack while it is not quiescent is permitted by the API,
* but when doing so there is no guarantee that sent data has been acknowledged by the peer or even transmitted,
* and there is the possibility that peers' connections will be reset.
*/
bool isQuiescent() const ONIXS_FIXENGINE_OVERRIDE {
assert(threadId() == Threading::ThisThread::id() && "should be performed from the same thread that created the stack");
return isQuiescentImpl();
}
/**
* \return the ID of the thread that created the stack.
*/
Threading::ThreadId threadId() const ONIXS_FIXENGINE_OVERRIDE {
return threadId_;
}
ReactorType::Enum type() const ONIXS_FIXENGINE_OVERRIDE {
return ReactorType::TcpStandard;
}
private:
void dispatchEventsImpl();
bool isQuiescentImpl() const;
class Impl;
Impl * const impl_;
Threading::ThreadId const threadId_;
#ifndef ONIXS_FIXENGINE_CXX11
Stack(const Stack &);
Stack & operator=(const Stack &);
#endif
friend class FIX::ReactorOperator;
};
}}}