2217
|
1 |
/*!
|
|
2 |
\page callbacks Using ns-3 callbacks
|
|
3 |
\anchor howtos-callbacks
|
|
4 |
|
|
5 |
\section null_callbacks Null Callbacks
|
|
6 |
|
|
7 |
<b>Question:</b> The API I am using calls for using a callback (in the
|
|
8 |
function signature), but I do not
|
|
9 |
want to provide one. Is there a way to provide a null callback?
|
|
10 |
|
|
11 |
<b>Answer:</b> Use the ns3::MakeNullCallback construct:
|
|
12 |
\code
|
|
13 |
template<typename R>
|
|
14 |
Callback< R, T1, T2, T3, T4, T5, T6 > ns3::MakeNullCallback (void)
|
|
15 |
\endcode
|
|
16 |
|
|
17 |
Example usage: The ns3::Socket class uses callbacks to indicate completion
|
|
18 |
of events such as a successful TCP connect(). These callbacks are set
|
|
19 |
in the following function:
|
|
20 |
\code
|
|
21 |
void Socket::SetConnectCallback (Callback<void, Ptr<Socket> > connectionSucceeded,
|
|
22 |
Callback<void, Ptr<Socket> > connectionFailed,
|
|
23 |
Callback<void, Ptr<Socket> > halfClose);
|
|
24 |
|
|
25 |
\endcode
|
|
26 |
But suppose you do not care about registering a callback for the
|
|
27 |
halfClose event (but you want to register one for the
|
|
28 |
connectionSucceeded and connectionFailed cases). In that case, you
|
|
29 |
can pass a null callback as the third argument. You just need to
|
|
30 |
pass a callback with the matching signature, as follows:
|
|
31 |
\code
|
|
32 |
localSocket->SetConnectCallback (
|
|
33 |
MakeCallback (&ConnectionSucceededCallback),
|
|
34 |
MakeCallback (&ConnectionFailedCallback),
|
|
35 |
MakeNullCallback<void, Ptr<Socket> > () );
|
|
36 |
\endcode
|
|
37 |
|
|
38 |
*/
|