ePrivacy and GPDR Cookie Consent by Cookie Consent

Firing events

Both synchronous and asynchronous state machines provide a “fire_event” method for sending an event to the state machine. The event is processed right away (for the synchronous state machine) or enqueued for processing (for the asynchronous state machine).

There area couple of macros for creating event classes inherited from specialized_event class. The list of the macros with description, is available on the Creating event classes page.

Creating an event with static method

There is a class implementation of the event interface called event_impl that can be used to create basic events.

The usage of the static member function create( _event_id, _event_priority ) will create an event with the given event ID and given event priority without parameters. DEFAULT_EVENT_PRIORITY is set as a default value for the event priority parameter.

Using the static methods

An example of usage for the static methods can be found on the Hello, yasmine! example page and it's going to look like this:

const sxy::event_id HELLO_EVENT = 1;
hello_yasmine_state_machine->fire_event( sxy::event_impl::create( HELLO_EVENT ) );

Using macro created event

As is described in the Creating event classes page, in yasmine there are macros for creating different event classes.

An example of macro use for creating event classes and firing events, can be found on the The classic farmroad example page. The code looks like this:

Y_EVENT_WITH_ID( EVENT_SWITCH_TO_RED_YELLOW, 1 );
traffic_light_state_machine_.fire_event( EVENT_SWITCH_TO_RED_YELLOW::create() );