Class Event::Initializer

Nested Relationships

This class is a nested type of Class Event.

Class Documentation

class Initializer

The Event::Initializer class is the Event equivalent to the rmf_task::Activator class. It consumes an Event::Description and produces

Public Types

template<typename Description>
using Initialize = std::function<StandbyPtr(const AssignIDPtr &id, const std::function<rmf_task::State()> &get_state, const ConstParametersPtr &parameters, const Description &description, std::function<void()> update)>

Signature for initializing an Event

Warning

The update function must not be triggered during initialization because upstream event handlers will not be ready to handle it. The event state will always be checked right after initialization is finished anyway, so there is no need to trigger this.

Template Parameters:

Description – A class that implements the Event::Description interface

Param id:

[in] An object to help assign an ID to each event

Param get_state:

[in] A callback for retrieving the current state of the robot

Param parameters:

[in] A reference to the parameters for the robot

Param description:

[in] The down-casted description of the event

Param backup_state:

[in] The serialized backup state of the Event, if the Event is being restored from a crash or disconnection. If the Event is not being restored, a std::nullopt will be passed in here.

Param update:

[in] A callback that will be triggered when a notable change happens for this event.

Return:

an Event in a Standby state

template<typename Description>
using Restore = std::function<ActivePtr(const AssignIDPtr &id, const std::function<rmf_task::State()> &get_state, const ConstParametersPtr &parameters, const Description &description, const nlohmann::json &backup_state, std::function<void()> update, std::function<void()> checkpoint, std::function<void()> finished)>

Signature for restoring an Event

Warning

The update function must not be triggered during initialization because upstream event handlers will not be ready to handle it. The event state will always be checked right after initialization is finished anyway, so there is no need to trigger this.

Template Parameters:

Description – A class that implements the Event::Description interface

Param id:

[in] An object to help assign an ID to each event

Param get_state:

[in] A callback for retrieving the current state of the robot

Param parameters:

[in] A reference to the parameters for the robot

Param description:

[in] The down-casted description of the event

Param backup_state:

[in] The backup state of the Event.

Param update:

[in] A callback that will be triggered when a notable change happens for this event.

Param checkpoint:

[in] A callback that will be triggered when the event reaches a “checkpoint” meaning that the task state should be backed up.

Param finished:

[in] A callback that will be triggered when the event reaches a Finished state

Return:

a restored Event in an Active state

Public Functions

Initializer()

Construct an empty Initializer.

template<typename Desc>
void add(Initialize<Desc> initializer, Restore<Desc> restorer)

Add a callback to convert from a Description to an event in standby mode.

StandbyPtr initialize(const AssignIDPtr &id, const std::function<rmf_task::State()> &get_state, const ConstParametersPtr &parameters, const Event::Description &description, std::function<void()> update) const

Initialize an event

Warning

The update function must not be triggered during initialization because upstream event handlers will not be ready to handle it. The event state will always be checked right after initialization is finished anyway, so there is no need to trigger this.

Parameters:
  • id[in] An object to help assign an ID to each event

  • get_state[in] A callback for retrieving the current state of the robot

  • parameters[in] A reference to the parameters for the robot

  • description[in] The description of the event

  • update[in] A callback that will be triggered when a notable change happens for this event.

Returns:

an Event in a Standby state

ActivePtr restore(const AssignIDPtr &id, const std::function<rmf_task::State()> &get_state, const ConstParametersPtr &parameters, const Event::Description &description, const nlohmann::json &backup, std::function<void()> update, std::function<void()> checkpoint, std::function<void()> finished) const

Signature for restoring an Event

Warning

The update function must not be triggered during initialization because upstream event handlers will not be ready to handle it. The event state will always be checked right after initialization is finished anyway, so there is no need to trigger this.

Parameters:
  • id[in] An object to help assign an ID to each event

  • get_state[in] A callback for retrieving the current state of the robot

  • parameters[in] A reference to the parameters for the robot

  • description[in] The down-casted description of the event

  • backup_state[in] The backup state of the Event.

  • update[in] A callback that will be triggered when a notable change happens for this event.

  • checkpoint[in] A callback that will be triggered when the event reaches a “checkpoint” meaning that the task state should be backed up.

  • finished[in] A callback that will be triggered when the event reaches a Finished state

Returns:

a restored Event in an Active state