Workspace 6.21.5
Public Member Functions | Static Public Member Functions | List of all members
StatusFlipper Class Reference

Observer used to safely flip the up to date status of an Updatable object. More...

#include <Workspace/DataExecution/Execution/statusflipper.h>

Inheritance diagram for StatusFlipper:
[legend]

Public Member Functions

 StatusFlipper (Updatable &target, bool finalState=true)
 
 ~StatusFlipper () override
 
void activate ()
 
bool getFinalState () const
 
bool isActivated () const
 
void setFinalState (bool b)
 
void update (const ObservableEvent &e) override
 
- Public Member Functions inherited from Observer
void destroy ()
 
const EventIDgetEventID () const
 
void moveToThread (QThread *thread)
 
virtual void update (const ObservableEvent &event)
 

Static Public Member Functions

static void oneShot (Updatable &target, bool finalState=true)
 

Additional Inherited Members

- Protected Member Functions inherited from Observer
 Observer (const Observer &)
 
 Observer (Observable &subject, const EventID &eventID, bool ownedBySubject=false, bool attach=true)
 
virtual ~Observer ()
 
bool isOwnedBySubject () const
 
void setOwnedBySubject (bool ownedBySubject) const
 
virtual bool updateInNotificationThread (const ObservableEvent &event)
 
virtual void updateInObserverThread (const ObservableEvent &event)
 

Detailed Description

The flipper is intended to safely alter the up to date status of the object by correctly interacting with an execution thread, if one is active. At the next opportunity to do so, the flipper will check if the current status is true. If it is, then it will attempt to carry out the flip. If it is false, the flipper assumes that no status change is required.

The flipper can be used in two modes. If configured with the final state set to true, the up to date status of the object will first be set to false and then immediately set to true again. If the final state is configured to be set to false, the second change back to true is omitted. In either case, all downstream objects will have their up to date status set to false as a result of the flip. This is the main purpose of the StatusFlipper class, not so much the setting of the up to date status of the object (although this is a useful side effect).

Constructor & Destructor Documentation

◆ StatusFlipper()

StatusFlipper ( Updatable target,
bool  finalState = true 
)

◆ ~StatusFlipper()

~StatusFlipper ( )
overridedefault

Member Function Documentation

◆ activate()

void activate ( )

◆ getFinalState()

bool getFinalState ( ) const
Returns
The final state the flipper will set the target object's up to date status to.

◆ isActivated()

bool isActivated ( ) const

◆ oneShot()

void oneShot ( Updatable target,
bool  finalState = true 
)
static
Parameters
targetThe Updatable object that will have its up to date status manipulated.
finalStateThe final state the Updatable object should have at the end of the status flip. It is passed to the StatusFlipper constructor as the second argument.

Creates a one-shot status flip that will be triggered immediately if target is not dependent on a running execution thread, or else delayed until the next update event of that running thread.

Note
If the up to date state of target is false and there is no execution thread running for the workspace target belongs to, then regardless of the value of finalState, target will not be brought up to date. This is because there are scenarios which could make this unsafe. For target to be marked up to date, it must be done by a running execution thread or target must already be up to date at the time oneShot() is called (in which case oneShot() will amount to flipping the status just so that update notifications are sent).

◆ setFinalState()

void setFinalState ( bool  b)
Parameters
bThe final state the flipper should set the target object's up to date status to.

◆ update()

void update ( const ObservableEvent e)
overridevirtual

Reimplemented from Observer.