Publication.hh
Go to the documentation of this file.
1/*
2 * Copyright (C) 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/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
35namespace gazebo
36{
37 namespace transport
38 {
41
45 class GZ_TRANSPORT_VISIBLE Publication :
46 public boost::enable_shared_from_this<Publication>
47 {
51 public: Publication(const std::string &_topic,
52 const std::string &_msgType);
53
55 public: virtual ~Publication();
56
59 public: std::string GetMsgType() const;
60
63 public: void AddSubscription(const CallbackHelperPtr _callback);
64
67 public: void AddSubscription(const NodePtr &_node);
68
71 public: void RemoveSubscription(const NodePtr &_node);
72
76 public: void RemoveSubscription(const std::string &_host,
77 unsigned int _port);
78
82 public: void RemoveTransport(const std::string &_host, unsigned
83 int _port);
84
87 public: unsigned int GetTransportCount() const;
88
91 public: unsigned int GetCallbackCount() const;
92
95 public: unsigned int PublisherCount() const;
96
99 public: unsigned int GetNodeCount() const;
100
103 public: unsigned int GetRemoteSubscriptionCount();
104
108 public: bool GetLocallyAdvertised() const;
109
113 public: void SetLocallyAdvertised(bool _value);
114
117 public: void LocalPublish(const std::string &_data);
118
125 public: int Publish(MessagePtr _msg,
126 boost::function<void(uint32_t)> _cb,
127 uint32_t _id);
128
131 public: void RemovePublisher(PublisherPtr _pub);
132
136 public: bool RemovePublisher(const uint32_t id);
137
141 public: void SetPrevMsg(uint32_t _pubId, MessagePtr _msg);
142
147 public: MessagePtr GetPrevMsg(uint32_t _pubId);
148
150 public: void ClearPrevMsgs();
151
155 public: void AddTransport(const PublicationTransportPtr &_publink);
156
161 public: bool HasTransport(const std::string &_host, unsigned int _port);
162
165 public: void AddPublisher(PublisherPtr _pub);
166
168 private: void RemoveNodes();
169
171 private: unsigned int id;
172
174 private: static unsigned int idCounter;
175
177 private: std::string topic;
178
180 private: std::string msgType;
181
183 private: std::list<CallbackHelperPtr> callbacks;
184
186 private: std::list<NodePtr> nodes;
187
189 private: std::list<unsigned int> removeNodes;
190
192 private: std::list<std::pair<std::string, unsigned int> > removeCallbacks;
193
195 private: std::list<PublicationTransportPtr> transports;
196
198 private: std::vector<PublisherPtr> publishers;
199
201 private: bool locallyAdvertised;
202
204 private: mutable boost::mutex nodeMutex;
205
207 private: mutable boost::mutex callbackMutex;
208
210 private: mutable boost::mutex nodeRemoveMutex;
211
213 private: std::map<uint32_t, MessagePtr> prevMsgs;
214 };
216 }
217}
218#endif
transport
Definition ConnectionManager.hh:35
Forward declarations for transport.
A publication for a topic.
Definition Publication.hh:47
void RemoveTransport(const std::string &_host, unsigned int _port)
Remove a transport.
MessagePtr GetPrevMsg(uint32_t _pubId)
Get a previous message for a publisher.
void AddSubscription(const CallbackHelperPtr _callback)
Subscribe a callback to our topic.
void LocalPublish(const std::string &_data)
Publish data to local subscribers (skip serialization)
unsigned int GetRemoteSubscriptionCount()
Get the number of remote subscriptions.
void AddTransport(const PublicationTransportPtr &_publink)
Add a transport.
unsigned int PublisherCount() const
Get the number of publishers.
int Publish(MessagePtr _msg, boost::function< void(uint32_t)> _cb, uint32_t _id)
Publish data to remote subscribers.
void SetPrevMsg(uint32_t _pubId, MessagePtr _msg)
Set the previous message for a publisher.
unsigned int GetCallbackCount() const
Get the number of callbacks.
void AddPublisher(PublisherPtr _pub)
Add a publisher.
void ClearPrevMsgs()
Clear all previous messages for a publisher.
unsigned int GetNodeCount() const
Get the number of nodes.
void AddSubscription(const NodePtr &_node)
Subscribe a node to our topic.
std::string GetMsgType() const
Get the type of message.
void RemoveSubscription(const std::string &_host, unsigned int _port)
Unsubscribe a a node by host/port from our topic.
bool HasTransport(const std::string &_host, unsigned int _port)
Does a given transport exist?
void RemoveSubscription(const NodePtr &_node)
Unsubscribe a node from our topic.
unsigned int GetTransportCount() const
Get the number of transports.
bool RemovePublisher(const uint32_t id)
Remove a publisher, based on a publisher ID.
void RemovePublisher(PublisherPtr _pub)
Remove a publisher.
bool GetLocallyAdvertised() const
Was the topic has been advertised from this process?
Publication(const std::string &_topic, const std::string &_msgType)
Constructor.
void SetLocallyAdvertised(bool _value)
Set whether this topic has been advertised from this process.
virtual ~Publication()
Destructor.
boost::shared_ptr< CallbackHelper > CallbackHelperPtr
boost shared pointer to transport::CallbackHelper
Definition CallbackHelper.hh:105
boost::shared_ptr< google::protobuf::Message > MessagePtr
Definition TransportTypes.hh:45
boost::shared_ptr< PublicationTransport > PublicationTransportPtr
Definition TransportTypes.hh:65
boost::shared_ptr< Publisher > PublisherPtr
Definition TransportTypes.hh:49
boost::shared_ptr< Node > NodePtr
Definition TransportTypes.hh:57
Forward declarations for the common classes.
Definition Animation.hh:27