next up previous contents index
Next: 5. Internet Node Up: 4. Core Modules Previous: 4.1.2 Event creation and   Contents   Index


4.2 Callbacks

The callback API in ns-3 is designed to minimize the overall coupling between various pieces of of the simulator by making each module depend on the callback API itself rather than depend on other modules. It acts as a sort of third-party to which work is delegated and which forwards this work to the proper target module. This callback API, being based on C++ templates, is type-safe; that is, it performs static type checks to enforce proper signature compatibility between callers and callees. The API is minimal, providing only two services:

The implementation is based on use of templates to implement the Functor Design Pattern. It is used to declare the type of a callback. Up to five arguments can be passed with the function pointer to the callback. Callback instances are built with the makeCallback template functions. Callback instances have plain old data (POD) semantics: the memory they allocate is managed automatically, without user intervention which allows one to pass around Callback instances by value. A sample program is found in samples/main-callback.cc


next up previous contents index
Next: 5. Internet Node Up: 4. Core Modules Previous: 4.1.2 Event creation and   Contents   Index
Tom Henderson 2007-06-17