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 
50  public: Publisher(const std::string &_topic, const std::string &_msgType,
51  unsigned int _limit);
52 
54  public: virtual ~Publisher();
55 
58  public: bool HasConnections() const;
59 
62  public: void WaitForConnection() const;
63 
67  public: void SetPublication(PublicationPtr &_publication, int _i);
68 
73  public: void Publish(const google::protobuf::Message &_message,
74  bool _block = false)
75  { this->PublishImpl(_message, _block); }
76 
81  public: template< typename M>
82  void Publish(M _message, bool _block = false)
83  { this->PublishImpl(_message, _block); }
84 
87  public: unsigned int GetOutgoingCount() const;
88 
89  private: void PublishImpl(const google::protobuf::Message &_message,
90  bool _block);
91 
94  public: std::string GetTopic() const;
95 
98  public: std::string GetMsgType() const;
99 
101  public: void SendMessage();
102 
104  public: bool GetLatching() const GAZEBO_DEPRECATED;
105 
108  public: std::string GetPrevMsg() const;
109 
111  private: void OnPublishComplete();
112 
113  private: std::string topic;
114  private: std::string msgType;
115  private: unsigned int queueLimit;
116  private: bool queueLimitWarned;
117  private: std::list<google::protobuf::Message *> messages;
118  private: mutable boost::recursive_mutex mutex;
119  private: PublicationPtr publications[2];
120 
121  private: google::protobuf::Message *prevMsg;
122  };
124  }
125 }
126 
127 #endif
128 
129