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/signals2.hpp>
00042
00043 #include <boost/function.hpp>
00044 #include <boost/shared_ptr.hpp>
00045 #include <boost/shared_array.hpp>
00046 #include <boost/enable_shared_from_this.hpp>
00047 #include <boost/thread/mutex.hpp>
00048 #include <boost/thread/recursive_mutex.hpp>
00049
00050 #define READ_BUFFER_SIZE (1024*64)
00051
00052 namespace ros
00053 {
00054
00055 class Transport;
00056 typedef boost::shared_ptr<Transport> TransportPtr;
00057 class Connection;
00058 typedef boost::shared_ptr<Connection> ConnectionPtr;
00059 typedef boost::function<void(const ConnectionPtr&, const boost::shared_array<uint8_t>&, uint32_t, bool)> ReadFinishedFunc;
00060 typedef boost::function<void(const ConnectionPtr&)> WriteFinishedFunc;
00061
00062 typedef boost::function<bool(const ConnectionPtr&, const Header&)> HeaderReceivedFunc;
00063
00070 class ROSCPP_DECL Connection : public boost::enable_shared_from_this<Connection>
00071 {
00072 public:
00073 enum DropReason
00074 {
00075 TransportDisconnect,
00076 HeaderError,
00077 Destructing,
00078 };
00079
00080 Connection();
00081 ~Connection();
00082
00086 void initialize(const TransportPtr& transport, bool is_server, const HeaderReceivedFunc& header_func);
00091 void drop(DropReason reason);
00092
00096 bool isDropped();
00097
00101 bool isSendingHeaderError() { return sending_header_error_; }
00102
00107 void sendHeaderError(const std::string& error_message);
00113 void writeHeader(const M_string& key_vals, const WriteFinishedFunc& finished_callback);
00114
00128 void read(uint32_t size, const ReadFinishedFunc& finished_callback);
00145 void write(const boost::shared_array<uint8_t>& buffer, uint32_t size, const WriteFinishedFunc& finished_callback, bool immedate = true);
00146
00147 typedef boost::signals2::signal<void(const ConnectionPtr&, DropReason reason)> DropSignal;
00148 typedef boost::function<void(const ConnectionPtr&, DropReason reason)> DropFunc;
00152 boost::signals2::connection addDropListener(const DropFunc& slot);
00153 void removeDropListener(const boost::signals2::connection& c);
00154
00158 void setHeaderReceivedCallback(const HeaderReceivedFunc& func);
00159
00163 const TransportPtr& getTransport() { return transport_; }
00167 Header& getHeader() { return header_; }
00168
00173 void setHeader(const Header& header) { header_ = header; }
00174
00175 std::string getCallerId();
00176 std::string getRemoteString();
00177
00178 private:
00182 void onReadable(const TransportPtr& transport);
00186 void onWriteable(const TransportPtr& transport);
00191 void onDisconnect(const TransportPtr& transport);
00192
00193
00194 void onHeaderWritten(const ConnectionPtr& conn);
00195 void onErrorHeaderWritten(const ConnectionPtr& conn);
00196 void onHeaderLengthRead(const ConnectionPtr& conn, const boost::shared_array<uint8_t>& buffer, uint32_t size, bool success);
00197 void onHeaderRead(const ConnectionPtr& conn, const boost::shared_array<uint8_t>& buffer, uint32_t size, bool success);
00198
00203 void readTransport();
00207 void writeTransport();
00208
00210 bool is_server_;
00212 bool dropped_;
00214 Header header_;
00216 TransportPtr transport_;
00218 HeaderReceivedFunc header_func_;
00219
00221 boost::shared_array<uint8_t> read_buffer_;
00223 uint32_t read_filled_;
00225 uint32_t read_size_;
00227 ReadFinishedFunc read_callback_;
00229 boost::recursive_mutex read_mutex_;
00231 bool reading_;
00235 volatile uint32_t has_read_callback_;
00236
00238 boost::shared_array<uint8_t> write_buffer_;
00240 uint32_t write_sent_;
00242 uint32_t write_size_;
00244 WriteFinishedFunc write_callback_;
00245 boost::mutex write_callback_mutex_;
00247 boost::recursive_mutex write_mutex_;
00249 bool writing_;
00253 volatile uint32_t has_write_callback_;
00254
00256 WriteFinishedFunc header_written_callback_;
00257
00259 DropSignal drop_signal_;
00260
00262 boost::recursive_mutex drop_mutex_;
00263
00265 bool sending_header_error_;
00266 };
00267 typedef boost::shared_ptr<Connection> ConnectionPtr;
00268
00269 }
00270
00271 #endif // ROSCPP_CONNECTION_H
roscpp
Author(s): Morgan Quigley, Josh Faust, Brian Gerkey, Troy Straszheim
autogenerated on Thu Jun 6 2019 21:10:05