17 #ifndef _TOPICMANAGER_HH_
18 #define _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);
99 public:
template<
typename M>
101 unsigned int _queueLimit,
104 google::protobuf::Message *msg =
NULL;
106 msg =
dynamic_cast<google::protobuf::Message *
>(&msgtype);
108 gzthrow(
"Advertise requires a google protobuf type");
110 this->UpdatePublications(_topic, msg->GetTypeName());
113 msg->GetTypeName(), _queueLimit, _hzRate));
115 std::string msgTypename;
119 msgTypename = msg->GetTypeName();
121 publication = this->FindPublication(_topic);
122 GZ_ASSERT(publication !=
NULL,
"FindPublication returned NULL");
124 publication->AddPublisher(pub);
125 if (!publication->GetLocallyAdvertised())
130 publication->SetLocallyAdvertised(
true);
131 pub->SetPublication(publication);
134 SubNodeMap::iterator iter2;
135 SubNodeMap::iterator stEnd2 = this->subscribedNodes.end();
136 for (iter2 = this->subscribedNodes.begin();
137 iter2 != stEnd2; ++iter2)
139 if (iter2->first == _topic)
141 std::list<NodePtr>::iterator liter;
142 std::list<NodePtr>::iterator lEnd = iter2->second.end();
143 for (liter = iter2->second.begin();
144 liter != lEnd; ++liter)
146 publication->AddSubscription(*liter);
156 public:
void Unadvertise(
const std::string &_topic);
166 public:
void Unadvertise(
const std::string &_topic,
const uint32_t _id);
174 public:
void Publish(
const std::string &_topic,
MessagePtr _message,
175 boost::function<
void(uint32_t)> _cb, uint32_t _id);
180 public:
void ConnectPubToSub(
const std::string &_topic,
185 public:
void ConnectSubToPub(
const msgs::Publish &_pub);
191 public:
void DisconnectPubFromSub(
const std::string &_topic,
192 const std::string &_host,
199 public:
void DisconnectSubFromPub(
const std::string &_topic,
200 const std::string &_host,
205 public:
void ConnectSubscribers(
const std::string &_topic);
212 public:
PublicationPtr UpdatePublications(
const std::string &_topic,
213 const std::string &_msgType);
217 public:
void RegisterTopicNamespace(
const std::string &_name);
221 public:
void GetTopicNamespaces(std::list<std::string> &_namespaces);
224 public:
void ClearBuffers();
228 public:
void PauseIncoming(
bool _pause);
232 public:
void AddNodeToProcess(
NodePtr _ptr);
235 typedef std::map<std::string, std::list<NodePtr> >
SubNodeMap;
237 private:
typedef std::map<std::string, PublicationPtr> PublicationPtr_M;
238 private: PublicationPtr_M advertisedTopics;
239 private: PublicationPtr_M::iterator advertisedTopicsEnd;
241 private: std::vector<NodePtr> nodes;
244 private: boost::unordered_set<NodePtr> nodesToProcess;
246 private: boost::recursive_mutex nodeMutex;
249 private: boost::mutex subscriberMutex;
252 private: boost::mutex processNodesMutex;
254 private:
bool pauseIncoming;
boost::shared_ptr< SubscriptionTransport > SubscriptionTransportPtr
Definition: TransportTypes.hh:69
Options for a subscription.
Definition: SubscribeOptions.hh:35
static ConnectionManager * Instance()
Get an instance of the singleton.
Definition: SingletonT.hh:36
#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
#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.
Singleton template class.
Definition: SingletonT.hh:33
PublisherPtr Advertise(const std::string &_topic, unsigned int _queueLimit, double _hzRate)
Advertise on a topic.
Definition: TopicManager.hh:100
Manages topics and their subscriptions.
Definition: TopicManager.hh:52
A publisher of messages on a topic.
Definition: Publisher.hh:43
boost::shared_ptr< Publication > PublicationPtr
Definition: TransportTypes.hh:61
std::map< std::string, std::list< NodePtr > > SubNodeMap
A map of string->list of Node pointers.
Definition: TopicManager.hh:235
boost::shared_ptr< google::protobuf::Message > MessagePtr
Definition: TransportTypes.hh:45
#define NULL
Definition: CommonTypes.hh:31
boost::shared_ptr< Node > NodePtr
Definition: TransportTypes.hh:57
GAZEBO_VISIBLE void Init(google::protobuf::Message &_message, const std::string &_id="")
Initialize a message.
#define GZ_TRANSPORT_VISIBLE
Definition: system.hh:159
boost::shared_ptr< Publisher > PublisherPtr
Definition: TransportTypes.hh:49