The Sparta Modeling Framework
Loading...
Searching...
No Matches
sparta::NotificationSourceBase::ObservationStateCallback Class Reference

Callback for observation-state of a NotificationSourceBase. More...

#include <NotificationSource.hpp>

Public Member Functions

 ObservationStateCallback (NotificationSourceBase &ns, ObservationStateChange type, callback_t callback)
 
 ObservationStateCallback (const ObservationStateCallback &)=delete
 
 ObservationStateCallback (ObservationStateCallback &&)=delete
 
ObservationStateCallbackoperator= (const ObservationStateCallback &)=delete
 
ObservationStateChange getType () const
 Get tyhe type of change associated with this callback instance.
 
void operator() (NotificationSourceBase const &ns, uint32_t observers) const
 Invoked the callback function.
 
void dump (std::ostream &o) const
 Dump string description to an ostream.
 

Detailed Description

Callback for observation-state of a NotificationSourceBase.

Use this to monitor changes in the observation state of a NotificationSource and bind some change to a callable. This object automatically binds the callback function to the notification source on construction and removes the callback on destruction. If the notification source is destroyed before this callback object, then the callback will never be invoked again and it will not attempt to deregister when eventually destroyed.

The intent of this feature is for some model to monitor the observation of some of its constituent notifications for both their lifetimes (which are hopefully the same). Creating and removing these callbacks throughout a simulation is not expected. An example use case is needing to change the state of a JIT model if someone is now observing some detail of execution (e.g. an instruction executed notification)

Warning
Do not attempt to create or delete callbacks within an observation state change callback. It will fail. Do not attempt to add or remove a NotificationObservers within a observation state change callback!
* class X{
* public:
*   NotificationSource<MyPayload> ns;
*   NotificationSource::ObservationStateCallback nscb;
*   MyConstructor(node)
*    : ns(node, ....),
*      nscb(ns, NotificationSourceBase::ObservationStateChange::SOLE_OBSERVER_REGISTERING, handleSoleObserverAdded_)
*   {}
*   void handleSoleObserverAdded_(NotificationSourceBase const & source, uint32_t new_observer_count) {
*   { ... }
* }
*
* 
Todo:
Add a multi-callback version of this class that handles both sole-[de]registering functions and both any-[de]registering functions
Todo:
Aoply this pattern (with code re-use) to Counter types as well so that Counter-incrementing code can change it's behavior and granularity to better support counter-based SPARTA tirggers

Definition at line 160 of file NotificationSource.hpp.

Constructor & Destructor Documentation

◆ ObservationStateCallback()

sparta::NotificationSourceBase::ObservationStateCallback::ObservationStateCallback ( NotificationSourceBase ns,
ObservationStateChange  type,
callback_t  callback 
)
inline

Definition at line 169 of file NotificationSource.hpp.

◆ ~ObservationStateCallback()

sparta::NotificationSourceBase::ObservationStateCallback::~ObservationStateCallback ( )
inline

Definition at line 180 of file NotificationSource.hpp.

Member Function Documentation

◆ dump()

void sparta::NotificationSourceBase::ObservationStateCallback::dump ( std::ostream &  o) const
inline

Dump string description to an ostream.

Definition at line 209 of file NotificationSource.hpp.

◆ getType()

ObservationStateChange sparta::NotificationSourceBase::ObservationStateCallback::getType ( ) const
inline

Get tyhe type of change associated with this callback instance.

Definition at line 195 of file NotificationSource.hpp.

◆ operator()()

void sparta::NotificationSourceBase::ObservationStateCallback::operator() ( NotificationSourceBase const &  ns,
uint32_t  observers 
) const
inline

Invoked the callback function.

Definition at line 200 of file NotificationSource.hpp.


The documentation for this class was generated from the following file: