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 64 of file server.h.

Member Typedef Documentation

◆ ClientID

ID to identify connected clients.

Definition at line 68 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 272 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 291 of file server.cpp.

◆ ~ProtobufStreamServer()

protobuf_comm::ProtobufStreamServer::~ProtobufStreamServer ( )

Destructor.

Definition at line 307 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 450 of file server.cpp.

Referenced by protobuf_clips::ClipsProtobufCommunicator::disable_server(), oprs_protobuf::OpenPRSProtobuf::oprs_pb_disconnect(), and signal_disconnected().

◆ 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 324 of file server.cpp.

Referenced by protobuf_clips::ClipsProtobufCommunicator::disable_server(), oprs_protobuf::OpenPRSProtobuf::oprs_pb_send(), send(), send_to_all(), and signal_disconnected().

◆ 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 342 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 386 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 354 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 397 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 412 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 425 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 437 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 114 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 120 of file server.h.

References disconnect(), and send().

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 108 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 102 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: