Class ScriptManager
Defined in File script_manager.hpp
Class Documentation
-
class ScriptManager
Central manager for diagnostic script operations.
Acts as the integration point between HTTP handlers and the pluggable ScriptProvider backend. Provides null-safety, exception isolation for plugin-provided backends, and logging. The backend is set once during gateway initialization via set_backend() and must not be changed while HTTP threads are active.
Thread safety: All methods are safe to call concurrently from multiple HTTP handler threads. The manager itself is stateless (delegates to backend).
Public Functions
-
ScriptManager() = default
-
ScriptManager(const ScriptManager&) = delete
-
ScriptManager &operator=(const ScriptManager&) = delete
-
ScriptManager(ScriptManager&&) = delete
-
ScriptManager &operator=(ScriptManager&&) = delete
-
void set_backend(ScriptProvider *backend)
Set the script backend provider. Must be called during initialization, before any HTTP threads start. Not thread-safe with concurrent method calls.
-
bool has_backend() const
- Returns:
true if a backend provider is configured
-
tl::expected<std::vector<ScriptInfo>, ScriptBackendErrorInfo> list_scripts(const std::string &entity_id)
List all scripts available for the given entity.
- Parameters:
entity_id – The entity to list scripts for
- Returns:
Vector of ScriptInfo or error
-
tl::expected<ScriptInfo, ScriptBackendErrorInfo> get_script(const std::string &entity_id, const std::string &script_id)
Get detailed information about a specific script.
- Parameters:
entity_id – The owning entity
script_id – The script to retrieve
- Returns:
ScriptInfo or error (e.g., NotFound)
-
tl::expected<ScriptUploadResult, ScriptBackendErrorInfo> upload_script(const std::string &entity_id, const std::string &filename, const std::string &content, const std::optional<nlohmann::json> &metadata)
Upload a new user-provided script.
- Parameters:
entity_id – The target entity
filename – Original filename of the uploaded script
content – Raw script content
metadata – Optional JSON metadata to associate with the script
- Returns:
Upload result containing the assigned script ID, or error
-
tl::expected<void, ScriptBackendErrorInfo> delete_script(const std::string &entity_id, const std::string &script_id)
Delete a user-uploaded script. Managed (built-in) scripts cannot be deleted.
- Parameters:
entity_id – The owning entity
script_id – The script to delete
- Returns:
void on success, or error (e.g., NotFound, ManagedScript)
-
tl::expected<ExecutionInfo, ScriptBackendErrorInfo> start_execution(const std::string &entity_id, const std::string &script_id, const ExecutionRequest &request)
Start a new script execution.
- Parameters:
entity_id – The target entity
script_id – The script to execute
request – Execution parameters (type, input parameters, proximity proof)
- Returns:
ExecutionInfo with the new execution ID, or error
-
tl::expected<ExecutionInfo, ScriptBackendErrorInfo> get_execution(const std::string &entity_id, const std::string &script_id, const std::string &execution_id)
Get the current status of a script execution.
- Parameters:
entity_id – The owning entity
script_id – The parent script
execution_id – The execution to query
- Returns:
ExecutionInfo or error (e.g., NotFound)
-
tl::expected<ExecutionInfo, ScriptBackendErrorInfo> control_execution(const std::string &entity_id, const std::string &script_id, const std::string &execution_id, const std::string &action)
Send a control action to a running execution (e.g., terminate).
- Parameters:
entity_id – The owning entity
script_id – The parent script
execution_id – The execution to control
action – The control action (e.g., “terminate”)
- Returns:
Updated ExecutionInfo or error
-
tl::expected<void, ScriptBackendErrorInfo> delete_execution(const std::string &entity_id, const std::string &script_id, const std::string &execution_id)
Delete an execution record. Only completed/failed/terminated executions can be deleted.
- Parameters:
entity_id – The owning entity
script_id – The parent script
execution_id – The execution to delete
- Returns:
void on success, or error
-
ScriptManager() = default