##

Publication.hh
Go to the documentation of this file.
/*
* Copyright (C) 2012 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef _PUBLICATION_HH_
#define _PUBLICATION_HH_
#include <utility>
#include <boost/function.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/thread/mutex.hpp>
#include <list>
#include <string>
#include <vector>
#include <map>
#include "gazebo/transport/CallbackHelper.hh"
#include "gazebo/transport/TransportTypes.hh"
#include "gazebo/transport/PublicationTransport.hh"
#include "gazebo/util/system.hh"
namespace gazebo
{
namespace transport
{
class GZ_TRANSPORT_VISIBLE Publication
{
public: Publication(const std::string &_topic,
const std::string &_msgType);
public: virtual ~Publication();
public: std::string GetMsgType() const;
public: void AddSubscription(const CallbackHelperPtr _callback);
public: void AddSubscription(const NodePtr &_node);
public: void RemoveSubscription(const NodePtr &_node);
public: void RemoveSubscription(const std::string &_host,
unsigned int _port);
public: void RemoveTransport(const std::string &_host, unsigned
int _port);
public: unsigned int GetTransportCount() const;
public: unsigned int GetCallbackCount() const;
public: unsigned int PublisherCount() const;
public: unsigned int GetNodeCount() const;
public: unsigned int GetRemoteSubscriptionCount();
public: bool GetLocallyAdvertised() const;
public: void SetLocallyAdvertised(bool _value);
public: void LocalPublish(const std::string &_data);
public: int Publish(MessagePtr _msg,
boost::function<void(uint32_t)> _cb,
uint32_t _id);
public: void RemovePublisher(PublisherPtr _pub);
public: bool RemovePublisher(const uint32_t id);
public: void SetPrevMsg(uint32_t _pubId, MessagePtr _msg);
public: MessagePtr GetPrevMsg(uint32_t _pubId);
public: void ClearPrevMsgs();
public: void AddTransport(const PublicationTransportPtr &_publink);
public: bool HasTransport(const std::string &_host, unsigned int _port);
public: void AddPublisher(PublisherPtr _pub);
private: void RemoveNodes();
private: unsigned int id;
private: static unsigned int idCounter;
private: std::string topic;
private: std::string msgType;
private: std::list<CallbackHelperPtr> callbacks;
private: std::list<NodePtr> nodes;
private: std::list<unsigned int> removeNodes;
private: std::list<std::pair<std::string, unsigned int> > removeCallbacks;
private: std::list<PublicationTransportPtr> transports;
private: std::vector<PublisherPtr> publishers;
private: bool locallyAdvertised;
private: mutable boost::mutex nodeMutex;
private: mutable boost::mutex callbackMutex;
private: mutable boost::mutex nodeRemoveMutex;
private: std::map<uint32_t, MessagePtr> prevMsgs;
};
}
}
#endif
gazebo::transport::Publication::RemovePublisher
void RemovePublisher(PublisherPtr _pub)
Remove a publisher.
gazebo::transport::Publication::Publication
Publication(const std::string &_topic, const std::string &_msgType)
Constructor.
gazebo
Forward declarations for the common classes.
Definition: Animation.hh:26
gazebo::transport::MessagePtr
boost::shared_ptr< google::protobuf::Message > MessagePtr
Definition: TransportTypes.hh:45
gazebo::transport::Publication::GetPrevMsg
MessagePtr GetPrevMsg(uint32_t _pubId)
Get a previous message for a publisher.
gazebo::transport::Publication::GetNodeCount
unsigned int GetNodeCount() const
Get the number of nodes.
gazebo::transport::Publication::GetCallbackCount
unsigned int GetCallbackCount() const
Get the number of callbacks.
gazebo::transport::Publication::SetLocallyAdvertised
void SetLocallyAdvertised(bool _value)
Set whether this topic has been advertised from this process.
gazebo::transport::PublisherPtr
boost::shared_ptr< Publisher > PublisherPtr
Definition: TransportTypes.hh:49
TransportTypes.hh
Forward declarations for transport.
gazebo::transport::Publication::~Publication
virtual ~Publication()
Destructor.
system.hh
CallbackHelper.hh
gazebo::transport::NodePtr
boost::shared_ptr< Node > NodePtr
Definition: TransportTypes.hh:57
gazebo::transport::Publication::ClearPrevMsgs
void ClearPrevMsgs()
Clear all previous messages for a publisher.
gazebo::transport::Publication::AddTransport
void AddTransport(const PublicationTransportPtr &_publink)
Add a transport.
gazebo::transport::Publication::SetPrevMsg
void SetPrevMsg(uint32_t _pubId, MessagePtr _msg)
Set the previous message for a publisher.
PublicationTransport.hh
gazebo::transport::Publication::GetLocallyAdvertised
bool GetLocallyAdvertised() const
Was the topic has been advertised from this process?
gazebo::transport::PublicationTransportPtr
boost::shared_ptr< PublicationTransport > PublicationTransportPtr
Definition: TransportTypes.hh:65
gazebo::transport::Publication::RemoveSubscription
void RemoveSubscription(const NodePtr &_node)
Unsubscribe a node from our topic.
gazebo::transport::Publication::GetTransportCount
unsigned int GetTransportCount() const
Get the number of transports.
gazebo::transport::Publication::Publish
int Publish(MessagePtr _msg, boost::function< void(uint32_t)> _cb, uint32_t _id)
Publish data to remote subscribers.
gazebo::transport::Publication::GetMsgType
std::string GetMsgType() const
Get the type of message.
gazebo::transport::Publication::AddPublisher
void AddPublisher(PublisherPtr _pub)
Add a publisher.
transport
transport
Definition: ConnectionManager.hh:35
gazebo::transport::Publication::AddSubscription
void AddSubscription(const CallbackHelperPtr _callback)
Subscribe a callback to our topic.
gazebo::transport::Publication::LocalPublish
void LocalPublish(const std::string &_data)
Publish data to local subscribers (skip serialization)
gazebo::transport::Publication::RemoveTransport
void RemoveTransport(const std::string &_host, unsigned int _port)
Remove a transport.
gazebo::transport::CallbackHelperPtr
boost::shared_ptr< CallbackHelper > CallbackHelperPtr
boost shared pointer to transport::CallbackHelper
Definition: CallbackHelper.hh:105
gazebo::transport::Publication::PublisherCount
unsigned int PublisherCount() const
Get the number of publishers.
gazebo::transport::Publication::GetRemoteSubscriptionCount
unsigned int GetRemoteSubscriptionCount()
Get the number of remote subscriptions.
gazebo::transport::Publication
A publication for a topic. This facilitates transport of messages.
Definition: Publication.hh:45
gazebo::transport::Publication::HasTransport
bool HasTransport(const std::string &_host, unsigned int _port)
Does a given transport exist?