Fawkes API  Fawkes Development Version
protobuf_comm::ProtobufStreamServer Class Reference

Stream server for protobuf message transmission. More...

#include <>>

Public Types

typedef unsigned int ClientID
 ID to identify connected clients. More...
 

Public Member Functions

 ProtobufStreamServer (unsigned short port)
 Constructor. More...
 
 ProtobufStreamServer (unsigned short port, std::vector< std::string > &proto_path)
 Constructor. More...
 
 ProtobufStreamServer (unsigned short port, MessageRegister *mr)
 Constructor. More...
 
 ~ProtobufStreamServer ()
 Destructor. More...
 
void send (ClientID client, uint16_t component_id, uint16_t msg_type, google::protobuf::Message &m)
 Send a message to the given client. More...
 
void send (ClientID client, uint16_t component_id, uint16_t msg_type, std::shared_ptr< google::protobuf::Message > m)
 Send a message. More...
 
void send (ClientID client, std::shared_ptr< google::protobuf::Message > m)
 Send a message. More...
 
void send (ClientID client, google::protobuf::Message &m)
 Send a message. More...
 
void send_to_all (uint16_t component_id, uint16_t msg_type, google::protobuf::Message &m)
 Send a message to all clients. More...
 
void send_to_all (uint16_t component_id, uint16_t msg_type, std::shared_ptr< google::protobuf::Message > m)
 Send a message to all clients. More...
 
void send_to_all (std::shared_ptr< google::protobuf::Message > m)
 Send a message to all clients. More...
 
void send_to_all (google::protobuf::Message &m)
 Send a message to all clients. More...
 
void disconnect (ClientID client)
 Disconnect specific client. More...
 
MessageRegistermessage_register ()
 Get the server's message register. More...
 
boost::signals2::signal< void(ClientID, uint16_t, uint16_t, std::shared_ptr< google::protobuf::Message >)> & signal_received ()
 Signal that is invoked when a message has been received. More...
 
boost::signals2::signal< void(ClientID, uint16_t, uint16_t, std::string)> & signal_receive_failed ()
 Signal that is invoked when receiving a message failed. More...
 
boost::signals2::signal< void(ClientID, boost::asio::ip::tcp::endpoint &)> & signal_connected ()
 Signal that is invoked when a new client has connected. More...
 
boost::signals2::signal< void(ClientID, const boost::system::error_code &)> & signal_disconnected ()
 Signal that is invoked when a new client has disconnected. More...
 

Detailed Description

Stream server for protobuf message transmission.

The server opens a TCP socket (IPv4) and waits for incoming connections. Each incoming connection is given a unique client ID. Signals are provided that can be used to react to connections and incoming data.

Author
Tim Niemueller

Definition at line 61 of file server.h.

Member Typedef Documentation

◆ ClientID

ID to identify connected clients.

Definition at line 65 of file server.h.

Constructor & Destructor Documentation

◆ ProtobufStreamServer() [1/3]

protobuf_comm::ProtobufStreamServer::ProtobufStreamServer ( unsigned short  port)

Constructor.

Parameters
portport to listen on

Definition at line 251 of file server.cpp.

◆ ProtobufStreamServer() [2/3]

protobuf_comm::ProtobufStreamServer::ProtobufStreamServer ( unsigned short  port,
std::vector< std::string > &  proto_path 
)

Constructor.

Parameters
portport to listen on
proto_pathfile paths to search for proto files. All message types within these files will automatically be registered and available for dynamic message creation.

Definition at line 270 of file server.cpp.

◆ ProtobufStreamServer() [3/3]

protobuf_comm::ProtobufStreamServer::ProtobufStreamServer ( unsigned short  port,
MessageRegister mr 
)

Constructor.

Parameters
portport to listen on
mrmessage register to use to (de)serialize messages

Definition at line 288 of file server.cpp.

◆ ~ProtobufStreamServer()

protobuf_comm::ProtobufStreamServer::~ProtobufStreamServer ( )

Destructor.

Definition at line 303 of file server.cpp.

Member Function Documentation

◆ disconnect()

void protobuf_comm::ProtobufStreamServer::disconnect ( ClientID  client)

Disconnect specific client.

Parameters
clientclient ID to disconnect from

Definition at line 447 of file server.cpp.

Referenced by oprs_protobuf::OpenPRSProtobuf::oprs_pb_disconnect().

◆ message_register()

MessageRegister& protobuf_comm::ProtobufStreamServer::message_register ( )
inline

Get the server's message register.

Returns
message register

Definition at line 94 of file server.h.

◆ send() [1/4]

