OptrisOptrisDocumentation

Documentation/OTC SDK/OTC SDK — C++ API referencev12.0

optris::sdk::RuleEngine

The rules that watch signals, and the alarms they raise.

A handle on one imager's rule set, reached through Imager::Alarms(). A rule watches a signal -- a region statistic, a device reading, a PIF channel or an application value -- and raises, warns or clears according to its condition.

Public types

EventCallback

std::function< void(const AlarmEvent &)> EventCallback

Called on the SDK's alarm action thread, never on the streaming thread.

Safe to call from any thread, and from one while an alarm is being delivered to another. Replacing a handler waits for a delivery already inside the one it replaces, so once this returns the old handler will not be called again and whatever it captured can be released.

The one thing it cannot do is replace a handler from inside that same handler. That is refused, with a line in the log, and the existing handler stays: a handler runs behind its own lock, so taking that lock to replace it would hang rather than wait. Do it from a thread of your own.

ActionErrorCallback

std::function< void(const ActionError &)> ActionErrorCallback

Reports an action that could not be carried out. The alarm state is unaffected.

Installed and replaced under the same rules as SetCallback().

ActionCompletedCallback

std::function< void(const ActionCompleted &)> ActionCompletedCallback

The handler SetActionCompletedCallback() installs.

Public functions

RuleEngine

RuleEngine(ClientBridge *bridge)

Add

auto Add(uint64_t region_id, Rule rule) -> uint64_t

Attach a rule to a region. When rule.input names a region signal, its slot is filled in from region_id, so the common case does not make the caller look one up.

Returns: The rule id, or 0 if the region or the rule is invalid. Why is logged as a warning that names the part refused (a region that does not exist, an input or reference that cannot be evaluated), which SetLogHandler() delivers; every Add() and Update() below logs its refusals the same way.

Add

auto Add(Rule rule) -> uint64_t

Add a rule not attached to any region -- a PIF alarm, a device alarm, or a free alarm on an application value.

Remove

auto Remove(uint64_t rule_id) -> bool

Update

auto Update(uint64_t rule_id, const std::function< void(Rule &)> &mutate) -> bool

Edit a rule in place. The mutation is validated before it is applied; an invalid edit is rejected and the rule is unchanged.

Get

auto Get(uint64_t rule_id) const -> std::optional< Rule >

Ids

auto Ids() const -> std::vector< uint64_t >

Add

auto Add(uint64_t region_id, Rule rule, SignalId reference) -> uint64_t

Add() with a reference, in one step, so the rule is never evaluated without it.

Returns: The rule id, or 0 if the region, the rule or the reference is invalid.

Add

auto Add(Rule rule, SignalId reference) -> uint64_t

Add(Rule) with a reference, for a rule attached to no region.

Update

auto Update(uint64_t rule_id, const std::function< void(Rule &)> &mutate, std::optional< SignalId > reference) -> bool

Update() that also sets the reference, or removes it when reference is empty, in one step. Validated as a whole: a rejected edit leaves both the rule and its reference unchanged.

SetReference

auto SetReference(uint64_t rule_id, SignalId reference) -> bool

Compare an installed rule's input with reference from its next evaluation on. Replaces any earlier reference.

Returns: false for an unknown rule or a refused reference, and the rule is then unchanged.

ClearReference

auto ClearReference(uint64_t rule_id) -> bool

Compare the rule's input alone again.

Returns: false for an unknown rule; true for a known one, whether or not it had a reference.

ReferenceOf

auto ReferenceOf(uint64_t rule_id) const -> std::optional< SignalId >

The reference an installed rule compares its input with, with its region slot resolved, or nullopt when it has none or the rule is unknown.

RegionOf

auto RegionOf(uint64_t rule_id) const -> uint64_t

The region a rule was added to, or 0 for a free rule and for an unknown id.

A region rule's own input names a generational slot, not a region id, and it is filled in by Add(); nothing on the Rule itself names the region it was attached to. Without this, a rule read back with Get() is a condition on "some region", which is not enough to show it again or to edit it.

StateOf

auto StateOf(uint64_t rule_id) const -> AlarmState

StatusOf

auto StatusOf(uint64_t rule_id) const -> AlarmStatus

StateOf(), plus whether the rule is kActive only because its latch is holding it there.

Use it to decide what Acknowledge() will do. When AlarmStatus::held_by_latch is true the value is back inside the limits and acknowledging releases the alarm; when it is false a kActive rule is still outside them and acknowledging re-arms the latch and changes nothing.

StateOfRegion

auto StateOfRegion(uint64_t region_id) const -> AlarmState

WorstState

auto WorstState() const -> AlarmState

Acknowledge

void Acknowledge(uint64_t rule_id)

Release a latch. If the condition still holds the alarm stays active and the latch re-arms -- acknowledging a ringing alarm never silences it.

AcknowledgeAll

void AcknowledgeAll()

Log

auto Log(size_t max) const -> std::vector< AlarmEvent >

The last N transitions, newest last. For a HUD that repaints faster than it subscribes.

SetCallback

void SetCallback(EventCallback callback)

RegisterCallback

auto RegisterCallback(EventCallback callback) -> uint32_t

Register a callback a CallbackAction can name by slot, when one global handler is not enough.

Safe to call from any thread, and while alarms are being delivered. Slots are never reused, so an index stays valid for the life of the camera.

Returns: the slot a CallbackAction can name. Calling this from inside an alarm callback is refused for the reason given on SetCallback(); the slot is still returned and still valid, but it holds no handler and firing it does nothing. The refusal is on the log.

SetActionErrorCallback

void SetActionErrorCallback(ActionErrorCallback callback)

SetActionCompletedCallback

void SetActionCompletedCallback(ActionCompletedCallback callback)

Reports an action that did not fail, and what it did.

The counterpart to SetActionErrorCallback(), installed and replaced under the same rules as SetCallback() and delivered on the same thread. A separate registration for the same reason the error channel is separate from SetCallback(): an application that subscribes to one is not silently subscribed to the other.

This is the only way to learn that an alarm's snapshot reached the disk. Three outcomes were invisible in three different ways before it existed -- a written file said nothing at all, a snapshot its own SnapshotAction::min_interval skipped returned silently, and one dropped from a full action queue was counted where nothing outside the SDK could read the count. An application was left inferring a file's existence from the file, and could not tell "skipped on purpose" from "failed" from "never fired" at all.

Do not read an attachment-provider call as a confirmation: the provider is asked while the still is being assembled, before anything is written. ActionOutcome::kWritten is reported after the writer has returned success.

Parameters

Name Description
callback The handler, or an empty function to stop.

GetActionDropCounts

auto GetActionDropCounts() const -> ActionDropCounts

What this source's actions have lost, as exact totals.

The reports the two callbacks above deliver are best effort; this is how an application learns that some never arrived. See ActionDropCounts. Safe to call from any thread at any time, including after the source has disconnected.

RegisterSignal

auto RegisterSignal(const std::string &name) -> uint32_t

Register an application signal so rules can watch it. Repeated calls with the same name return the same slot.

PublishSignal

void PublishSignal(uint32_t slot, double value)

Publish a new value for an application signal. Rules on it are evaluated immediately.

The SDK does not know what an application signal measures, so it does not convert value, whatever SetTemperatureUnit() chose: a rule on it compares its limits with the number as published.

ReadSignal

auto ReadSignal(SignalId id) const -> SignalValue

Read any signal, in any domain -- a region statistic, camera telemetry, a PIF channel, or an application value.