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);
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())
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,
165 public:
void Unadvertise(
const std::string &_topic);
175 public:
void Unadvertise(
const std::string &_topic,
const uint32_t _id);
183 public:
void Publish(
const std::string &_topic,
MessagePtr _message,
184 boost::function<
void(uint32_t)> _cb, uint32_t _id);
189 public:
void ConnectPubToSub(
const std::string &_topic,
194 public:
void ConnectSubToPub(
const msgs::Publish &_pub);
200 public:
void DisconnectPubFromSub(
const std::string &_topic,
201 const std::string &_host,
208 public:
void DisconnectSubFromPub(
const std::string &_topic,
209 const std::string &_host,
214 public:
void ConnectSubscribers(
const std::string &_topic);
221 public:
PublicationPtr UpdatePublications(
const std::string &_topic,
222 const std::string &_msgType);
226 public:
void RegisterTopicNamespace(
const std::string &_name);
230 public:
void GetTopicNamespaces(std::list<std::string> &_namespaces);
233 public:
void ClearBuffers();
237 public:
void PauseIncoming(
bool _pause);
241 public:
void AddNodeToProcess(
NodePtr _ptr);
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;
249 private: SubNodeMap subscribedNodes;
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;
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:55
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:102
GAZEBO_VISIBLE void Init(google::protobuf::Message &_message, const std::string &_id="")
Initialize a message.
transport
Definition: TopicManager.hh:44
PublisherPtr Advertise(const std::string &_topic, unsigned int _queueLimit, double _hzRate)
Advertise on a topic.
Definition: TopicManager.hh:149
std::map< std::string, std::list< NodePtr > > SubNodeMap
A map of string->list of Node pointers.
Definition: TopicManager.hh:244
#define GZ_SINGLETON_DECLARE(visibility, n1, n2, singletonType)
Helper to declare typed SingletonT.
Definition: SingletonT.hh:61
static ConnectionManager * Instance()
Get an instance of the singleton.
Definition: SingletonT.hh:36