37 #ifndef _PROTOBUF_CLIPS_COMMUNICATOR_H_
38 #define _PROTOBUF_CLIPS_COMMUNICATOR_H_
40 #include <core/threading/mutex.h>
41 #include <protobuf_comm/server.h>
47 namespace protobuf_comm {
48 class ProtobufStreamClient;
49 class ProtobufBroadcastPeer;
56 namespace protobuf_clips {
66 std::vector<std::string> &proto_path,
75 protobuf_comm::ProtobufStreamServer *
83 const std::map<long int, protobuf_comm::ProtobufBroadcastPeer *> &
91 protobuf_comm::MessageRegister &
94 return *message_register_;
100 boost::signals2::signal<void(protobuf_comm::ProtobufStreamServer::ClientID,
101 std::shared_ptr<google::protobuf::Message>)> &
104 return sig_server_sent_;
110 boost::signals2::signal<
111 void(std::string,
unsigned short, std::shared_ptr<google::protobuf::Message>)> &
114 return sig_client_sent_;
120 boost::signals2::signal<void(
long, std::shared_ptr<google::protobuf::Message>)> &
123 return sig_peer_sent_;
129 CLIPS::Value clips_pb_register_type(std::string full_name);
130 CLIPS::Values clips_pb_field_names(
void *msgptr);
131 CLIPS::Value clips_pb_has_field(
void *msgptr, std::string field_name);
132 CLIPS::Value clips_pb_field_value(
void *msgptr, std::string field_name);
133 CLIPS::Value clips_pb_field_type(
void *msgptr, std::string field_name);
134 CLIPS::Value clips_pb_field_label(
void *msgptr, std::string field_name);
135 CLIPS::Values clips_pb_field_list(
void *msgptr, std::string field_name);
136 CLIPS::Value clips_pb_field_is_list(
void *msgptr, std::string field_name);
137 CLIPS::Value clips_pb_create(std::string full_name);
138 CLIPS::Value clips_pb_ref(
void *msgptr);
139 void clips_pb_destroy(
void *msgptr);
140 void clips_pb_set_field(
void *msgptr, std::string field_name, CLIPS::Value value);
141 void clips_pb_add_list(
void *msgptr, std::string field_name, CLIPS::Value value);
142 void clips_pb_send(
long int client_id,
void *msgptr);
143 std::string clips_pb_tostring(
void *msgptr);
144 long int clips_pb_client_connect(std::string host,
int port);
145 void clips_pb_disconnect(
long int client_id);
146 void clips_pb_broadcast(
long int peer_id,
void *msgptr);
147 void clips_pb_enable_server(
int port);
149 long int clips_pb_peer_create(std::string host,
int port);
150 long int clips_pb_peer_create_local(std::string host,
int send_port,
int recv_port);
151 long int clips_pb_peer_create_crypto(std::string host,
153 std::string crypto_key =
"",
154 std::string cipher =
"");
155 long int clips_pb_peer_create_local_crypto(std::string host,
158 std::string crypto_key =
"",
159 std::string cipher =
"");
160 void clips_pb_peer_destroy(
long int peer_id);
161 void clips_pb_peer_setup_crypto(
long int peer_id, std::string crypto_key, std::string cipher);
163 typedef enum { CT_SERVER, CT_CLIENT, CT_PEER } ClientType;
164 void clips_assert_message(std::pair<std::string, unsigned short> & endpoint,
167 std::shared_ptr<google::protobuf::Message> &msg,
169 long int client_id = 0);
170 void handle_server_client_connected(protobuf_comm::ProtobufStreamServer::ClientID client,
171 boost::asio::ip::tcp::endpoint & endpoint);
172 void handle_server_client_disconnected(protobuf_comm::ProtobufStreamServer::ClientID client,
173 const boost::system::error_code & error);
175 void handle_server_client_msg(protobuf_comm::ProtobufStreamServer::ClientID client,
176 uint16_t component_id,
178 std::shared_ptr<google::protobuf::Message> msg);
180 void handle_server_client_fail(protobuf_comm::ProtobufStreamServer::ClientID client,
181 uint16_t component_id,
185 void handle_peer_msg(
long int peer_id,
186 boost::asio::ip::udp::endpoint & endpoint,
187 uint16_t component_id,
189 std::shared_ptr<google::protobuf::Message> msg);
190 void handle_peer_recv_error(
long int peer_id,
191 boost::asio::ip::udp::endpoint &endpoint,
193 void handle_peer_send_error(
long int peer_id, std::string msg);
195 void handle_client_connected(
long int client_id);
196 void handle_client_disconnected(
long int client_id,
const boost::system::error_code &error);
197 void handle_client_msg(
long int client_id,
200 std::shared_ptr<google::protobuf::Message> msg);
201 void handle_client_receive_fail(
long int client_id,
206 static std::string to_string(
const CLIPS::Value &v);
209 CLIPS::Environment *clips_;
214 protobuf_comm::MessageRegister * message_register_;
215 protobuf_comm::ProtobufStreamServer *server_;
217 boost::signals2::signal<void(protobuf_comm::ProtobufStreamServer::ClientID,
218 std::shared_ptr<google::protobuf::Message>)>
220 boost::signals2::signal<
221 void(std::string,
unsigned short, std::shared_ptr<google::protobuf::Message>)>
223 boost::signals2::signal<void(
long int, std::shared_ptr<google::protobuf::Message>)>
227 long int next_client_id_;
229 std::map<long int, protobuf_comm::ProtobufStreamServer::ClientID> server_clients_;
230 typedef std::map<protobuf_comm::ProtobufStreamServer::ClientID, long int> RevServerClientMap;
231 RevServerClientMap rev_server_clients_;
232 std::map<long int, protobuf_comm::ProtobufStreamClient *> clients_;
233 std::map<long int, protobuf_comm::ProtobufBroadcastPeer *> peers_;
235 std::map<long int, std::pair<std::string, unsigned short>> client_endpoints_;
237 std::list<std::string> functions_;
238 CLIPS::Fact::pointer avail_fact_;
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.
const std::map< long int, protobuf_comm::ProtobufBroadcastPeer * > & peers() const
Get protobuf_comm peers.
void enable_server(int port)
Enable protobuf stream server.
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.
ClipsProtobufCommunicator(CLIPS::Environment *env, fawkes::Mutex &env_mutex, fawkes::Logger *logger=NULL)
Constructor.
protobuf_comm::MessageRegister & message_register()
Get the communicator's message register.
protobuf_comm::ProtobufStreamServer * server() const
Get Protobuf server.
~ClipsProtobufCommunicator()
Destructor.
void disable_server()
Disable protobu stream 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.
Fawkes library namespace.