DCSModulesAPI  1.0.0
DCS sub project containing all the control modules as libraries.
Classes | Enumerations | Functions | Variables
DCS::Network::Message Namespace Reference

Handles default messaging via a simple fixed protocol. More...

Classes

struct  DefaultMessage
 

Enumerations

enum  Operation {
  Operation::NO_OP = 0, Operation::REQUEST = 1, Operation::RESPONSE = 4, Operation::EVT_SUB = 7,
  Operation::EVT_UNSUB = 9, Operation::OP_ERROR, Operation::CON_VALID, Operation::DATA
}
 Defines the message operation modes in the tcp/ip connection. More...
 

Functions

DCS_API DCS::Utils::AsyncItem< DCS::Registry::SVReturnSendAsync (Operation op, u8 *data, i32 size)
 Sends an asynchronous message to the server. More...
 
DCS_API Registry::SVReturn SendSync (Operation op, u8 *data, i32 size)
 Sends a synchronous message to the server. More...
 
DCS_REGISTER_EVENT DCS_API void FibSeqEvt ()
 A Sample Event possible to implement in the server/API. When called, returns the next number in the Fibbonacci sequence.
 
DCS_INTERNAL_TEST Registry::SVReturn WaitForId (u64 id)
 
DCS_INTERNAL_TEST void SetMsgIdCondition (DefaultMessage &msg)
 
DCS_INTERNAL_TEST void NotifyPromise (DefaultMessage &msg)
 
DCS_INTERNAL_TEST DefaultMessage Alloc (i32 size)
 
DCS_INTERNAL_TEST void SetCopyIdAndCode (DefaultMessage &msg, u8 *data)
 
DCS_INTERNAL_TEST void SetCopyId (DefaultMessage &msg, u8 opcode, u64 id, u8 *data)
 
DCS_INTERNAL_TEST void SetNew (DefaultMessage &msg, u8 opcode, u8 *data)
 
DCS_INTERNAL_TEST DefaultMessage Copy (DefaultMessage &msg)
 
DCS_INTERNAL_TEST void Delete (DefaultMessage &msg)
 
DCS_INTERNAL_TEST void ScheduleTransmission (DefaultMessage msg)
 
DCS_INTERNAL_TEST void EmitEvent (u8 EVT_ID, u8 *evtData, i32 size)
 

Variables

std::mutex message_m
 
std::condition_variable lsync
 
DefaultMessage lmessage
 

Detailed Description

Handles default messaging via a simple fixed protocol.

If you wish to send a custom message not defined via this protocol, it is possible to implement on top of it and sending pure data to the server/client via the Message::Operation::DATA token. Sending data is async and uses custom DataIn/DataOut user defined callbacks to handle the binary data. The default max message size is 4096 bytes due to the custom FIFO queue max memory size (which can be changed).

Sending default messages is easy through the use of the Send*(Operation, u8*, i32) functions.

See also
Message::SendAsync(Operation, u8*, i32)
Message::SendSync(Operation, u8*, i32)

All the data is assumed to be in the same byte-order as the machine. As tought this code will not work if host and client are of different endianness. Being most systems x86_64 this should not pose a problem for a simple system.

Enumeration Type Documentation

Defines the message operation modes in the tcp/ip connection.

Enumerator
NO_OP 

Do nothing.

REQUEST 

Request a function call to the server.

RESPONSE 

Send back a response to the client.

EVT_SUB 

Subscribe to a server-side event.

EVT_UNSUB 

Unsubscribe from a previously subscribed event.

OP_ERROR 

Send an error to the client/server.

CON_VALID 

Server connection validity message.

DATA 

Send or receive data only.

Function Documentation

DCS::Utils::AsyncItem< DCS::Registry::SVReturn > DCS::Network::Message::SendAsync ( Operation  op,
u8 data,
i32  size 
)

Sends an asynchronous message to the server.

See also
DCS::Registry
Parameters
opThe type of operation to perform server-side.
dataThe DefaultMessage formated message. Expects diferent data deppending on the operation.
sizeSize of the data bytes.
Returns
Server async response (similar to std::future).
DCS::Registry::SVReturn DCS::Network::Message::SendSync ( Operation  op,
u8 data,
i32  size 
)

Sends a synchronous message to the server.

See also
DCS::Registry
Parameters
opThe type of operation to perform server-side.
dataThe DefaultMessage formated message. Expects diferent data deppending on the operation.
sizeSize of the data bytes.
Returns
Waits, blocking the calling thread, for the server response (see Registry::SVReturn).
Examples:
sockets/simple_client.cpp.