All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Publication.hh
Go to the documentation of this file.
1 /*
2  * Copyright 2012 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 
18 #ifndef _PUBLICATION_HH_
19 #define _PUBLICATION_HH_
20 
21 #include <utility>
22 #include <boost/shared_ptr.hpp>
23 #include <boost/thread/mutex.hpp>
24 #include <list>
25 #include <string>
26 #include <vector>
27 
31 
32 namespace gazebo
33 {
34  namespace transport
35  {
38 
43  {
47  public: Publication(const std::string &_topic,
48  const std::string &_msgType);
49 
51  public: virtual ~Publication();
52 
55  public: std::string GetMsgType() const;
56 
59  public: void AddSubscription(const CallbackHelperPtr _callback);
60 
63  public: void AddSubscription(const NodePtr &_node);
64 
67  public: void RemoveSubscription(const NodePtr &_node);
68 
72  public: void RemoveSubscription(const std::string &_host,
73  unsigned int _port);
74 
78  public: void RemoveTransport(const std::string &_host, unsigned
79  int _port);
80 
83  public: unsigned int GetTransportCount() const;
84 
87  public: unsigned int GetCallbackCount() const;
88 
91  public: unsigned int GetNodeCount() const;
92 
95  public: unsigned int GetRemoteSubscriptionCount();
96 
100  public: bool GetLocallyAdvertised() const;
101 
105  public: void SetLocallyAdvertised(bool _value);
106 
109  public: void LocalPublish(const std::string &_data);
110 
115  public: void Publish(MessagePtr _msg,
116  const boost::function<void()> &_cb = NULL);
117 
121  public: void AddTransport(const PublicationTransportPtr &_publink);
122 
127  public: bool HasTransport(const std::string &_host, unsigned int _port);
128 
131  public: void AddPublisher(PublisherPtr _pub);
132 
134  private: void RemoveNodes();
135 
137  private: unsigned int id;
138 
140  private: static unsigned int idCounter;
141 
143  private: std::string topic;
144 
146  private: std::string msgType;
147 
149  private: std::list<CallbackHelperPtr> callbacks;
150 
152  private: std::list<NodePtr> nodes;
153 
155  private: std::list<unsigned int> removeNodes;
156 
158  private: std::list<std::pair<std::string, unsigned int> > removeCallbacks;
159 
161  private: std::list<PublicationTransportPtr> transports;
162 
164  private: std::vector<PublisherPtr> publishers;
165 
167  private: bool locallyAdvertised;
168 
170  private: mutable boost::mutex nodeMutex;
171 
173  private: mutable boost::mutex callbackMutex;
174 
176  private: mutable boost::mutex nodeRemoveMutex;
177  };
179  }
180 }
181 #endif