29#ifndef A11_ACTIONS_REGISTRY_H_
30#define A11_ACTIONS_REGISTRY_H_
37#include <absl/base/thread_annotations.h>
38#include <absl/container/flat_hash_map.h>
39#include <absl/status/status.h>
40#include <absl/status/statusor.h>
45#include "thread/boost_primitives.h"
49class AuthorizationContextStore;
83 absl::Status
Unregister(std::string_view action_name);
85 [[nodiscard]]
bool IsRegistered(std::string_view action_name)
const;
87 absl::StatusOr<ActionSchema>
GetSchema(std::string_view action_name)
const;
89 absl::StatusOr<ActionHandler>
GetHandler(std::string_view action_name)
const;
100 absl::StatusOr<std::shared_ptr<Action>>
MakeAction(
101 std::string_view action_name, std::string action_id = {},
102 std::shared_ptr<nodes::NodeMap> node_map =
nullptr,
103 std::shared_ptr<net::WireStream> stream =
nullptr,
104 std::shared_ptr<service::Session>
session =
nullptr);
111 std::string_view action_name, std::string action_id = {});
118 std::shared_ptr<ActionRegistry>
Copy(
bool clear_autofills =
true)
const;
121 std::shared_ptr<AuthorizationContextStore> contexts);
124 const std::shared_ptr<Action>& action)
const;
127 mutable thread::Mutex mu_;
128 absl::flat_hash_map<std::string, ActionSchema> schemas_ ABSL_GUARDED_BY(mu_);
129 absl::flat_hash_map<std::string, ActionHandler> handlers_
130 ABSL_GUARDED_BY(mu_);
131 std::shared_ptr<AuthorizationContextStore> authorization_contexts_
132 ABSL_GUARDED_BY(mu_);
A11's unit of work: the Action and its supporting types.
Schemas describing an action's typed interface and its settings.
std::shared_ptr< service::Session > session
Definition authorization.cc:326
A thread-safe catalogue mapping action names to schema and handler.
Definition registry.h:59
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:177
std::vector< std::string > ListRegisteredActions() const
Returns the names of all registered actions.
Definition registry.cc:184
absl::Status Unregister(std::string_view action_name)
Removes the registration for action_name.
Definition registry.cc:77
void SetAuthorizationContexts(std::shared_ptr< AuthorizationContextStore > contexts)
Require incoming application actions to resolve installed authorization.
Definition registry.cc:229
absl::Status RegisterSync(std::string action_name, ActionSchema schema, SyncActionHandler handler)
Registers an action with a synchronous handler.
Definition registry.cc:67
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:150
std::shared_ptr< ActionRegistry > Copy(bool clear_autofills=true) const
Returns a copy of this registry.
Definition registry.cc:202
absl::Status Register(std::string action_name, ActionSchema schema, ActionHandler handler={})
Registers an action under action_name.
Definition registry.cc:38
bool IsRegistered(std::string_view action_name) const
Whether action_name is registered.
Definition registry.cc:95
absl::StatusOr< ActionSchema > GetSchema(std::string_view action_name) const
Returns the schema for action_name, or NotFound.
Definition registry.cc:106
absl::StatusOr< ActionHandler > GetHandler(std::string_view action_name) const
Returns the handler for action_name, or NotFound.
Definition registry.cc:127
absl::Status ResolveAuthorization(const std::shared_ptr< Action > &action) const
Bind the configured authorization context before an action starts.
Definition registry.cc:235
std::function< absl::Status(std::shared_ptr< Action >)> SyncActionHandler
Synchronous action handler returning a completion status.
Definition action.h:92
std::function< a11::Task(std::shared_ptr< Action >)> ActionHandler
Asynchronous action handler: runs the action, returns an awaitable.
Definition action.h:90
The full typed interface of an action.
Definition schema.h:138
A11's core wire value types: chunks, node fragments and messages.