13#ifndef __BAOSLIB_TRANSPORT_IO_H__
14#define __BAOSLIB_TRANSPORT_IO_H__
16#include "baos/BaosLib_export.h"
20#include "transport/ProtocolStack.h"
22#include "wzcpp/features/concurrent/executor.h"
23#include "wzcpp/features/timer/timer.h"
40namespace wz::baos::transport
58 using Clock = std::chrono::system_clock;
59 using UPtr = std::unique_ptr<TransportIO>;
61 enum class PromiseState
70 PromiseState state{PromiseState::UNUSED};
81 wzcpp::ExecutorBase& executor,
82 wzcpp::TimerManager<Clock>& timerManager);
106 template <
typename LayerType>
107 void addLayer(std::uint32_t layerId)
109 transportStack_->addLayer(std::make_unique<LayerType>(layerId, *transportStack_, timerManager_));
112 ProtocolLayer& getLayer(
unsigned int layerId);
156 void onTimersElapsed(wzcpp::TimerManager<Clock>::TimerIdList& timerIds);
164 virtual void sendToIo(
const Buffer& frame) = 0;
167 static std::atomic<std::uint64_t>
msgId;
169 std::atomic<bool> shouldStop_{
false};
172 bool stopped_{
false};
175 std::atomic<bool> isOpen_{
false};
180 wzcpp::TimerManager<Clock>::AllTimersCallbackId timerCallbackId_{0};
Code regarding Input/Output Events.
Base class for a Transport input output connection.
Definition TransportIO.h:56
std::unique_ptr< ProtocolStack > transportStack_
The transport stack to use for actual sending and receiving.
Definition TransportIO.h:168
virtual void send(const Buffer &frame)=0
Send a baos frame.
virtual void eventHandler()=0
Handles the incoming IOEvents.
virtual void waitForFinished()=0
Wait till the worker of this class has finished.
TransportIO & operator=(const TransportIO &)=delete
TransportMsgQueue msgQueue_
Reference to the message queue in which events will be posted by this class.
Definition TransportIO.h:176
std::chrono::system_clock Clock
An alias for the clock internaly used.
Definition TransportIO.h:58
std::unique_ptr< TransportIO > UPtr
Alias for a std::unique_ptr to this class.
Definition TransportIO.h:59
std::unique_lock< std::mutex > UniqueLock
Alias for unique lock used by this class.
Definition TransportIO.h:60
wzcpp::TimerManager< Clock > & timerManager_
Reference to the timer manager used by this transport IO.
Definition TransportIO.h:179
BaosPromise connectionPromise_
A promise to be resolved when the connection is established, or disconnected.
Definition TransportIO.h:181
bool isIdle() const
Get the idle state of the Transport connection.
virtual bool isOpen()
Get the open state of the Transport connection.
TransportIO(BaosMsgQueue &msgQueue, wzcpp::ExecutorBase &executor, wzcpp::TimerManager< Clock > &timerManager)
Construct a new TransportIO object with a given message queue and executor.
BaosMsgQueue & bMsgQ_
Reference to the message queue in which baos events will be posted by this class.
Definition TransportIO.h:177
std::condition_variable cvFinished_
Condition variable which is set when the receiver worker has stopped.
Definition TransportIO.h:170
TransportIO(const TransportIO &)=delete
std::mutex cvFinished_mut_
The correponding mutex for the cvFinished_ condition variable.
Definition TransportIO.h:171
wzcpp::ExecutorBase & executor_
Reference to the executor to use for running the receive(RX) worker.
Definition TransportIO.h:178
TransportIO(TransportIO &&)=delete
TransportIO & operator=(TransportIO &&)=delete
virtual void close()=0
Close the Transport connection.
static std::atomic< std::uint64_t > msgId
Used to generate a continuous unique message id.
Definition TransportIO.h:167
Global types and configuration for the whole SDK.
std::promise< BaseResponse::SPtr > ResponsePromise
Definition Response.h:95
std::vector< std::uint8_t > Buffer
An alias type for a byte buffer.
Definition config.h:71
wzcpp::ConcurrentDeque< IOEvent > BaosMsgQueue
Alias for a concurrent queue with IOEvents.
Definition IOEvent.h:96
wzcpp::ConcurrentDeque< IOEvent > TransportMsgQueue
Alias for a concurrent queue with IOEvents used by the transport layer.
Definition IOEvent.h:97
Definition TransportIO.h:68