SubscribeOptions.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2015 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 #include "gazebo/util/system.hh"
25 
26 namespace gazebo
27 {
28  namespace transport
29  {
32 
36  {
38  public: SubscribeOptions()
39  : latching(false)
40  {}
41 
47  public: template<class M>
48  void Init(const std::string &_topic, NodePtr _node,
49  bool _latching)
50  {
51  google::protobuf::Message *msg = NULL;
52  M msgtype;
53  msg = dynamic_cast<google::protobuf::Message *>(&msgtype);
54  if (!msg)
55  gzthrow("Subscribe requires a google protobuf type");
56 
57  this->node = _node;
58  this->topic = _topic;
59  this->msgType = msg->GetTypeName();
60  this->latching = _latching;
61  }
62 
69  public: void Init(const std::string &_topic, NodePtr _node,
70  bool _latching)
71  {
72  this->node = _node;
73  this->topic = _topic;
74  this->msgType = "raw";
75  this->latching = _latching;
76  }
77 
80  public: NodePtr GetNode() const
81  {
82  return this->node;
83  }
84 
87  public: std::string GetTopic() const
88  {
89  return this->topic;
90  }
91 
94  public: std::string GetMsgType() const
95  {
96  return this->msgType;
97  }
98 
101  public: bool GetLatching() const
102  {
103  return this->latching;
104  }
105 
106  private: std::string topic;
107  private: std::string msgType;
108  private: NodePtr node;
109  private: bool latching;
110  };
112  }
113 }
114 
115 #endif
116 
117 
Options for a subscription.
Definition: SubscribeOptions.hh:35
#define gzthrow(msg)
This macro logs an error to the throw stream and throws an exception that contains the file name and ...
Definition: Exception.hh:39
void Init(const std::string &_topic, NodePtr _node, bool _latching)
Initialize the options.
Definition: SubscribeOptions.hh:48
bool GetLatching() const
Are we latching?
Definition: SubscribeOptions.hh:101
std::string GetTopic() const
Get the topic we're subscribed to.
Definition: SubscribeOptions.hh:87
NodePtr GetNode() const
Get the node we're subscribed to.
Definition: SubscribeOptions.hh:80
#define NULL
Definition: CommonTypes.hh:30
boost::shared_ptr< Node > NodePtr
Definition: TransportTypes.hh:57
SubscribeOptions()
Constructor.
Definition: SubscribeOptions.hh:38
std::string GetMsgType() const
Get the type of the topic we're subscribed to.
Definition: SubscribeOptions.hh:94
#define GAZEBO_VISIBLE
Use to represent "symbol visible" if supported.
Definition: system.hh:48
void Init(const std::string &_topic, NodePtr _node, bool _latching)
Initialize the options.
Definition: SubscribeOptions.hh:69