Workspace 6.21.5
Public Types | Public Member Functions | List of all members
Updater Class Reference

Updates a workspace. More...

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

Inheritance diagram for Updater:
[legend]

Public Types

enum  ExecutionMode { ExecuteContinuously , ExecuteOnce }
 
- Public Types inherited from Task
enum  State {
  Dormant , Scheduled , Running , Aborted ,
  Finished
}
 
enum  TaskBehaviour { GrowThreadPool = 0x01 , AutoDelete = 0x02 , RunRemotely = 0x04 }
 

Public Member Functions

 Updater ()
 
 ~Updater () override
 
void addToUpdateSet (Updatable &updatable, bool addToFront=false)
 
void clearErrorSource ()
 
UpdatablecurrentUpdatableCausingQueuing ()
 
bool currentUpdateIsDelayed () const
 
void delayCurrentUpdate (Updatable &delayedSource)
 
void doTask () override
 
void flushLog ()
 
UpdatablegetErrorSource () const
 
ExecutionMode getExecutionMode () const
 
bool getStopRequested () const
 
QObject * getThreadObject ()
 
bool isPaused () const
 
bool isReadyToProcessUpdateRequests () const
 
bool isRunning ()
 
void logText (const QString &msg)
 
void moveToMainThread () override
 
void pauseUpdate ()
 
void popUpdatableToQueueChangesOn (Updatable &u)
 
void processUpdateSet ()
 
void pushUpdatableToQueueChangesOn (Updatable &u)
 
void removeFromUpdateSet (Updatable &updatable)
 
void requestStop ()
 
void resetStopRequestFlag ()
 
void setErrorSource (Updatable &errorSource)
 
void setExecutionMode (ExecutionMode mode)
 
void stopAndWaitUntilFinishedRunning ()
 
void terminate ()
 
void transferWorkspace (Workspace &workspace, Updater *fromUpdater)
 
- Public Member Functions inherited from Observable
virtual ~Observable ()
 
void attachObserver (Observer &observer)
 
void destroy ()
 
void detachObserver (Observer &observer)
 
void notifyEvent (const ObservableEvent &event)
 
- Public Member Functions inherited from Task
 Task (bool growThreadPool, bool autoDelete, bool runRemotely)
 
 Task (TaskBehaviours behaviours)
 
 ~Task () override
 
State getState () const
 
bool getSupportsRemoteExecution () const
 
virtual void moveToMainThread ()
 
 Q_DECLARE_FLAGS (TaskBehaviours, TaskBehaviour)
 
void run () override
 
void setState (State)
 
void setSupportsRemoteExecution (bool)
 

Additional Inherited Members

- Signals inherited from Task
void aborted ()
 
void finished ()
 
void started ()
 
- Protected Member Functions inherited from Observable
 Observable ()
 
 Observable (const Observable &)
 
virtual void doTask ()=0
 

Detailed Description

An instance of Updater is created for each thread of execution used by workspaces in an application. Workspaces each have an Updater associated with them, with child workspaces generally sharing the Updater of their parent. The main exception to this is when the child workspace(s) have been explicitly configured to run in their own Updater.

Clients would not normally create their own Updater instance directly. This process is normally done automatically by a workspace whenever the Updater is needed internally. Clients can call Workspace::getUpdater() and the Updater will be created if necessary as part of that call. This is particularly important when nested workspaces are taken into consideration, since the process of re-parenting a workspace can delete an Updater which was previously created for the workspace before it had any parent workspace. If clients only ever call Workspace::getUpdater() and never construct their own Updater instance, the lifetime of the various Updaters will be properly managed behind the scenes automatically.

An Updater will not be running when it is first created. In order to actually allow execution to occur, something has to call the Updater's start() member function. This will start up the thread's event loop and set it processing the items that have been passed to it for keeping up to date. Once it has done these things, it will return immediately without waiting for those things to finish. The caller can check whether a thread is running with isRunning() and it can attach an observer for ExecutionFinishedEvent notifications if it wants to be notified when something causes the thread to stop (generally a workspace execution error or an explicit call to the stop() member function). Clients can also use the wait() member function to block their own thread until the Updater stops, but be aware that this would only make sense if either the Updater is not running in continuous mode or if some other thread will cause the Updater to stop. Clients can also use the getLastResult() member function to check whether the last time the Updater stopped was due to an error or through normal means.

