signal9.h
Go to the documentation of this file.
1 /*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2010, 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_SIGNAL9_H
36 #define MESSAGE_FILTERS_SIGNAL9_H
37 
38 #include <boost/noncopyable.hpp>
39 
40 #include "connection.h"
41 #include "null_types.h"
42 #include <ros/message_event.h>
43 #include <ros/parameter_adapter.h>
44 
45 #include <boost/bind.hpp>
46 #include <boost/thread/mutex.hpp>
47 
48 namespace message_filters
49 {
51 
52 template<typename M0, typename M1, typename M2, typename M3, typename M4, typename M5, typename M6, typename M7, typename M8>
54 {
55 public:
65 
66  virtual ~CallbackHelper9() {}
67 
68  virtual void call(bool nonconst_force_copy, const M0Event& e0, const M1Event& e1, const M2Event& e2, const M3Event& e3,
69  const M4Event& e4, const M5Event& e5, const M6Event& e6, const M7Event& e7, const M8Event& e8) = 0;
70 
72 };
73 
74 template<typename P0, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8>
76  public CallbackHelper9<typename ParameterAdapter<P0>::Message,
77  typename ParameterAdapter<P1>::Message,
78  typename ParameterAdapter<P2>::Message,
79  typename ParameterAdapter<P3>::Message,
80  typename ParameterAdapter<P4>::Message,
81  typename ParameterAdapter<P5>::Message,
82  typename ParameterAdapter<P6>::Message,
83  typename ParameterAdapter<P7>::Message,
84  typename ParameterAdapter<P8>::Message>
85 {
86 private:
96  typedef typename A0::Event M0Event;
97  typedef typename A1::Event M1Event;
98  typedef typename A2::Event M2Event;
99  typedef typename A3::Event M3Event;
100  typedef typename A4::Event M4Event;
101  typedef typename A5::Event M5Event;
102  typedef typename A6::Event M6Event;
103  typedef typename A7::Event M7Event;
104  typedef typename A8::Event M8Event;
105 
106 public:
107  typedef boost::function<void(typename A0::Parameter, typename A1::Parameter, typename A2::Parameter,
108  typename A3::Parameter, typename A4::Parameter, typename A5::Parameter,
109  typename A6::Parameter, typename A7::Parameter, typename A8::Parameter)> Callback;
110 
111  CallbackHelper9T(const Callback& cb)
112  : callback_(cb)
113  {
114  }
115 
116  virtual void call(bool nonconst_force_copy, const M0Event& e0, const M1Event& e1, const M2Event& e2, const M3Event& e3,
117  const M4Event& e4, const M5Event& e5, const M6Event& e6, const M7Event& e7, const M8Event& e8)
118  {
119  M0Event my_e0(e0, nonconst_force_copy || e0.nonConstWillCopy());
120  M1Event my_e1(e1, nonconst_force_copy || e0.nonConstWillCopy());
121  M2Event my_e2(e2, nonconst_force_copy || e0.nonConstWillCopy());
122  M3Event my_e3(e3, nonconst_force_copy || e0.nonConstWillCopy());
123  M4Event my_e4(e4, nonconst_force_copy || e0.nonConstWillCopy());
124  M5Event my_e5(e5, nonconst_force_copy || e0.nonConstWillCopy());
125  M6Event my_e6(e6, nonconst_force_copy || e0.nonConstWillCopy());
126  M7Event my_e7(e7, nonconst_force_copy || e0.nonConstWillCopy());
127  M8Event my_e8(e8, nonconst_force_copy || e0.nonConstWillCopy());
128  callback_(A0::getParameter(e0),
129  A1::getParameter(e1),
130  A2::getParameter(e2),
131  A3::getParameter(e3),
132  A4::getParameter(e4),
133  A5::getParameter(e5),
134  A6::getParameter(e6),
135  A7::getParameter(e7),
136  A8::getParameter(e8));
137  }
138 
139 private:
140  Callback callback_;
141 };
142 
143 template<typename M0, typename M1, typename M2, typename M3, typename M4, typename M5, typename M6, typename M7, typename M8>
144 class Signal9
145 {
147  typedef std::vector<CallbackHelper9Ptr> V_CallbackHelper9;
148 
149 public:
169 
170  template<typename P0, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8>
171  Connection addCallback(const boost::function<void(P0, P1, P2, P3, P4, P5, P6, P7, P8)>& callback)
172  {
174 
175  boost::mutex::scoped_lock lock(mutex_);
176  callbacks_.push_back(CallbackHelper9Ptr(helper));
177  return Connection(boost::bind(&Signal9::removeCallback, this, callbacks_.back()));
178  }
179 
180  template<typename P0, typename P1>
181  Connection addCallback(void(*callback)(P0, P1))
182  {
183  return addCallback(boost::function<void(P0, P1, NullP, NullP, NullP, NullP, NullP, NullP, NullP)>(boost::bind(callback, _1, _2)));
184  }
185 
186  template<typename P0, typename P1, typename P2>
187  Connection addCallback(void(*callback)(P0, P1, P2))
188  {
189  return addCallback(boost::function<void(P0, P1, P2, NullP, NullP, NullP, NullP, NullP, NullP)>(boost::bind(callback, _1, _2, _3)));
190  }
191 
192  template<typename P0, typename P1, typename P2, typename P3>
193  Connection addCallback(void(*callback)(P0, P1, P2, P3))
194  {
195  return addCallback(boost::function<void(P0, P1, P2, P3, NullP, NullP, NullP, NullP, NullP)>(boost::bind(callback, _1, _2, _3, _4)));
196  }
197 
198  template<typename P0, typename P1, typename P2, typename P3, typename P4>
199  Connection addCallback(void(*callback)(P0, P1, P2, P3, P4))
200  {
201  return addCallback(boost::function<void(P0, P1, P2, P3, P4, NullP, NullP, NullP, NullP)>(boost::bind(callback, _1, _2, _3, _4, _5)));
202  }
203 
204  template<typename P0, typename P1, typename P2, typename P3, typename P4, typename P5>
205  Connection addCallback(void(*callback)(P0, P1, P2, P3, P4, P5))
206  {
207  return addCallback(boost::function<void(P0, P1, P2, P3, P4, P5, NullP, NullP, NullP)>(boost::bind(callback, _1, _2, _3, _4, _5, _6)));
208  }
209 
210  template<typename P0, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6>
211  Connection addCallback(void(*callback)(P0, P1, P2, P3, P4, P5, P6))
212  {
213  return addCallback(boost::function<void(P0, P1, P2, P3, P4, P5, P6, NullP, NullP)>(boost::bind(callback, _1, _2, _3, _4, _5, _6, _7)));
214  }
215 
216  template<typename P0, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7>
217  Connection addCallback(void(*callback)(P0, P1, P2, P3, P4, P5, P6, P7))
218  {
219  return addCallback(boost::function<void(P0, P1, P2, P3, P4, P5, P6, P7, NullP)>(boost::bind(callback, _1, _2, _3, _4, _5, _6, _7, _8)));
220  }
221 
222  template<typename P0, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8>
223  Connection addCallback(void(*callback)(P0, P1, P2, P3, P4, P5, P6, P7, P8))
224  {
225  return addCallback(boost::function<void(P0, P1, P2, P3, P4, P5, P6, P7, P8)>(boost::bind(callback, _1, _2, _3, _4, _5, _6, _7, _8, _9)));
226  }
227 
228  template<typename T, typename P0, typename P1>
229  Connection addCallback(void(T::*callback)(P0, P1), T* t)
230  {
231  return addCallback(boost::function<void(P0, P1, NullP, NullP, NullP, NullP, NullP, NullP, NullP)>(boost::bind(callback, t, _1, _2)));
232  }
233 
234  template<typename T, typename P0, typename P1, typename P2>
235  Connection addCallback(void(T::*callback)(P0, P1, P2), T* t)
236  {
237  return addCallback(boost::function<void(P0, P1, P2, NullP, NullP, NullP, NullP, NullP, NullP)>(boost::bind(callback, t, _1, _2, _3)));
238  }
239 
240  template<typename T, typename P0, typename P1, typename P2, typename P3>
241  Connection addCallback(void(T::*callback)(P0, P1, P2, P3), T* t)
242  {
243  return addCallback(boost::function<void(P0, P1, P2, P3, NullP, NullP, NullP, NullP, NullP)>(boost::bind(callback, t, _1, _2, _3, _4)));
244  }
245 
246  template<typename T, typename P0, typename P1, typename P2, typename P3, typename P4>
247  Connection addCallback(void(T::*callback)(P0, P1, P2, P3, P4), T* t)
248  {
249  return addCallback(boost::function<void(P0, P1, P2, P3, P4, NullP, NullP, NullP, NullP)>(boost::bind(callback, t, _1, _2, _3, _4, _5)));
250  }
251 
252  template<typename T, typename P0, typename P1, typename P2, typename P3, typename P4, typename P5>
253  Connection addCallback(void(T::*callback)(P0, P1, P2, P3, P4, P5), T* t)
254  {
255  return addCallback(boost::function<void(P0, P1, P2, P3, P4, P5, NullP, NullP, NullP)>(boost::bind(callback, t, _1, _2, _3, _4, _5, _6)));
256  }
257 
258  template<typename T, typename P0, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6>
259  Connection addCallback(void(T::*callback)(P0, P1, P2, P3, P4, P5, P6), T* t)
260  {
261  return addCallback(boost::function<void(P0, P1, P2, P3, P4, P5, P6, NullP, NullP)>(boost::bind(callback, t, _1, _2, _3, _4, _5, _6, _7)));
262  }
263 
264  template<typename T, typename P0, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7>
265  Connection addCallback(void(T::*callback)(P0, P1, P2, P3, P4, P5, P6, P7), T* t)
266  {
267  return addCallback(boost::function<void(P0, P1, P2, P3, P4, P5, P6, P7, NullP)>(boost::bind(callback, t, _1, _2, _3, _4, _5, _6, _7, _8)));
268  }
269 
270  template<typename C>
271  Connection addCallback( C& callback)
272  {
273  return addCallback<const M0ConstPtr&,
274  const M1ConstPtr&,
275  const M2ConstPtr&,
276  const M3ConstPtr&,
277  const M4ConstPtr&,
278  const M5ConstPtr&,
279  const M6ConstPtr&,
280  const M7ConstPtr&,
281  const M8ConstPtr&>(boost::bind(callback, _1, _2, _3, _4, _5, _6, _7, _8, _9));
282  }
283 
284  void removeCallback(const CallbackHelper9Ptr& helper)
285  {
286  boost::mutex::scoped_lock lock(mutex_);
287  typename V_CallbackHelper9::iterator it = std::find(callbacks_.begin(), callbacks_.end(), helper);
288  if (it != callbacks_.end())
289  {
290  callbacks_.erase(it);
291  }
292  }
293 
294  void call(const M0Event& e0, const M1Event& e1, const M2Event& e2, const M3Event& e3, const M4Event& e4,
295  const M5Event& e5, const M6Event& e6, const M7Event& e7, const M8Event& e8)
296  {
297  boost::mutex::scoped_lock lock(mutex_);
298  bool nonconst_force_copy = callbacks_.size() > 1;
299  typename V_CallbackHelper9::iterator it = callbacks_.begin();
300  typename V_CallbackHelper9::iterator end = callbacks_.end();
301  for (; it != end; ++it)
302  {
303  const CallbackHelper9Ptr& helper = *it;
304  helper->call(nonconst_force_copy, e0, e1, e2, e3, e4, e5, e6, e7, e8);
305  }
306  }
307 
308 private:
309  boost::mutex mutex_;
310  V_CallbackHelper9 callbacks_;
311 };
312 
313 } // message_filters
314 
315 #endif // MESSAGE_FILTERS_SIGNAL9_H
316 
317 
Connection addCallback(void(T::*callback)(P0, P1, P2, P3, P4, P5, P6, P7), T *t)
Definition: signal9.h:265
boost::shared_ptr< M7 const > M7ConstPtr
Definition: signal9.h:166
CallbackHelper9T(const Callback &cb)
Definition: signal9.h:111
ros::MessageEvent< M8 const > M8Event
Definition: signal9.h:64
Connection addCallback(void(*callback)(P0, P1, P2))
Definition: signal9.h:187
ParameterAdapter< P5 > A5
Definition: signal9.h:92
ros::MessageEvent< M3 const > M3Event
Definition: signal9.h:59
Connection addCallback(void(T::*callback)(P0, P1, P2, P3, P4, P5, P6), T *t)
Definition: signal9.h:259
bool nonConstWillCopy() const
void call(const M0Event &e0, const M1Event &e1, const M2Event &e2, const M3Event &e3, const M4Event &e4, const M5Event &e5, const M6Event &e6, const M7Event &e7, const M8Event &e8)
Definition: signal9.h:294
Connection addCallback(void(*callback)(P0, P1, P2, P3, P4, P5, P6, P7))
Definition: signal9.h:217
ros::MessageEvent< M5 const > M5Event
Definition: signal9.h:61
ros::MessageEvent< M2 const > M2Event
Definition: signal9.h:58
boost::shared_ptr< M8 const > M8ConstPtr
Definition: signal9.h:167
ros::MessageEvent< M1 const > M1Event
Definition: signal9.h:57
boost::shared_ptr< M0 const > M0ConstPtr
Definition: signal9.h:159
Connection addCallback(void(T::*callback)(P0, P1), T *t)
Definition: signal9.h:229
Connection addCallback(void(*callback)(P0, P1, P2, P3, P4, P5))
Definition: signal9.h:205
ros::MessageEvent< M2 const > M2Event
Definition: signal9.h:152
ros::MessageEvent< M6 const > M6Event
Definition: signal9.h:62
ParameterAdapter< P3 > A3
Definition: signal9.h:90
ParameterAdapter< P2 > A2
Definition: signal9.h:89
virtual void call(bool nonconst_force_copy, const M0Event &e0, const M1Event &e1, const M2Event &e2, const M3Event &e3, const M4Event &e4, const M5Event &e5, const M6Event &e6, const M7Event &e7, const M8Event &e8)
Definition: signal9.h:116
Connection addCallback(void(*callback)(P0, P1))
Definition: signal9.h:181
const boost::shared_ptr< NullType const > & NullP
Definition: signal9.h:168
ros::MessageEvent< M6 const > M6Event
Definition: signal9.h:156
Connection addCallback(void(T::*callback)(P0, P1, P2), T *t)
Definition: signal9.h:235
std::vector< CallbackHelper9Ptr > V_CallbackHelper9
Definition: signal9.h:147
ParameterAdapter< P0 > A0
Definition: signal9.h:87
Connection addCallback(void(T::*callback)(P0, P1, P2, P3), T *t)
Definition: signal9.h:241
boost::function< void(typename A0::Parameter, typename A1::Parameter, typename A2::Parameter, typename A3::Parameter, typename A4::Parameter, typename A5::Parameter, typename A6::Parameter, typename A7::Parameter, typename A8::Parameter)> Callback
Definition: signal9.h:109
boost::shared_ptr< M6 const > M6ConstPtr
Definition: signal9.h:165
boost::shared_ptr< CallbackHelper9 > Ptr
Definition: signal9.h:71
V_CallbackHelper9 callbacks_
Definition: signal9.h:310
boost::shared_ptr< M5 const > M5ConstPtr
Definition: signal9.h:164
Connection addCallback(void(*callback)(P0, P1, P2, P3, P4, P5, P6, P7, P8))
Definition: signal9.h:223
ros::MessageEvent< M3 const > M3Event
Definition: signal9.h:153
Connection addCallback(void(*callback)(P0, P1, P2, P3))
Definition: signal9.h:193
ParameterAdapter< P6 > A6
Definition: signal9.h:93
ros::MessageEvent< M8 const > M8Event
Definition: signal9.h:158
ros::MessageEvent< M1 const > M1Event
Definition: signal9.h:151
ros::MessageEvent< M4 const > M4Event
Definition: signal9.h:60
Connection addCallback(void(T::*callback)(P0, P1, P2, P3, P4, P5), T *t)
Definition: signal9.h:253
ParameterAdapter< P7 > A7
Definition: signal9.h:94
boost::shared_ptr< M4 const > M4ConstPtr
Definition: signal9.h:163
boost::shared_ptr< M3 const > M3ConstPtr
Definition: signal9.h:162
ros::MessageEvent< M7 const > M7Event
Definition: signal9.h:63
boost::shared_ptr< M2 const > M2ConstPtr
Definition: signal9.h:161
Connection addCallback(void(T::*callback)(P0, P1, P2, P3, P4), T *t)
Definition: signal9.h:247
ParameterAdapter< P8 > A8
Definition: signal9.h:95
boost::shared_ptr< CallbackHelper9< M0, M1, M2, M3, M4, M5, M6, M7, M8 > > CallbackHelper9Ptr
Definition: signal9.h:146
ParameterAdapter< P1 > A1
Definition: signal9.h:88
ros::MessageEvent< M4 const > M4Event
Definition: signal9.h:154
Connection addCallback(void(*callback)(P0, P1, P2, P3, P4, P5, P6))
Definition: signal9.h:211
ros::MessageEvent< M0 const > M0Event
Definition: signal9.h:150
ros::MessageEvent< M7 const > M7Event
Definition: signal9.h:157
Connection addCallback(const boost::function< void(P0, P1, P2, P3, P4, P5, P6, P7, P8)> &callback)
Definition: signal9.h:171
boost::shared_ptr< M1 const > M1ConstPtr
Definition: signal9.h:160
boost::mutex mutex_
Definition: signal9.h:309
ParameterAdapter< P4 > A4
Definition: signal9.h:91
Encapsulates a connection from one filter to another (or to a user-specified callback) ...
Definition: connection.h:48
ros::MessageEvent< M0 const > M0Event
Definition: signal9.h:56
Connection addCallback(C &callback)
Definition: signal9.h:271
virtual void call(bool nonconst_force_copy, const M0Event &e0, const M1Event &e1, const M2Event &e2, const M3Event &e3, const M4Event &e4, const M5Event &e5, const M6Event &e6, const M7Event &e7, const M8Event &e8)=0
void removeCallback(const CallbackHelper9Ptr &helper)
Definition: signal9.h:284
ros::MessageEvent< M5 const > M5Event
Definition: signal9.h:155
Connection addCallback(void(*callback)(P0, P1, P2, P3, P4))
Definition: signal9.h:199


message_filters
Author(s): Josh Faust, Vijay Pradeep
autogenerated on Thu Apr 25 2019 02:31:05