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>
103 const std::string &_msgTypeName,
104 unsigned int _queueLimit,
107 this->UpdatePublications(_topic, _msgTypeName);
110 _msgTypeName, _queueLimit, _hzRate));
115 "FindPublication returned nullptr");
117 publication->AddPublisher(pub);
118 if (!publication->GetLocallyAdvertised())
120 ConnectionManager::Instance()->Advertise(_topic,
124 publication->SetLocallyAdvertised(
true);
125 pub->SetPublication(publication);
127 for (
auto &iter2 : this->subscribedNodes)
129 if (iter2.first == _topic)
131 for (
const auto liter : iter2.second)
133 publication->AddSubscription(liter);
148 public:
template<
typename M>
150 unsigned int _queueLimit,
153 google::protobuf::Message *msg =
nullptr;
155 msg =
dynamic_cast<google::protobuf::Message *
>(&msgtype);
157 gzthrow(
"Advertise requires a google protobuf type");
159 return this->Advertise(_topic, msg->GetTypeName(), _queueLimit,
175 public:
void Unadvertise(
const std::string &_topic,
const uint32_t _id);
184 boost::function<
void(uint32_t)> _cb, uint32_t _id);
201 const std::string &_host,
209 const std::string &_host,
222 const std::string &_msgType);
244 typedef std::map<std::string, std::list<NodePtr> >
SubNodeMap;
246 private:
typedef std::map<std::string, PublicationPtr> PublicationPtr_M;
247 private: PublicationPtr_M advertisedTopics;
248 private: PublicationPtr_M::iterator advertisedTopicsEnd;
250 private: std::vector<NodePtr> nodes;
253 private: boost::unordered_set<NodePtr> nodesToProcess;
255 private: boost::recursive_mutex nodeMutex;
258 private: boost::mutex subscriberMutex;
261 private: boost::mutex processNodesMutex;
263 private:
bool pauseIncoming;
#define GZ_ASSERT(_expr, _msg)
This macro define the standard way of launching an exception inside gazebo.
Definition Assert.hh:24
transport
Definition ConnectionManager.hh:35
gazebo
Definition TopicManager.hh:44
transport
Definition TopicManager.hh:44
Forward declarations for transport.
Singleton template class.
Definition SingletonT.hh:34
A publisher of messages on a topic.
Definition Publisher.hh:46
Options for a subscription.
Definition SubscribeOptions.hh:36
Manages topics and their subscriptions.
Definition TopicManager.hh:56
void Fini()
Finalize the manager.
void ClearBuffers()
Clear all buffers.
void Unadvertise(PublisherPtr _pub)
Unadvertise a publisher.
void PauseIncoming(bool _pause)
Pause or unpause processing of incoming messages.
std::map< std::string, std::list< NodePtr > > SubNodeMap
A map of string->list of Node pointers.
Definition TopicManager.hh:244
void Init()
Initialize the manager.
SubscriberPtr Subscribe(const SubscribeOptions &_options)
Subscribe to a topic.
void RemoveNode(unsigned int _id)
Remove a node by its id.
void Publish(const std::string &_topic, MessagePtr _message, boost::function< void(uint32_t)> _cb, uint32_t _id)
Send a message.
void Unadvertise(const std::string &_topic, const uint32_t _id)
Unadvertise a publisher, based on a publisher id.
void AddNode(NodePtr _node)
Add a node to the manager.
void RegisterTopicNamespace(const std::string &_name)
Register a new topic namespace.
PublicationPtr UpdatePublications(const std::string &_topic, const std::string &_msgType)
Update our list of advertised topics.
void GetTopicNamespaces(std::list< std::string > &_namespaces)
Get all the topic namespaces.
void ProcessNodes(bool _onlyOut=false)
Process all nodes under management.
void ConnectSubToPub(const msgs::Publish &_pub)
Connect a local Subscriber to a remote Publisher.
void AddNodeToProcess(NodePtr _ptr)
Add a node to the list of nodes that requires processing.
void DisconnectSubFromPub(const std::string &_topic, const std::string &_host, unsigned int _port)
Disconnect all local subscribers from a remote publisher.
void ConnectSubscribers(const std::string &_topic)
Connect all subscribers on a topic to known publishers.
void Unadvertise(const std::string &_topic)
Unadvertise a topic.
PublicationPtr FindPublication(const std::string &_topic)
Find a publication object by topic.
void ConnectPubToSub(const std::string &_topic, const SubscriptionTransportPtr _sublink)
Connection a local Publisher to a remote Subscriber.
void Unsubscribe(const std::string &_topic, const NodePtr &_sub)
Unsubscribe from a topic.
void DisconnectPubFromSub(const std::string &_topic, const std::string &_host, unsigned int _port)
Disconnect a local publisher from a remote subscriber.
PublisherPtr Advertise(const std::string &_topic, unsigned int _queueLimit, double _hzRate)
Advertise on a topic.
Definition TopicManager.hh:149
PublisherPtr Advertise(const std::string &_topic, const std::string &_msgTypeName, unsigned int _queueLimit, double _hzRate)
Advertise on a topic.
Definition TopicManager.hh:102
#define GZ_SINGLETON_DECLARE(visibility, n1, n2, singletonType)
Helper to declare typed SingletonT.
Definition SingletonT.hh:58
#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< Publication > PublicationPtr
Definition TransportTypes.hh:61
boost::shared_ptr< Subscriber > SubscriberPtr
Definition TransportTypes.hh:53
boost::shared_ptr< google::protobuf::Message > MessagePtr
Definition TransportTypes.hh:45
boost::shared_ptr< SubscriptionTransport > SubscriptionTransportPtr
Definition TransportTypes.hh:69
boost::shared_ptr< Publisher > PublisherPtr
Definition TransportTypes.hh:49
boost::shared_ptr< Node > NodePtr
Definition TransportTypes.hh:57
Forward declarations for the common classes.
Definition Animation.hh:27