Fawkes API
Fawkes Development Version
|
#include "oprs_protobuf.h"
Public Member Functions | |
OpenPRSProtobuf (std::vector< std::string > &proto_path) | |
Constructor. More... | |
~OpenPRSProtobuf () | |
Destructor. More... | |
protobuf_comm::ProtobufStreamServer * | server () const |
Get Protobuf server. More... | |
const std::map< long int, protobuf_comm::ProtobufBroadcastPeer * > & | peers () const |
Get protobuf_comm peers. More... | |
protobuf_comm::MessageRegister & | message_register () |
Get the communicator's message register. More... | |
boost::signals2::signal< void(protobuf_comm::ProtobufStreamServer::ClientID, std::shared_ptr< google::protobuf::Message >)> & | signal_server_sent () |
Signal invoked for a message that has been sent to a server client. More... | |
boost::signals2::signal< void(std::string, unsigned short, std::shared_ptr< google::protobuf::Message >)> & | signal_client_sent () |
Signal invoked for a message that has been sent to a client. More... | |
boost::signals2::signal< void(long int, std::shared_ptr< google::protobuf::Message >)> & | signal_peer_sent () |
Signal invoked for a message that has been sent via broadcast. More... | |
bool | oprs_pb_register_type (std::string full_name) |
Register a new message type. More... | |
Term * | oprs_pb_field_names (void *msgptr) |
Get field names of message. More... | |
bool | oprs_pb_has_field (void *msgptr, std::string field_name) |
Check if message has a specific field. More... | |
Term * | oprs_pb_field_value (void *msgptr, std::string field_name) |
Get properly typed field value. More... | |
Term * | oprs_pb_field_type (void *msgptr, std::string field_name) |
Get type if a specific field. More... | |
Term * | oprs_pb_field_label (void *msgptr, std::string field_name) |
Get a fields label. More... | |
Term * | oprs_pb_field_list (void *msgptr, std::string field_name) |
Get list of values of a given message field. More... | |
bool | oprs_pb_field_is_list (void *msgptr, std::string field_name) |
Check if a given field is a list (repeated field). More... | |
std::shared_ptr< google::protobuf::Message > * | oprs_create_msg (std::string full_name) |
Create a new message of given type. More... | |
Term * | oprs_pb_ref (void *msgptr) |
Create new reference to message. More... | |
Term * | oprs_pb_destroy (void *msgptr) |
Destroy given message (reference). More... | |
void | oprs_pb_set_field (void *msgptr, std::string field_name, Term *value) |
Set a field. More... | |
void | oprs_pb_add_list (void *msgptr, std::string field_name, Term *value) |
Add value to a repeated field. More... | |
void | oprs_pb_send (long int client_id, void *msgptr) |
Send message to a specific client. More... | |
Term * | oprs_pb_client_connect (std::string host, int port) |
Connect as a client to the given server. More... | |
void | oprs_pb_disconnect (long int client_id) |
Disconnect a given client. More... | |
void | oprs_pb_broadcast (long int peer_id, void *msgptr) |
Broadcast a message through a peer. More... | |
void | oprs_pb_enable_server (int port) |
Enable protobuf stream server. More... | |
void | oprs_pb_disable_server () |
Disable protobuf stream server. More... | |
Term * | oprs_pb_peer_create (const std::string &host, int port) |
Enable protobuf peer. More... | |
Term * | oprs_pb_peer_create_local (const std::string &host, int send_port, int recv_port) |
Enable protobuf peer. More... | |
Term * | oprs_pb_peer_create_crypto (const std::string &host, int port, const std::string &crypto_key="", const std::string &cipher="") |
Enable protobuf peer. More... | |
Term * | oprs_pb_peer_create_local_crypto (const std::string &host, int send_port, int recv_port, const std::string &crypto_key="", const std::string &cipher="") |
Enable protobuf peer. More... | |
void | oprs_pb_peer_destroy (long int peer_id) |
Disable peer. More... | |
void | oprs_pb_peer_setup_crypto (long int peer_id, const std::string &crypto_key, const std::string &cipher) |
Setup crypto for peer. More... | |
bool | oprs_pb_events_pending () |
Check if there are pending events. More... | |
void | oprs_pb_process () |
Process all pending events. More... | |
OpenPRS protobuf integration class. This class adds functionality related to protobuf to OpenPRS. It supports the creation of communication channels through protobuf_comm. An instance maintains its own message register shared among server, peer, and clients.
Definition at line 57 of file oprs_protobuf.h.
oprs_protobuf::OpenPRSProtobuf::OpenPRSProtobuf | ( | std::vector< std::string > & | proto_path | ) |
Constructor.
proto_path | proto path passed to a newly instantiated message register |
Definition at line 66 of file oprs_protobuf.cpp.
oprs_protobuf::OpenPRSProtobuf::~OpenPRSProtobuf | ( | ) |
Destructor.
Definition at line 72 of file oprs_protobuf.cpp.
|
inline |
Get the communicator's message register.
Definition at line 82 of file oprs_protobuf.h.
std::shared_ptr< google::protobuf::Message > * oprs_protobuf::OpenPRSProtobuf::oprs_create_msg | ( | std::string | full_name | ) |
Create a new message of given type.
full_name | name of message type (fully qualified, i.e. including package name) |
std::runtime_error | thrown if creating the message failed |
Definition at line 241 of file oprs_protobuf.cpp.
void oprs_protobuf::OpenPRSProtobuf::oprs_pb_add_list | ( | void * | msgptr, |
std::string | field_name, | ||
Term * | value | ||
) |
Add value to a repeated field.
msgptr | message |
field_name | name of the field |
value | term which must contain a single properly typed value. |
Definition at line 616 of file oprs_protobuf.cpp.
void oprs_protobuf::OpenPRSProtobuf::oprs_pb_broadcast | ( | long int | peer_id, |
void * | msgptr | ||
) |
Broadcast a message through a peer.
peer_id | ID broadcast peer to send through |
msgptr | message to send |
Definition at line 836 of file oprs_protobuf.cpp.
Term * oprs_protobuf::OpenPRSProtobuf::oprs_pb_client_connect | ( | std::string | host, |
int | port | ||
) |
Connect as a client to the given server.
Note that this will perform an asynchronous connect. A (protobuf-client-connected) or (protobuf-client-disconnected) fact is asserted during (pb-process) in the case of success or failure.
host | host to connect to |
port | TCP port to connect to |
Definition at line 758 of file oprs_protobuf.cpp.
References protobuf_comm::ProtobufStreamClient::async_connect(), protobuf_comm::ProtobufStreamClient::signal_connected(), protobuf_comm::ProtobufStreamClient::signal_disconnected(), protobuf_comm::ProtobufStreamClient::signal_receive_failed(), and protobuf_comm::ProtobufStreamClient::signal_received().
Term * oprs_protobuf::OpenPRSProtobuf::oprs_pb_destroy | ( | void * | msgptr | ) |
Destroy given message (reference).
This will decrement the reference count to the message and delete it. The message itself is deleted if the reference counter reaches zero.
msgptr | message (reference) to delete, any access to this message afterwards is illegal. |
Definition at line 270 of file oprs_protobuf.cpp.
void oprs_protobuf::OpenPRSProtobuf::oprs_pb_disable_server | ( | ) |
Disable protobuf stream server.
Definition at line 105 of file oprs_protobuf.cpp.
void oprs_protobuf::OpenPRSProtobuf::oprs_pb_disconnect | ( | long int | client_id | ) |
Disconnect a given client.
client_id | ID of client to disconnect, can be a server client ID or a client ID |
Definition at line 865 of file oprs_protobuf.cpp.
References protobuf_comm::ProtobufStreamServer::disconnect().
void oprs_protobuf::OpenPRSProtobuf::oprs_pb_enable_server | ( | int | port | ) |
Enable protobuf stream server.
port | TCP port to listen on for connections |
Definition at line 87 of file oprs_protobuf.cpp.
References protobuf_comm::ProtobufStreamServer::signal_connected(), protobuf_comm::ProtobufStreamServer::signal_disconnected(), protobuf_comm::ProtobufStreamServer::signal_receive_failed(), and protobuf_comm::ProtobufStreamServer::signal_received().
bool oprs_protobuf::OpenPRSProtobuf::oprs_pb_events_pending | ( | ) |
Check if there are pending events.
Definition at line 1037 of file oprs_protobuf.cpp.
References fawkes::LockQueue< Type >::mutex().
bool oprs_protobuf::OpenPRSProtobuf::oprs_pb_field_is_list | ( | void * | msgptr, |
std::string | field_name | ||
) |
Check if a given field is a list (repeated field).
msgptr | message |
field_name | name of the field |
Definition at line 975 of file oprs_protobuf.cpp.
Term * oprs_protobuf::OpenPRSProtobuf::oprs_pb_field_label | ( | void * | msgptr, |
std::string | field_name | ||
) |
Get a fields label.
msgptr | message for which to get the field type |
field_name | name of the field |
Definition at line 377 of file oprs_protobuf.cpp.
Term * oprs_protobuf::OpenPRSProtobuf::oprs_pb_field_list | ( | void * | msgptr, |
std::string | field_name | ||
) |
Get list of values of a given message field.
msgptr | message |
field_name | field to retrieve |
Definition at line 893 of file oprs_protobuf.cpp.
References oprs_pb_field_value().
Term * oprs_protobuf::OpenPRSProtobuf::oprs_pb_field_names | ( | void * | msgptr | ) |
Get field names of message.
msgptr | user pointer to message |
Definition at line 286 of file oprs_protobuf.cpp.
Term * oprs_protobuf::OpenPRSProtobuf::oprs_pb_field_type | ( | void * | msgptr, |
std::string | field_name | ||
) |
Get type if a specific field.
msgptr | message for which to get the field type |
field_name | name of the field |
Definition at line 309 of file oprs_protobuf.cpp.
Term * oprs_protobuf::OpenPRSProtobuf::oprs_pb_field_value | ( | void * | msgptr, |
std::string | field_name | ||
) |
Get properly typed field value.
msgptr | message for which to get the field type |
field_name | name of the field |
Definition at line 402 of file oprs_protobuf.cpp.
Referenced by oprs_pb_field_list().
bool oprs_protobuf::OpenPRSProtobuf::oprs_pb_has_field | ( | void * | msgptr, |
std::string | field_name | ||
) |
Check if message has a specific field.
This is relevant in particular for optional fields.
msgptr | message |
field_name | name of the field |
Definition at line 350 of file oprs_protobuf.cpp.
Term * oprs_protobuf::OpenPRSProtobuf::oprs_pb_peer_create | ( | const std::string & | address, |
int | port | ||
) |
Enable protobuf peer.
address | IP address to send messages to |
port | UDP port to send and receive messages |
Definition at line 175 of file oprs_protobuf.cpp.
References oprs_pb_peer_create_local_crypto().
Term * oprs_protobuf::OpenPRSProtobuf::oprs_pb_peer_create_crypto | ( | const std::string & | address, |
int | port, | ||
const std::string & | crypto_key = "" , |
||
const std::string & | cipher = "" |
||
) |
Enable protobuf peer.
address | IP address to send messages to |
port | UDP port to send and receive messages |
crypto_key | encryption key |
cipher | cipher suite, see BufferEncryptor for supported types |
Definition at line 161 of file oprs_protobuf.cpp.
References oprs_pb_peer_create_local_crypto().
Term * oprs_protobuf::OpenPRSProtobuf::oprs_pb_peer_create_local | ( | const std::string & | address, |
int | send_port, | ||
int | recv_port | ||
) |
Enable protobuf peer.
address | IP address to send messages to |
send_port | UDP port to send messages to |
recv_port | UDP port to receive messages on, 0 to use the same as the send_port |
Definition at line 187 of file oprs_protobuf.cpp.
References oprs_pb_peer_create_local_crypto().
Term * oprs_protobuf::OpenPRSProtobuf::oprs_pb_peer_create_local_crypto | ( | const std::string & | address, |
int | send_port, | ||
int | recv_port, | ||
const std::string & | crypto_key = "" , |
||
const std::string & | cipher = "" |
||
) |
Enable protobuf peer.
address | IP address to send messages to |
send_port | UDP port to send messages to |
recv_port | UDP port to receive messages on, 0 to use the same as the send_port |
crypto_key | encryption key |
cipher | cipher suite, see BufferEncryptor for supported types |
Definition at line 120 of file oprs_protobuf.cpp.
References protobuf_comm::ProtobufBroadcastPeer::signal_received(), protobuf_comm::ProtobufBroadcastPeer::signal_recv_error(), and protobuf_comm::ProtobufBroadcastPeer::signal_send_error().
Referenced by oprs_pb_peer_create(), oprs_pb_peer_create_crypto(), and oprs_pb_peer_create_local().
void oprs_protobuf::OpenPRSProtobuf::oprs_pb_peer_destroy | ( | long int | peer_id | ) |
Disable peer.
peer_id | ID of the peer to destroy |
Definition at line 196 of file oprs_protobuf.cpp.
void oprs_protobuf::OpenPRSProtobuf::oprs_pb_peer_setup_crypto | ( | long int | peer_id, |
const std::string & | crypto_key, | ||
const std::string & | cipher | ||
) |
Setup crypto for peer.
peer_id | ID of the peer to destroy |
crypto_key | encryption key |
cipher | cipher suite, see BufferEncryptor for supported types |
Definition at line 210 of file oprs_protobuf.cpp.
void oprs_protobuf::OpenPRSProtobuf::oprs_pb_process | ( | ) |
Process all pending events.
This will process events and assert appropriate facts.
Definition at line 994 of file oprs_protobuf.cpp.
References fawkes::LockQueue< Type >::mutex().
Term * oprs_protobuf::OpenPRSProtobuf::oprs_pb_ref | ( | void * | msgptr | ) |
Create new reference to message.
msgptr | message to create reference for |
msgptr
Definition at line 252 of file oprs_protobuf.cpp.
bool oprs_protobuf::OpenPRSProtobuf::oprs_pb_register_type | ( | std::string | full_name | ) |
Register a new message type.
full_name | full name of type to register |
Definition at line 224 of file oprs_protobuf.cpp.
void oprs_protobuf::OpenPRSProtobuf::oprs_pb_send | ( | long int | client_id, |
void * | msgptr | ||
) |
Send message to a specific client.
client_id | ID of the client, this can be a server client ID, a client ID, or a peer ID (message will then be broadcasted). |
msgptr | message to send |
Definition at line 793 of file oprs_protobuf.cpp.
References protobuf_comm::ProtobufStreamServer::send().
void oprs_protobuf::OpenPRSProtobuf::oprs_pb_set_field | ( | void * | msgptr, |
std::string | field_name, | ||
Term * | value | ||
) |
Set a field.
msgptr | message for which to get the field type |
field_name | name of the field |
value | term which must contain a single properly typed value. |
Definition at line 454 of file oprs_protobuf.cpp.
|
inline |
|
inline |
|
inline |
Signal invoked for a message that has been sent to a client.
Definition at line 102 of file oprs_protobuf.h.
|
inline |
Signal invoked for a message that has been sent via broadcast.
Definition at line 111 of file oprs_protobuf.h.
|
inline |
Signal invoked for a message that has been sent to a server client.
Definition at line 92 of file oprs_protobuf.h.