Fawkes API  Fawkes Development Version
oprs_protobuf::OpenPRSProtobuf Class Reference

#include "oprs_protobuf.h"

Public Member Functions

 OpenPRSProtobuf (std::vector< std::string > &proto_path)
 Constructor. More...
 
 ~OpenPRSProtobuf ()
 Destructor. More...
 
protobuf_comm::ProtobufStreamServerserver () const
 Get Protobuf server. More...
 
const std::map< long int, protobuf_comm::ProtobufBroadcastPeer * > & peers () const
 Get protobuf_comm peers. More...
 
protobuf_comm::MessageRegistermessage_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...
 

Detailed Description

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.

Author
Tim Niemueller

Definition at line 56 of file oprs_protobuf.h.

Constructor & Destructor Documentation

◆ OpenPRSProtobuf()

oprs_protobuf::OpenPRSProtobuf::OpenPRSProtobuf ( std::vector< std::string > &  proto_path)

Constructor.

Parameters
proto_pathproto path passed to a newly instantiated message register

Definition at line 65 of file oprs_protobuf.cpp.

◆ ~OpenPRSProtobuf()

oprs_protobuf::OpenPRSProtobuf::~OpenPRSProtobuf ( )

Destructor.

Definition at line 71 of file oprs_protobuf.cpp.

Member Function Documentation

◆ message_register()

protobuf_comm::MessageRegister& oprs_protobuf::OpenPRSProtobuf::message_register ( )
inline

Get the communicator's message register.

Returns
message register

Definition at line 81 of file oprs_protobuf.h.

◆ oprs_create_msg()

std::shared_ptr< google::protobuf::Message > * oprs_protobuf::OpenPRSProtobuf::oprs_create_msg ( std::string  full_name)

Create a new message of given type.

Parameters
full_namename of message type (fully qualified, i.e. including package name)
Returns
shared pointer to new mesage
Exceptions
std::runtime_errorthrown if creating the message failed

Definition at line 240 of file oprs_protobuf.cpp.

◆ oprs_pb_add_list()

void oprs_protobuf::OpenPRSProtobuf::oprs_pb_add_list ( void *  msgptr,
std::string  field_name,
Term *  value 
)

Add value to a repeated field.

Parameters
msgptrmessage
field_namename of the field
valueterm which must contain a single properly typed value.

Definition at line 615 of file oprs_protobuf.cpp.

◆ oprs_pb_broadcast()

void oprs_protobuf::OpenPRSProtobuf::oprs_pb_broadcast ( long int  peer_id,
void *  msgptr 
)

Broadcast a message through a peer.

Parameters
peer_idID broadcast peer to send through
msgptrmessage to send

Definition at line 835 of file oprs_protobuf.cpp.

◆ oprs_pb_client_connect()

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.

Parameters
hosthost to connect to
portTCP port to connect to
Returns
Term with a long long of the client ID

Definition at line 757 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().

◆ oprs_pb_destroy()

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.

Parameters
msgptrmessage (reference) to delete, any access to this message afterwards is illegal.
Returns
T

Definition at line 269 of file oprs_protobuf.cpp.

◆ oprs_pb_disable_server()

void oprs_protobuf::OpenPRSProtobuf::oprs_pb_disable_server ( )

Disable protobuf stream server.

Definition at line 104 of file oprs_protobuf.cpp.

◆ oprs_pb_disconnect()

void oprs_protobuf::OpenPRSProtobuf::oprs_pb_disconnect ( long int  client_id)

Disconnect a given client.

Parameters
client_idID of client to disconnect, can be a server client ID or a client ID

Definition at line 864 of file oprs_protobuf.cpp.

References protobuf_comm::ProtobufStreamServer::disconnect().

◆ oprs_pb_enable_server()

void oprs_protobuf::OpenPRSProtobuf::oprs_pb_enable_server ( int  port)

◆ oprs_pb_events_pending()

bool oprs_protobuf::OpenPRSProtobuf::oprs_pb_events_pending ( )

Check if there are pending events.

Returns
true if there are pending events, false otherwise

Definition at line 1036 of file oprs_protobuf.cpp.

References fawkes::LockQueue< Type >::mutex().

◆ oprs_pb_field_is_list()

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).

Parameters
msgptrmessage
field_namename of the field
Returns
true if the field is a list, false otherwise

Definition at line 974 of file oprs_protobuf.cpp.

◆ oprs_pb_field_label()

Term * oprs_protobuf::OpenPRSProtobuf::oprs_pb_field_label ( void *  msgptr,
std::string  field_name 
)

Get a fields label.

Parameters
msgptrmessage for which to get the field type
field_namename of the field
Returns
Term with Symbol, one of INVALID-MESSAGE, DOES-NOT-EXIST, OPTIONAL, REPEATED, UNKNOWN

Definition at line 376 of file oprs_protobuf.cpp.

◆ oprs_pb_field_list()

Term * oprs_protobuf::OpenPRSProtobuf::oprs_pb_field_list ( void *  msgptr,
std::string  field_name 
)

Get list of values of a given message field.

Parameters
msgptrmessage
field_namefield to retrieve
Returns
term which contains a Lisp list with properly typed values, or a symbol in case of an error

Definition at line 892 of file oprs_protobuf.cpp.

References oprs_pb_field_value().

◆ oprs_pb_field_names()

Term * oprs_protobuf::OpenPRSProtobuf::oprs_pb_field_names ( void *  msgptr)

Get field names of message.

Parameters
msgptruser pointer to message
Returns
term containing lisp list of field names

Definition at line 285 of file oprs_protobuf.cpp.

◆ oprs_pb_field_type()

Term * oprs_protobuf::OpenPRSProtobuf::oprs_pb_field_type ( void *  msgptr,
std::string  field_name 
)

Get type if a specific field.

Parameters
msgptrmessage for which to get the field type
field_namename of the field
Returns
term with a symbol for the type

Definition at line 308 of file oprs_protobuf.cpp.

◆ oprs_pb_field_value()

Term * oprs_protobuf::OpenPRSProtobuf::oprs_pb_field_value ( void *  msgptr,
std::string  field_name 
)

Get properly typed field value.

Parameters
msgptrmessage for which to get the field type
field_namename of the field
Returns
Term with value of proper type

Definition at line 401 of file oprs_protobuf.cpp.

Referenced by oprs_pb_field_list().

◆ oprs_pb_has_field()

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.

Parameters
msgptrmessage
field_namename of the field
Returns
true if the field is present, false otherwise

Definition at line 349 of file oprs_protobuf.cpp.

◆ oprs_pb_peer_create()

Term * oprs_protobuf::OpenPRSProtobuf::oprs_pb_peer_create ( const std::string &  address,
int  port 
)

Enable protobuf peer.

Parameters
addressIP address to send messages to
portUDP port to send and receive messages
Returns
peer identifier

Definition at line 174 of file oprs_protobuf.cpp.

References oprs_pb_peer_create_local_crypto().

◆ oprs_pb_peer_create_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.

Parameters
addressIP address to send messages to
portUDP port to send and receive messages
crypto_keyencryption key
ciphercipher suite, see BufferEncryptor for supported types
Returns
peer identifier

Definition at line 160 of file oprs_protobuf.cpp.

References oprs_pb_peer_create_local_crypto().

◆ oprs_pb_peer_create_local()

Term * oprs_protobuf::OpenPRSProtobuf::oprs_pb_peer_create_local ( const std::string &  address,
int  send_port,
int  recv_port 
)

Enable protobuf peer.

Parameters
addressIP address to send messages to
send_portUDP port to send messages to
recv_portUDP port to receive messages on, 0 to use the same as the send_port
Returns
peer identifier

Definition at line 186 of file oprs_protobuf.cpp.

References oprs_pb_peer_create_local_crypto().

◆ 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.

Parameters
addressIP address to send messages to
send_portUDP port to send messages to
recv_portUDP port to receive messages on, 0 to use the same as the send_port
crypto_keyencryption key
ciphercipher suite, see BufferEncryptor for supported types
Returns
peer identifier

Definition at line 119 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().

◆ oprs_pb_peer_destroy()

void oprs_protobuf::OpenPRSProtobuf::oprs_pb_peer_destroy ( long int  peer_id)

Disable peer.

Parameters
peer_idID of the peer to destroy

Definition at line 195 of file oprs_protobuf.cpp.

◆ oprs_pb_peer_setup_crypto()

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.

Parameters
peer_idID of the peer to destroy
crypto_keyencryption key
ciphercipher suite, see BufferEncryptor for supported types

Definition at line 209 of file oprs_protobuf.cpp.

◆ oprs_pb_process()

void oprs_protobuf::OpenPRSProtobuf::oprs_pb_process ( )

Process all pending events.

This will process events and assert appropriate facts.

Definition at line 993 of file oprs_protobuf.cpp.

References fawkes::LockQueue< Type >::mutex().

◆ oprs_pb_ref()

Term * oprs_protobuf::OpenPRSProtobuf::oprs_pb_ref ( void *  msgptr)

Create new reference to message.

Parameters
msgptrmessage to create reference for
Returns
new message reference pointing to the very same message as msgptr

Definition at line 251 of file oprs_protobuf.cpp.

◆ oprs_pb_register_type()

bool oprs_protobuf::OpenPRSProtobuf::oprs_pb_register_type ( std::string  full_name)

Register a new message type.

Parameters
full_namefull name of type to register
Returns
true if the type was successfully registered, false otherwise

Definition at line 223 of file oprs_protobuf.cpp.

◆ oprs_pb_send()

void oprs_protobuf::OpenPRSProtobuf::oprs_pb_send ( long int  client_id,
void *  msgptr 
)

Send message to a specific client.

Parameters
client_idID of the client, this can be a server client ID, a client ID, or a peer ID (message will then be broadcasted).
msgptrmessage to send

Definition at line 792 of file oprs_protobuf.cpp.

References protobuf_comm::ProtobufStreamServer::send().

◆ oprs_pb_set_field()

void oprs_protobuf::OpenPRSProtobuf::oprs_pb_set_field ( void *  msgptr,
std::string  field_name,
Term *  value 
)

Set a field.

Parameters
msgptrmessage for which to get the field type
field_namename of the field
valueterm which must contain a single properly typed value.

Definition at line 453 of file oprs_protobuf.cpp.

◆ peers()

const std::map<long int, protobuf_comm::ProtobufBroadcastPeer *>& oprs_protobuf::OpenPRSProtobuf::peers ( ) const
inline

Get protobuf_comm peers.

Returns
protobuf_comm peer

Definition at line 73 of file oprs_protobuf.h.

◆ server()

protobuf_comm::ProtobufStreamServer* oprs_protobuf::OpenPRSProtobuf::server ( ) const
inline

Get Protobuf server.

Returns
protobuf server

Definition at line 65 of file oprs_protobuf.h.

◆ signal_client_sent()

boost::signals2::signal< void(std::string, unsigned short, std::shared_ptr<google::protobuf::Message>)>& oprs_protobuf::OpenPRSProtobuf::signal_client_sent ( )
inline

Signal invoked for a message that has been sent to a client.

Returns
signal

Definition at line 101 of file oprs_protobuf.h.

◆ signal_peer_sent()

boost::signals2::signal<void(long int, std::shared_ptr<google::protobuf::Message>)>& oprs_protobuf::OpenPRSProtobuf::signal_peer_sent ( )
inline

Signal invoked for a message that has been sent via broadcast.

Returns
signal

Definition at line 110 of file oprs_protobuf.h.

◆ signal_server_sent()

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

Signal invoked for a message that has been sent to a server client.

Returns
signal

Definition at line 91 of file oprs_protobuf.h.


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