37 #ifndef _OPENPRS_AGENT_OPRS_PROTOBUF_H_
38 #define _OPENPRS_AGENT_OPRS_PROTOBUF_H_
40 #include <core/threading/mutex.h>
41 #include <core/utils/lock_queue.h>
42 #include <protobuf_comm/server.h>
47 #include <oprs-type-pub.h>
48 #include <oprs-type_f-pub.h>
50 namespace protobuf_comm {
51 class ProtobufStreamClient;
52 class ProtobufBroadcastPeer;
55 namespace oprs_protobuf {
73 const std::map<long int, protobuf_comm::ProtobufBroadcastPeer *> &
84 return *message_register_;
91 std::shared_ptr<google::protobuf::Message>)> &
94 return sig_server_sent_;
100 boost::signals2::signal<
101 void(std::string,
unsigned short, std::shared_ptr<google::protobuf::Message>)> &
104 return sig_client_sent_;
110 boost::signals2::signal<void(
long int, std::shared_ptr<google::protobuf::Message>)> &
113 return sig_peer_sent_;
124 std::shared_ptr<google::protobuf::Message> *
oprs_create_msg(std::string full_name);
140 const std::string &crypto_key =
"",
141 const std::string &cipher =
"");
145 const std::string &crypto_key =
"",
146 const std::string &cipher =
"");
149 const std::string &crypto_key,
150 const std::string &cipher);
156 typedef enum { CT_SERVER, CT_CLIENT, CT_PEER } ClientType;
157 void clips_assert_message(std::pair<std::string, unsigned short> & endpoint,
160 std::shared_ptr<google::protobuf::Message> &msg,
162 unsigned int client_id = 0);
164 boost::asio::ip::tcp::endpoint & endpoint);
166 const boost::system::error_code & error);
169 uint16_t component_id,
171 std::shared_ptr<google::protobuf::Message> msg);
174 uint16_t component_id,
178 void handle_peer_msg(
long int peer_id,
179 boost::asio::ip::udp::endpoint & endpoint,
180 uint16_t component_id,
182 std::shared_ptr<google::protobuf::Message> msg);
183 void handle_peer_recv_error(
long int peer_id,
184 boost::asio::ip::udp::endpoint &endpoint,
186 void handle_peer_send_error(
long int peer_id,
const std::string &msg);
188 void handle_client_connected(
long int client_id);
189 void handle_client_disconnected(
long int client_id,
const boost::system::error_code &error);
190 void handle_client_msg(
long int client_id,
193 std::shared_ptr<google::protobuf::Message> msg);
194 void handle_client_receive_fail(
long int client_id,
197 const std::string &msg);
198 void oprs_assert_message(std::string & endpoint_host,
199 unsigned short endpoint_port,
202 std::shared_ptr<google::protobuf::Message> &msg,
203 OpenPRSProtobuf::ClientType ct,
204 unsigned int client_id);
205 void oprs_assert_server_client_event(
long int client_id,
209 void oprs_assert_client_event(
long int client_id,
bool connect);
212 std::shared_ptr<protobuf_comm::MessageRegister> message_register_;
216 std::shared_ptr<google::protobuf::Message>)>
218 boost::signals2::signal<
219 void(std::string,
unsigned short, std::shared_ptr<google::protobuf::Message>)>
221 boost::signals2::signal<void(
long int, std::shared_ptr<google::protobuf::Message>)>
225 long int next_client_id_;
227 std::map<long int, protobuf_comm::ProtobufStreamServer::ClientID> server_clients_;
228 typedef std::map<protobuf_comm::ProtobufStreamServer::ClientID, long int> RevServerClientMap;
229 RevServerClientMap rev_server_clients_;
230 std::map<long int, protobuf_comm::ProtobufStreamClient *> clients_;
231 std::map<long int, protobuf_comm::ProtobufBroadcastPeer *> peers_;
233 std::map<long int, std::pair<std::string, unsigned short>> client_endpoints_;
239 std::shared_ptr<google::protobuf::Message>,