All events considered part of the Updater API will be subclasses of ExecutionEvent. Other events may be issued by an Updater, but they are either forwarded from elsewhere or are meant for internal use.

Note
All member functions are thread-safe.

Member Enumeration Documentation

◆ ExecutionMode

Enumerates the execution modes of an Updater.

Enumerator
ExecuteContinuously 

Specifies the Updater will update the workspaces to which it is attached indefinitely.

ExecuteOnce 

Specifies the Updater will update the workspaces to which it is attached once only.

Constructor & Destructor Documentation

◆ Updater()

Updater ( )

Clients would not normally create their own Updater instance directly. This process is normally done automatically by a workspace whenever the execution thread is needed internally. See the Updater class details for more information.

◆ ~Updater()

~Updater ( )
overridedefault

Member Function Documentation

◆ addToUpdateSet()

void addToUpdateSet ( Updatable updatable,
bool  addToFront = false 
)
Parameters
updatableThe updatable object to add to the update set. If it is already in the set, its reference count will be increased by one.
addToFrontAdd the updatable to the front. If it is already in the set, move it to the front.

When processUpdateSet() is called, all objects in the update set will be brought up to date by the execution thread. It is allowable to add more objects to the update set during execution, since addToUpdateSet() is threadsafe.

The order in which updates occur is undefined. So as to ensure that all objects in the set are updated fairly, the order is rotated during execution. If the order of evaluation is important, this needs to be expressed in the workspace itself via dependency relationships.

Although you can add and remove items to/from the update set during execution, you cannot add and remove the objects themselves to/from the workspace while execution is taking place.

The items in the update set are reference-counted. Each call to addToUpdateSet() must eventually have a matching call to removeFromUpdateSet().

See also
removeFromUpdateSet()

◆ clearErrorSource()

void clearErrorSource ( )

This function clears the current error source and raises an ExecutionErrorEvent notification before returning

◆ currentUpdatableCausingQueuing()

Updatable * currentUpdatableCausingQueuing ( )
Returns
The Updatable we are currently queuing changes because of or NULL if changes are not being queued.

◆ currentUpdateIsDelayed()

bool currentUpdateIsDelayed ( ) const
Returns
True if the execution thread has been asked to delay the update to whatever is currently being updated.
Warning
This function must only be called from the execution thread and only while it is running (ie in the middle of an update). Unlike delayCurrentUpdate(), however, it may be called by client code, typically to check if it should log error messages due to failed updates. Still, it is usually only workspace code which needs to check for this since most client code only logs error messages when something inside its own execute() function fails.

◆ delayCurrentUpdate()

void delayCurrentUpdate ( Updatable delayedSource)
Warning
Client code generally never calls this function. It is only meant to be called by the workspace code when it detects a request to update something which is inside some kind of loop and therefore should not be updated directly but rather only as a consequence of the loop update.
Parameters
delayedSourceThis should be the object on which the current update is being delayed. It is only needed in case the execution thread ends up detecting a circular dependency and needs to provide an object within that circular dependency along with its AbortExecutionEvent notification.

Calling this funciton informs the execution thread that whatever it is currently trying to bring up to date, it needs to be delayed because it relies on something else. This normally only applies to something inside some kind of loop requesting to be updated before the loop itself. By delaying the object's update until after the loop, it will be updated in due course anyway as part of the loop processing.

Warning
This function must only be called from the execution thread and only while it is running (ie in the middle of an update).
See also
currentUpdateIsDelayed()

◆ doTask()

void doTask ( )
overridevirtual

Performs the task of updating a set of updatable objects.

Implements Task.

◆ flushLog()

void flushLog ( )

Ensures that all data sent to the log has been flushed. This usually only matters when data is being sent to a file and the text is being buffered, but buffering may also be used on other log destinations as well. Calling flushLog() ensures that all text has been sent to the logging destination.

◆ getErrorSource()

Updatable * getErrorSource ( ) const
Returns
The updatable object associated with the current error, or a null pointer if there is no current error.
See also
setErrorSource(), clearErrorSource()

◆ getExecutionMode()

Updater::ExecutionMode getExecutionMode ( ) const

Returns the ExecutionMode of the Updater.

Returns
The Updater's ExecutionMode.

◆ getStopRequested()

bool getStopRequested ( ) const
Returns
True if there is already an active stop request.

