11 #ifndef SERIALIZATION_CONNECTION_HPP 12 #define SERIALIZATION_CONNECTION_HPP 15 #include <boost/archive/text_iarchive.hpp> 16 #include <boost/archive/text_oarchive.hpp> 17 #include <boost/bind.hpp> 18 #include <boost/shared_ptr.hpp> 19 #include <boost/tuple/tuple.hpp> 51 template <
typename T,
typename Handler>
55 std::ostringstream archive_stream;
56 boost::archive::text_oarchive archive(archive_stream);
58 outbound_data_ = archive_stream.str();
61 std::ostringstream header_stream;
62 header_stream << std::setw(header_length)
63 << std::hex << outbound_data_.size();
64 if (!header_stream || header_stream.str().size() != header_length)
71 outbound_header_ = header_stream.str();
75 std::vector<asio::const_buffer>
buffers;
78 asio::async_write(socket_, buffers, handler);
82 template <
typename T,
typename Handler>
88 T&, boost::tuple<Handler>)
89 = &connection::handle_read_header<T, Handler>;
92 this, asio::placeholders::error, boost::ref(t),
93 boost::make_tuple(handler)));
99 template <
typename T,
typename Handler>
101 T& t, boost::tuple<Handler> handler)
105 boost::get<0>(handler)(e);
110 std::istringstream is(std::string(inbound_header_, header_length));
111 std::size_t inbound_data_size = 0;
112 if (!(is >> std::hex >> inbound_data_size))
116 boost::get<0>(handler)(error);
121 inbound_data_.resize(inbound_data_size);
124 T&, boost::tuple<Handler>)
125 = &connection::handle_read_data<T, Handler>;
128 asio::placeholders::error, boost::ref(t), handler));
133 template <
typename T,
typename Handler>
135 T& t, boost::tuple<Handler> handler)
139 boost::get<0>(handler)(e);
146 std::string archive_data(&inbound_data_[0], inbound_data_.size());
147 std::istringstream archive_stream(archive_data);
148 boost::archive::text_iarchive archive(archive_stream);
151 catch (std::exception& e)
155 boost::get<0>(handler)(error);
160 boost::get<0>(handler)(e);
169 enum { header_length = 8 };
172 std::string outbound_header_;
175 std::string outbound_data_;
178 char inbound_header_[header_length];
181 std::vector<char> inbound_data_;
188 #endif // SERIALIZATION_CONNECTION_HPP void async_read(T &t, Handler handler)
Asynchronously read a data structure from the socket.
Provides core I/O functionality.
post(ASIO_MOVE_ARG(CompletionHandler) handler)
Request the io_service to invoke the given handler and return immediately.
pylon Camera Software Suite for Linux for Use with Basler Gigabit the pylon Viewer and the IP Configurator applications might not be available System I340 and I350 series Although the pylon software will work with any GigE network we would recommend to use one of these adapters USB For U3V devices a USB3 capable USB controller is necessary For best performance and stability we highly recommend a kernel the following settings should be i e
Provides stream-oriented socket functionality.
mutable_buffers_1 buffer(const mutable_buffer &b)
Create a new modifiable buffer from an existing buffer.
boost::shared_ptr< connection > connection_ptr
void handle_read_data(const asio::error_code &e, T &t, boost::tuple< Handler > handler)
Handle a completed read of message data.
connection(asio::io_service &io_service)
Constructor.
void async_write(const T &t, Handler handler)
Asynchronously write a data structure to the socket.
const MutableBufferSequence & buffers
int bind(socket_type s, const socket_addr_type *addr, std::size_t addrlen, asio::error_code &ec)
The connection class provides serialization primitives on top of a socket.
Class to represent an error code value.
asio::io_service & get_io_service()
Get the io_service associated with the object.
asio::ip::tcp::socket & socket()
void handle_read_header(const asio::error_code &e, T &t, boost::tuple< Handler > handler)