|
Fawkes API
Fawkes Development Version
|
OpenPRS protobuf integration class. More...
#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 (std::string host, int port) |
| Enable protobuf peer. More... | |
| Term * | oprs_pb_peer_create_local (std::string host, int send_port, int recv_port) |
| Enable protobuf peer. More... | |
| Term * | oprs_pb_peer_create_crypto (std::string host, int port, std::string crypto_key="", std::string cipher="") |
| Enable protobuf peer. More... | |
| Term * | oprs_pb_peer_create_local_crypto (std::string host, int send_port, int recv_port, std::string crypto_key="", 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, std::string crypto_key, 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 60 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 70 of file oprs_protobuf.cpp.
| oprs_protobuf::OpenPRSProtobuf::~OpenPRSProtobuf | ( | ) |
Destructor.
Definition at line 78 of file oprs_protobuf.cpp.
|
inline |
Get the communicator's message register.
Definition at line 79 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 251 of file oprs_protobuf.cpp.
References protobuf_comm::MessageRegister::new_message_for().
| 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 625 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 848 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 770 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 282 of file oprs_protobuf.cpp.
| void oprs_protobuf::OpenPRSProtobuf::oprs_pb_disable_server | ( | ) |
Disable protobuf stream server.
Definition at line 114 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 875 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 94 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 1041 of file oprs_protobuf.cpp.
References fawkes::LockQueue< Type >::mutex(), and fawkes::LockQueue< Type >::push_locked().
| 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 988 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 389 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 904 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 298 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 322 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 412 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 363 of file oprs_protobuf.cpp.
| Term * oprs_protobuf::OpenPRSProtobuf::oprs_pb_peer_create | ( | 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 180 of file oprs_protobuf.cpp.
References oprs_pb_peer_create_local_crypto().
| Term * oprs_protobuf::OpenPRSProtobuf::oprs_pb_peer_create_crypto | ( | std::string | address, |
| int | port, | ||
| std::string | crypto_key = "", |
||
| 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 168 of file oprs_protobuf.cpp.
References oprs_pb_peer_create_local_crypto().
| Term * oprs_protobuf::OpenPRSProtobuf::oprs_pb_peer_create_local | ( | 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 192 of file oprs_protobuf.cpp.
References oprs_pb_peer_create_local_crypto().
| Term * oprs_protobuf::OpenPRSProtobuf::oprs_pb_peer_create_local_crypto | ( | std::string | address, |
| int | send_port, | ||
| int | recv_port, | ||
| std::string | crypto_key = "", |
||
| 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 130 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 203 of file oprs_protobuf.cpp.
| void oprs_protobuf::OpenPRSProtobuf::oprs_pb_peer_setup_crypto | ( | long int | peer_id, |
| std::string | crypto_key, | ||
| 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 218 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 1007 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 264 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 232 of file oprs_protobuf.cpp.
References protobuf_comm::MessageRegister::add_message_type().
| 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 804 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 467 of file oprs_protobuf.cpp.
|
inline |
|
inline |
|
inline |
Signal invoked for a message that has been sent to a client.
Definition at line 94 of file oprs_protobuf.h.
|
inline |
Signal invoked for a message that has been sent via broadcast.
Definition at line 100 of file oprs_protobuf.h.
|
inline |
Signal invoked for a message that has been sent to a server client.
Definition at line 87 of file oprs_protobuf.h.