Publisher.hh
00001 /* 00002 * Copyright 2011 Nate Koenig & Andrew Howard 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 * 00016 */ 00017 /* Desc: Handles pushing messages out on a named topic 00018 * Author: Nate Koenig 00019 */ 00020 00021 #ifndef PUBLISHER_HH 00022 #define PUBLISHER_HH 00023 00024 #include <boost/thread.hpp> 00025 #include <google/protobuf/message.h> 00026 #include "transport/TransportTypes.hh" 00027 00028 namespace gazebo 00029 { 00030 namespace transport 00031 { 00034 00036 class Publisher 00037 { 00039 public: Publisher(unsigned int _limit, bool _latch); 00040 00044 public: Publisher(const std::string &topic, const std::string &msg_type, 00045 unsigned int _limit, bool _latch); 00046 00048 public: virtual ~Publisher(); 00049 00050 public: bool HasConnections() const; 00051 00052 public: void SetPublication(PublicationPtr &_publication, int _i); 00053 00055 public: void Publish( const google::protobuf::Message &_message, 00056 bool _block = false) 00057 { this->PublishImpl(_message, _block); } 00058 00059 public: template< typename M> 00060 void Publish(M _message, bool _block=false) 00061 { this->PublishImpl(_message, _block); } 00062 00063 public: unsigned int GetOutgoingCount() const; 00064 00065 private: void PublishImpl(const google::protobuf::Message &_message, 00066 bool _block); 00067 00069 public: std::string GetTopic() const; 00070 00072 public: std::string GetMsgType() const; 00073 00075 public: void SendMessage(); 00076 public: bool GetLatching() const; 00077 00078 public: std::string GetPrevMsg() const; 00079 00081 private: void OnPublishComplete(); 00082 00083 private: std::string topic; 00084 private: std::string msgType; 00085 private: unsigned int queueLimit; 00086 private: std::list<google::protobuf::Message *> messages; 00087 private: boost::recursive_mutex *mutex; 00088 private: PublicationPtr publications[2]; 00089 00090 private: bool latch; 00091 private: std::string prevMsg; 00092 }; 00094 } 00095 } 00096 00097 #endif

1.7.5.1