simple_filter.h
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 *********************************************************************/
34 
35 #ifndef MESSAGE_FILTERS_SIMPLE_FILTER_H
36 #define MESSAGE_FILTERS_SIMPLE_FILTER_H
37 
38 #include <boost/noncopyable.hpp>
39 
40 #include "connection.h"
41 #include "signal1.h"
42 #include <ros/message_event.h>
44 
45 #include <boost/bind.hpp>
46 
47 #include <string>
48 
49 namespace message_filters
50 {
51 
59 template<class M>
60 class SimpleFilter : public boost::noncopyable
61 {
62 public:
64  typedef boost::function<void(const MConstPtr&)> Callback;
66  typedef boost::function<void(const EventType&)> EventCallback;
67 
72  template<typename C>
73  Connection registerCallback(const C& callback)
74  {
75  typename CallbackHelper1<M>::Ptr helper = signal_.addCallback(Callback(callback));
76  return Connection(boost::bind(&Signal::removeCallback, &signal_, helper));
77  }
78 
83  template<typename P>
84  Connection registerCallback(const boost::function<void(P)>& callback)
85  {
86  return Connection(boost::bind(&Signal::removeCallback, &signal_, signal_.addCallback(callback)));
87  }
88 
93  template<typename P>
94  Connection registerCallback(void(*callback)(P))
95  {
96  typename CallbackHelper1<M>::Ptr helper = signal_.template addCallback<P>(boost::bind(callback, boost::placeholders::_1));
97  return Connection(boost::bind(&Signal::removeCallback, &signal_, helper));
98  }
99 
104  template<typename T, typename P>
105  Connection registerCallback(void(T::*callback)(P), T* t)
106  {
107  typename CallbackHelper1<M>::Ptr helper = signal_.template addCallback<P>(boost::bind(callback, t, boost::placeholders::_1));
108  return Connection(boost::bind(&Signal::removeCallback, &signal_, helper));
109  }
110 
114  void setName(const std::string& name) { name_ = name; }
118  const std::string& getName() { return name_; }
119 
120 protected:
124  void signalMessage(const MConstPtr& msg)
125  {
126  ros::MessageEvent<M const> event(msg);
127 
128  signal_.call(event);
129  }
130 
134  void signalMessage(const ros::MessageEvent<M const>& event)
135  {
136  signal_.call(event);
137  }
138 
139 private:
140  typedef Signal1<M> Signal;
141 
142  Signal signal_;
143 
144  std::string name_;
145 };
146 
147 }
148 
149 #endif
150 
message_filters::SimpleFilter::getName
const std::string & getName()
Get the name of this filter. For debugging use.
Definition: simple_filter.h:182
boost::shared_ptr
message_filters::Signal1::call
void call(const ros::MessageEvent< M const > &event)
Definition: signal1.h:142
message_filters::SimpleFilter::MConstPtr
boost::shared_ptr< M const > MConstPtr
Definition: simple_filter.h:127
message_filters::SimpleFilter::Signal
Signal1< M > Signal
Definition: simple_filter.h:204
subscription_callback_helper.h
signal1.h
message_filters::SimpleFilter::EventCallback
boost::function< void(const EventType &)> EventCallback
Definition: simple_filter.h:130
message_filters::CallbackHelper1::Ptr
boost::shared_ptr< CallbackHelper1< M > > Ptr
Definition: signal1.h:121
message_filters::SimpleFilter::name_
std::string name_
Definition: simple_filter.h:208
message_filters::Signal1::addCallback
CallbackHelper1Ptr addCallback(const boost::function< void(P)> &callback)
Definition: signal1.h:123
message_filters::SimpleFilter::signal_
Signal signal_
Definition: simple_filter.h:206
connection.h
message_filters::Signal1
Definition: signal1.h:116
message_filters::Signal1::removeCallback
void removeCallback(const CallbackHelper1Ptr &helper)
Definition: signal1.h:132
message_filters::SimpleFilter::setName
void setName(const std::string &name)
Set the name of this filter. For debugging use.
Definition: simple_filter.h:178
message_filters::SimpleFilter::Callback
boost::function< void(const MConstPtr &)> Callback
Definition: simple_filter.h:128
message_filters::SimpleFilter::registerCallback
Connection registerCallback(const C &callback)
Register a callback to be called when this filter has passed.
Definition: simple_filter.h:137
message_filters
Definition: cache.h:47
message_filters::SimpleFilter::signalMessage
void signalMessage(const MConstPtr &msg)
Call all registered callbacks, passing them the specified message.
Definition: simple_filter.h:188
message_event.h
ros::MessageEvent
message_filters::SimpleFilter::EventType
ros::MessageEvent< M const > EventType
Definition: simple_filter.h:129


message_filters
Author(s): Josh Faust, Vijay Pradeep, Dirk Thomas
autogenerated on Sat Jan 2 2021 04:00:11