$darkmode
transition_event.hpp File Reference
#include <string>
#include <cloe/registrar.hpp>
#include <cloe/trigger.hpp>
Include dependency graph for transition_event.hpp:

Go to the source code of this file.

Classes

class  cloe::events::Transition< T >
 
class  cloe::events::TransitionFactory< T >
 

Typedefs

template<typename T >
using cloe::events::TransitionCallback = DirectCallback< Transition< T >, T >
 

Detailed Description

See also
cloe/trigger/transition_event.cpp

This file defines the Transition event and the corresponding TransitionFactory and TransitionCallback.

These can be used to trigger an event when a certain transition occurs, for example from one enum value to another.

For example, let us say that our model would like to provide users a way to trigger when certain changes in the ACC state machine occur. Let us assume that the state enum contains values:

enum AccState { ... ACC_ACTIVE = 1, ACC_OVERRIDE = 3 };

void to_json(Json& j, const AccState& s); void from_json(const Json& j, AccState& s);

These could be exposed to the user as strings or as integers. The user should then be able to insert a trigger with the event corresponding to:

ACC_ACTIVE transitions to TARGET_SET_SPEED {"name": "acc_state", "from": 1, "to": 3} "acc_state=1->3"

The model will need to add the TransitionCallback to its class:

std::shared_ptr<events::TransitionCallback<AccState>> callback_set_speed_;

And in it's enroll(Registrar& r) method, it should register the callback:

callback_set_speed_ = register_event<events::Transition<AccState>, AccState>( r, std::make_unique<events::TransitionFactory<AccState>>( name() + "/acc_state", "ACC state transitions (int)"));

In the process(const Sync& s) method, the trigger can then be called:

callback_set_speed_->trigger(s, acc_state_);