topic_manager.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) 2009, 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 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_TOPIC_MANAGER_H
30 #define ROSCPP_TOPIC_MANAGER_H
31 
32 #include "forwards.h"
33 #include "common.h"
34 #include "ros/serialization.h"
35 #include "rosout_appender.h"
36 
37 #include "xmlrpcpp/XmlRpcValue.h"
38 
39 #include <mutex>
40 //#include <boost/thread/recursive_mutex.hpp>
41 
42 namespace roswrap
43 {
44 
45 class Message;
46 struct SubscribeOptions;
47 struct AdvertiseOptions;
48 
49 class TopicManager;
50 typedef std::shared_ptr<TopicManager> TopicManagerPtr;
51 
52 class PollManager;
53 typedef std::shared_ptr<PollManager> PollManagerPtr;
54 
55 class XMLRPCManager;
56 typedef std::shared_ptr<XMLRPCManager> XMLRPCManagerPtr;
57 
58 class ConnectionManager;
59 typedef std::shared_ptr<ConnectionManager> ConnectionManagerPtr;
60 
61 class SubscriptionCallbackHelper;
62 typedef std::shared_ptr<SubscriptionCallbackHelper> SubscriptionCallbackHelperPtr;
63 
65 {
66 public:
67  static const TopicManagerPtr& instance();
68 
69  TopicManager();
70  ~TopicManager();
71 
72  void start();
73  void shutdown();
74 
75  bool subscribe(const SubscribeOptions& ops);
76  bool unsubscribe(const std::string &_topic, const SubscriptionCallbackHelperPtr& helper);
77 
78  bool advertise(const AdvertiseOptions& ops, const SubscriberCallbacksPtr& callbacks);
79  bool unadvertise(const std::string &topic, const SubscriberCallbacksPtr& callbacks);
80 
85  void getAdvertisedTopics(V_string& topics);
86 
91  void getSubscribedTopics(V_string& topics);
92 
103  PublicationPtr lookupPublication(const std::string& topic);
104 
111  size_t getNumSubscribers(const std::string &_topic);
112  size_t getNumSubscriptions();
113 
120  size_t getNumPublishers(const std::string &_topic);
121 
122  template<typename M>
123  void publish(const std::string& topic, const M& message)
124  {
125  using namespace serialization;
126 
128  publish(topic, std::bind(serializeMessage<M>, std::ref(message)), m);
129  }
130 
131  void publish(const std::string &_topic, const std::function<SerializedMessage(void)>& serfunc, SerializedMessage& m);
132 
133  void incrementSequence(const std::string &_topic);
134  bool isLatched(const std::string& topic);
135 
136 private:
142  bool addSubCallback(const SubscribeOptions& ops);
143 
156  bool requestTopic(const std::string &topic, XmlRpc::XmlRpcValue &protos, XmlRpc::XmlRpcValue &ret);
157 
158  // Must lock the advertised topics mutex before calling this function
159  bool isTopicAdvertised(const std::string& topic);
160 
161  bool registerSubscriber(const SubscriptionPtr& s, const std::string& datatype);
162  bool unregisterSubscriber(const std::string& topic);
163  bool unregisterPublisher(const std::string& topic);
164 
165  PublicationPtr lookupPublicationWithoutLock(const std::string &topic);
166 
167  void processPublishQueues();
168 
175  void getBusStats(XmlRpc::XmlRpcValue &stats);
176 
183  void getBusInfo(XmlRpc::XmlRpcValue &info);
184 
191  void getSubscriptions(XmlRpc::XmlRpcValue &subscriptions);
192 
199  void getPublications(XmlRpc::XmlRpcValue &publications);
200 
211  bool pubUpdate(const std::string &topic, const std::vector<std::string> &pubs);
212 
213  void pubUpdateCallback(XmlRpc::XmlRpcValue& params, XmlRpc::XmlRpcValue& result);
214  void requestTopicCallback(XmlRpc::XmlRpcValue& params, XmlRpc::XmlRpcValue& result);
215  void getBusStatsCallback(XmlRpc::XmlRpcValue& params, XmlRpc::XmlRpcValue& result);
216  void getBusInfoCallback(XmlRpc::XmlRpcValue& params, XmlRpc::XmlRpcValue& result);
217  void getSubscriptionsCallback(XmlRpc::XmlRpcValue& params, XmlRpc::XmlRpcValue& result);
218  void getPublicationsCallback(XmlRpc::XmlRpcValue& params, XmlRpc::XmlRpcValue& result);
219 
220  bool isShuttingDown() { return shutting_down_; }
221 
222  std::mutex subs_mutex_;
224 
225  boost::recursive_mutex advertised_topics_mutex_;
227  std::list<std::string> advertised_topic_names_;
229 
230  volatile bool shutting_down_;
232 
236 };
237 
238 } // namespace roswrap
239 
240 #endif // ROSCPP_TOPIC_MANAGER_H
roswrap::XMLRPCManagerPtr
std::shared_ptr< XMLRPCManager > XMLRPCManagerPtr
Definition: forwards.h:172
unsubscribe
void unsubscribe()
roswrap::TopicManager::advertised_topics_mutex_
boost::recursive_mutex advertised_topics_mutex_
Definition: topic_manager.h:225
roswrap::TopicManager::advertised_topic_names_mutex_
std::mutex advertised_topic_names_mutex_
Definition: topic_manager.h:228
roswrap::TopicManager::isShuttingDown
bool isShuttingDown()
Definition: topic_manager.h:220
roswrap::ConnectionManagerPtr
std::shared_ptr< ConnectionManager > ConnectionManagerPtr
Definition: connection_manager.h:42
forwards.h
roswrap::message_traits::datatype
const char * datatype()
returns DataType<M>::value();
Definition: message_traits.h:236
roswrap::TopicManagerPtr
std::shared_ptr< TopicManager > TopicManagerPtr
Definition: forwards.h:168
roswrap::TopicManager::shutting_down_
volatile bool shutting_down_
Definition: topic_manager.h:230
roswrap::this_node::getSubscribedTopics
ROSCPP_DECL void getSubscribedTopics(V_string &topics)
Get the list of topics subscribed to by this node.
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::TopicManager::xmlrpc_manager_
XMLRPCManagerPtr xmlrpc_manager_
Definition: topic_manager.h:235
roswrap::AdvertiseOptions
Encapsulates all options available for creating a Publisher.
Definition: advertise_options.h:42
roswrap::SerializedMessage
Definition: serialized_message.h:40
message
def message(msg, *args, **kwargs)
roswrap::this_node::getAdvertisedTopics
ROSCPP_DECL void getAdvertisedTopics(V_string &topics)
Get the list of topics advertised by this node.
roswrap::TopicManager::connection_manager_
ConnectionManagerPtr connection_manager_
Definition: topic_manager.h:234
roswrap::SubscriptionCallbackHelperPtr
std::shared_ptr< SubscriptionCallbackHelper > SubscriptionCallbackHelperPtr
Definition: message_deserializer.h:43
roswrap::TopicManager::subscriptions_
L_Subscription subscriptions_
Definition: topic_manager.h:223
subscribe
void subscribe()
roswrap
Definition: param_modi.cpp:41
roswrap::PollManagerPtr
std::shared_ptr< PollManager > PollManagerPtr
Definition: connection_manager.h:39
roswrap::TopicManager::poll_manager_
PollManagerPtr poll_manager_
Definition: topic_manager.h:233
roswrap::TopicManager::advertised_topics_
V_Publication advertised_topics_
Definition: topic_manager.h:226
common.h
roswrap::L_Subscription
std::list< SubscriptionPtr > L_Subscription
Definition: forwards.h:77
roswrap::TopicManager::publish
void publish(const std::string &topic, const M &message)
Definition: topic_manager.h:123
roswrap::TopicManager
Definition: topic_manager.h:64
sick_scan_base.h
rosout_appender.h
roswrap::TopicManager::subs_mutex_
std::mutex subs_mutex_
Definition: topic_manager.h:222
roswrap::SubscriberCallbacksPtr
std::shared_ptr< SubscriberCallbacks > SubscriberCallbacksPtr
Definition: forwards.h:128
roswrap::PublicationPtr
std::shared_ptr< Publication > PublicationPtr
Definition: forwards.h:68
roswrap::TopicManager::shutting_down_mutex_
std::mutex shutting_down_mutex_
Definition: topic_manager.h:231
ROSCPP_DECL
#define ROSCPP_DECL
Definition: roswrap/src/cfgsimu/sick_scan/ros/common.h:63
roswrap::TopicManager::advertised_topic_names_
std::list< std::string > advertised_topic_names_
Definition: topic_manager.h:227
roswrap::SubscribeOptions
Encapsulates all options available for creating a Subscriber.
Definition: subscribe_options.h:44
roswrap::start
ROSCPP_DECL void start()
Actually starts the internals of the node (spins up threads, starts the network polling and xmlrpc lo...
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::V_string
std::vector< std::string > V_string
Definition: datatypes.h:44
roswrap::V_Publication
std::vector< PublicationPtr > V_Publication
Definition: forwards.h:70


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