advertisement_checker.cpp
Go to the documentation of this file.
1 /*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2008, Willow Garage, Inc.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
17 * * Neither the name of the Willow Garage nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 *********************************************************************/
35 #include <boost/foreach.hpp>
36 
37 namespace image_proc {
38 
40  const std::string& name)
41  : nh_(nh),
42  name_(name)
43 {
44 }
45 
46 void AdvertisementChecker::timerCb()
47 {
48  ros::master::V_TopicInfo topic_info;
49  if (!ros::master::getTopics(topic_info)) return;
50 
51  ros::V_string::iterator topic_it = topics_.begin();
52  while (topic_it != topics_.end())
53  {
54  // Should use std::find_if
55  bool found = false;
56  ros::master::V_TopicInfo::iterator info_it = topic_info.begin();
57  while (!found && info_it != topic_info.end())
58  {
59  found = (*topic_it == info_it->name);
60  ++info_it;
61  }
62  if (found)
63  topic_it = topics_.erase(topic_it);
64  else
65  {
66  ROS_WARN_NAMED(name_, "The input topic '%s' is not yet advertised", topic_it->c_str());
67  ++topic_it;
68  }
69  }
70 
71  if (topics_.empty())
72  stop();
73 }
74 
75 void AdvertisementChecker::start(const ros::V_string& topics, double duration)
76 {
77  topics_.clear();
78  BOOST_FOREACH(const std::string& topic, topics)
79  topics_.push_back(nh_.resolveName(topic));
80 
81  ros::NodeHandle nh;
82  timer_ = nh.createWallTimer(ros::WallDuration(duration),
83  boost::bind(&AdvertisementChecker::timerCb, this));
84  timerCb();
85 }
86 
87 void AdvertisementChecker::stop()
88 {
89  timer_.stop();
90 }
91 
92 } // namespace image_proc
ros::master::getTopics
ROSCPP_DECL bool getTopics(V_TopicInfo &topics)
image_proc::AdvertisementChecker::AdvertisementChecker
AdvertisementChecker(const ros::NodeHandle &nh=ros::NodeHandle(), const std::string &name=std::string())
Definition: advertisement_checker.cpp:71
ros::master::V_TopicInfo
std::vector< TopicInfo > V_TopicInfo
image_proc
Definition: advertisement_checker.h:39
ROS_WARN_NAMED
#define ROS_WARN_NAMED(name,...)
ros::V_string
std::vector< std::string > V_string
ros::WallDuration
advertisement_checker.h
ros::NodeHandle::createWallTimer
WallTimer createWallTimer(WallDuration period, const WallTimerCallback &callback, bool oneshot=false, bool autostart=true) const
ros::NodeHandle


image_proc
Author(s): Patrick Mihelich, Kurt Konolige, Jeremy Leibs
autogenerated on Wed Jan 24 2024 03:57:17