base interface and implementation for all actors, including supervisors
More...
#include <actor.hpp>
|
using | GenericMethod = void(ActorBase::*)(Message &) |
| alias for generic message handler
|
|
using | MethodEntry = void(*)(Message &, ActorBase &, Handler &) |
| alias for method entry, enough to actually perfrom message delivery
|
|
base interface and implementation for all actors, including supervisors
◆ ActorBase()
rotor_light::ActorBase::ActorBase |
( |
char * |
backends, |
|
|
size_t |
backends_count |
|
) |
| |
|
protected |
main actor ctor, takes pointer to backend storage and backends count.
Sets the fail policy to escalate by default.
◆ add_event()
template<typename Ctx >
EventId rotor_light::ActorBase::add_event |
( |
Duration |
delta, |
|
|
Callback |
callback, |
|
|
void * |
data |
|
) |
| |
adds event, which will trigger in THREAD context after the specified duration by invoking callbacke with the supplied data.
The templated ctx is either ctx::thread (masks/unmasks interrupts) or ctx::interrupt (does nothing).
◆ advance_init()
virtual void rotor_light::ActorBase::advance_init |
( |
| ) |
|
|
protectedvirtual |
this method is invoked, when actor received "change state" message from it's supervisor, i.e. to advance from "off" state to "initialized" state.
The idea to override this method in your actor class to perform some hardware initialization, may be asynchronously, and when it is ready call the advance_init() in the parent class to acknowledge successful initialization to supervisor.
If the initialization fails, then instead of invoking the method, the actor should send message::ChangeStateAck
with the false value.
Reimplemented in rotor_light::SupervisorBase.
◆ advance_start()
virtual void rotor_light::ActorBase::advance_start |
( |
| ) |
|
|
protectedvirtual |
this method is invoked, when supervisor is ready to operate, i.e. all other actors acknowledged successful initialialization and it is time to initiate communication.
Usually this is "pro-active" method, i.e. to send high-level request to let all messaging machinery work
Reimplemented in rotor_light::SupervisorBase.
◆ advance_stop()
virtual void rotor_light::ActorBase::advance_stop |
( |
| ) |
|
|
protectedvirtual |
this method is invoked when the actor is acked to shutdown by supervisor.
The idea is to override the method in a derived class, shutdown hardware (possibly asynchronously), and then invoke the method of the parent class.
Contrary to the advance_init
method, this method have to be invoked sooner or later.
Reimplemented in rotor_light::SupervisorBase.
◆ bind()
virtual uint8_t rotor_light::ActorBase::bind |
( |
ActorId |
initial_value, |
|
|
SupervisorBase * |
supervisor, |
|
|
Context & |
context |
|
) |
| |
|
virtual |
◆ cancel_event()
void rotor_light::ActorBase::cancel_event |
( |
EventId |
event_id | ) |
|
cancels previously created event
◆ get_fail_policy()
FailPolicy rotor_light::ActorBase::get_fail_policy |
( |
| ) |
const |
|
inline |
returns fail policy of the actor
◆ get_id()
ActorId rotor_light::ActorBase::get_id |
( |
| ) |
const |
|
inline |
◆ get_state()
State rotor_light::ActorBase::get_state |
( |
| ) |
const |
|
inline |
returns current state of the actor
◆ initialize()
virtual void rotor_light::ActorBase::initialize |
( |
| ) |
|
|
virtual |
Perform actor intialization, namely subscription to methods. Can ba invoked multiple times, if the actor is restarted several times.
Reimplemented in rotor_light::SupervisorBase.
◆ send()
template<typename Ctx , typename MessageType , typename... Args>
bool rotor_light::ActorBase::send |
( |
size_t |
queue_index, |
|
|
Args... |
args |
|
) |
| |
emplaces new message into appropriate queue
Creates a new messsage of the specified type "in-place" of the specified queue/priority; all supplied args are forwarded to the message contructor
Returns true if the message was succesfully created, and false otherwise, i.e. if the queue is full.
◆ set_fail_policy()
void rotor_light::ActorBase::set_fail_policy |
( |
FailPolicy |
value | ) |
|
|
inline |
◆ stop()
void rotor_light::ActorBase::stop |
( |
| ) |
|
sends self a shutdown request message. The actor is NOT immediatly stopped.
◆ subscribe()
template<typename Method >
void rotor_light::ActorBase::subscribe |
( |
Method |
method | ) |
|
|
inline |
performs instant subscription to the specified message handler
This method should be invoked from initialize()
◆ fail_policy
FailPolicy rotor_light::ActorBase::fail_policy |
|
protected |
◆ id
ActorId rotor_light::ActorBase::id |
|
protected |
actor unique id, assigned once upon bind
method
◆ mask
ActorId rotor_light::ActorBase::mask |
|
protected |
actor mask, used for messages routing.
For simple actors (non-supervisors) it is equal to actor id
For supervisors it is includes actor ids of all owned child-actors, including masks of child-supervisors etc.
◆ min_handlers_amount
constexpr size_t rotor_light::ActorBase::min_handlers_amount = 1 |
|
staticconstexpr |
the minimum amount of handles, which should a derived actor class pre-allocate
◆ state
State rotor_light::ActorBase::state = State::off |
|
protected |
◆ supervisor
pointer to the owner/supervisor
The documentation for this struct was generated from the following files:
- /home/b/development/cpp/cpp-rotor-light/include/rotor-light/actor.hpp
- /home/b/development/cpp/cpp-rotor-light/include/rotor-light/supervisor.hpp