Publication.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2015 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/function.hpp>
23 #include <boost/shared_ptr.hpp>
24 #include <boost/thread/mutex.hpp>
25 #include <list>
26 #include <string>
27 #include <vector>
28 #include <map>
29 
33 #include "gazebo/util/system.hh"
34 
35 namespace gazebo
36 {
37  namespace transport
38  {
41 
46  {
50  public: Publication(const std::string &_topic,
51  const std::string &_msgType);
52 
54  public: virtual ~Publication();
55 
58  public: std::string GetMsgType() const;
59 
62  public: void AddSubscription(const CallbackHelperPtr _callback);
63 
66  public: void AddSubscription(const NodePtr &_node);
67 
70  public: void RemoveSubscription(const NodePtr &_node);
71 
75  public: void RemoveSubscription(const std::string &_host,
76  unsigned int _port);
77 
81  public: void RemoveTransport(const std::string &_host, unsigned
82  int _port);
83 
86  public: unsigned int GetTransportCount() const;
87 
90  public: unsigned int GetCallbackCount() const;
91 
94  public: unsigned int GetNodeCount() const;
95 
98  public: unsigned int GetRemoteSubscriptionCount();
99 
103  public: bool GetLocallyAdvertised() const;
104 
108  public: void SetLocallyAdvertised(bool _value);
109 
112  public: void LocalPublish(const std::string &_data);
113 
120  public: int Publish(MessagePtr _msg,
121  boost::function<void(uint32_t)> _cb,
122  uint32_t _id);
123 
126  public: void RemovePublisher(PublisherPtr _pub);
127 
131  public: void SetPrevMsg(uint32_t _pubId, MessagePtr _msg);
132 
137  public: MessagePtr GetPrevMsg(uint32_t _pubId);
138 
142  public: void AddTransport(const PublicationTransportPtr &_publink);
143 
148  public: bool HasTransport(const std::string &_host, unsigned int _port);
149 
152  public: void AddPublisher(PublisherPtr _pub);
153 
155  private: void RemoveNodes();
156 
158  private: unsigned int id;
159 
161  private: static unsigned int idCounter;
162 
164  private: std::string topic;
165 
167  private: std::string msgType;
168 
170  private: std::list<CallbackHelperPtr> callbacks;
171 
173  private: std::list<NodePtr> nodes;
174 
176  private: std::list<unsigned int> removeNodes;
177 
179  private: std::list<std::pair<std::string, unsigned int> > removeCallbacks;
180 
182  private: std::list<PublicationTransportPtr> transports;
183 
185  private: std::vector<PublisherPtr> publishers;
186 
188  private: bool locallyAdvertised;
189 
191  private: mutable boost::mutex nodeMutex;
192 
194  private: mutable boost::mutex callbackMutex;
195 
197  private: mutable boost::mutex nodeRemoveMutex;
198 
200  private: std::map<uint32_t, MessagePtr> prevMsgs;
201  };
203  }
204 }
205 #endif
Forward declarations for the common classes.
Definition: Animation.hh:33
Forward declarations for transport.
A publication for a topic.
Definition: Publication.hh:45
boost::shared_ptr< google::protobuf::Message > MessagePtr
Definition: TransportTypes.hh:45
boost::shared_ptr< Node > NodePtr
Definition: TransportTypes.hh:57
#define GZ_TRANSPORT_VISIBLE
Definition: system.hh:166
boost::shared_ptr< Publisher > PublisherPtr
Definition: TransportTypes.hh:49
boost::shared_ptr< CallbackHelper > CallbackHelperPtr
boost shared pointer to transport::CallbackHelper
Definition: CallbackHelper.hh:101
boost::shared_ptr< PublicationTransport > PublicationTransportPtr
Definition: TransportTypes.hh:65