##

Publisher.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.
*
*/
/* Desc: Handles pushing messages out on a named topic
* Author: Nate Koenig
*/
#ifndef GAZEBO_TRANSPORT_PUBLISHER_HH_
#define GAZEBO_TRANSPORT_PUBLISHER_HH_
#include <google/protobuf/message.h>
#include <boost/thread.hpp>
#include <string>
#include <list>
#include <map>
#include "gazebo/common/Time.hh"
#include "gazebo/transport/TransportTypes.hh"
#include "gazebo/util/system.hh"
namespace gazebo
{
namespace transport
{
class GZ_TRANSPORT_VISIBLE Publisher
{
public: Publisher(const std::string &_topic, const std::string &_msgType,
unsigned int _limit, double _hzRate);
public: virtual ~Publisher();
public: bool HasConnections() const;
public: void WaitForConnection() const;
public: bool WaitForConnection(const common::Time &_timeout) const;
public: void SetPublication(PublicationPtr _publication);
public: void Publish(const google::protobuf::Message &_message,
bool _block = false)
{ this->PublishImpl(_message, _block); }
public: template< typename M>
void Publish(M _message, bool _block = false)
{ this->PublishImpl(_message, _block); }
public: unsigned int GetOutgoingCount() const;
public: std::string GetTopic() const;
public: std::string GetMsgType() const;
public: void SendMessage();
public: void SetNode(NodePtr _node);
public: std::string GetPrevMsg() const;
public: MessagePtr GetPrevMsgPtr() const;
public: void Fini();
public: uint32_t Id() const;
private: void PublishImpl(const google::protobuf::Message &_message,
bool _block);
private: void OnPublishComplete(uint32_t _id);
private: std::string topic;
private: std::string msgType;
private: unsigned int queueLimit;
private: double updatePeriod;
private: bool queueLimitWarned;
private: std::list<MessagePtr> messages;
private: mutable boost::mutex mutex;
private: PublicationPtr publication;
private: NodePtr node;
private: common::Time currentTime;
private: common::Time prevPublishTime;
private: uint32_t pubId;
private: std::map<uint32_t, int> pubIds;
private: uint32_t id;
private: static uint32_t idCounter;
};
}
}
#endif
gazebo::transport::Publisher::Fini
void Fini()
Finalize the publisher.
Time.hh
gazebo::transport::Publisher::Id
uint32_t Id() const
Get the id of this publisher.
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::common::Time
A Time class, can be used to hold wall- or sim-time. stored as sec and nano-sec.
Definition: Time.hh:47
TransportTypes.hh
Forward declarations for transport.
gazebo::transport::Publisher::Publish
void Publish(M _message, bool _block=false)
Publish an arbitrary message on the topic.
Definition: Publisher.hh:89
system.hh
gazebo::transport::PublicationPtr
boost::shared_ptr< Publication > PublicationPtr
Definition: TransportTypes.hh:61
gazebo::transport::NodePtr
boost::shared_ptr< Node > NodePtr
Definition: TransportTypes.hh:57
gazebo::transport::Publisher::SetNode
void SetNode(NodePtr _node)
Set our containing node.
gazebo::transport::Publisher::SetPublication
void SetPublication(PublicationPtr _publication)
Set the publication object for a particular publication.
gazebo::transport::Publisher::HasConnections
bool HasConnections() const
Are there any connections?
gazebo::transport::Publisher::GetTopic
std::string GetTopic() const
Get the topic name.
gazebo::transport::Publisher::GetMsgType
std::string GetMsgType() const
Get the message type.
gazebo::transport::Publisher::Publisher
Publisher(const std::string &_topic, const std::string &_msgType, unsigned int _limit, double _hzRate)
Constructor.
gazebo::transport::Publisher
A publisher of messages on a topic.
Definition: Publisher.hh:43
gazebo::transport::Publisher::~Publisher
virtual ~Publisher()
Destructor.
gazebo::transport::Publisher::GetPrevMsg
std::string GetPrevMsg() const
Get the previously published message.
gazebo::transport::Publisher::GetPrevMsgPtr
MessagePtr GetPrevMsgPtr() const
Get the previously published message.
transport
transport
Definition: ConnectionManager.hh:35
gazebo::transport::Publisher::Publish
void Publish(const google::protobuf::Message &_message, bool _block=false)
Publish a protobuf message on the topic.
Definition: Publisher.hh:80
gazebo::transport::Publisher::SendMessage
void SendMessage()
Send latest message over the wire. For internal use only.
gazebo::transport::Publisher::WaitForConnection
void WaitForConnection() const
Block until a connection has been established with this publisher.
gazebo::transport::Publisher::GetOutgoingCount
unsigned int GetOutgoingCount() const
Get the number of outgoing messages.