37 #ifndef _PROTOBUF_COMM_CLIENT_H_
38 #define _PROTOBUF_COMM_CLIENT_H_
40 #include <google/protobuf/message.h>
41 #include <protobuf_comm/frame_header.h>
42 #include <protobuf_comm/message_register.h>
43 #include <protobuf_comm/queue_entry.h>
45 #include <boost/asio.hpp>
46 #include <boost/signals2.hpp>
53 namespace protobuf_comm {
55 class ProtobufStreamClient
69 return *message_register_;
84 void send(uint16_t component_id, uint16_t msg_type, google::protobuf::Message &m);
86 void send(std::shared_ptr<google::protobuf::Message> m);
87 void send(google::protobuf::Message &m);
92 boost::signals2::signal<void(uint16_t, uint16_t, std::shared_ptr<google::protobuf::Message>)> &
101 boost::signals2::signal<void(uint16_t, uint16_t, std::string)> &
104 return sig_recv_failed_;
110 boost::signals2::signal<void()> &
113 return sig_connected_;
119 boost::signals2::signal<void(
const boost::system::error_code &)> &
122 return sig_disconnected_;
127 void disconnect_nosig();
129 void handle_resolve(
const boost::system::error_code & err,
130 boost::asio::ip::tcp::resolver::iterator endpoint_iterator);
131 void handle_connect(
const boost::system::error_code &err);
132 void handle_write(
const boost::system::error_code &error,
136 void handle_read_header(
const boost::system::error_code &error);
137 void handle_read_message(
const boost::system::error_code &error);
141 std::mutex asio_mutex_;
142 boost::asio::io_service io_service_;
143 boost::asio::ip::tcp::resolver resolver_;
144 boost::asio::ip::tcp::socket socket_;
145 boost::asio::io_service::work io_service_work_;
147 boost::signals2::signal<void(uint16_t, uint16_t, std::shared_ptr<google::protobuf::Message>)>
149 boost::signals2::signal<void(uint16_t, uint16_t, std::string)> sig_recv_failed_;
150 boost::signals2::signal<void()> sig_connected_;
151 boost::signals2::signal<void(
const boost::system::error_code &)> sig_disconnected_;
153 std::thread asio_thread_;
155 std::queue<QueueEntry *> outbound_queue_;
156 std::mutex outbound_mutex_;
157 bool outbound_active_;
159 void * in_frame_header_;
160 size_t in_frame_header_size_;
161 size_t in_data_size_;
165 bool own_message_register_;
167 frame_header_version_t frame_header_version_;