#include <qb/actor.h>
Classes | |
class | EventBuilder |
Helper to build Events. More... | |
Protected Member Functions | |
Registered Event | |
void | on (KillEvent const &event) |
Receiving this event will kill the Actor. More... | |
Construction/Destruction | |
Actor ()=default | |
virtual | ~Actor ()=default |
virtual bool | onInit ()=0 |
DerivedActor should implement this method. More... | |
void | kill () const |
Public Accessors | |
ActorId | id () const |
uint16_t | getIndex () const |
uint64_t | time () const |
Get current time. More... | |
bool | isAlive () const |
Check if Actor is alive. More... | |
Public Member Functions | |
This part describes how to manage Actor loop callback, events registration, several ways to send events and create referenced actors. | |
template<typename _Actor > | |
void | registerCallback (_Actor &actor) const |
Register a looped callback. More... | |
template<typename _Actor > | |
void | unregisterCallback (_Actor &actor) const |
Unregister actor callback. More... | |
template<typename _Event , typename _Actor > | |
void | registerEvent (_Actor &actor) |
Actor will listen on new _Event. More... | |
template<typename _Event , typename _Actor > | |
void | unregisterEvent (_Actor &actor) |
Actor will stop listening _Event. More... | |
EventBuilder | to (ActorId const dest) const |
Get EventBuilder for ActorId destination. More... | |
template<typename _Event , typename ... _Args> | |
_Event & | push (ActorId const &dest, _Args &&...args) const |
Send a new ordered event. More... | |
template<typename _Event , typename ... _Args> | |
void | send (ActorId const &dest, _Args &&...args) const |
Send a new unordered event. More... | |
void | reply (Event &event) const |
Reply an event. More... | |
void | forward (ActorId const dest, Event &event) const |
Forward an event. More... | |
ProxyPipe | getPipe (ActorId const dest) const |
Get access to unidirectional out events pipe. More... | |
template<typename _Actor , typename ... _Args> | |
_Actor * | addRefActor (_Args &&...args) const |
Create new referenced _Actor. More... | |
Actor base class.
The Actor sends event messages to be received by another Actor, which is then treated by an Event handler.
All UserActors should inherit from Actor class.
|
protecteddefault |
|
protectedvirtualdefault |
|
protectedpure virtual |
DerivedActor should implement this method.
example:
void qb::Actor::kill | ( | ) | const |
Kill the Actor
|
protected |
Receiving this event will kill the Actor.
event | received event |
This event can be overloaded by DerivedActor.
example:
uint16_t qb::Actor::getIndex | ( | ) | const |
Get current core index
uint64_t qb::Actor::time | ( | ) | const |
Get current time.
void qb::Actor::registerCallback | ( | _Actor & | actor | ) | const |
Register a looped callback.
actor | reference of DerivedActor |
The registered callback will be called each VirtualCore loop.
_Actor must inherit and implement ICallback interface.
example:
void qb::Actor::unregisterCallback | ( | _Actor & | actor | ) | const |
Unregister actor callback.
actor | reference of DerivedActor |
example:
void qb::Actor::registerEvent | ( | _Actor & | actor | ) |
void qb::Actor::unregisterEvent | ( | _Actor & | actor | ) |
Actor will stop listening _Event.
_Event | DerivedEvent type |
actor | reference of DerivedActor |
example:
EventBuilder qb::Actor::to | ( | ActorId const | dest | ) | const |
Get EventBuilder for ActorId destination.
dest | ActorId destination |
A way to push chained events to destination Actor.
example:
_Event& qb::Actor::push | ( | ActorId const & | dest, |
_Args &&... | args | ||
) | const |
Send a new ordered event.
_Event | DerivedEvent type |
dest | destination ActorId |
args | arguments to forward to the constructor of the _Event |
All events pushed to same actors id in context will be received ordered by push order.
example:
void qb::Actor::send | ( | ActorId const & | dest, |
_Args &&... | args | ||
) | const |
Send a new unordered event.
_Event | DerivedEvent type |
dest | destination ActorId |
args | arguments to forward to the constructor of the _Event |
All events sent using send function are not guaranteed to be received in order.
example:
void qb::Actor::reply | ( | Event & | event | ) | const |
_Actor* qb::Actor::addRefActor | ( | _Args &&... | args | ) | const |
Create new referenced _Actor.
_Actor | DerivedActor type |
args | arguments to forward to the constructor of the _Actor |
create and initialize new _Actor on same VirtualCore as the callee Actor.
example: