Go to the documentation of this file.
17 #ifndef GAZEBO_TRANSPORT_TOPICMANAGER_HH_
18 #define GAZEBO_TRANSPORT_TOPICMANAGER_HH_
20 #include <boost/bind.hpp>
21 #include <boost/function.hpp>
26 #include <boost/unordered/unordered_set.hpp>
73 public:
void AddNode(
NodePtr _node);
77 public:
void RemoveNode(
unsigned int _id);
82 public:
void ProcessNodes(
bool _onlyOut =
false);
93 public:
void Unsubscribe(
const std::string &_topic,
const NodePtr &_sub);
102 public:
template<
typename M>
104 unsigned int _queueLimit,
107 google::protobuf::Message *msg =
NULL;
109 msg =
dynamic_cast<google::protobuf::Message *
>(&msgtype);
111 gzthrow(
"Advertise requires a google protobuf type");
113 this->UpdatePublications(_topic, msg->GetTypeName());
116 msg->GetTypeName(), _queueLimit, _hzRate));
118 std::string msgTypename;
122 msgTypename = msg->GetTypeName();
124 publication = this->FindPublication(_topic);
125 GZ_ASSERT(publication !=
NULL,
"FindPublication returned NULL");
127 publication->AddPublisher(pub);
128 if (!publication->GetLocallyAdvertised())
133 publication->SetLocallyAdvertised(
true);
134 pub->SetPublication(publication);
137 SubNodeMap::iterator iter2;
138 SubNodeMap::iterator stEnd2 = this->subscribedNodes.end();
139 for (iter2 = this->subscribedNodes.begin();
140 iter2 != stEnd2; ++iter2)
142 if (iter2->first == _topic)
144 std::list<NodePtr>::iterator liter;
145 std::list<NodePtr>::iterator lEnd = iter2->second.end();
146 for (liter = iter2->second.begin();
147 liter != lEnd; ++liter)
149 publication->AddSubscription(*liter);
159 public:
void Unadvertise(
const std::string &_topic);
169 public:
void Unadvertise(
const std::string &_topic,
const uint32_t _id);
177 public:
void Publish(
const std::string &_topic,
MessagePtr _message,
178 boost::function<
void(uint32_t)> _cb, uint32_t _id);
183 public:
void ConnectPubToSub(
const std::string &_topic,
188 public:
void ConnectSubToPub(
const msgs::Publish &_pub);
194 public:
void DisconnectPubFromSub(
const std::string &_topic,
195 const std::string &_host,
202 public:
void DisconnectSubFromPub(
const std::string &_topic,
203 const std::string &_host,
208 public:
void ConnectSubscribers(
const std::string &_topic);
215 public:
PublicationPtr UpdatePublications(
const std::string &_topic,
216 const std::string &_msgType);
220 public:
void RegisterTopicNamespace(
const std::string &_name);
224 public:
void GetTopicNamespaces(std::list<std::string> &_namespaces);
227 public:
void ClearBuffers();
231 public:
void PauseIncoming(
bool _pause);
235 public:
void AddNodeToProcess(
NodePtr _ptr);
238 typedef std::map<std::string, std::list<NodePtr> >
SubNodeMap;
240 private:
typedef std::map<std::string, PublicationPtr> PublicationPtr_M;
241 private: PublicationPtr_M advertisedTopics;
242 private: PublicationPtr_M::iterator advertisedTopicsEnd;
244 private: std::vector<NodePtr> nodes;
247 private: boost::unordered_set<NodePtr> nodesToProcess;
249 private: boost::recursive_mutex nodeMutex;
252 private: boost::mutex subscriberMutex;
255 private: boost::mutex processNodesMutex;
257 private:
bool pauseIncoming;
Options for a subscription.
Definition: SubscribeOptions.hh:35
Forward declarations for the common classes.
Definition: Animation.hh:26
boost::shared_ptr< google::protobuf::Message > MessagePtr
Definition: TransportTypes.hh:45
#define NULL
Definition: CommonTypes.hh:31
Singleton template class.
Definition: SingletonT.hh:33
#define gzthrow(msg)
This macro logs an error to the throw stream and throws an exception that contains the file name and ...
Definition: Exception.hh:39
boost::shared_ptr< Publisher > PublisherPtr
Definition: TransportTypes.hh:49
Forward declarations for transport.
#define GZ_ASSERT(_expr, _msg)
This macro define the standard way of launching an exception inside gazebo.
Definition: Assert.hh:24
boost::shared_ptr< Subscriber > SubscriberPtr
Definition: TransportTypes.hh:53
boost::shared_ptr< Publication > PublicationPtr
Definition: TransportTypes.hh:61
boost::shared_ptr< Node > NodePtr
Definition: TransportTypes.hh:57
boost::shared_ptr< SubscriptionTransport > SubscriptionTransportPtr
Definition: TransportTypes.hh:69
transport
Definition: TopicManager.hh:44
Manages topics and their subscriptions.
Definition: TopicManager.hh:55
A publisher of messages on a topic.
Definition: Publisher.hh:43
gazebo
Definition: TopicManager.hh:44
GAZEBO_VISIBLE void Init(google::protobuf::Message &_message, const std::string &_id="")
Initialize a message.
static ConnectionManager * Instance()
Get an instance of the singleton.
Definition: SingletonT.hh:36
PublisherPtr Advertise(const std::string &_topic, unsigned int _queueLimit, double _hzRate)
Advertise on a topic.
Definition: TopicManager.hh:103
#define GZ_SINGLETON_DECLARE(visibility, n1, n2, singletonType)
Helper to declare typed SingletonT.
Definition: SingletonT.hh:61
std::map< std::string, std::list< NodePtr > > SubNodeMap
A map of string->list of Node pointers.
Definition: TopicManager.hh:238