Gromacs
2024.4
|
#include <gromacs/mdrunutility/mdmodulesnotifier.h>
Inherits MDModulesNotifierBase.
Organizes notifications about an event of interest to modules.
An object of this type permits modules to subscribe to the corresponding event. The template types of this type encode what information is available when the event occurs. Modules subscribe()
by providing a callback function that accepts a single parameter of such an event type. The code that handles that event has the responsibilty to call notify()
afterwards. The subscribed modules then receive the callback with the requested event type as an argument.
See gmx::MDModulesNotifiers for sequence diagrams for an example.
This suits scenarios where several objects are built (or re-built) and one or more modules need to know when one or more of such objects are available (or updated), so they can adapt their internal state accordingly. Examples include responding to loading input data, or to changes related to a recurring process like checkpointing or partitioning. The coupling between these modules is now expressed indirectly. This improves the modularity and testability of those modules.
The implementation provides the necessary flexibility to be parameterized with multiple event types and provide callback()
and notify() methods corresponding to each related event. This is done by inheriting from a series of base classes, each of which handles a single type of event. BuildMDModulesNotifier implements the details. To create a class of this type that provides two events with callbacks that receive respectively types TypeA and TypeB, use BuildMDModulesNotifier<TypeA, TypeB>::type.
CallParameter | of the function to be notified |
MDModulesNotifierBase | class to be extended with a notification with CallParameter |
Public Member Functions | |
void | notify (const CallParameter callParameter) const |
Notifies subscribers of the event described by callbackParameter . More... | |
void | subscribe (std::function< void(const CallParameter)> callBackFunction) |
Add callback function to be called when notify() is called. More... | |
|
inline |
Notifies subscribers of the event described by callbackParameter
.
[in] | callParameter | of the function to be called back |
|
inline |
Add callback function to be called when notify()
is called.
[in] | callBackFunction | to be called |