8#ifndef SEN_KERNEL_TRANSPORT_H
9#define SEN_KERNEL_TRANSPORT_H
24#include "stl/sen/kernel/basic_types.stl.h"
82class UniqueByteBufferManagerImpl;
87 using BufferType = std::vector<uint8_t>;
101 std::unique_ptr<UniqueByteBufferManagerImpl> pImpl_;
126 const ProcessInfo& processInfo,
128 std::string busName) = 0;
141 bool ensureNotDropped) = 0;
181 [[nodiscard]]
virtual const ProcessInfo&
getOwnInfo() const noexcept = 0;
184 virtual
void stop() noexcept = 0;
193 virtual TimerId
startTimer(std::chrono::steady_clock::duration timeout, std::function<
void()>&& timeoutCallback) = 0;
203using TransportFactory = std::function<std::unique_ptr<Transport>(
const std::string&, std::unique_ptr<Tracer> tracer)>;
230struct std::hash<
sen::kernel::ParticipantAddr>
236 seed ^= hasher(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
241 std::size_t seed = 150783;
Here we define a set of template meta-programming helpers to let the compiler take some decisions bas...
Contiguous view of elements of type T. Inspired by http://www.open-std.org/jtc1/sc22/wg21/docs/papers...
Definition span.h:34
CRTP class that wraps T to make it a strong type.
Definition strong_type.h:72
typename StrongTypeBase< uint32_t >::ValueType ValueType
Definition strong_type.h:75
virtual TransportStats fetchStats() const =0
Fetch the current statistics.
virtual void localParticipantLeftBus(ObjectOwnerId participant, BusId bus, const std::string &busName)=0
Notify other participants that there's a local participant that recently left a bus.
virtual void sendTo(ParticipantAddr &to, BusId &busId, TransportMode mode, MemBlockPtr data1, MemBlockPtr data2)=0
Send a compound message (typically header and data) over a bus to a participant using a given mode.
virtual void stop() noexcept=0
Stop the message exchange.
virtual void sendTo(ParticipantAddr &to, BusId &busId, TransportMode mode, MemBlockPtr data)=0
Send a message over a bus to a participant using a given mode.
virtual ~Transport()=default
virtual const ProcessInfo & getOwnInfo() const noexcept=0
The process info of this process.
virtual bool cancelTimer(TimerId id)=0
Cancels a timer, avoiding its expiration.
Transport(std::string_view sessionName)
A transport instance is created per connected session (which is unique within a kernel).
virtual void stopIO() noexcept
Definition include/sen/kernel/transport.h:186
virtual void start(TransportListener *listener)=0
Start the message exchange, and set the listener that will react to inputs. This method is non-blocki...
virtual void localParticipantJoinedBus(ObjectOwnerId participant, BusId bus, const std::string &busName)=0
Notify other participants that there's a local participant that recently joined a bus.
virtual TimerId startTimer(std::chrono::steady_clock::duration timeout, std::function< void()> &&timeoutCallback)=0
Starts an asio asynchronous timer that executes a callback when the steady_clock timeout is reached.
Interface for the internal Sen element that reacts to transport events.
Definition include/sen/kernel/transport.h:106
virtual void remoteParticipantLeftBus(ParticipantAddr addr, BusId bus, std::string busName)=0
Some participant left a bus.
virtual ByteBufferManager & getBufferManager()=0
Returns access to the buffer manager for easy access to memory buffers.
virtual void remoteMessageReceived(ObjectOwnerId to, BusId busId, Span< const uint8_t > msg, ByteBufferHandle buffer, bool ensureNotDropped)=0
Direct message received on a bus (independently of the communication channel).
virtual ~TransportListener()=default
ByteBufferManager::ByteBufferHandle ByteBufferHandle
Definition include/sen/kernel/transport.h:115
TransportListener()=default
virtual void remoteParticipantJoinedBus(ParticipantAddr addr, const ProcessInfo &processInfo, BusId bus, std::string busName)=0
Some participant is part of, or recently joined a bus.
UniqueByteBufferManager ByteBufferManager
Definition include/sen/kernel/transport.h:114
virtual void remoteProcessLost(ProcessId who)=0
A process is not reachable anymore.
virtual void remoteBroadcastMessageReceived(BusId busId, Span< const uint8_t > msg, ByteBufferHandle buffer)=0
Message received on a bus via broadcast.
Definition include/sen/kernel/transport.h:85
ByteBufferHandle getBuffer(size_t size)
Returns a handle to a buffer that fix size elements.
std::unique_ptr< BufferType, sen::std_util::move_only_function< void(BufferType *)> > ByteBufferHandle
Definition include/sen/kernel/transport.h:90
UniqueByteBufferManager()
~UniqueByteBufferManager()
void * userData
Allows transport implementations to inject information.
Definition include/sen/kernel/transport.h:61
ObjectOwnerId id
Definition include/sen/kernel/transport.h:59
std::size_t udpSentBytes
Definition include/sen/kernel/transport.h:147
std::size_t tcpReceivedBytes
Definition include/sen/kernel/transport.h:150
ProcessId proc
Definition include/sen/kernel/transport.h:58
std::size_t tcpSentBytes
Definition include/sen/kernel/transport.h:149
std::size_t udpReceivedBytes
Definition include/sen/kernel/transport.h:148
std::shared_ptr< FixedMemoryBlock > BestEffortBlockPtr
Pointer to a memory block of fixed size, used for best effort communication.
Definition include/sen/kernel/transport.h:71
bool operator!=(const ParticipantAddr &lhs, const ParticipantAddr &rhs) noexcept
std::vector< BestEffortBlockPtr > BestEffortBufferList
A list (vector) of fixed-size memory blocks.
Definition include/sen/kernel/transport.h:77
uint32_t getKernelProtocolVersion() noexcept
The protocol version of kernel messaging.
bool operator==(const ParticipantAddr &lhs, const ParticipantAddr &rhs) noexcept
constexpr std::size_t maxBestEffortMessageSize
The maximum UDP payload size.
Definition include/sen/kernel/transport.h:68
std::function< std::unique_ptr< Transport >(const std::string &, std::unique_ptr< Tracer > tracer)> TransportFactory
A function that creates a transport given a session name.
Definition include/sen/kernel/transport.h:203
std::shared_ptr< ResizableHeapBlock > ReliableBlockPtr
Pointer to a resizable memory block, used for reliable communication.
Definition include/sen/kernel/transport.h:74
To identify remote participants.
Definition include/sen/kernel/transport.h:57
Global transport statistics.
Definition include/sen/kernel/transport.h:146
TransportMode
How to transport information.
Definition type.h:56
Strong type for the unique identifier for a transport timer.
Definition native_object_impl.h:39
detail::MoveOnlyFunctionImpl< FwdArgs... > move_only_function
Definition move_only_function.h:256
#define SEN_STRONG_TYPE_HASHABLE(name)
Makes your strong type std::hashable. NOLINTNEXTLINE.
Definition strong_type.h:188
#define SEN_STRONG_TYPE(name, native_type)
Helper macro to define strong types. NOLINTNEXTLINE.
Definition strong_type.h:179
Utility to indicate that your class wants to be passed by value in some of the library calls.
Definition class_helpers.h:34
Definition include/sen/kernel/transport.h:47
void * userData
Allows transport implementations to inject information.
Definition include/sen/kernel/transport.h:52
StrongType< uint32_t, BusId > Base
Definition include/sen/kernel/transport.h:48
std::size_t operator()(const sen::kernel::ParticipantAddr &val) const noexcept
Definition include/sen/kernel/transport.h:239
void hashCombine(std::size_t &seed, const T &v) const noexcept
Definition include/sen/kernel/transport.h:233