All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Publisher.hh
Go to the documentation of this file.
1 /*
2  * Copyright 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 /* Desc: Handles pushing messages out on a named topic
18  * Author: Nate Koenig
19  */
20 
21 #ifndef _PUBLISHER_HH_
22 #define _PUBLISHER_HH_
23 
24 #include <google/protobuf/message.h>
25 #include <boost/thread.hpp>
26 #include <string>
27 #include <list>
28 
30 
31 namespace gazebo
32 {
33  namespace transport
34  {
37 
40  class Publisher
41  {
43  public: Publisher(const std::string &_topic, const std::string &_msgType,
44  unsigned int _limit, bool _latch) GAZEBO_DEPRECATED;
45 
52  public: Publisher(const std::string &_topic, const std::string &_msgType,
53  unsigned int _limit, double _hzRate);
54 
56  public: virtual ~Publisher();
57 
60  public: bool HasConnections() const;
61 
64  public: void WaitForConnection() const;
65 
69  public: void SetPublication(PublicationPtr &_publication, int _i);
70 
75  public: void Publish(const google::protobuf::Message &_message,
76  bool _block = false)
77  { this->PublishImpl(_message, _block); }
78 
83  public: template< typename M>
84  void Publish(M _message, bool _block = false)
85  { this->PublishImpl(_message, _block); }
86 
89  public: unsigned int GetOutgoingCount() const;
90 
91  private: void PublishImpl(const google::protobuf::Message &_message,
92  bool _block);
93 
96  public: std::string GetTopic() const;
97 
100  public: std::string GetMsgType() const;
101 
103  public: void SendMessage();
104 
106  public: bool GetLatching() const GAZEBO_DEPRECATED;
107 
110  public: std::string GetPrevMsg() const;
111 
113  private: void OnPublishComplete();
114 
116  private: std::string topic;
117 
119  private: std::string msgType;
120 
123  private: unsigned int queueLimit;
124 
127  private: double updatePeriod;
128 
131  private: bool queueLimitWarned;
132 
134  private: std::list<google::protobuf::Message *> messages;
135 
137  private: mutable boost::recursive_mutex mutex;
138 
141  private: PublicationPtr publications[2];
142 
144  private: google::protobuf::Message *prevMsg;
145 
146  private: common::Time currentTime;
147  private: common::Time prevPublishTime;
148  };
150  }
151 }
152 #endif