base interface and implementation for all supervisors
More...
#include <supervisor.hpp>
|
using | Parent = ActorBase |
|
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
|
|
|
| SupervisorBase (char *backends, size_t backends_count, ActorBase **actors, details::ChildState *states, size_t actors_count) |
|
QueueBase * | get_queue () |
|
void | initialize () override |
|
void | start (bool poll_timer=false) |
| starts all actors (initialize, wait confirmation etc.) More...
|
|
virtual void | bind (Context &context, ActorId value=0) |
|
uint8_t | bind (ActorId initial_value, SupervisorBase *supervisor, Context &context) override |
|
void | process () |
|
void | advance_init () override |
|
void | advance_start () override |
|
void | advance_stop () override |
|
PlannerBase * | get_planner () |
|
| ActorBase (const ActorBase &)=delete |
|
| ActorBase (ActorBase &&)=delete |
|
virtual void | initialize () |
|
virtual uint8_t | bind (ActorId initial_value, SupervisorBase *supervisor, Context &context) |
|
ActorId | get_id () const |
|
State | get_state () const |
|
FailPolicy | get_fail_policy () const |
|
void | set_fail_policy (FailPolicy value) |
|
void | stop () |
|
template<typename Ctx > |
EventId | add_event (Duration delta, Callback callback, void *data) |
|
void | cancel_event (EventId event_id) |
|
template<typename Ctx , typename MessageType , typename... Args> |
bool | send (size_t queue_index, Args... args) |
| emplaces new message into appropriate queue More...
|
|
template<typename Method > |
void | subscribe (Method method) |
|
base interface and implementation for all supervisors
◆ Parent
convenient alias to the parent struct
◆ SupervisorBase()
rotor_light::SupervisorBase::SupervisorBase |
( |
char * |
backends, |
|
|
size_t |
backends_count, |
|
|
ActorBase ** |
actors, |
|
|
details::ChildState * |
states, |
|
|
size_t |
actors_count |
|
) |
| |
◆ advance_init()
void rotor_light::SupervisorBase::advance_init |
( |
| ) |
|
|
overridevirtual |
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 from rotor_light::ActorBase.
◆ advance_start()
void rotor_light::SupervisorBase::advance_start |
( |
| ) |
|
|
overridevirtual |
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 from rotor_light::ActorBase.
◆ advance_stop()
void rotor_light::SupervisorBase::advance_stop |
( |
| ) |
|
|
overridevirtual |
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 from rotor_light::ActorBase.
◆ bind() [1/2]
uint8_t rotor_light::SupervisorBase::bind |
( |
ActorId |
initial_value, |
|
|
SupervisorBase * |
supervisor, |
|
|
Context & |
context |
|
) |
| |
|
overridevirtual |
assign actor id, supervisor and context. Performed only ONCE per program lifetime
Reimplemented from rotor_light::ActorBase.
◆ bind() [2/2]
virtual void rotor_light::SupervisorBase::bind |
( |
Context & |
context, |
|
|
ActorId |
value = 0 |
|
) |
| |
|
virtual |
Binds context to the supervisor and all its children. Permanent actorIds are created and assigned during this phase.
This method should be invoked only once in lifetime of actors.
◆ get_planner()
PlannerBase * rotor_light::SupervisorBase::get_planner |
( |
| ) |
|
|
inline |
returns pointer to the planner
◆ get_queue()
QueueBase * rotor_light::SupervisorBase::get_queue |
( |
| ) |
|
|
inline |
◆ initialize()
void rotor_light::SupervisorBase::initialize |
( |
| ) |
|
|
overridevirtual |
Perform actor intialization, namely subscription to methods. Can ba invoked multiple times, if the actor is restarted several times.
Reimplemented from rotor_light::ActorBase.
◆ on_refhesh_timer()
refreshes time, processes expired time events and re-schedules RefreshTime
message
The method can be overriden to do something useful "on idle".
◆ process()
void rotor_light::SupervisorBase::process |
( |
| ) |
|
"Main loop" of the framework, which does messages dispatching. As the new messages are usually generated during messages dispatching this method never exits under normal circumstances.
It can exit in two cases:
- There are no more messages. This might happen if the endless timer polling is enabled in
start
method. This means, that you intentionally do that, e.g. to enter into a sleep mode and do some power-saving before the next event. Platform-specific sleep and awake codes should be implemented to achive that.
- Supervisor has terminated, and there is no sense of further restart attempts. Usually that means, that supervisor did its best, all restarts (having sense) has been applied without effect, and nothing can be done, possibly due to unrecoverable hardware failure; or the supervisor has terminated due to its job is done. Usually that means board restart or poweroff.
◆ start()
void rotor_light::SupervisorBase::start |
( |
bool |
poll_timer = false | ) |
|
starts all actors (initialize, wait confirmation etc.)
- Parameters
-
poll_timer | whether RefreshTime message should be send self on idle. When it is, the process method will never exit in normal circumstances |
◆ actors
ActorBase** rotor_light::SupervisorBase::actors |
|
protected |
pointer to child actor holding pointers
◆ actors_count
size_t rotor_light::SupervisorBase::actors_count |
|
protected |
the amount of child actors
◆ min_handlers_amount
constexpr size_t rotor_light::SupervisorBase::min_handlers_amount |
|
staticconstexpr |
Initial value:=
static constexpr size_t min_handlers_amount
Definition: actor.hpp:55
the minimum amount of handles, which should a derived actor class pre-allocate
◆ now
NowFunction rotor_light::SupervisorBase::now |
|
protected |
function pointer, which can return "now"
◆ planner
◆ queue
QueueBase* rotor_light::SupervisorBase::queue |
|
protected |
pointer to the master queue
◆ states
pointer to child actor states
The documentation for this struct was generated from the following file:
- /home/b/development/cpp/cpp-rotor-light/include/rotor-light/supervisor.hpp