topic_manager.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2009, Willow Garage, Inc.
00003  *
00004  * Redistribution and use in source and binary forms, with or without
00005  * modification, are permitted provided that the following conditions are met:
00006  *   * Redistributions of source code must retain the above copyright notice,
00007  *     this list of conditions and the following disclaimer.
00008  *   * Redistributions in binary form must reproduce the above copyright
00009  *     notice, this list of conditions and the following disclaimer in the
00010  *     documentation and/or other materials provided with the distribution.
00011  *   * Neither the names of Willow Garage, Inc. nor the names of its
00012  *     contributors may be used to endorse or promote products derived from
00013  *     this software without specific prior written permission.
00014  *
00015  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00016  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00017  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00018  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00019  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00020  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00021  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00022  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00023  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00024  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00025  * POSSIBILITY OF SUCH DAMAGE.
00026  */
00027 
00028 #ifndef ROSCPP_TOPIC_MANAGER_H
00029 #define ROSCPP_TOPIC_MANAGER_H
00030 
00031 #include "forwards.h"
00032 #include "common.h"
00033 #include "ros/serialization.h"
00034 #include "rosout_appender.h"
00035 
00036 #include "XmlRpcValue.h"
00037 
00038 #include <boost/thread/mutex.hpp>
00039 #include <boost/thread/recursive_mutex.hpp>
00040 
00041 namespace ros
00042 {
00043 
00044 class Message;
00045 struct SubscribeOptions;
00046 struct AdvertiseOptions;
00047 
00048 class TopicManager;
00049 typedef boost::shared_ptr<TopicManager> TopicManagerPtr;
00050 
00051 class PollManager;
00052 typedef boost::shared_ptr<PollManager> PollManagerPtr;
00053 
00054 class XMLRPCManager;
00055 typedef boost::shared_ptr<XMLRPCManager> XMLRPCManagerPtr;
00056 
00057 class ConnectionManager;
00058 typedef boost::shared_ptr<ConnectionManager> ConnectionManagerPtr;
00059 
00060 class SubscriptionCallbackHelper;
00061 typedef boost::shared_ptr<SubscriptionCallbackHelper> SubscriptionCallbackHelperPtr;
00062 
00063 class ROSCPP_DECL TopicManager
00064 {
00065 public:
00066   static const TopicManagerPtr& instance();
00067 
00068   TopicManager();
00069   ~TopicManager();
00070 
00071   void start();
00072   void shutdown();
00073 
00074   bool subscribe(const SubscribeOptions& ops);
00075   bool unsubscribe(const std::string &_topic, const SubscriptionCallbackHelperPtr& helper);
00076 
00077   bool advertise(const AdvertiseOptions& ops, const SubscriberCallbacksPtr& callbacks);
00078   bool unadvertise(const std::string &topic, const SubscriberCallbacksPtr& callbacks);
00079 
00084   void getAdvertisedTopics(V_string& topics);
00085 
00090   void getSubscribedTopics(V_string& topics);
00091 
00102   PublicationPtr lookupPublication(const std::string& topic);
00103 
00110   size_t getNumSubscribers(const std::string &_topic);
00111   size_t getNumSubscriptions();
00112 
00119   size_t getNumPublishers(const std::string &_topic);
00120 
00121   template<typename M>
00122   void publish(const std::string& topic, const M& message)
00123   {
00124     using namespace serialization;
00125 
00126     SerializedMessage m;
00127     publish(topic, boost::bind(serializeMessage<M>, boost::ref(message)), m);
00128   }
00129 
00130   void publish(const std::string &_topic, const boost::function<SerializedMessage(void)>& serfunc, SerializedMessage& m);
00131 
00132   void incrementSequence(const std::string &_topic);
00133   bool isLatched(const std::string& topic);
00134 
00135 private:
00141   bool addSubCallback(const SubscribeOptions& ops);
00142 
00155   bool requestTopic(const std::string &topic, XmlRpc::XmlRpcValue &protos, XmlRpc::XmlRpcValue &ret);
00156 
00157   // Must lock the advertised topics mutex before calling this function
00158   bool isTopicAdvertised(const std::string& topic);
00159 
00160   bool registerSubscriber(const SubscriptionPtr& s, const std::string& datatype);
00161   bool unregisterSubscriber(const std::string& topic);
00162   bool unregisterPublisher(const std::string& topic);
00163 
00164   PublicationPtr lookupPublicationWithoutLock(const std::string &topic);
00165 
00166   void processPublishQueues();
00167 
00174   void getBusStats(XmlRpc::XmlRpcValue &stats);
00175 
00182   void getBusInfo(XmlRpc::XmlRpcValue &info);
00183 
00190   void getSubscriptions(XmlRpc::XmlRpcValue &subscriptions);
00191 
00198   void getPublications(XmlRpc::XmlRpcValue &publications);
00199 
00210   bool pubUpdate(const std::string &topic, const std::vector<std::string> &pubs);
00211 
00212   void pubUpdateCallback(XmlRpc::XmlRpcValue& params, XmlRpc::XmlRpcValue& result);
00213   void requestTopicCallback(XmlRpc::XmlRpcValue& params, XmlRpc::XmlRpcValue& result);
00214   void getBusStatsCallback(XmlRpc::XmlRpcValue& params, XmlRpc::XmlRpcValue& result);
00215   void getBusInfoCallback(XmlRpc::XmlRpcValue& params, XmlRpc::XmlRpcValue& result);
00216   void getSubscriptionsCallback(XmlRpc::XmlRpcValue& params, XmlRpc::XmlRpcValue& result);
00217   void getPublicationsCallback(XmlRpc::XmlRpcValue& params, XmlRpc::XmlRpcValue& result);
00218 
00219   bool isShuttingDown() { return shutting_down_; }
00220 
00221   boost::mutex subs_mutex_;
00222   L_Subscription subscriptions_;
00223 
00224   boost::recursive_mutex advertised_topics_mutex_;
00225   V_Publication advertised_topics_;
00226   std::list<std::string> advertised_topic_names_;
00227   boost::mutex advertised_topic_names_mutex_;
00228 
00229   volatile bool shutting_down_;
00230   boost::mutex shutting_down_mutex_;
00231 
00232   PollManagerPtr poll_manager_;
00233   ConnectionManagerPtr connection_manager_;
00234   XMLRPCManagerPtr xmlrpc_manager_;
00235 };
00236 
00237 } // namespace ros
00238 
00239 #endif // ROSCPP_TOPIC_MANAGER_H


roscpp
Author(s): Morgan Quigley, Josh Faust, Brian Gerkey, Troy Straszheim
autogenerated on Thu Jun 6 2019 21:10:05