17 #ifndef GAZEBO_TRANSPORT_TOPICMANAGER_HH_
18 #define GAZEBO_TRANSPORT_TOPICMANAGER_HH_
21 #ifndef BOOST_BIND_GLOBAL_PLACEHOLDERS
22 #define BOOST_BIND_GLOBAL_PLACEHOLDERS
24 #include <boost/bind.hpp>
25 #include <boost/function.hpp>
30 #include <boost/unordered/unordered_set.hpp>
107 const std::string &_msgTypeName,
108 unsigned int _queueLimit,
111 this->UpdatePublications(_topic, _msgTypeName);
114 _msgTypeName, _queueLimit, _hzRate));
119 "FindPublication returned nullptr");
121 publication->AddPublisher(pub);
122 if (!publication->GetLocallyAdvertised())
128 publication->SetLocallyAdvertised(
true);
129 pub->SetPublication(publication);
131 for (
auto &iter2 : this->subscribedNodes)
133 if (iter2.first == _topic)
135 for (
const auto &liter : iter2.second)
137 publication->AddSubscription(liter);
152 public:
template<
typename M>
154 unsigned int _queueLimit,
157 google::protobuf::Message *msg =
nullptr;
159 msg =
dynamic_cast<google::protobuf::Message *
>(&msgtype);
161 gzthrow(
"Advertise requires a google protobuf type");
163 return this->Advertise(_topic, msg->GetTypeName(), _queueLimit,
179 public:
void Unadvertise(
const std::string &_topic,
const uint32_t _id);
188 boost::function<
void(uint32_t)> _cb, uint32_t _id);
205 const std::string &_host,
213 const std::string &_host,
226 const std::string &_msgType);
248 typedef std::map<std::string, std::list<NodePtr> >
SubNodeMap;
250 private:
typedef std::map<std::string, PublicationPtr> PublicationPtr_M;
251 private: PublicationPtr_M advertisedTopics;
252 private: PublicationPtr_M::iterator advertisedTopicsEnd;
254 private: std::vector<NodePtr> nodes;
257 private: boost::unordered_set<NodePtr> nodesToProcess;
259 private: boost::recursive_mutex nodeMutex;
262 private: boost::mutex subscriberMutex;
265 private: boost::mutex processNodesMutex;
267 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: TopicManager.hh:48
Forward declarations for transport.
Singleton template class.
Definition: SingletonT.hh:34
static ConnectionManager * Instance()
Get an instance of the singleton.
Definition: SingletonT.hh:36
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:60
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:248
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:153
PublisherPtr Advertise(const std::string &_topic, const std::string &_msgTypeName, unsigned int _queueLimit, double _hzRate)
Advertise on a topic.
Definition: TopicManager.hh:106
#define GZ_SINGLETON_DECLARE(visibility, n1, n2, singletonType)
Helper to declare typed SingletonT.
Definition: SingletonT.hh:61
#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