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 (C) 2012-2014 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 #include <map>
28 
32 #include "gazebo/util/system.hh"
33 
34 namespace gazebo
35 {
36  namespace transport
37  {
40 
45  {
49  public: Publication(const std::string &_topic,
50  const std::string &_msgType);
51 
53  public: virtual ~Publication();
54 
57  public: std::string GetMsgType() const;
58 
61  public: void AddSubscription(const CallbackHelperPtr _callback);
62 
65  public: void AddSubscription(const NodePtr &_node);
66 
69  public: void RemoveSubscription(const NodePtr &_node);
70 
74  public: void RemoveSubscription(const std::string &_host,
75  unsigned int _port);
76 
80  public: void RemoveTransport(const std::string &_host, unsigned
81  int _port);
82 
85  public: unsigned int GetTransportCount() const;
86 
89  public: unsigned int GetCallbackCount() const;
90 
93  public: unsigned int GetNodeCount() const;
94 
97  public: unsigned int GetRemoteSubscriptionCount();
98 
102  public: bool GetLocallyAdvertised() const;
103 
107  public: void SetLocallyAdvertised(bool _value);
108 
111  public: void LocalPublish(const std::string &_data);
112 
119  public: int Publish(MessagePtr _msg,
120  boost::function<void(uint32_t)> _cb,
121  uint32_t _id);
122 
125  public: void RemovePublisher(PublisherPtr _pub);
126 
130  public: void SetPrevMsg(uint32_t _pubId, MessagePtr _msg);
131 
136  public: MessagePtr GetPrevMsg(uint32_t _pubId);
137 
141  public: void AddTransport(const PublicationTransportPtr &_publink);
142 
147  public: bool HasTransport(const std::string &_host, unsigned int _port);
148 
151  public: void AddPublisher(PublisherPtr _pub);
152 
154  private: void RemoveNodes();
155 
157  private: unsigned int id;
158 
160  private: static unsigned int idCounter;
161 
163  private: std::string topic;
164 
166  private: std::string msgType;
167 
169  private: std::list<CallbackHelperPtr> callbacks;
170 
172  private: std::list<NodePtr> nodes;
173 
175  private: std::list<unsigned int> removeNodes;
176 
178  private: std::list<std::pair<std::string, unsigned int> > removeCallbacks;
179 
181  private: std::list<PublicationTransportPtr> transports;
182 
184  private: std::vector<PublisherPtr> publishers;
185 
187  private: bool locallyAdvertised;
188 
190  private: mutable boost::mutex nodeMutex;
191 
193  private: mutable boost::mutex callbackMutex;
194 
196  private: mutable boost::mutex nodeRemoveMutex;
197 
199  private: std::map<uint32_t, MessagePtr> prevMsgs;
200  };
202  }
203 }
204 #endif