void protobuf_comm::ProtobufStreamServer::send ( ClientID  client,
uint16_t  component_id,
uint16_t  msg_type,
google::protobuf::Message &  m 
)

Send a message to the given client.

Parameters
clientID of the client to addresss
component_idID of the component to address
msg_typenumeric message type
mmessage to send

Definition at line 319 of file server.cpp.

Referenced by oprs_protobuf::OpenPRSProtobuf::oprs_pb_send(), send(), and send_to_all().

◆ send() [2/4]

void protobuf_comm::ProtobufStreamServer::send ( ClientID  client,
uint16_t  component_id,
uint16_t  msg_type,
std::shared_ptr< google::protobuf::Message >  m 
)

Send a message.

Parameters
clientID of the client to addresss
component_idID of the component to address
msg_typenumeric message type
mMessage to send

Definition at line 338 of file server.cpp.

References send().

◆ send() [3/4]

void protobuf_comm::ProtobufStreamServer::send ( ClientID  client,
std::shared_ptr< google::protobuf::Message >  m 
)

Send a message.

Parameters
clientID of the client to addresss
mMessage to send, the message must have an CompType enum type to specify component ID and message type.

Definition at line 382 of file server.cpp.

References send().

◆ send() [4/4]

void protobuf_comm::ProtobufStreamServer::send ( ClientID  client,
google::protobuf::Message &  m 
)

Send a message.

Parameters
clientID of the client to addresss
mMessage to send, the message must have an CompType enum type to specify component ID and message type.

Definition at line 352 of file server.cpp.

References send().

◆ send_to_all() [1/4]

void protobuf_comm::ProtobufStreamServer::send_to_all ( uint16_t  component_id,
uint16_t  msg_type,
google::protobuf::Message &  m 
)

Send a message to all clients.

Parameters
component_idID of the component to address
msg_typenumeric message type
mmessage to send

Definition at line 393 of file server.cpp.

References send().

◆ send_to_all() [2/4]

void protobuf_comm::ProtobufStreamServer::send_to_all ( uint16_t  component_id,
uint16_t  msg_type,
std::shared_ptr< google::protobuf::Message >  m 
)

Send a message to all clients.

Parameters
component_idID of the component to address
msg_typenumeric message type
mmessage to send

Definition at line 409 of file server.cpp.

References send().

◆ send_to_all() [3/4]

void protobuf_comm::ProtobufStreamServer::send_to_all ( std::shared_ptr< google::protobuf::Message >  m)

Send a message to all clients.

Parameters
mmessage to send

Definition at line 423 of file server.cpp.

References send().

◆ send_to_all() [4/4]

void protobuf_comm::ProtobufStreamServer::send_to_all ( google::protobuf::Message &  m)

Send a message to all clients.

Parameters
mmessage to send

Definition at line 435 of file server.cpp.

References send().

◆ signal_connected()

boost::signals2::signal<void(ClientID, boost::asio::ip::tcp::endpoint &)>& protobuf_comm::ProtobufStreamServer::signal_connected ( )
inline

Signal that is invoked when a new client has connected.

Returns
signal

Definition at line 122 of file server.h.

Referenced by protobuf_clips::ClipsProtobufCommunicator::enable_server(), and oprs_protobuf::OpenPRSProtobuf::oprs_pb_enable_server().

◆ signal_disconnected()

boost::signals2::signal<void(ClientID, const boost::system::error_code &)>& protobuf_comm::ProtobufStreamServer::signal_disconnected ( )
inline

Signal that is invoked when a new client has disconnected.

Returns
signal

Definition at line 131 of file server.h.

Referenced by protobuf_clips::ClipsProtobufCommunicator::enable_server(), and oprs_protobuf::OpenPRSProtobuf::oprs_pb_enable_server().

◆ signal_receive_failed()

boost::signals2::signal<void(ClientID, uint16_t, uint16_t, std::string)>& protobuf_comm::ProtobufStreamServer::signal_receive_failed ( )
inline

Signal that is invoked when receiving a message failed.

Returns
signal

Definition at line 113 of file server.h.

Referenced by protobuf_clips::ClipsProtobufCommunicator::enable_server(), and oprs_protobuf::OpenPRSProtobuf::oprs_pb_enable_server().

◆ signal_received()

boost::signals2::signal< void(ClientID, uint16_t, uint16_t, std::shared_ptr<google::protobuf::Message>)>& protobuf_comm::ProtobufStreamServer::signal_received ( )
inline

Signal that is invoked when a message has been received.

Returns
signal

Definition at line 104 of file server.h.

Referenced by protobuf_clips::ClipsProtobufCommunicator::enable_server(), and oprs_protobuf::OpenPRSProtobuf::oprs_pb_enable_server().


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