Class TriggerManager
Defined in File trigger_manager.hpp
Nested Relationships
Nested Types
Class Documentation
-
class TriggerManager
Central coordinator for triggers.
Owns trigger lifecycle (CRUD), subscribes to ResourceChangeNotifier for resource change events, evaluates conditions using ConditionRegistry, stores pending events for SSE stream pickup, and manages entity hierarchy matching and persistence via TriggerStore.
Public Types
-
using OnRemovedCallback = std::function<void(const std::string &trigger_id)>
Callback invoked when a trigger is removed.
Public Functions
-
TriggerManager(ResourceChangeNotifier ¬ifier, ConditionRegistry &conditions, TriggerStore &store, const TriggerConfig &config)
-
~TriggerManager()
-
TriggerManager(const TriggerManager&) = delete
-
TriggerManager &operator=(const TriggerManager&) = delete
-
tl::expected<TriggerInfo, TriggerCreateError> create(const TriggerCreateRequest &req)
Create a new trigger. Validates condition type and params.
-
std::optional<TriggerInfo> get(const std::string &trigger_id)
Get a trigger by ID.
-
std::vector<TriggerInfo> list(const std::string &entity_id)
List all triggers for a given entity.
-
tl::expected<TriggerInfo, TriggerCreateError> update(const std::string &trigger_id, int new_lifetime)
Update a trigger’s lifetime.
-
bool remove(const std::string &trigger_id)
Remove a trigger. Returns true if found and removed.
-
bool wait_for_event(const std::string &trigger_id, std::chrono::milliseconds timeout)
Block until an event is available for the given trigger, or timeout. Returns true if woken by event/shutdown, false on timeout.
-
bool is_active(const std::string &trigger_id)
Check if a trigger is active (exists, not terminated, not expired).
-
std::optional<nlohmann::json> consume_pending_event(const std::string &trigger_id)
Consume the pending event for SSE delivery. Returns nullopt if no event.
-
void set_on_removed(OnRemovedCallback callback)
-
void shutdown()
Shut down - wakes all waiting threads and marks all triggers inactive.
-
void load_persistent_triggers()
Load persistent triggers from the store (on gateway restart).
-
void set_entity_children_fn(EntityChildrenFn fn)
Set the entity hierarchy resolver. Called by GatewayNode after cache is available.
-
void set_topic_subscriber(TriggerTopicSubscriber *subscriber)
Set the topic subscriber for data trigger subscriptions. Called by GatewayNode after TriggerTopicSubscriber is created.
-
void set_log_manager(LogManager *log_manager)
Set the LogManager for trigger log_settings integration. Called by GatewayNode after both TriggerManager and LogManager are available.
-
void set_entity_exists_fn(EntityExistsFn fn)
Set the entity existence checker. Called by GatewayNode after cache is available.
-
using OnRemovedCallback = std::function<void(const std::string &trigger_id)>