Skip to main content

EventFilter

Overview​

OPC UA Part 4 §7.18 EventFilter:

  • select_clauses — Which fields to capture
  • where_clause — Filter criteria (not currently implemented; leave blank)

SimpleAttributeOperand Fields: type_definition_id / browse_path / attribute_id / index_range.

On the C++ side, these two structures are merely type definitions; they are not subscribed

Session::SubscribeEvents(std::string const& node_id = "", Subscription* existing = nullptr) to.No parameters EventFilter, which fields to capture areThe 4 Hard-Coded Ones SelectClause:Severity / Message / SourceName / Time。

So, C++ is currently...Can't be changed You can't specify which fields to retrieve either WhereClause. To create a custom filter, you have to use the C convenience layer; if you DarraUa_EventSubscription_SubscribeWithFilter(sub, object_node_id, filter, cb, ctx, &out_mi) pass a NULL filter, it falls back to these 4 default fields.

API​

namespace darra::opcua {

/// SimpleAttributeOperand (Part 4 §7.4.4.5)
struct SimpleAttributeOperand {
std::string type_definition_id; // Event type NodeId, such as "i=2041"; blank = wildcard BaseEventType
std::vector<std::string> browse_path; // Such as ["Severity"] / ["EnabledState","Id"]; empty = select all
AttributeId attribute_id = AttributeId::Value;
std::string index_range; // NumericRange String; Empty = All
};

/// EventFilter (Part 4 §7.18)
struct EventFilter {
std::vector<SimpleAttributeOperand> select_clauses;
std::string where_clause; // V1 Not implemented; leave blank
};
}

Both are struct fields — there is no method for them. The SDK targets C++17, so the example uses positional initialization (do not use explicit .field = initialization — that is C++20).

Code Example​

#include <darra/opcua/client.hpp>
#include <darra/opcua/event_filter.hpp>
#include <iostream>

using namespace darra::opcua;

Session s("opc.tcp://localhost:4840");
s.Connect();
Subscription sub = s.CreateSubscription(500.0);

// 1) Create a filter type (currently, you can only create it; you cannot pass it in SubscribeEvents)
EventFilter filter;
filter.select_clauses = {
SimpleAttributeOperand{ "i=2041", {"EventId"} },
SimpleAttributeOperand{ "i=2041", {"EventType"} },
SimpleAttributeOperand{ "i=2041", {"SourceName"} },
SimpleAttributeOperand{ "i=2041", {"Time"} },
SimpleAttributeOperand{ "i=2041", {"Message"} },
SimpleAttributeOperand{ "i=2041", {"Severity"} },
SimpleAttributeOperand{ "i=2782", {"ConditionId"} },
SimpleAttributeOperand{ "i=2915", {"ActiveState", "Id"} },
};

// 2) Actual subscription — only two parameters, no filter
EventSubscription ev = s.SubscribeEvents("i=2253", &sub);

// 3) The callback returns a fixed set of 5 named fields, not a `fields[]` array.
ev.on_event() = [](EventArrivedEventArgs const& e) {
std::cout << "sev=" << e.severity << " " << e.message
<< " src=" << e.source_name << "\n";
};

Field Quick Reference​

Callback parameters EventArrivedEventArgs areName Field, it is not an array fields[], nor does it have these AsBoolean() access methods: AsByteString() / AsDateTime() / AsUInt16() /:

FieldTypeNote
severityuint16_tSeverity 1-1000
messagestd::stringLocalizedText.text
source_namestd::string
timeint64_tFileTime(UTC 100ns since 1601)
event_typestd::stringCurrently, the string is empty.(SelectClauses Excludes EventType)

Below is the standard OPC UA BaseEventType / ConditionType field table for reference; fields other than these 4 cannot currently be captured by the SDK:

EventTypeBrowsePathMeaningCan it be caught right now?
BaseEventType (i=2041){"Severity"}Severity 1-1000Can (Fixed SelectClause)
BaseEventType{"Message"}Message TextCan (Fixed SelectClause)
BaseEventType{"SourceName"}Source NameCapable (Fixed SelectClause)
BaseEventType{"Time"}Event TimeCan (Fixed SelectClause)
BaseEventType{"EventId"}Unique Event IDCan't
BaseEventType{"EventType"}Event Type NodeIdCan't
ConditionType (i=2782){"ConditionId"}Conditions NodeIdCan't
AcknowledgeableConditionType (i=2881){"AckedState", "Id"}bool Is AckCan't
AlarmConditionType (i=2915){"ActiveState", "Id"}bool IsActiveCan't

Implementation Notes​

  • There are always 4 fields to extract SelectClause:Severity / Message / SourceName / Time, not 5—use 4 as the standard
  • where_clause Not implemented; leave blank
  • Failure to catch EventId / ConditionId, directly affects Alarm and Confirmation 's Acknowledge / Confirm / AddComment(they need to event_id)— See the explanation of the skills gap on that page

Best Practices​

  • To customize fields or filters, use the C layer. DarraUa_EventSubscription_SubscribeWithFilter
  • Callbacks are executed synchronously on the Publish thread, and resets are handled by the queue.

Cross-Language Comparison​

ItemC#PythonJavaC++RustC
EventFilterEventFilterEventFilterEventFilterDef.FilterEventFilterEventFilterDarraUa_EventFilter
SimpleAttributeOperandSimpleAttributeOperandSimpleAttributeOperandEventFilterDef.OperandSimpleAttributeOperandSimpleAttributeOperandDarraUa_SimpleAttributeOperand
Event Subscription with a Filtersubscribe(..., filter)subscribe(..., filter)subscribe(..., Filter)Nonesubscribe(..., filter)DarraUa_EventSubscription_SubscribeWithFilter

Java has different type names: Yes EventFilterDef.Filter / EventFilterDef.Operand(EventFilterDef.java), No EventFilter / SimpleAttributeOperand. C++ is the only language that does not have an "event subscription entry point with a filter."

Next Step​