XII Release 0.1.0
Loading...
Searching...
No Matches
xiiIpcChannel Class Referenceabstract

Base class for a communication channel between processes. More...

#include <IpcChannel.h>

Classes

struct  ConnectionState
 
struct  Mode
 

Public Types

using ReceiveCallback = xiiDelegate<void(xiiArrayPtr<const xiiUInt8> message)>
 

Public Member Functions

void Connect ()
 Connects async. On success, m_Events will be broadcasted.
 
void Disconnect ()
 Disconnect async. On completion, m_Events will be broadcasted.
 
bool IsConnected () const
 Returns whether we have a connection.
 
xiiEnum< ConnectionStateGetConnectionState () const
 Returns the current state of the connection.
 
bool Send (xiiArrayPtr< const xiiUInt8 > data)
 Sends a message. pMsg can be destroyed after the call.
 
void SetReceiveCallback (ReceiveCallback callback)
 
xiiResult WaitForMessages (xiiTime timeout)
 Block and wait for new messages and call ProcessMessages.
 

Static Public Member Functions

static xiiInternal::NewInstance< xiiIpcChannelCreatePipeChannel (xiiStringView sAddress, Mode::Enum mode)
 Creates an IPC communication channel using pipes.
 
static xiiInternal::NewInstance< xiiIpcChannelCreateNetworkChannel (xiiStringView sAddress, Mode::Enum mode)
 

Public Attributes

xiiEvent< const xiiIpcChannelEvent &, xiiMutexm_Events
 Will be sent from any thread.
 

Protected Types

enum  Constants : xiiUInt32 { HEADER_SIZE = 8 , MAGIC_VALUE = 'USED' , MAX_MESSAGE_SIZE = 1024 * 1024 * 16 }
 

Protected Member Functions

 xiiIpcChannel (xiiStringView sAddress, Mode::Enum mode)
 
virtual bool RequiresRegularTick ()
 Override this and return true, if the surrounding infrastructure should call the 'Tick()' function.
 
virtual void Tick ()
 Can implement regular updates, e.g. for polling network state.
 
virtual void InternalConnect ()=0
 Called on worker thread after Connect was called.
 
virtual void InternalDisconnect ()=0
 Called on worker thread after Disconnect was called.
 
virtual void InternalSend ()=0
 Called on worker thread to sent pending messages.
 
virtual bool NeedWakeup () const =0
 Called by Send to determine whether the message loop need to be woken up.
 
void SetConnectionState (xiiEnum< ConnectionState > state)
 
void ReceiveData (xiiArrayPtr< const xiiUInt8 > data)
 Implementation needs to call this when new data has been received. data can be invalidated after the function.
 
void FlushPendingOperations ()
 

Protected Attributes

xiiThreadID m_ThreadId = 0
 
xiiAtomicInteger< ConnectionState::Enumm_iConnectionState = ConnectionState::Disconnected
 
xiiString m_sAddress
 
const xiiEnum< Modem_Mode
 
xiiMessageLoopm_pOwner = nullptr
 
xiiMutex m_OutputQueueMutex
 
xiiDeque< xiiContiguousMemoryStreamStoragem_OutputQueue
 
xiiDynamicArray< xiiUInt8 > m_MessageAccumulator
 Message is assembled in here.
 
xiiMutex m_ReceiveCallbackMutex
 
ReceiveCallback m_ReceiveCallback
 
xiiThreadSignal m_IncomingMessages
 

Friends

class xiiMessageLoop
 

Detailed Description

Base class for a communication channel between processes.

The channel allows for byte blobs to be send back and forth between two processes. A client should only try to connect to a server once the server has changed to ConnectionState::Connecting as this indicates the server is ready to be conneccted to.

Use xiiIpcChannel:CreatePipeChannel to create an IPC pipe instance. To send more complex messages accross, you can create a xiiIpcProcessMessageProtocol on top of the channel.

Member Enumeration Documentation

◆ Constants

enum xiiIpcChannel::Constants : xiiUInt32
protected
Enumerator
HEADER_SIZE 

Magic value and size xiiUint32.

MAGIC_VALUE 

Magic value.

MAX_MESSAGE_SIZE 

Arbitrary message size limit.

Member Function Documentation

◆ CreatePipeChannel()

xiiInternal::NewInstance< xiiIpcChannel > xiiIpcChannel::CreatePipeChannel ( xiiStringView sAddress,
Mode::Enum mode )
static

Creates an IPC communication channel using pipes.

Parameters
sAddressName of the pipe, must be unique on a system and less than 200 characters.
modeWhether to run in client or server mode.

The documentation for this class was generated from the following files: