topic.h
Go to the documentation of this file.
1 #include "sick_scan/sick_scan_base.h" /* Base definitions included in all header files, added by add_sick_scan_base_header.py. Do not edit this line. */
2 /*
3  * Software License Agreement (BSD License)
4  *
5  * Copyright (c) 2009, Willow Garage, Inc.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above
15  * copyright notice, this list of conditions and the following
16  * disclaimer in the documentation and/or other materials provided
17  * with the distribution.
18  * * Neither the name of Willow Garage, Inc. nor the names of its
19  * contributors may be used to endorse or promote products derived
20  * from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  */
35 
36 #ifndef ROSCPP_TOPIC_H
37 #define ROSCPP_TOPIC_H
38 
39 #include "common.h"
40 #include "node_handle.h"
41 #include <memory>
42 
43 namespace roswrap
44 {
45 namespace topic
46 {
47 
51 ROSCPP_DECL void waitForMessageImpl(SubscribeOptions& ops, const std::function<bool(void)>& ready_pred, NodeHandle& nh, ros::Duration timeout);
52 
53 template<class M>
55 {
56 public:
57  typedef std::shared_ptr<M const> MConstPtr;
58  void callback(const MConstPtr& message)
59  {
60  message_ = message;
61  }
62 
63  bool hasMessage()
64  {
65  return static_cast<bool>(message_);
66  }
67 
69  {
70  return message_;
71  }
72 
73 private:
75 };
76 
86 template<class M>
87 std::shared_ptr<M const> waitForMessage(const std::string& topic, NodeHandle& nh, ros::Duration timeout)
88 {
89  SubscribeHelper<M> helper;
90  SubscribeOptions ops;
91  ops.template init<M>(topic, 1, std::bind(&SubscribeHelper<M>::callback, &helper, std::placeholders::_1));
92 
93  waitForMessageImpl(ops, std::bind(&SubscribeHelper<M>::hasMessage, &helper), nh, timeout);
94 
95  return helper.getMessage();
96 }
97 
105 template<class M>
106 std::shared_ptr<M const> waitForMessage(const std::string& topic)
107 {
108  ros::NodeHandle nh;
109  return waitForMessage<M>(topic, nh, ros::Duration());
110 }
111 
120 template<class M>
121 std::shared_ptr<M const> waitForMessage(const std::string& topic, ros::Duration timeout)
122 {
123  ros::NodeHandle nh;
124  return waitForMessage<M>(topic, nh, timeout);
125 }
126 
135 template<class M>
136 std::shared_ptr<M const> waitForMessage(const std::string& topic, ros::NodeHandle& nh)
137 {
138  return waitForMessage<M>(topic, nh, ros::Duration());
139 }
140 
141 } // namespace topic
142 } // namespace roswrap
143 
144 #endif // ROSCPP_TOPIC_H
roswrap::topic::SubscribeHelper::hasMessage
bool hasMessage()
Definition: topic.h:63
roswrap::topic::waitForMessageImpl
ROSCPP_DECL void waitForMessageImpl(SubscribeOptions &ops, const std::function< bool(void)> &ready_pred, NodeHandle &nh, ros::Duration timeout)
Internal method, do not use.
message
def message(msg, *args, **kwargs)
roswrap::topic::SubscribeHelper
Definition: topic.h:54
roswrap::topic::waitForMessage
std::shared_ptr< M const > waitForMessage(const std::string &topic, NodeHandle &nh, ros::Duration timeout)
Wait for a single message to arrive on a topic, with timeout.
Definition: topic.h:87
roswrap::topic::SubscribeHelper::callback
void callback(const MConstPtr &message)
Definition: topic.h:58
roswrap::topic::SubscribeHelper::message_
MConstPtr message_
Definition: topic.h:74
roswrap
Definition: param_modi.cpp:41
roswrap::NodeHandle
roscpp's interface for creating subscribers, publishers, etc.
Definition: node_handle.h:87
common.h
sick_scan_base.h
sick_generic_device_finder.timeout
timeout
Definition: sick_generic_device_finder.py:113
ROSCPP_DECL
#define ROSCPP_DECL
Definition: roswrap/src/cfgsimu/sick_scan/ros/common.h:63
roswrap::SubscribeOptions
Encapsulates all options available for creating a Subscriber.
Definition: subscribe_options.h:44
ros::Duration
node_handle.h
roswrap::topic::SubscribeHelper::MConstPtr
std::shared_ptr< M const > MConstPtr
Definition: topic.h:57
ros::NodeHandle
roswrap::topic::SubscribeHelper::getMessage
MConstPtr getMessage()
Definition: topic.h:68


sick_scan_xd
Author(s): Michael Lehning , Jochen Sprickerhof , Martin Günther
autogenerated on Fri Oct 25 2024 02:47:12