37 #ifndef __OPENPRS_AGENT_OPRS_PROTOBUF_H_ 38 #define __OPENPRS_AGENT_OPRS_PROTOBUF_H_ 40 #include <oprs-type-pub.h> 41 #include <oprs-type_f-pub.h> 46 #include <protobuf_comm/server.h> 47 #include <core/threading/mutex.h> 48 #include <core/utils/lock_queue.h> 51 class ProtobufStreamClient;
52 class ProtobufBroadcastPeer;
73 const std::map<long int, protobuf_comm::ProtobufBroadcastPeer *> &
80 {
return *message_register_; }
86 std::shared_ptr<google::protobuf::Message>)> &
92 boost::signals2::signal<void (std::string,
unsigned short,
93 std::shared_ptr<google::protobuf::Message>)> &
99 boost::signals2::signal<void (long int, std::shared_ptr<google::protobuf::Message>)> &
102 bool oprs_pb_register_type(std::string full_name);
103 Term * oprs_pb_field_names(
void *msgptr);
104 bool oprs_pb_has_field(
void *msgptr, std::string field_name);
105 Term * oprs_pb_field_value(
void *msgptr, std::string field_name);
106 Term * oprs_pb_field_type(
void *msgptr, std::string field_name);
107 Term * oprs_pb_field_label(
void *msgptr, std::string field_name);
108 Term * oprs_pb_field_list(
void *msgptr, std::string field_name);
109 bool oprs_pb_field_is_list(
void *msgptr, std::string field_name);
110 std::shared_ptr<google::protobuf::Message> * oprs_create_msg(std::string full_name);
111 Term * oprs_pb_ref(
void *msgptr);
112 Term * oprs_pb_destroy(
void *msgptr);
113 void oprs_pb_set_field(
void *msgptr, std::string field_name, Term *value);
114 void oprs_pb_add_list(
void *msgptr, std::string field_name, Term *value);
115 void oprs_pb_send(
long int client_id,
void *msgptr);
116 Term * oprs_pb_client_connect(std::string host,
int port);
117 void oprs_pb_disconnect(
long int client_id);
118 void oprs_pb_broadcast(
long int peer_id,
void *msgptr);
119 void oprs_pb_enable_server(
int port);
120 void oprs_pb_disable_server();
122 Term * oprs_pb_peer_create(std::string host,
int port);
123 Term * oprs_pb_peer_create_local(std::string host,
124 int send_port,
int recv_port);
125 Term * oprs_pb_peer_create_crypto(std::string host,
int port,
126 std::string crypto_key =
"", std::string cipher =
"");
127 Term * oprs_pb_peer_create_local_crypto(std::string host,
128 int send_port,
int recv_port,
129 std::string crypto_key =
"", std::string cipher =
"");
130 void oprs_pb_peer_destroy(
long int peer_id);
131 void oprs_pb_peer_setup_crypto(
long int peer_id,
132 std::string crypto_key, std::string cipher);
134 bool oprs_pb_events_pending();
135 void oprs_pb_process();
139 CT_SERVER, CT_CLIENT, CT_PEER
141 void clips_assert_message(std::pair<std::string, unsigned short> &endpoint,
142 uint16_t comp_id, uint16_t msg_type,
143 std::shared_ptr<google::protobuf::Message> &msg,
144 ClientType ct,
unsigned int client_id = 0);
146 boost::asio::ip::tcp::endpoint &endpoint);
148 const boost::system::error_code &error);
151 uint16_t component_id, uint16_t msg_type,
152 std::shared_ptr<google::protobuf::Message> msg);
155 uint16_t component_id, uint16_t msg_type,
158 void handle_peer_msg(
long int peer_id,
159 boost::asio::ip::udp::endpoint &endpoint,
160 uint16_t component_id, uint16_t msg_type,
161 std::shared_ptr<google::protobuf::Message> msg);
162 void handle_peer_recv_error(
long int peer_id, boost::asio::ip::udp::endpoint &endpoint, std::string msg);
163 void handle_peer_send_error(
long int peer_id, std::string msg);
165 void handle_client_connected(
long int client_id);
166 void handle_client_disconnected(
long int client_id,
167 const boost::system::error_code &error);
168 void handle_client_msg(
long int client_id,
169 uint16_t comp_id, uint16_t msg_type,
170 std::shared_ptr<google::protobuf::Message> msg);
171 void handle_client_receive_fail(
long int client_id,
172 uint16_t comp_id, uint16_t msg_type, std::string msg);
173 void oprs_assert_message(std::string &endpoint_host,
unsigned short endpoint_port,
174 uint16_t comp_id, uint16_t msg_type,
175 std::shared_ptr<google::protobuf::Message> &msg,
176 OpenPRSProtobuf::ClientType ct,
177 unsigned int client_id);
178 void oprs_assert_server_client_event(
long int client_id,
179 std::string &host,
unsigned short port,
bool connect);
180 void oprs_assert_client_event(
long int client_id,
bool connect);
187 std::shared_ptr<google::protobuf::Message>)> sig_server_sent_;
188 boost::signals2::signal<void (std::string,
unsigned short,
189 std::shared_ptr<google::protobuf::Message>)> sig_client_sent_;
190 boost::signals2::signal<void (long int, std::shared_ptr<google::protobuf::Message>)> sig_peer_sent_;
193 long int next_client_id_;
196 std::map<long int, protobuf_comm::ProtobufStreamServer::ClientID> server_clients_;
197 typedef std::map<protobuf_comm::ProtobufStreamServer::ClientID, long int> RevServerClientMap;
198 RevServerClientMap rev_server_clients_;
199 std::map<long int, protobuf_comm::ProtobufStreamClient *> clients_;
200 std::map<long int, protobuf_comm::ProtobufBroadcastPeer *> peers_;
202 std::map<long int, std::pair<std::string, unsigned short>> client_endpoints_;
205 std::tuple<std::string,
unsigned short, uint16_t, uint16_t,
206 std::shared_ptr<google::protobuf::Message>, ClientType,
unsigned int>> q_msgs_;
OpenPRS protobuf integration class.
const std::map< long int, protobuf_comm::ProtobufBroadcastPeer * > & peers() const
Get protobuf_comm peers.
unsigned int ClientID
ID to identify connected clients.
Register to map msg type numbers to Protobuf messages.
protobuf_comm::MessageRegister & message_register()
Get the communicator's message register.
protobuf_comm::ProtobufStreamServer * server() const
Get Protobuf server.
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.
Stream server for protobuf message transmission.
Mutex mutual exclusion lock.
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.
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.