rotor_light
real-time C++ actor micro-framework for embedded systems, supervisable
rotor_light::ActorBase Struct Reference

base interface and implementation for all actors, including supervisors More...

#include <actor.hpp>

Inheritance diagram for rotor_light::ActorBase:
rotor_light::Actor< HandlersCount > rotor_light::SupervisorBase rotor_light::Supervisor< HandlersCount, Actors >

Classes

struct  Handler
 runtime info about message subscription handler More...
 
struct  handler_traits
 helps method signature extraction More...
 
struct  handler_traits< void(A::*)(M &)>
 

Public Types

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
 

Public Member Functions

 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)
 

Static Public Attributes

static constexpr size_t min_handlers_amount = 1
 

Protected Member Functions

 ActorBase (char *backends, size_t backends_count)
 
virtual void advance_init ()
 
virtual void advance_start ()
 
virtual void advance_stop ()
 

Protected Attributes

ActorId id
 
ActorId mask
 
State state = State::off
 
SupervisorBasesupervisor
 
FailPolicy fail_policy
 

Friends

struct SupervisorBase
 

Detailed Description

base interface and implementation for all actors, including supervisors

Constructor & Destructor Documentation

◆ 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.

Member Function Documentation

◆ 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

assign actor id, supervisor and context. Performed only ONCE per program lifetime

Reimplemented in rotor_light::SupervisorBase.

◆ 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

returns actor id

◆ 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

set actor fail policy

◆ 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()

Member Data Documentation

◆ fail_policy

FailPolicy rotor_light::ActorBase::fail_policy
protected

actor's fail policy

◆ 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

current actor state

◆ supervisor

SupervisorBase* rotor_light::ActorBase::supervisor
protected

pointer to the owner/supervisor


The documentation for this struct was generated from the following files: