A Discrete-Event Network Simulator
API
traced-callback.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2005,2006,2007 INRIA
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19  */
20 
21 #ifndef TRACED_CALLBACK_H
22 #define TRACED_CALLBACK_H
23 
24 #include <list>
25 #include "callback.h"
26 
33 namespace ns3 {
34 
58 template<typename T1 = empty, typename T2 = empty,
59  typename T3 = empty, typename T4 = empty,
60  typename T5 = empty, typename T6 = empty,
61  typename T7 = empty, typename T8 = empty>
63 {
64 public:
66  TracedCallback ();
72  void ConnectWithoutContext (const CallbackBase & callback);
82  void Connect (const CallbackBase & callback, std::string path);
88  void DisconnectWithoutContext (const CallbackBase & callback);
95  void Disconnect (const CallbackBase & callback, std::string path);
105  void operator() (void) const;
111  void operator() (T1 a1) const;
119  void operator() (T1 a1, T2 a2) const;
129  void operator() (T1 a1, T2 a2, T3 a3) const;
141  void operator() (T1 a1, T2 a2, T3 a3, T4 a4) const;
155  void operator() (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) const;
171  void operator() (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6) const;
189  void operator() (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6, T7 a7) const;
209  void operator() (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6, T7 a7, T8 a8) const;
218  // Uint32Callback appears to be the only one used at the moment.
219  // Feel free to add typedef's for any other POD you need.
220  typedef void (* Uint32Callback)(const uint32_t value);
224 private:
237  typedef std::list<Callback<void,T1,T2,T3,T4,T5,T6,T7,T8> > CallbackList;
239  CallbackList m_callbackList;
240 };
241 
242 } // namespace ns3
243 
244 
245 /********************************************************************
246  * Implementation of the templates declared above.
247  ********************************************************************/
248 
249 namespace ns3 {
250 
251 template<typename T1, typename T2,
252  typename T3, typename T4,
253  typename T5, typename T6,
254  typename T7, typename T8>
256  : m_callbackList ()
257 {
258 }
259 template<typename T1, typename T2,
260  typename T3, typename T4,
261  typename T5, typename T6,
262  typename T7, typename T8>
263 void
265 {
267  cb.Assign (callback);
268  m_callbackList.push_back (cb);
269 }
270 template<typename T1, typename T2,
271  typename T3, typename T4,
272  typename T5, typename T6,
273  typename T7, typename T8>
274 void
276 {
278  cb.Assign (callback);
279  Callback<void,T1,T2,T3,T4,T5,T6,T7,T8> realCb = cb.Bind (path);
280  m_callbackList.push_back (realCb);
281 }
282 template<typename T1, typename T2,
283  typename T3, typename T4,
284  typename T5, typename T6,
285  typename T7, typename T8>
286 void
288 {
289  for (typename CallbackList::iterator i = m_callbackList.begin ();
290  i != m_callbackList.end (); /* empty */)
291  {
292  if ((*i).IsEqual (callback))
293  {
294  i = m_callbackList.erase (i);
295  }
296  else
297  {
298  i++;
299  }
300  }
301 }
302 template<typename T1, typename T2,
303  typename T3, typename T4,
304  typename T5, typename T6,
305  typename T7, typename T8>
306 void
308 {
310  cb.Assign (callback);
311  Callback<void,T1,T2,T3,T4,T5,T6,T7,T8> realCb = cb.Bind (path);
312  DisconnectWithoutContext (realCb);
313 }
314 template<typename T1, typename T2,
315  typename T3, typename T4,
316  typename T5, typename T6,
317  typename T7, typename T8>
318 void
320 {
321  for (typename CallbackList::const_iterator i = m_callbackList.begin ();
322  i != m_callbackList.end (); i++)
323  {
324  (*i)();
325  }
326 }
327 template<typename T1, typename T2,
328  typename T3, typename T4,
329  typename T5, typename T6,
330  typename T7, typename T8>
331 void
333 {
334  for (typename CallbackList::const_iterator i = m_callbackList.begin ();
335  i != m_callbackList.end (); i++)
336  {
337  (*i)(a1);
338  }
339 }
340 template<typename T1, typename T2,
341  typename T3, typename T4,
342  typename T5, typename T6,
343  typename T7, typename T8>
344 void
346 {
347  for (typename CallbackList::const_iterator i = m_callbackList.begin ();
348  i != m_callbackList.end (); i++)
349  {
350  (*i)(a1, a2);
351  }
352 }
353 template<typename T1, typename T2,
354  typename T3, typename T4,
355  typename T5, typename T6,
356  typename T7, typename T8>
357 void
359 {
360  for (typename CallbackList::const_iterator i = m_callbackList.begin ();
361  i != m_callbackList.end (); i++)
362  {
363  (*i)(a1, a2, a3);
364  }
365 }
366 template<typename T1, typename T2,
367  typename T3, typename T4,
368  typename T5, typename T6,
369  typename T7, typename T8>
370 void
372 {
373  for (typename CallbackList::const_iterator i = m_callbackList.begin ();
374  i != m_callbackList.end (); i++)
375  {
376  (*i)(a1, a2, a3, a4);
377  }
378 }
379 template<typename T1, typename T2,
380  typename T3, typename T4,
381  typename T5, typename T6,
382  typename T7, typename T8>
383 void
384 TracedCallback<T1,T2,T3,T4,T5,T6,T7,T8>::operator() (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) const
385 {
386  for (typename CallbackList::const_iterator i = m_callbackList.begin ();
387  i != m_callbackList.end (); i++)
388  {
389  (*i)(a1, a2, a3, a4, a5);
390  }
391 }
392 template<typename T1, typename T2,
393  typename T3, typename T4,
394  typename T5, typename T6,
395  typename T7, typename T8>
396 void
397 TracedCallback<T1,T2,T3,T4,T5,T6,T7,T8>::operator() (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6) const
398 {
399  for (typename CallbackList::const_iterator i = m_callbackList.begin ();
400  i != m_callbackList.end (); i++)
401  {
402  (*i)(a1, a2, a3, a4, a5, a6);
403  }
404 }
405 template<typename T1, typename T2,
406  typename T3, typename T4,
407  typename T5, typename T6,
408  typename T7, typename T8>
409 void
410 TracedCallback<T1,T2,T3,T4,T5,T6,T7,T8>::operator() (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6, T7 a7) const
411 {
412  for (typename CallbackList::const_iterator i = m_callbackList.begin ();
413  i != m_callbackList.end (); i++)
414  {
415  (*i)(a1, a2, a3, a4, a5, a6, a7);
416  }
417 }
418 template<typename T1, typename T2,
419  typename T3, typename T4,
420  typename T5, typename T6,
421  typename T7, typename T8>
422 void
423 TracedCallback<T1,T2,T3,T4,T5,T6,T7,T8>::operator() (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6, T7 a7, T8 a8) const
424 {
425  for (typename CallbackList::const_iterator i = m_callbackList.begin ();
426  i != m_callbackList.end (); i++)
427  {
428  (*i)(a1, a2, a3, a4, a5, a6, a7, a8);
429  }
430 }
431 
432 } // namespace ns3
433 
434 #endif /* TRACED_CALLBACK_H */
Forward calls to a chain of Callback.
void operator()(void) const
Functor which invokes the chain of Callbacks.
void Assign(const CallbackBase &other)
Adopt the other's implementation, if type compatible.
Definition: callback.h:1219
Callback< R, T2, T3, T4, T5, T6, T7, T8, T9 > Bind(T a)
Bind the first arguments.
Definition: callback.h:1029
Base class for Callback class.
Definition: callback.h:906
void DisconnectWithoutContext(std::string path, const CallbackBase &cb)
Definition: config.cc:738
Declaration of the various callback functions.
void(* Uint32Callback)(const uint32_t value)
TracedCallback signature for POD.
void DisconnectWithoutContext(const CallbackBase &callback)
Remove from the chain a Callback which was connected without a context.
void Disconnect(const CallbackBase &callback, std::string path)
Remove from the chain a Callback which was connected with a context.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void Connect(const CallbackBase &callback, std::string path)
Append a Callback to the chain with a context.
CallbackList m_callbackList
The chain of Callbacks.
void ConnectWithoutContext(const CallbackBase &callback)
Append a Callback to the chain (without a context).
TracedCallback()
Constructor.
std::list< Callback< void, T1, T2, T3, T4, T5, T6, T7, T8 > > CallbackList
Container type for holding the chain of Callbacks.