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> 70 public:
void AddNode(
NodePtr _node);
74 public:
void RemoveNode(
unsigned int _id);
79 public:
void ProcessNodes(
bool _onlyOut =
false);
90 public:
void Unsubscribe(
const std::string &_topic,
const NodePtr &_sub);
100 const std::string &_msgTypeName,
101 unsigned int _queueLimit,
104 this->UpdatePublications(_topic, _msgTypeName);
107 _msgTypeName, _queueLimit, _hzRate));
112 "FindPublication returned nullptr");
114 publication->AddPublisher(pub);
115 if (!publication->GetLocallyAdvertised())
121 publication->SetLocallyAdvertised(
true);
122 pub->SetPublication(publication);
124 for (
auto &iter2 : this->subscribedNodes)
126 if (iter2.first == _topic)
128 for (
const auto liter : iter2.second)
130 publication->AddSubscription(liter);
145 public:
template<
typename M>
147 unsigned int _queueLimit,
150 google::protobuf::Message *msg =
nullptr;
152 msg =
dynamic_cast<google::protobuf::Message *
>(&msgtype);
154 gzthrow(
"Advertise requires a google protobuf type");
156 return this->Advertise(_topic, msg->GetTypeName(), _queueLimit,
162 public:
void Unadvertise(
const std::string &_topic);
172 public:
void Unadvertise(
const std::string &_topic,
const uint32_t _id);
180 public:
void Publish(
const std::string &_topic,
MessagePtr _message,
181 boost::function<
void(uint32_t)> _cb, uint32_t _id);
186 public:
void ConnectPubToSub(
const std::string &_topic,
191 public:
void ConnectSubToPub(
const msgs::Publish &_pub);
197 public:
void DisconnectPubFromSub(
const std::string &_topic,
198 const std::string &_host,
205 public:
void DisconnectSubFromPub(
const std::string &_topic,
206 const std::string &_host,
211 public:
void ConnectSubscribers(
const std::string &_topic);
218 public:
PublicationPtr UpdatePublications(
const std::string &_topic,
219 const std::string &_msgType);
223 public:
void RegisterTopicNamespace(
const std::string &_name);
227 public:
void GetTopicNamespaces(std::list<std::string> &_namespaces);
230 public:
void ClearBuffers();
234 public:
void PauseIncoming(
bool _pause);
238 public:
void AddNodeToProcess(
NodePtr _ptr);
241 typedef std::map<std::string, std::list<NodePtr> >
SubNodeMap;
243 private:
typedef std::map<std::string, PublicationPtr> PublicationPtr_M;
244 private: PublicationPtr_M advertisedTopics;
245 private: PublicationPtr_M::iterator advertisedTopicsEnd;
246 private: SubNodeMap subscribedNodes;
247 private: std::vector<NodePtr> nodes;
250 private: boost::unordered_set<NodePtr> nodesToProcess;
252 private: boost::recursive_mutex nodeMutex;
255 private: boost::mutex subscriberMutex;
258 private: boost::mutex processNodesMutex;
260 private:
bool pauseIncoming;
Options for a subscription.
Definition: SubscribeOptions.hh:35
#define GZ_ASSERT(_expr, _msg)
This macro define the standard way of launching an exception inside gazebo.
Definition: Assert.hh:24
Forward declarations for the common classes.
Definition: Animation.hh:26
boost::shared_ptr< google::protobuf::Message > MessagePtr
Definition: TransportTypes.hh:45
#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
Forward declarations for transport.
boost::shared_ptr< Publisher > PublisherPtr
Definition: TransportTypes.hh:49
boost::shared_ptr< Subscriber > SubscriberPtr
Definition: TransportTypes.hh:53
Singleton template class.
Definition: SingletonT.hh:33
boost::shared_ptr< Node > NodePtr
Definition: TransportTypes.hh:57
boost::shared_ptr< Publication > PublicationPtr
Definition: TransportTypes.hh:61
boost::shared_ptr< SubscriptionTransport > SubscriptionTransportPtr
Definition: TransportTypes.hh:69
Manages topics and their subscriptions.
Definition: TopicManager.hh:52
A publisher of messages on a topic.
Definition: Publisher.hh:44
PublisherPtr Advertise(const std::string &_topic, const std::string &_msgTypeName, unsigned int _queueLimit, double _hzRate)
Advertise on a topic.
Definition: TopicManager.hh:99
GAZEBO_VISIBLE void Init(google::protobuf::Message &_message, const std::string &_id="")
Initialize a message.
PublisherPtr Advertise(const std::string &_topic, unsigned int _queueLimit, double _hzRate)
Advertise on a topic.
Definition: TopicManager.hh:146
std::map< std::string, std::list< NodePtr > > SubNodeMap
A map of string->list of Node pointers.
Definition: TopicManager.hh:241
static ConnectionManager * Instance()
Get an instance of the singleton.
Definition: SingletonT.hh:36