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 
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  boost::function<void(uint32_t)> _cb,
117  uint32_t _id);
118 
122  public: void AddTransport(const PublicationTransportPtr &_publink);
123 
128  public: bool HasTransport(const std::string &_host, unsigned int _port);
129 
132  public: void AddPublisher(PublisherPtr _pub);
133 
135  private: void RemoveNodes();
136 
138  private: unsigned int id;
139 
141  private: static unsigned int idCounter;
142 
144  private: std::string topic;
145 
147  private: std::string msgType;
148 
150  private: std::list<CallbackHelperPtr> callbacks;
151 
153  private: std::list<NodePtr> nodes;
154 
156  private: std::list<unsigned int> removeNodes;
157 
159  private: std::list<std::pair<std::string, unsigned int> > removeCallbacks;
160 
162  private: std::list<PublicationTransportPtr> transports;
163 
165  private: std::vector<PublisherPtr> publishers;
166 
168  private: bool locallyAdvertised;
169 
171  private: mutable boost::mutex nodeMutex;
172 
174  private: mutable boost::mutex callbackMutex;
175 
177  private: mutable boost::mutex nodeRemoveMutex;
178  };
180  }
181 }
182 #endif