SEDNL  .
Simple Event Driven Network Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Classes | Typedefs | Functions
SedNL Namespace Reference

The SedNL library namespace. More...

Classes

class  Slot
 A slot which can contain a callback. More...
 
class  Connection
 Define the the Connection type wich handle a connection and allow sending Event objects. More...
 
class  Event
 A user event. More...
 
class  ConsumerDescriptor
 Contain a consumer mutex / condition variable. More...
 
class  EventConsumer
 A consumer object. It consume certain kind of events from an EventListener. More...
 
class  EventListener
 Listen from events and incoming connections. More...
 
class  Exception
 The root of SedNL's exception tree. More...
 
class  TemplateException
 Describe how to build a SedNL::Exception. More...
 
class  NonCopyable
 Class inheriting from NonCopyable won't be copyable. More...
 
class  Packet
 A packet. More...
 
class  PacketReader
 A reader (allow reading content from a Packet). More...
 
class  Poller
 
class  RingBuf
 A ring buffer, for implementation purpose. More...
 
struct  Serializer
 
class  SafeType
 Allow to protect a type T with a mutex. More...
 
class  SafeQueue
 A std::queue like protected with a mutex. More...
 
class  SocketAddress
 Contains an inet address (ip(v4 or v6) and port). More...
 
class  SocketInterface
 Describe functions that Connection, TCPClient and TCPServer should have (like a connected / unconnected state). More...
 
class  TCPClient
 Create a connection to a server. More...
 
class  TCPServer
 Bind a server socket (to allow listening for incoming connections). More...
 

Typedefs

template<typename... Args>
using SlotMap = std::unordered_map< std::string, Slot< Args...>>
 
typedef TemplateException
< TypeExceptionT > 
TypeException
 Exception throw when the type asked/given isn't the type expected.
 
typedef TemplateException
< NetworkExceptionT > 
NetworkException
 Exception throw by the low level network part of the library.
 
typedef TemplateException
< EventExceptionT > 
EventException
 Exception throw by the event part of the library.
 
typedef TemplateException
< PacketExceptionT > 
PacketException
 Exception throw when packet are read with the wrong format.
 
typedef std::vector< ByteByteArray
 
typedef int8_t Int8
 8 bits integer
 
typedef int16_t Int16
 16 bits integer
 
typedef int32_t Int32
 32 bits integer
 
typedef int64_t Int64
 64 bits integer
 
typedef uint8_t UInt8
 8 bits integer
 
typedef uint16_t UInt16
 16 bits integer
 
typedef uint32_t UInt32
 32 bits integer
 
typedef uint64_t UInt64
 64 bits integer
 
typedef UInt8 Byte
 A byte.
 
typedef int FileDescriptor
 A (socket) file descriptor.
 

Functions

template<typename... Args>
Event make_packet (const std::string &event_name, Args...args)
 Allow creating easily new events. More...
 
SEDNL_API std::ostream & operator<< (std::ostream &os, const Event &e)
 Display an Event in a JSON like format. More...
 
void swap (Event &a, Event &b) noexcept
 
template<typename... Args>
Event make_event (const std::string &event_name, Args...args)
 
template<>
PacketPacket::operator<< < std::string > (std::string dt)
 
template<typename T >
PacketReaderoperator>> (Packet &p, T &dt)
 
SEDNL_API std::ostream & operator<< (std::ostream &os, const Packet &p)
 Write a short description of a packet in a JSON like fashion. More...
 
template<typename... Args>
void read_as_object (PacketReader &packet_reader, Args &...args)
 Read all the argument as an object of length number_of_args(args). More...
 
template<typename... Args>
Packet make_packet (Args...args)
 Allow creating easily new packets. More...
 
template<typename... Args>
void write_to_packet (Packet &packet, Args...args)
 Allow writing easily into packets. More...
 
template<typename... Args>
void read_from_packet (PacketReader &packet_reader, Args &...args)
 Allow reading data from a PacketReader. More...
 
SEDNL_API const char * type_to_string (Packet::Type type)
 Convert a type to it's name as a string. More...
 
SEDNL_API std::ostream & operator<< (std::ostream &os, Packet::Type type)
 Call type_to_string and output it. More...
 
template<typename... Args>
unsigned short number_of_args (Args...args)
 Give the number of arguments passed to it. More...
 
void swap (Packet &a, Packet &b) noexcept
 
template<typename T , typename... Args>
void write_to_packet (Packet &p, T arg, Args...args)
 
void write_to_packet (Packet &)
 
