15#ifndef A11_ACTIONS_REGISTRY_H_
16#define A11_ACTIONS_REGISTRY_H_
23#include <absl/base/thread_annotations.h>
24#include <absl/container/flat_hash_map.h>
25#include <absl/status/status.h>
26#include <absl/status/statusor.h>
31#include "thread/boost_primitives.h"
62 absl::Status
Unregister(std::string_view action_name);
64 [[nodiscard]]
bool IsRegistered(std::string_view action_name)
const;
66 absl::StatusOr<ActionSchema>
GetSchema(std::string_view action_name)
const;
68 absl::StatusOr<ActionHandler>
GetHandler(std::string_view action_name)
const;
79 absl::StatusOr<std::shared_ptr<Action>>
MakeAction(
80 std::string_view action_name, std::string action_id = {},
81 std::shared_ptr<nodes::NodeMap> node_map =
nullptr,
82 std::shared_ptr<net::WireStream> stream =
nullptr,
83 std::shared_ptr<service::Session> session =
nullptr);
90 std::string_view action_name, std::string action_id = {});
97 std::shared_ptr<ActionRegistry>
Copy(
bool clear_autofills =
true)
const;
100 mutable thread::Mutex mu_;
101 absl::flat_hash_map<std::string, ActionSchema> schemas_ ABSL_GUARDED_BY(mu_);
102 absl::flat_hash_map<std::string, ActionHandler> handlers_
103 ABSL_GUARDED_BY(mu_);
A11's unit of work: the Action and its supporting types.
A thread-safe catalogue mapping action names to schema and handler.
Definition registry.h:43
absl::StatusOr< data::ActionMessage > MakeActionMessage(std::string_view action_name, std::string action_id={})
Builds the wire a11::data::ActionMessage for a registered action.
Definition registry.cc:120
std::vector< std::string > ListRegisteredActions() const
Returns the names of all registered actions.
Definition registry.cc:127
absl::Status Unregister(std::string_view action_name)
Removes the registration for action_name.
Definition registry.cc:55
absl::Status RegisterSync(std::string action_name, ActionSchema schema, SyncActionHandler handler)
Registers an action with a synchronous handler.
Definition registry.cc:45
absl::StatusOr< std::shared_ptr< Action > > MakeAction(std::string_view action_name, std::string action_id={}, std::shared_ptr< nodes::NodeMap > node_map=nullptr, std::shared_ptr< net::WireStream > stream=nullptr, std::shared_ptr< service::Session > session=nullptr)
Builds a runnable Action for a registered action.
Definition registry.cc:101
std::shared_ptr< ActionRegistry > Copy(bool clear_autofills=true) const
Returns a copy of this registry.
Definition registry.cc:138
absl::Status Register(std::string action_name, ActionSchema schema, ActionHandler handler={})
Registers an action under action_name.
Definition registry.cc:23
bool IsRegistered(std::string_view action_name) const
Whether action_name is registered.
Definition registry.cc:67
absl::StatusOr< ActionSchema > GetSchema(std::string_view action_name) const
Returns the schema for action_name, or NotFound.
Definition registry.cc:74
absl::StatusOr< ActionHandler > GetHandler(std::string_view action_name) const
Returns the handler for action_name, or NotFound.
Definition registry.cc:86
std::function< absl::Status(std::shared_ptr< Action >)> SyncActionHandler
Synchronous action handler returning a completion status.
Definition action.h:70
std::function< a11::Task(std::shared_ptr< Action >)> ActionHandler
Asynchronous action handler: runs the action, returns an awaitable.
Definition action.h:68
Schemas describing an action's typed interface and its settings.
The full typed interface of an action.
Definition schema.h:107
A11's core wire value types: chunks, node fragments and messages.