tomh@345
|
1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
tomh@345
|
2 |
/*
|
tomh@345
|
3 |
* Copyright (c) 2005,2006,2007 INRIA
|
tomh@345
|
4 |
* All rights reserved.
|
tomh@345
|
5 |
*
|
tomh@345
|
6 |
* This program is free software; you can redistribute it and/or modify
|
tomh@345
|
7 |
* it under the terms of the GNU General Public License version 2 as
|
tomh@345
|
8 |
* published by the Free Software Foundation;
|
tomh@345
|
9 |
*
|
tomh@345
|
10 |
* This program is distributed in the hope that it will be useful,
|
tomh@345
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
tomh@345
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
tomh@345
|
13 |
* GNU General Public License for more details.
|
tomh@345
|
14 |
*
|
tomh@345
|
15 |
* You should have received a copy of the GNU General Public License
|
tomh@345
|
16 |
* along with this program; if not, write to the Free Software
|
tomh@345
|
17 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
tomh@345
|
18 |
*
|
tomh@345
|
19 |
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
|
tomh@345
|
20 |
*/
|
tomh@345
|
21 |
|
mathieu@2482
|
22 |
#ifndef TRACED_CALLBACK_H
|
mathieu@2482
|
23 |
#define TRACED_CALLBACK_H
|
tomh@345
|
24 |
|
tomh@345
|
25 |
#include <list>
|
mathieu@1335
|
26 |
#include "callback.h"
|
tomh@345
|
27 |
|
tomh@345
|
28 |
namespace ns3 {
|
tomh@345
|
29 |
|
tomh@345
|
30 |
/**
|
tomh@345
|
31 |
* \brief log arbitrary number of parameters to a matching ns3::Callback
|
mathieu@1389
|
32 |
* \ingroup tracing
|
tomh@345
|
33 |
*
|
tomh@345
|
34 |
* Whenever operator () is invoked on this class, the call and its arguments
|
tomh@345
|
35 |
* are forwarded to the internal matching ns3::Callback.
|
tomh@345
|
36 |
*/
|
tomh@345
|
37 |
template<typename T1 = empty, typename T2 = empty,
|
tomh@345
|
38 |
typename T3 = empty, typename T4 = empty>
|
mathieu@2482
|
39 |
class TracedCallback
|
mathieu@2462
|
40 |
{
|
tomh@345
|
41 |
public:
|
mathieu@2482
|
42 |
TracedCallback ();
|
mathieu@2466
|
43 |
void Connect (const CallbackBase & callback);
|
mathieu@2466
|
44 |
void Disconnect (const CallbackBase & callback);
|
mathieu@1343
|
45 |
void operator() (void) const;
|
mathieu@1343
|
46 |
void operator() (T1 a1) const;
|
mathieu@1343
|
47 |
void operator() (T1 a1, T2 a2) const;
|
mathieu@1343
|
48 |
void operator() (T1 a1, T2 a2, T3 a3) const;
|
mathieu@1343
|
49 |
void operator() (T1 a1, T2 a2, T3 a3, T4 a4) const;
|
tomh@345
|
50 |
|
tomh@345
|
51 |
private:
|
mathieu@2462
|
52 |
typedef std::list<Callback<void,T1,T2,T3,T4> > CallbackList;
|
tomh@345
|
53 |
CallbackList m_callbackList;
|
tomh@345
|
54 |
};
|
tomh@345
|
55 |
|
mathieu@2462
|
56 |
} // namespace ns3
|
tomh@345
|
57 |
|
tomh@345
|
58 |
// implementation below.
|
tomh@345
|
59 |
|
tomh@345
|
60 |
namespace ns3 {
|
tomh@345
|
61 |
|
mathieu@1419
|
62 |
|
mathieu@1419
|
63 |
template<typename T1, typename T2,
|
mathieu@1419
|
64 |
typename T3, typename T4>
|
mathieu@2482
|
65 |
TracedCallback<T1,T2,T3,T4>::TracedCallback ()
|
tomh@345
|
66 |
: m_callbackList ()
|
tomh@345
|
67 |
{}
|
tomh@345
|
68 |
template<typename T1, typename T2,
|
tomh@345
|
69 |
typename T3, typename T4>
|
tomh@345
|
70 |
void
|
mathieu@2482
|
71 |
TracedCallback<T1,T2,T3,T4>::Connect (const CallbackBase & callback)
|
tomh@345
|
72 |
{
|
mathieu@2462
|
73 |
Callback<void,T1,T2,T3,T4> cb;
|
mathieu@529
|
74 |
cb.Assign (callback);
|
tomh@345
|
75 |
m_callbackList.push_back (cb);
|
tomh@345
|
76 |
}
|
tomh@345
|
77 |
template<typename T1, typename T2,
|
tomh@345
|
78 |
typename T3, typename T4>
|
tomh@345
|
79 |
void
|
mathieu@2482
|
80 |
TracedCallback<T1,T2,T3,T4>::Disconnect (const CallbackBase & callback)
|
tomh@345
|
81 |
{
|
tomh@345
|
82 |
for (typename CallbackList::iterator i = m_callbackList.begin ();
|
tomh@345
|
83 |
i != m_callbackList.end (); /* empty */)
|
tomh@345
|
84 |
{
|
tomh@345
|
85 |
if ((*i).IsEqual (callback))
|
tomh@345
|
86 |
{
|
tomh@345
|
87 |
i = m_callbackList.erase (i);
|
tomh@345
|
88 |
}
|
tomh@345
|
89 |
else
|
tomh@345
|
90 |
{
|
tomh@345
|
91 |
i++;
|
tomh@345
|
92 |
}
|
tomh@345
|
93 |
}
|
tomh@345
|
94 |
}
|
tomh@345
|
95 |
template<typename T1, typename T2,
|
tomh@345
|
96 |
typename T3, typename T4>
|
tomh@345
|
97 |
void
|
mathieu@2482
|
98 |
TracedCallback<T1,T2,T3,T4>::operator() (void) const
|
tomh@345
|
99 |
{
|
mathieu@1343
|
100 |
for (typename CallbackList::const_iterator i = m_callbackList.begin ();
|
tomh@345
|
101 |
i != m_callbackList.end (); i++)
|
tomh@345
|
102 |
{
|
mathieu@2462
|
103 |
(*i) ();
|
tomh@345
|
104 |
}
|
tomh@345
|
105 |
}
|
tomh@345
|
106 |
template<typename T1, typename T2,
|
tomh@345
|
107 |
typename T3, typename T4>
|
tomh@345
|
108 |
void
|
mathieu@2482
|
109 |
TracedCallback<T1,T2,T3,T4>::operator() (T1 a1) const
|
tomh@345
|
110 |
{
|
mathieu@1343
|
111 |
for (typename CallbackList::const_iterator i = m_callbackList.begin ();
|
tomh@345
|
112 |
i != m_callbackList.end (); i++)
|
tomh@345
|
113 |
{
|
mathieu@2462
|
114 |
(*i) (a1);
|
tomh@345
|
115 |
}
|
tomh@345
|
116 |
}
|
tomh@345
|
117 |
template<typename T1, typename T2,
|
tomh@345
|
118 |
typename T3, typename T4>
|
tomh@345
|
119 |
void
|
mathieu@2482
|
120 |
TracedCallback<T1,T2,T3,T4>::operator() (T1 a1, T2 a2) const
|
tomh@345
|
121 |
{
|
mathieu@1343
|
122 |
for (typename CallbackList::const_iterator i = m_callbackList.begin ();
|
tomh@345
|
123 |
i != m_callbackList.end (); i++)
|
tomh@345
|
124 |
{
|
mathieu@2462
|
125 |
(*i) (a1, a2);
|
tomh@345
|
126 |
}
|
tomh@345
|
127 |
}
|
tomh@345
|
128 |
template<typename T1, typename T2,
|
tomh@345
|
129 |
typename T3, typename T4>
|
tomh@345
|
130 |
void
|
mathieu@2482
|
131 |
TracedCallback<T1,T2,T3,T4>::operator() (T1 a1, T2 a2, T3 a3) const
|
tomh@345
|
132 |
{
|
mathieu@1343
|
133 |
for (typename CallbackList::const_iterator i = m_callbackList.begin ();
|
tomh@345
|
134 |
i != m_callbackList.end (); i++)
|
tomh@345
|
135 |
{
|
mathieu@2462
|
136 |
(*i) (a1, a2, a3);
|
tomh@345
|
137 |
}
|
tomh@345
|
138 |
}
|
tomh@345
|
139 |
template<typename T1, typename T2,
|
tomh@345
|
140 |
typename T3, typename T4>
|
tomh@345
|
141 |
void
|
mathieu@2482
|
142 |
TracedCallback<T1,T2,T3,T4>::operator() (T1 a1, T2 a2, T3 a3, T4 a4) const
|
tomh@345
|
143 |
{
|
mathieu@1343
|
144 |
for (typename CallbackList::const_iterator i = m_callbackList.begin ();
|
tomh@345
|
145 |
i != m_callbackList.end (); i++)
|
tomh@345
|
146 |
{
|
mathieu@2462
|
147 |
(*i) (a1, a2, a3, a4);
|
tomh@345
|
148 |
}
|
tomh@345
|
149 |
}
|
tomh@345
|
150 |
|
tomh@345
|
151 |
}//namespace ns3
|
tomh@345
|
152 |
|
mathieu@2482
|
153 |
#endif /* TRACED_CALLBACK_H */
|