template<typename T , typename... Args>
void read_from_packet (PacketReader &p, T &arg, Args &...args)
 
void read_from_packet (PacketReader &)
 
unsigned short number_of_args_aux ()
 
template<typename T , typename... Args>
unsigned short number_of_args_aux (T, Args...args)
 
template<typename... Args>
void write_as_object (Packet &packet, Args &...args)
 
template<typename T , typename... Args>
void serializer_serialize (Packet &packet, T &inst, Args &...args)
 
template<typename T , typename... Args>
void serializer_unserialize (PacketReader &packet_reader, T &inst, Args &...args)
 

Detailed Description

The SedNL library namespace.

Function Documentation

template<typename... Args>
Event SedNL::make_packet ( const std::string &  event_name,
Args...  args 
)

Allow creating easily new events.

You can create an event with make_event(event_name, arg1, arg2, ...).

Parameters
[in]event_nameName of the event.
[in]argsValues to write into the packet.
Returns
The newly created event.
template<typename... Args>
Packet SedNL::make_packet ( Args...  args)

Allow creating easily new packets.

You can create a packet with make_packet(arg1, arg2, ...).

Parameters
argsValues to store in the new packet.
Returns
The newly created packet.

Definition at line 64 of file Packet.ipp.

template<typename... Args>
unsigned short SedNL::number_of_args ( Args...  args)
inline

Give the number of arguments passed to it.

Return the number of arguments given. For example, number_of_args("str", 42, 0.1f) return 3.

Returns
The number of arguments given to this function.

Definition at line 104 of file Packet.ipp.

SEDNL_API std::ostream& SedNL::operator<< ( std::ostream &  os,
const Event &  e 
)

Display an Event in a JSON like format.

Parameters
[out]osThe output stream.
[in]eThe packet to show.
Returns
The output stream.
SEDNL_API std::ostream& SedNL::operator<< ( std::ostream &  os,
const Packet &  p 
)

Write a short description of a packet in a JSON like fashion.

The output is { data1 : type1, data2 : type2, ..., datan : typen, }.

Parameters
[out]osThe output stream.
[in]pThe packet to show.
Returns
The output stream.
SEDNL_API std::ostream& SedNL::operator<< ( std::ostream &  os,
Packet::Type  type 
)

Call type_to_string and output it.

Parameters
[out]osThe output stream.
[in]typeThe type to show.
Returns
The output stream.
template<typename... Args>
void SedNL::read_as_object ( PacketReader &  packet_reader,
Args &...  args 
)

Read all the argument as an object of length number_of_args(args).

Its the same behavior as unserialising a serialisable object containing fields in the same order and same type as args. See SEDNL_SERIALIZABLE in Serializer.hpp.

Parameters
[in]packet_readerReader from wich to read data.
[out]argsVariables to write into.

Definition at line 119 of file Packet.ipp.

template<typename... Args>
void SedNL::read_from_packet ( PacketReader &  packet_reader,
Args &...  args 
)

Allow reading data from a PacketReader.

You can read a packet with read_from_packet(packet_reader, arg1, arg2, ...)

Parameters
[in]packet_readerStream to read data from.
[out]argsVariables in which data are stored.
void SedNL::swap ( Event &  a,
Event &  b 
)
inlinenoexcept

Swap two events.

Swap the content of a with the content of .

Parameters
[in,out]aFirst Event to swap.
[in,out]bSecond Event to swap.

Definition at line 41 of file Event.ipp.

void SedNL::swap ( Packet &  a,
Packet &  b 
)
inlinenoexcept

Swap two packets.

Swap the content of a with the content of b.

Parameters
[in,out]aFirst Packet to swap.
[in,out]bSecond Packet to swap.

Definition at line 35 of file Packet.ipp.

SEDNL_API const char* SedNL::type_to_string ( Packet::Type  type)

Convert a type to it's name as a string.

Parameters
[in]typeThe type to convert.
Returns
The type's name as a readable string.
template<typename... Args>
void SedNL::write_as_object ( Packet &  packet,
Args &...  args 
)

This produce the same behavior as serialising an object containing the values args with Packet::operator<<().

Definition at line 110 of file Packet.ipp.

template<typename... Args>
void SedNL::write_to_packet ( Packet &  packet,
Args...  args 
)

Allow writing easily into packets.

You can write into a packet with write_to_packet(packet, arg1, arg2, ...)

Parameters
[out]packetPacet in which data are stored.
[in]argsData to write sequencialy into the packet.