All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SubscribeOptions.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 #ifndef _SUBSCRIBEOPTIONS_HH_
18 #define _SUBSCRIBEOPTIONS_HH_
19 
20 #include <boost/function.hpp>
21 #include <boost/shared_ptr.hpp>
22 #include <string>
24 
25 namespace gazebo
26 {
27  namespace transport
28  {
31 
35  {
37  public: SubscribeOptions()
38  : latching(false)
39  {}
40 
46  public: template<class M>
47  void Init(const std::string &_topic, NodePtr _node,
48  bool _latching)
49  {
50  google::protobuf::Message *msg = NULL;
51  M msgtype;
52  msg = dynamic_cast<google::protobuf::Message *>(&msgtype);
53  if (!msg)
54  gzthrow("Subscribe requires a google protobuf type");
55 
56  this->node = _node;
57  this->topic = _topic;
58  this->msgType = msg->GetTypeName();
59  this->latching = _latching;
60  }
61 
68  public: void Init(const std::string &_topic, NodePtr _node,
69  bool _latching)
70  {
71  this->node = _node;
72  this->topic = _topic;
73  this->msgType = "raw";
74  this->latching = _latching;
75  }
76 
79  public: NodePtr GetNode() const
80  {
81  return this->node;
82  }
83 
86  public: std::string GetTopic() const
87  {
88  return this->topic;
89  }
90 
93  public: std::string GetMsgType() const
94  {
95  return this->msgType;
96  }
97 
100  public: bool GetLatching() const
101  {
102  return this->latching;
103  }
104 
105  private: std::string topic;
106  private: std::string msgType;
107  private: NodePtr node;
108  private: bool latching;
109  };
111  }
112 }
113 
114 #endif
115 
116