|
The **Active Object** design pattern decouples method execution from method invocation.
|
|
The **Active Object** design pattern decouples method execution from method invocation.
|
|
An active object is an object that "runs" in a *separate thread*.
|
|
An active object is an object that "runs" in a _separate thread_.
|
|
|
|
|
|
It can be useful for in a situation in which an object has to periodically pop elements from a queue, which are in turn produced by a second thread or for example for a receiver object that has to continuously check for incoming messages.
|
|
It can be useful for in a situation in which an object has to periodically pop elements from a queue, which are in turn produced by a second thread or for example for a receiver object that has to continuously check for incoming messages.
|
|
|
|
|
... | @@ -7,9 +7,9 @@ In `src/shared/` you can find the corresponding template. |
... | @@ -7,9 +7,9 @@ In `src/shared/` you can find the corresponding template. |
|
|
|
|
|
## Implementation
|
|
## Implementation
|
|
The most relevant functions are:
|
|
The most relevant functions are:
|
|
- **virtual bool start()**: creates a Miosix Thread, which in turn call *threadLauncher()*. It returns a bool indicating whether the thread was correctly created or not.
|
|
- **virtual bool start()**: creates a Miosix Thread, which in turn call _threadLauncher()_. It returns a bool indicating whether the thread was correctly created or not.
|
|
- **virtual void stop()**: stop the ActiveObject's and join its thread.
|
|
- **virtual void stop()**: stop the ActiveObject's and join its thread.
|
|
- **static void threadLauncher(void\* arg)**: private static function that is executed from the thread, which in turn calls the *run()* method.
|
|
- **static void threadLauncher(void\* arg)**: private static function that is executed from the thread, which in turn calls the _run()_ method.
|
|
- **virtual void run()**: protected method, should be overridden with the code that you want to run in the thread.
|
|
- **virtual void run()**: protected method, should be overridden with the code that you want to run in the thread.
|
|
|
|
|
|
## Example
|
|
## Example
|
... | | ... | |