00001 /*! 00002 \page callbacks Using ns-3 callbacks 00003 \anchor howtos-callbacks 00004 00005 \section null_callbacks Null Callbacks 00006 00007 <b>Question:</b> The API I am using calls for using a callback (in the 00008 function signature), but I do not 00009 want to provide one. Is there a way to provide a null callback? 00010 00011 <b>Answer:</b> Use the ns3::MakeNullCallback construct: 00012 \code 00013 template<typename R> 00014 Callback< R, T1, T2, T3, T4, T5, T6 > ns3::MakeNullCallback (void) 00015 \endcode 00016 00017 Example usage: The ns3::Socket class uses callbacks to indicate completion 00018 of events such as a successful TCP connect(). These callbacks are set 00019 in the following function: 00020 \code 00021 void Socket::SetConnectCallback (Callback<void, Ptr<Socket> > connectionSucceeded, 00022 Callback<void, Ptr<Socket> > connectionFailed, 00023 Callback<void, Ptr<Socket> > halfClose); 00024 00025 \endcode 00026 But suppose you do not care about registering a callback for the 00027 halfClose event (but you want to register one for the 00028 connectionSucceeded and connectionFailed cases). In that case, you 00029 can pass a null callback as the third argument. You just need to 00030 pass a callback with the matching signature, as follows: 00031 \code 00032 localSocket->SetConnectCallback ( 00033 MakeCallback (&ConnectionSucceededCallback), 00034 MakeCallback (&ConnectionFailedCallback), 00035 MakeNullCallback<void, Ptr<Socket> > () ); 00036 \endcode 00037 00038 */