Action Engine
Loading...
Searching...
No Matches
act::ActionRegistry Class Reference

Detailed Description

A registry for ActionEngine actions.

This class is used to register actions with their schemas and handlers, and provides methods to create action messages and instances based on the registered schemas.

#include <actionengine/actions/registry.h>

Public Member Functions

void Register (std::string_view name, const ActionSchema &schema, const ActionHandler &handler)
 Registers an action with the given name, schema, and handler.
 
bool IsRegistered (std::string_view name) const
 Checks if an action with the given name is registered.
 
ActionMessage MakeActionMessage (std::string_view name, std::string_view id) const
 Creates an ActionMessage for the action with the given name and ID.
 
std::unique_ptr< ActionMakeAction (std::string_view name, std::string_view action_id="", std::vector< Port > inputs={}, std::vector< Port > outputs={}) const
 Creates an action instance based on the registered schema and handler.
 
const ActionSchemaGetSchema (std::string_view name) const
 Gets the schema of the action with the given name.
 
const ActionHandler & GetHandler (std::string_view name) const
 Gets the handler of the action with the given name.
 

Member Function Documentation

◆ GetHandler()

const ActionHandler & act::ActionRegistry::GetHandler ( std::string_view name) const
nodiscard

Gets the handler of the action with the given name.

Note: TERMINATES if the action is not registered, so you must use IsRegistered() before calling this method to ensure the action exists.

Parameters
nameThe name of the action whose handler is requested.
Returns
The ActionHandler of the action with the given name.

◆ GetSchema()

const ActionSchema & act::ActionRegistry::GetSchema ( std::string_view name) const
nodiscard

Gets the schema of the action with the given name.

Note: TERMINATES if the action is not registered, so you must use IsRegistered() before calling this method to ensure the action exists.

Parameters
nameThe name of the action whose schema is requested.
Returns
The ActionSchema of the action with the given name.

◆ IsRegistered()

bool act::ActionRegistry::IsRegistered ( std::string_view name) const
nodiscard

Checks if an action with the given name is registered.

Notice that when dealing with a particular registry whose content you are not sure about, you MUST always check if the action is registered before using any other methods, as otherwise they will fail, terminating the program with a CHECK failure.

Parameters
nameThe name of the action to check.
Returns
True if the action is registered, false otherwise.

◆ MakeAction()

std::unique_ptr< Action > act::ActionRegistry::MakeAction ( std::string_view name,
std::string_view action_id = "",
std::vector< Port > inputs = {},
std::vector< Port > outputs = {} ) const
nodiscard

Creates an action instance based on the registered schema and handler.

This method creates an Action object that can be used to call or run the action with the specified inputs and outputs. The action will be created with the schema and handler registered under the given name.

Note: TERMINATES if the action is not registered, so you must use IsRegistered() before calling this method to ensure the action exists.

Parameters
nameThe key of the action to create, which must be registered.
action_idThe ID of the action instance. If empty, a unique ID will be generated.
inputsA vector of input ports for the action.
outputsA vector of output ports for the action.
Returns
An owning pointer to the newly created Action instance.

◆ MakeActionMessage()

ActionMessage act::ActionRegistry::MakeActionMessage ( std::string_view name,
std::string_view id ) const
nodiscard

Creates an ActionMessage for the action with the given name and ID.

This method generates an ActionMessage that can be used to call the action by sending it in a WireMessage over a WireStream.

Note: TERMINATES if the action is not registered, so you must use IsRegistered() before calling this method to ensure the action exists.

Parameters
nameThe name of the action.
idThe ID of the action instance. Must not be empty.
Returns
An ActionMessage representing the action with the given name and ID.

◆ Register()

void act::ActionRegistry::Register ( std::string_view name,
const ActionSchema & schema,
const ActionHandler & handler )

Registers an action with the given name, schema, and handler.

This method adds the action to the registry, allowing it to be created later using MakeAction or MakeActionMessage.

Parameters
nameThe name of the action. Must be unique within the registry.
schemaThe schema of the action, defining its inputs and outputs.
handlerThe handler function that will be called when the action is executed.

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