subscription.h
Go to the documentation of this file.
1 #include "sick_scan/sick_scan_base.h" /* Base definitions included in all header files, added by add_sick_scan_base_header.py. Do not edit this line. */
2 /*
3  * Copyright (C) 2008, Morgan Quigley and Willow Garage, Inc.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * * Redistributions of source code must retain the above copyright notice,
8  * this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the names of Stanford University or Willow Garage, Inc. nor the names of its
13  * contributors may be used to endorse or promote products derived from
14  * this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26  * POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #ifndef ROSCPP_SUBSCRIPTION_H
30 #define ROSCPP_SUBSCRIPTION_H
31 
32 #include <queue>
33 #include "ros/common.h"
34 #include "ros/header.h"
35 #include "ros/forwards.h"
36 #include "ros/transport_hints.h"
37 #include "ros/xmlrpc_manager.h"
38 #include "ros/statistics.h"
39 #include "xmlrpcpp/XmlRpc.h"
40 
41 #include <thread>
42 #include <memory>
43 #include <memory>
44 
45 namespace roswrap
46 {
47 
48 class PublisherLink;
49 typedef std::shared_ptr<PublisherLink> PublisherLinkPtr;
50 
51 class SubscriptionCallback;
52 typedef std::shared_ptr<SubscriptionCallback> SubscriptionCallbackPtr;
53 
55 typedef std::shared_ptr<SubscriptionQueue> SubscriptionQueuePtr;
56 
58 typedef std::shared_ptr<MessageDeserializer> MessageDeserializerPtr;
59 
61 typedef std::shared_ptr<SubscriptionCallbackHelper> SubscriptionCallbackHelperPtr;
62 
66 class ROSCPP_DECL Subscription : public std::enable_shared_from_this<Subscription>
67 {
68 public:
69  Subscription(const std::string &name, const std::string& md5sum, const std::string& datatype, const TransportHints& transport_hints);
70  virtual ~Subscription();
71 
75  void drop();
79  void shutdown();
84  bool pubUpdate(const std::vector<std::string> &pubs);
89  bool negotiateConnection(const std::string& xmlrpc_uri);
90 
91  void addLocalConnection(const PublicationPtr& pub);
92 
96  bool isDropped() { return dropped_; }
97  XmlRpc::XmlRpcValue getStats();
98  void getInfo(XmlRpc::XmlRpcValue& info);
99 
100  bool addCallback(const SubscriptionCallbackHelperPtr& helper, const std::string& md5sum, CallbackQueueInterface* queue, int32_t queue_size, const VoidConstPtr& tracked_object, bool allow_concurrent_callbacks);
101  void removeCallback(const SubscriptionCallbackHelperPtr& helper);
102 
103  typedef std::map<std::string, std::string> M_string;
104 
109  uint32_t handleMessage(const SerializedMessage& m, bool ser, bool nocopy, const std::shared_ptr<M_string>& connection_header, const PublisherLinkPtr& link);
110 
111  const std::string datatype();
112  const std::string md5sum();
113 
117  void removePublisherLink(const PublisherLinkPtr& pub_link);
118 
119  const std::string& getName() const { return name_; }
120  uint32_t getNumCallbacks() const { return (uint32_t)callbacks_.size(); }
121  uint32_t getNumPublishers();
122 
123  // We'll keep a list of these objects, representing in-progress XMLRPC
124  // connections to other nodes.
126  {
127  public:
128  PendingConnection(XmlRpc::XmlRpcClient* client, TransportUDPPtr udp_transport, const SubscriptionWPtr& parent, const std::string& remote_uri)
129  : client_(client)
130  , udp_transport_(udp_transport)
131  , parent_(parent)
132  , remote_uri_(remote_uri)
133  {}
134 
136  {
137  delete client_;
138  }
139 
140  XmlRpc::XmlRpcClient* getClient() const { return client_; }
141  TransportUDPPtr getUDPTransport() const { return udp_transport_; }
142 
144  {
146  }
147 
149  {
150  disp->removeSource(client_);
151  }
152 
153  virtual bool check()
154  {
155  SubscriptionPtr parent = parent_.lock();
156  if (!parent)
157  {
158  return true;
159  }
160 
161  XmlRpc::XmlRpcValue result;
162  if (client_->executeCheckDone(result))
163  {
164  parent->pendingConnectionDone(std::dynamic_pointer_cast<PendingConnection>(shared_from_this()), result);
165  return true;
166  }
167 
168  return false;
169  }
170 
171  const std::string& getRemoteURI() { return remote_uri_; }
172 
173  private:
177  std::string remote_uri_;
178  };
179  typedef std::shared_ptr<PendingConnection> PendingConnectionPtr;
180 
181  void pendingConnectionDone(const PendingConnectionPtr& pending_conn, XmlRpc::XmlRpcValue& result);
182 
183  void getPublishTypes(bool& ser, bool& nocopy, const std::type_info& ti);
184 
185  void headerReceived(const PublisherLinkPtr& link, const Header& h);
186 
187 private:
188  Subscription(const Subscription &); // not copyable
189  Subscription &operator =(const Subscription &); // nor assignable
190 
191  void dropAllConnections();
192 
193  void addPublisherLink(const PublisherLinkPtr& link);
194 
196  {
198 
199  // Only used if callback_queue_ is non-NULL (NodeHandle API)
204  };
205  typedef std::shared_ptr<CallbackInfo> CallbackInfoPtr;
206  typedef std::vector<CallbackInfoPtr> V_CallbackInfo;
207 
208  std::string name_;
209  std::mutex md5sum_mutex_;
210  std::string md5sum_;
211  std::string datatype_;
212  std::mutex callbacks_mutex_;
215 
216  bool dropped_;
218  std::mutex shutdown_mutex_;
219 
220  typedef std::set<PendingConnectionPtr> S_PendingConnection;
223 
224  typedef std::vector<PublisherLinkPtr> V_PublisherLink;
227 
229 
231 
232  struct LatchInfo
233  {
236  std::shared_ptr<std::map<std::string, std::string> > connection_header;
238  };
239 
240  typedef std::map<PublisherLinkPtr, LatchInfo> M_PublisherLinkToLatchInfo;
242 
243  typedef std::vector<std::pair<const std::type_info*, MessageDeserializerPtr> > V_TypeAndDeserializer;
245 };
246 
247 }
248 
249 #endif
250 
roswrap::message_traits::md5sum
const char * md5sum()
returns MD5Sum<M>::value();
Definition: message_traits.h:227
roswrap::Subscription::PendingConnection::~PendingConnection
~PendingConnection()
Definition: subscription.h:135
XmlRpc::XmlRpcDispatch::WritableEvent
WritableEvent
roswrap::Subscription::LatchInfo::link
PublisherLinkPtr link
Definition: subscription.h:235
roswrap::Subscription::PendingConnection::PendingConnection
PendingConnection(XmlRpc::XmlRpcClient *client, TransportUDPPtr udp_transport, const SubscriptionWPtr &parent, const std::string &remote_uri)
Definition: subscription.h:128
roswrap::SubscriptionQueuePtr
std::shared_ptr< SubscriptionQueue > SubscriptionQueuePtr
Definition: subscription.h:54
roswrap::Subscription
Manages a subscription on a single topic.
Definition: subscription.h:66
roswrap::Subscription::shutdown_mutex_
std::mutex shutdown_mutex_
Definition: subscription.h:218
roswrap::Subscription::PendingConnection::getUDPTransport
TransportUDPPtr getUDPTransport() const
Definition: subscription.h:141
roswrap::Subscription::M_string
std::map< std::string, std::string > M_string
Definition: subscription.h:103
roswrap::Subscription::CallbackInfo::callback_queue_
CallbackQueueInterface * callback_queue_
Definition: subscription.h:197
roswrap::message_traits::datatype
const char * datatype()
returns DataType<M>::value();
Definition: message_traits.h:236
roswrap::Subscription::LatchInfo
Definition: subscription.h:232
roswrap::Subscription::LatchInfo::connection_header
std::shared_ptr< std::map< std::string, std::string > > connection_header
Definition: subscription.h:236
roswrap::Subscription::nonconst_callbacks_
uint32_t nonconst_callbacks_
Definition: subscription.h:214
roswrap::Subscription::M_PublisherLinkToLatchInfo
std::map< PublisherLinkPtr, LatchInfo > M_PublisherLinkToLatchInfo
Definition: subscription.h:240
roswrap::Subscription::CallbackInfo
Definition: subscription.h:195
roswrap::MessageDeserializerPtr
std::shared_ptr< MessageDeserializer > MessageDeserializerPtr
Definition: message_deserializer.h:62
roswrap::Subscription::V_CallbackInfo
std::vector< CallbackInfoPtr > V_CallbackInfo
Definition: subscription.h:206
roswrap::Subscription::transport_hints_
TransportHints transport_hints_
Definition: subscription.h:228
pub
ros::Publisher pub
Definition: pcl_converter.cpp:73
roswrap::shutdown
ROSCPP_DECL void shutdown()
Disconnects everything and unregisters from the master. It is generally not necessary to call this fu...
Definition: rossimu.cpp:269
roswrap::Subscription::getName
const std::string & getName() const
Definition: subscription.h:119
roswrap::Subscription::LatchInfo::message
SerializedMessage message
Definition: subscription.h:234
roswrap::Subscription::S_PendingConnection
std::set< PendingConnectionPtr > S_PendingConnection
Definition: subscription.h:220
roswrap::Subscription::pending_connections_
S_PendingConnection pending_connections_
Definition: subscription.h:221
roswrap::Subscription::md5sum_mutex_
std::mutex md5sum_mutex_
Definition: subscription.h:209
roswrap::Subscription::md5sum_
std::string md5sum_
Definition: subscription.h:210
XmlRpc::XmlRpcClient
A class to send XML RPC requests to a server and return the results.
Definition: XmlRpcClient.h:27
roswrap::VoidConstWPtr
std::weak_ptr< void const > VoidConstWPtr
Definition: forwards.h:55
roswrap::Subscription::CallbackInfoPtr
std::shared_ptr< CallbackInfo > CallbackInfoPtr
Definition: subscription.h:205
roswrap::Subscription::callbacks_mutex_
std::mutex callbacks_mutex_
Definition: subscription.h:212
roswrap::TransportUDPPtr
std::shared_ptr< TransportUDP > TransportUDPPtr
Definition: forwards.h:62
roswrap::Subscription::statistics_
StatisticsLogger statistics_
Definition: subscription.h:230
roswrap::SubscriptionWPtr
std::weak_ptr< Subscription > SubscriptionWPtr
Definition: forwards.h:76
roswrap::Subscription::PendingConnection::remote_uri_
std::string remote_uri_
Definition: subscription.h:177
roswrap::Subscription::pending_connections_mutex_
std::mutex pending_connections_mutex_
Definition: subscription.h:222
roswrap::Subscription::shutting_down_
bool shutting_down_
Definition: subscription.h:217
roswrap::SerializedMessage
Definition: serialized_message.h:40
XmlRpc::XmlRpcDispatch::addSource
void addSource(XmlRpcSource *source, unsigned eventMask)
roswrap::Subscription::LatchInfo::receipt_time
ros::Time receipt_time
Definition: subscription.h:237
api.setup.name
name
Definition: python/api/setup.py:12
roswrap::SubscriptionCallbackHelperPtr
std::shared_ptr< SubscriptionCallbackHelper > SubscriptionCallbackHelperPtr
Definition: message_deserializer.h:43
sick_scan_xd_api_test.queue_size
queue_size
Definition: sick_scan_xd_api_test.py:353
roswrap::MessageDeserializer
Definition: message_deserializer.h:46
roswrap::Subscription::CallbackInfo::has_tracked_object_
bool has_tracked_object_
Definition: subscription.h:202
roswrap::Subscription::PendingConnection::parent_
SubscriptionWPtr parent_
Definition: subscription.h:176
roswrap::Subscription::PendingConnectionPtr
std::shared_ptr< PendingConnection > PendingConnectionPtr
Definition: subscription.h:179
roswrap::Subscription::dropped_
bool dropped_
Definition: subscription.h:216
roswrap::StatisticsLogger
This class logs statistics data about a ROS connection and publishs them periodically on a common top...
Definition: statistics.h:50
roswrap::CallbackQueueInterface
Abstract interface for a queue used to handle all callbacks within roscpp.
Definition: callback_queue_interface.h:83
roswrap::Subscription::PendingConnection::check
virtual bool check()
Definition: subscription.h:153
roswrap::Subscription::CallbackInfo::subscription_queue_
SubscriptionQueuePtr subscription_queue_
Definition: subscription.h:201
roswrap
Definition: param_modi.cpp:41
XmlRpc::XmlRpcDispatch::removeSource
void removeSource(XmlRpcSource *source)
roswrap::Subscription::latched_messages_
M_PublisherLinkToLatchInfo latched_messages_
Definition: subscription.h:241
roswrap::Subscription::PendingConnection::udp_transport_
TransportUDPPtr udp_transport_
Definition: subscription.h:175
roswrap::SubscriptionQueue
Definition: subscription_queue.h:51
roswrap::SubscriptionCallbackPtr
std::shared_ptr< SubscriptionCallback > SubscriptionCallbackPtr
Definition: subscription.h:51
roswrap::Subscription::PendingConnection::removeFromDispatch
virtual void removeFromDispatch(XmlRpc::XmlRpcDispatch *disp)
Definition: subscription.h:148
roswrap::Subscription::callbacks_
V_CallbackInfo callbacks_
Definition: subscription.h:213
roswrap::Subscription::PendingConnection::client_
XmlRpc::XmlRpcClient * client_
Definition: subscription.h:174
roswrap::Subscription::datatype_
std::string datatype_
Definition: subscription.h:211
ros::Time
roswrap::Subscription::CallbackInfo::tracked_object_
VoidConstWPtr tracked_object_
Definition: subscription.h:203
roswrap::TransportHints
Provides a way of specifying network transport hints to ros::NodeHandle::subscribe() and someday ros:...
Definition: transport_hints.h:55
roswrap::Header
Provides functionality to parse a connection header and retrieve values from it.
Definition: header.h:53
sick_scan_base.h
roswrap::Subscription::CallbackInfo::helper_
SubscriptionCallbackHelperPtr helper_
Definition: subscription.h:200
XmlRpc::XmlRpcDispatch
roswrap::Subscription::V_TypeAndDeserializer
std::vector< std::pair< const std::type_info *, MessageDeserializerPtr > > V_TypeAndDeserializer
Definition: subscription.h:243
roswrap::ASyncXMLRPCConnection
Definition: xmlrpc_manager.h:61
roswrap::SubscriptionCallbackHelper
Abstract base class used by subscriptions to deal with concrete message types through a common interf...
Definition: subscription_callback_helper.h:70
roswrap::Subscription::getNumCallbacks
uint32_t getNumCallbacks() const
Definition: subscription.h:120
roswrap::PublicationPtr
std::shared_ptr< Publication > PublicationPtr
Definition: forwards.h:68
roswrap::Subscription::PendingConnection
Definition: subscription.h:125
ROSCPP_DECL
#define ROSCPP_DECL
Definition: roswrap/src/cfgsimu/sick_scan/ros/common.h:63
roswrap::Subscription::PendingConnection::getClient
XmlRpc::XmlRpcClient * getClient() const
Definition: subscription.h:140
XmlRpc::XmlRpcDispatch::Exception
Exception
roswrap::Subscription::isDropped
bool isDropped()
Returns whether this Subscription has been dropped or not.
Definition: subscription.h:96
roswrap::Subscription::name_
std::string name_
Definition: subscription.h:208
roswrap::PublisherLinkPtr
std::shared_ptr< PublisherLink > PublisherLinkPtr
Definition: forwards.h:80
roswrap::Subscription::PendingConnection::addToDispatch
virtual void addToDispatch(XmlRpc::XmlRpcDispatch *disp)
Definition: subscription.h:143
roswrap::Subscription::PendingConnection::getRemoteURI
const std::string & getRemoteURI()
Definition: subscription.h:171
roswrap::Subscription::V_PublisherLink
std::vector< PublisherLinkPtr > V_PublisherLink
Definition: subscription.h:224
roswrap::Subscription::publisher_links_mutex_
std::mutex publisher_links_mutex_
Definition: subscription.h:226
roswrap::VoidConstPtr
std::shared_ptr< void const > VoidConstPtr
Definition: forwards.h:54
roswrap::Subscription::publisher_links_
V_PublisherLink publisher_links_
Definition: subscription.h:225
XmlRpc::XmlRpcValue
RPC method arguments and results are represented by Values.
Definition: XmlRpcValue.h:25
roswrap::SubscriptionPtr
std::shared_ptr< Subscription > SubscriptionPtr
Definition: forwards.h:74
roswrap::Subscription::cached_deserializers_
V_TypeAndDeserializer cached_deserializers_
Definition: subscription.h:244


sick_scan_xd
Author(s): Michael Lehning , Jochen Sprickerhof , Martin Günther
autogenerated on Fri Oct 25 2024 02:47:12