A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
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
51
template
<
typename
... Ts>
52
class
TracedCallback
53
{
54
public
:
56
TracedCallback
();
62
void
ConnectWithoutContext
(
const
CallbackBase
& callback);
72
void
Connect
(
const
CallbackBase
& callback, std::string path);
78
void
DisconnectWithoutContext
(
const
CallbackBase
& callback);
85
void
Disconnect
(
const
CallbackBase
& callback, std::string path);
91
void
operator()
(Ts... args)
const
;
96
bool
IsEmpty
()
const
;
97
104
// Uint32Callback appears to be the only one used at the moment.
105
// Feel free to add typedef's for any other POD you need.
106
typedef
void (*
Uint32Callback
)(
const
uint32_t value);
109
private
:
115
typedef
std::list
<
Callback
<void,Ts...> >
CallbackList
;
117
CallbackList
m_callbackList
;
118
};
119
120
}
// namespace ns3
121
122
123
/********************************************************************
124
* Implementation of the templates declared above.
125
********************************************************************/
126
127
namespace
ns3
{
128
129
template
<
typename
... Ts>
130
TracedCallback<Ts...>::TracedCallback
()
131
: m_callbackList ()
132
{}
133
template
<
typename
... Ts>
134
void
135
TracedCallback<Ts...>::ConnectWithoutContext
(
const
CallbackBase
& callback)
136
{
137
Callback
<void,Ts...> cb;
138
if
(!cb.Assign (callback))
139
{
140
NS_FATAL_ERROR_NO_MSG
();
141
}
142
m_callbackList.push_back (cb);
143
}
144
template
<
typename
... Ts>
145
void
146
TracedCallback<Ts...>::Connect
(
const
CallbackBase
& callback, std::string path)
147
{
148
Callback
<void,std::string,Ts...> cb;
149
if
(!cb.Assign (callback))
150
{
151
NS_FATAL_ERROR
(
"when connecting to "
<< path);
152
}
153
Callback
<void,Ts...> realCb = cb.
Bind
(path);
154
m_callbackList.push_back (realCb);
155
}
156
template
<
typename
... Ts>
157
void
158
TracedCallback<Ts...>::DisconnectWithoutContext
(
const
CallbackBase
& callback)
159
{
160
for
(
typename
CallbackList::iterator i = m_callbackList.begin ();
161
i != m_callbackList.end ();
/* empty */
)
162
{
163
if
((*i).IsEqual (callback))
164
{
165
i = m_callbackList.erase (i);
166
}
167
else
168
{
169
i++;
170
}
171
}
172
}
173
template
<
typename
... Ts>
174
void
175
TracedCallback<Ts...>::Disconnect
(
const
CallbackBase
& callback, std::string path)
176
{
177
Callback
<void,std::string,Ts...> cb;
178
if
(!cb.Assign (callback))
179
{
180
NS_FATAL_ERROR
(
"when disconnecting from "
<< path);
181
}
182
Callback
<void,Ts...> realCb = cb.
Bind
(path);
183
DisconnectWithoutContext
(realCb);
184
}
185
template
<
typename
... Ts>
186
void
187
TracedCallback<Ts...>::operator()
(Ts... args)
const
188
{
189
for
(
typename
CallbackList::const_iterator i = m_callbackList.begin ();
190
i != m_callbackList.end (); i++)
191
{
192
(*i)(args...);
193
}
194
}
195
196
template
<
typename
... Ts>
197
bool
198
TracedCallback<Ts...>::IsEmpty
()
const
199
{
200
return
m_callbackList.empty ();
201
}
202
203
}
// namespace ns3
204
205
#endif
/* TRACED_CALLBACK_H */
ns3::TracedCallback::DisconnectWithoutContext
void DisconnectWithoutContext(const CallbackBase &callback)
Remove from the chain a Callback which was connected without a context.
Definition:
traced-callback.h:158
ns3::TracedCallback::CallbackList
std::list< Callback< void, Ts... > > CallbackList
Container type for holding the chain of Callbacks.
Definition:
traced-callback.h:115
ns3::Callback
Callback template class.
Definition:
callback.h:1279
ns3::TracedCallback::m_callbackList
CallbackList m_callbackList
The chain of Callbacks.
Definition:
traced-callback.h:117
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::TracedCallback::ConnectWithoutContext
void ConnectWithoutContext(const CallbackBase &callback)
Append a Callback to the chain (without a context).
Definition:
traced-callback.h:135
callback.h
Declaration of the various callback functions.
ns3::TracedCallback::Uint32Callback
void(* Uint32Callback)(const uint32_t value)
TracedCallback signature for POD.
Definition:
traced-callback.h:106
NS_FATAL_ERROR
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition:
fatal-error.h:165
NS_FATAL_ERROR_NO_MSG
#define NS_FATAL_ERROR_NO_MSG()
Report a fatal error and terminate.
Definition:
fatal-error.h:128
ns3::TracedCallback::TracedCallback
TracedCallback()
Constructor.
Definition:
traced-callback.h:130
ns3::Callback::Bind
Callback< R, T2, T3, T4, T5, T6, T7, T8, T9 > Bind(T a)
Bind the first arguments.
Definition:
callback.h:1329
ns3::TracedCallback::Connect
void Connect(const CallbackBase &callback, std::string path)
Append a Callback to the chain with a context.
Definition:
traced-callback.h:146
ns3::Config::DisconnectWithoutContext
void DisconnectWithoutContext(std::string path, const CallbackBase &cb)
Definition:
config.cc:914
list
#define list
Definition:
openflow-interface.h:47
ns3::TracedCallback::operator()
void operator()(Ts... args) const
Functor which invokes the chain of Callbacks.
Definition:
traced-callback.h:187
ns3::CallbackBase
Base class for Callback class.
Definition:
callback.h:1196
ns3::TracedCallback::Disconnect
void Disconnect(const CallbackBase &callback, std::string path)
Remove from the chain a Callback which was connected with a context.
Definition:
traced-callback.h:175
ns3::TracedCallback
Forward calls to a chain of Callback.
Definition:
traced-callback.h:53
ns3::TracedCallback::IsEmpty
bool IsEmpty() const
Checks if the Callbacks list is empty.
Definition:
traced-callback.h:198
src
core
model
traced-callback.h
Generated on Fri Oct 1 2021 17:02:58 for ns-3 by
1.8.20