Action Engine
Loading...
Searching...
No Matches
registry.h
Go to the documentation of this file.
1// Copyright 2025 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#ifndef ACTIONENGINE_ACTIONS_REGISTRY_H_
16#define ACTIONENGINE_ACTIONS_REGISTRY_H_
17
18#include <memory>
19#include <string>
20#include <string_view>
21#include <vector>
22
23#include <absl/container/flat_hash_map.h>
24
27
36
37namespace act {
38
48 public:
62 void Register(std::string_view name, const ActionSchema& schema,
63 const ActionHandler& handler);
64
78 [[nodiscard]] bool IsRegistered(std::string_view name) const;
79
96 [[nodiscard]] ActionMessage MakeActionMessage(std::string_view name,
97 std::string_view id) const;
98
120 [[nodiscard]] std::unique_ptr<Action> MakeAction(
121 std::string_view name, std::string_view action_id = "",
122 std::vector<Port> inputs = {}, std::vector<Port> outputs = {}) const;
123
135 [[nodiscard]] const ActionSchema& GetSchema(std::string_view name) const;
136
148 [[nodiscard]] const ActionHandler& GetHandler(std::string_view name) const;
149
150 [[nodiscard]] std::vector<std::string> ListRegisteredActions() const {
151 std::vector<std::string> names;
152 names.reserve(schemas_.size());
153 for (const auto& [name, _] : schemas_) {
154 names.push_back(name);
155 }
156 return names;
157 }
158
159 absl::flat_hash_map<std::string, ActionSchema> schemas_;
160 absl::flat_hash_map<std::string, ActionHandler> handlers_;
161};
162} // namespace act
163
164#endif // ACTIONENGINE_ACTIONS_REGISTRY_H_
Definition registry.h:47
std::unique_ptr< Action > MakeAction(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.
Definition registry.cc:41
const ActionSchema & GetSchema(std::string_view name) const
Gets the schema of the action with the given name.
Definition registry.cc:53
const ActionHandler & GetHandler(std::string_view name) const
Gets the handler of the action with the given name.
Definition registry.cc:57
ActionMessage MakeActionMessage(std::string_view name, std::string_view id) const
Creates an ActionMessage for the action with the given name and ID.
Definition registry.cc:36
bool IsRegistered(std::string_view name) const
Checks if an action with the given name is registered.
Definition registry.cc:32
void Register(std::string_view name, const ActionSchema &schema, const ActionHandler &handler)
Registers an action with the given name, schema, and handler.
Definition registry.cc:26
A type that represents schemas for ActionEngine actions.
Definition types.h:232
Definition schema.h:68
ActionEngine data structures used to implement actions and nodes (data streams).