◆ getThreadObject()

QObject * getThreadObject ( )
Returns
The QObject associated with a running execution thread, or a null pointer if the thread is not running.

This function is mostly useful when you want to parent something to a QObject that belongs to an execution thread. When the execution thread stops, the QObject is destroyed and so will all of the QObject's children. Client code should not try to use the returned QObject for anything other than setting it as parent for something else.

◆ isPaused()

bool isPaused ( ) const
Returns
True if the execution thread is currently paused. This is mostly useful for verifying assumptions during development.

◆ isReadyToProcessUpdateRequests()

bool isReadyToProcessUpdateRequests ( ) const

Returns true if the Updater is ready to start processing events.

◆ isRunning()

bool isRunning ( )

Returns true if the Updater is running.

◆ logText()

void logText ( const QString &  msg)
Parameters
msgThe message to log.

◆ moveToMainThread()

void moveToMainThread ( )
overridevirtual

Reimplemented from Task.

◆ pauseUpdate()

void pauseUpdate ( )

◆ popUpdatableToQueueChangesOn()

void popUpdatableToQueueChangesOn ( Updatable u)

Pop an Updatable off the queue changes list

See also
pushUpdatableToQueueChangesOn()

◆ processUpdateSet()

void processUpdateSet ( )

Request that the updater thread brings all items in the update set up to date. This function can be called multiple times and without fear of accumulating unnecessary requests for an update. The thread will ensure that no more than one pending processing request is created. Extra requests are simply discarded.

It is also safe to call this function even if the execution thread is not running, since the function call raises a notification that the thread responds to only if it is running.

◆ pushUpdatableToQueueChangesOn()

void pushUpdatableToQueueChangesOn ( Updatable u)

If an Updatable wants all data changes to be queued while it is updating then it can push itself onto this list. The DataUpdater observer will check the top of this list and wont give WidgetConnectors a chance to make any changes during PauseUpdate events if something is there.

◆ removeFromUpdateSet()

void removeFromUpdateSet ( Updatable updatable)
Parameters
updatableThe updatable object to remove from the update set. It will have its reference count decreased by one and will only be actually removed if the reference count for it drops to zero.

When processUpdateSet() is called, all objects in the update set will be brought up to date by the execution thread. It is allowable to remove an object from the update set during execution, since this function is threadsafe. Note, however, that it is not allowable to delete an object during execution. Were an object to be removed, it would be possible that the thread is currently updating it, so callers cannot do anything with an object while execution is in progress.

The items in the update set are reference-counted. Each call to removeFromUpdateSet() should have had a matching addToUpdateSet() in the past. Only once the reference count drops to zero will the item actually be removed from the update set, since while the reference count is a positive number, something still wants it to be updated.

See also
addToUpdateSet()

◆ requestStop()

void requestStop ( )

Request that the updater thread stops, but let it try to do so gracefully. This normally means allowing the currently executing operation to complete before stopping. If you really want the thread to stop straight away, call terminate() instead. Note, however, that this will likely result in corrupted data.

◆ resetStopRequestFlag()

void resetStopRequestFlag ( )

◆ setErrorSource()

void setErrorSource ( Updatable errorSource)
Parameters
errorSourceThe object that has just encountered an error during execution.

This function is typically called by Operation::update() when a call to its execute() function fails. The call to setErrorSource() is made just before update() returns false. The main purpose of this call is to allow interested parties to be notified of the error and to be able to find out what the source of the error was. Note that any error message should already have been output by the operation and so is not available nor required here.

This function will raise an ExecutionErrorEvent notification before returning.

See also
getErrorSource(), clearErrorSource()

◆ setExecutionMode()

void setExecutionMode ( ExecutionMode  mode)

Configures the execution mode of the UpdaterImpl.

Parameters
modeThe execution mode.

◆ stopAndWaitUntilFinishedRunning()

void stopAndWaitUntilFinishedRunning ( )

Requests the updater thread stop and waits (i.e. blocks) until the workspace has finished being updated.

◆ terminate()

void terminate ( )

Cause the thread to stop execution immediately. This is generally not recommended, since it will likely result in corrupted data. This function is a blunt instrument to be used only in desperate situations (typically error handling and aborting an application). Clients should prefer to call stop() instead where possible.

◆ transferWorkspace()

void transferWorkspace ( Workspace workspace,
Updater fromUpdater 
)