SmartSoft Component-Developer API
|
Encapsulates a user-level thread. More...
#include <smartITask.h>
Public Member Functions | |
ITask (IComponent *component=nullptr) | |
Default constructor. More... | |
virtual | ~ITask ()=default |
Default destructor. More... | |
virtual int | start ()=0 |
Creates and starts a new thread (if not yet started) More... | |
virtual int | stop (const bool wait_till_stopped=true)=0 |
Stops the currently active thread (if it was started before) More... | |
Public Member Functions inherited from Smart::IShutdownObserver | |
IShutdownObserver (ShutdownSubject *subject=nullptr) | |
The default constructor. More... | |
virtual | ~IShutdownObserver () |
The default destructor. More... | |
Protected Member Functions | |
virtual void | on_shutdown () |
Default implementation of the IShutdownObserver interface. More... | |
virtual bool | test_canceled ()=0 |
Tests whether the thread has been signaled to stop. More... | |
virtual void | sleep_for (const Duration &duration)=0 |
Blocks execution of the calling thread during the span of time specified by rel_time. More... | |
virtual int | task_execution ()=0 |
Method which runs in a separate thread if activated. More... | |
Protected Member Functions inherited from Smart::IShutdownObserver | |
void | attach_self_to (ShutdownSubject *subject) |
call this method from within the constructor of derived classes More... | |
void | detach_self_from (ShutdownSubject *subject) |
this method is called within the destructor More... | |
Encapsulates a user-level thread.
ITasks should be used to implement user-level threads within a component. ITasks are managed by the provided IComponent instance. For example, during component shutdown, the ITask are automatically triggered to stop(). In this way, user-threads can properly shutdown and clean-up their local resources such as e.g. closing internally used device drivers. Please overload the on_shutdown() upcall method in case you need to perform individual cleanup procedures.
|
inline |
Default constructor.
|
virtualdefault |
Default destructor.
|
inlineprotectedvirtual |
Default implementation of the IShutdownObserver interface.
The default shutdown procedure is to call the stop() method which triggers the thread to stop and awaits until it is closed using the internal join method.
Implements Smart::IShutdownObserver.
Reimplemented in Smart::IManagedTask.
|
protectedpure virtual |
Blocks execution of the calling thread during the span of time specified by rel_time.
Thread-sleeping is sometimes platform-specific. This method encapsulates the blocking sleep. Calling this method blocks the execution of the calling thread for a time specified by rel_time.
duration | relative time duration for the thread to sleep |
|
pure virtual |
Creates and starts a new thread (if not yet started)
A new thread is spawned if no thread has been spawned yet before for this instance.
|
pure virtual |
Stops the currently active thread (if it was started before)
The internal thread is signaled to stop. If wait_till_stopped is set to true then the call to this method blocks until the internal thread has actually exited (typically using thread.join() internally).
wait_till_stopped | waits until the thread has been exited |
|
protectedpure virtual |
Method which runs in a separate thread if activated.
The task_execution() method has to be provided (i.e. overloaded) by the user and it implements the activity of the task object.
Implemented in Smart::IManagedTask.
|
protectedpure virtual |
Tests whether the thread has been signaled to stop.
This method allows to implement cooperative thread stopping.