37 #ifndef __PROTOBUF_CLIPS_COMMUNICATOR_H_ 38 #define __PROTOBUF_CLIPS_COMMUNICATOR_H_ 44 #include <protobuf_comm/server.h> 45 #include <core/threading/mutex.h> 48 class ProtobufStreamClient;
49 class ProtobufBroadcastPeer;
67 std::vector<std::string> &proto_path,
71 void enable_server(
int port);
72 void disable_server();
81 const std::map<long int, protobuf_comm::ProtobufBroadcastPeer *> &
88 {
return *message_register_; }
94 std::shared_ptr<google::protobuf::Message>)> &
100 boost::signals2::signal<void (std::string,
unsigned short,
101 std::shared_ptr<google::protobuf::Message>)> &
107 boost::signals2::signal<void (
long,
108 std::shared_ptr<google::protobuf::Message>)> &
114 CLIPS::Value clips_pb_register_type(std::string full_name);
115 CLIPS::Values clips_pb_field_names(
void *msgptr);
116 CLIPS::Value clips_pb_has_field(
void *msgptr, std::string field_name);
117 CLIPS::Value clips_pb_field_value(
void *msgptr, std::string field_name);
118 CLIPS::Value clips_pb_field_type(
void *msgptr, std::string field_name);
119 CLIPS::Value clips_pb_field_label(
void *msgptr, std::string field_name);
120 CLIPS::Values clips_pb_field_list(
void *msgptr, std::string field_name);
121 CLIPS::Value clips_pb_field_is_list(
void *msgptr, std::string field_name);
122 CLIPS::Value clips_pb_create(std::string full_name);
123 CLIPS::Value clips_pb_ref(
void *msgptr);
124 void clips_pb_destroy(
void *msgptr);
125 void clips_pb_set_field(
void *msgptr, std::string field_name, CLIPS::Value value);
126 void clips_pb_add_list(
void *msgptr, std::string field_name, CLIPS::Value value);
127 void clips_pb_send(
long int client_id,
void *msgptr);
128 std::string clips_pb_tostring(
void *msgptr);
129 long int clips_pb_client_connect(std::string host,
int port);
130 void clips_pb_disconnect(
long int client_id);
131 void clips_pb_broadcast(
long int peer_id,
void *msgptr);
132 void clips_pb_enable_server(
int port);
134 long int clips_pb_peer_create(std::string host,
int port);
135 long int clips_pb_peer_create_local(std::string host,
136 int send_port,
int recv_port);
137 long int clips_pb_peer_create_crypto(std::string host,
int port,
138 std::string crypto_key =
"", std::string cipher =
"");
139 long int clips_pb_peer_create_local_crypto(std::string host,
140 int send_port,
int recv_port,
141 std::string crypto_key =
"", std::string cipher =
"");
142 void clips_pb_peer_destroy(
long int peer_id);
143 void clips_pb_peer_setup_crypto(
long int peer_id,
144 std::string crypto_key, std::string cipher);
148 CT_SERVER, CT_CLIENT, CT_PEER
150 void clips_assert_message(std::pair<std::string, unsigned short> &endpoint,
151 uint16_t comp_id, uint16_t msg_type,
152 std::shared_ptr<google::protobuf::Message> &msg,
153 ClientType ct,
unsigned int client_id = 0);
155 boost::asio::ip::tcp::endpoint &endpoint);
157 const boost::system::error_code &error);
160 uint16_t component_id, uint16_t msg_type,
161 std::shared_ptr<google::protobuf::Message> msg);
164 uint16_t component_id, uint16_t msg_type,
167 void handle_peer_msg(
long int peer_id,
168 boost::asio::ip::udp::endpoint &endpoint,
169 uint16_t component_id, uint16_t msg_type,
170 std::shared_ptr<google::protobuf::Message> msg);
171 void handle_peer_recv_error(
long int peer_id, boost::asio::ip::udp::endpoint &endpoint, std::string msg);
172 void handle_peer_send_error(
long int peer_id, std::string msg);
174 void handle_client_connected(
long int client_id);
175 void handle_client_disconnected(
long int client_id,
176 const boost::system::error_code &error);
177 void handle_client_msg(
long int client_id,
178 uint16_t comp_id, uint16_t msg_type,
179 std::shared_ptr<google::protobuf::Message> msg);
180 void handle_client_receive_fail(
long int client_id,
181 uint16_t comp_id, uint16_t msg_type, std::string msg);
183 static std::string to_string(
const CLIPS::Value &v);
186 CLIPS::Environment *clips_;
195 std::shared_ptr<google::protobuf::Message>)> sig_server_sent_;
196 boost::signals2::signal<void (std::string,
unsigned short,
197 std::shared_ptr<google::protobuf::Message>)> sig_client_sent_;
198 boost::signals2::signal<void (long int, std::shared_ptr<google::protobuf::Message>)> sig_peer_sent_;
201 long int next_client_id_;
204 std::map<long int, protobuf_comm::ProtobufStreamServer::ClientID> server_clients_;
205 typedef std::map<protobuf_comm::ProtobufStreamServer::ClientID, long int> RevServerClientMap;
206 RevServerClientMap rev_server_clients_;
207 std::map<long int, protobuf_comm::ProtobufStreamClient *> clients_;
208 std::map<long int, protobuf_comm::ProtobufBroadcastPeer *> peers_;
210 std::map<long int, std::pair<std::string, unsigned short>> client_endpoints_;
212 std::list<std::string> functions_;
213 CLIPS::Fact::pointer avail_fact_;
Fawkes library namespace.
unsigned int ClientID
ID to identify connected clients.
const std::map< long int, protobuf_comm::ProtobufBroadcastPeer * > & peers() const
Get protobuf_comm peers.
Register to map msg type numbers to Protobuf messages.
protobuf_comm::ProtobufStreamServer * server() const
Get Protobuf server.
Stream server for protobuf message transmission.
protobuf_comm::MessageRegister & message_register()
Get the communicator's message register.
boost::signals2::signal< void(long, std::shared_ptr< google::protobuf::Message >)> & signal_peer_sent()
Signal invoked for a message that has been sent via broadcast.
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.
Mutex mutual exclusion lock.
CLIPS protobuf integration class.
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.