Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #ifndef ROSCPP_CONNECTION_H
00036 #define ROSCPP_CONNECTION_H
00037
00038 #include "ros/header.h"
00039 #include "common.h"
00040
00041 #include <boost/signals.hpp>
00042 #include <boost/function.hpp>
00043 #include <boost/shared_ptr.hpp>
00044 #include <boost/shared_array.hpp>
00045 #include <boost/enable_shared_from_this.hpp>
00046 #include <boost/thread/mutex.hpp>
00047 #include <boost/thread/recursive_mutex.hpp>
00048
00049 #define READ_BUFFER_SIZE (1024*64)
00050
00051 namespace ros
00052 {
00053
00054 class Transport;
00055 typedef boost::shared_ptr<Transport> TransportPtr;
00056 class Connection;
00057 typedef boost::shared_ptr<Connection> ConnectionPtr;
00058 typedef boost::function<void(const ConnectionPtr&, const boost::shared_array<uint8_t>&, uint32_t, bool)> ReadFinishedFunc;
00059 typedef boost::function<void(const ConnectionPtr&)> WriteFinishedFunc;
00060
00061 typedef boost::function<bool(const ConnectionPtr&, const Header&)> HeaderReceivedFunc;
00062
00069 class ROSCPP_DECL Connection : public boost::enable_shared_from_this<Connection>
00070 {
00071 public:
00072 enum DropReason
00073 {
00074 TransportDisconnect,
00075 HeaderError,
00076 Destructing,
00077 };
00078
00079 Connection();
00080 ~Connection();
00081
00085 void initialize(const TransportPtr& transport, bool is_server, const HeaderReceivedFunc& header_func);
00090 void drop(DropReason reason);
00091
00095 bool isDropped();
00096
00100 bool isSendingHeaderError() { return sending_header_error_; }
00101
00106 void sendHeaderError(const std::string& error_message);
00112 void writeHeader(const M_string& key_vals, const WriteFinishedFunc& finished_callback);
00113
00127 void read(uint32_t size, const ReadFinishedFunc& finished_callback);
00144 void write(const boost::shared_array<uint8_t>& buffer, uint32_t size, const WriteFinishedFunc& finished_callback, bool immedate = true);
00145
00146 typedef boost::signal<void(const ConnectionPtr&, DropReason reason)> DropSignal;
00147 typedef boost::function<void(const ConnectionPtr&, DropReason reason)> DropFunc;
00151 boost::signals::connection addDropListener(const DropFunc& slot);
00152 void removeDropListener(const boost::signals::connection& c);
00153
00157 void setHeaderReceivedCallback(const HeaderReceivedFunc& func);
00158
00162 const TransportPtr& getTransport() { return transport_; }
00166 Header& getHeader() { return header_; }
00167
00172 void setHeader(const Header& header) { header_ = header; }
00173
00174 std::string getCallerId();
00175 std::string getRemoteString();
00176
00177 private:
00181 void onReadable(const TransportPtr& transport);
00185 void onWriteable(const TransportPtr& transport);
00190 void onDisconnect(const TransportPtr& transport);
00191
00192
00193 void onHeaderWritten(const ConnectionPtr& conn);
00194 void onErrorHeaderWritten(const ConnectionPtr& conn);
00195 void onHeaderLengthRead(const ConnectionPtr& conn, const boost::shared_array<uint8_t>& buffer, uint32_t size, bool success);
00196 void onHeaderRead(const ConnectionPtr& conn, const boost::shared_array<uint8_t>& buffer, uint32_t size, bool success);
00197
00202 void readTransport();
00206 void writeTransport();
00207
00209 bool is_server_;
00211 bool dropped_;
00213 Header header_;
00215 TransportPtr transport_;
00217 HeaderReceivedFunc header_func_;
00218
00220 boost::shared_array<uint8_t> read_buffer_;
00222 uint32_t read_filled_;
00224 uint32_t read_size_;
00226 ReadFinishedFunc read_callback_;
00228 boost::recursive_mutex read_mutex_;
00230 bool reading_;
00234 volatile uint32_t has_read_callback_;
00235
00237 boost::shared_array<uint8_t> write_buffer_;
00239 uint32_t write_sent_;
00241 uint32_t write_size_;
00243 WriteFinishedFunc write_callback_;
00244 boost::mutex write_callback_mutex_;
00246 boost::recursive_mutex write_mutex_;
00248 bool writing_;
00252 volatile uint32_t has_write_callback_;
00253
00255 WriteFinishedFunc header_written_callback_;
00256
00258 DropSignal drop_signal_;
00259
00261 boost::recursive_mutex drop_mutex_;
00262
00264 bool sending_header_error_;
00265 };
00266 typedef boost::shared_ptr<Connection> ConnectionPtr;
00267
00268 }
00269
00270 #endif // ROSCPP_CONNECTION_H
roscpp
Author(s): Morgan Quigley, Josh Faust, Brian Gerkey, Troy Straszheim
autogenerated on Fri Aug 28 2015 12:33:10