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.
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() /:
| Field | Type | Note |
|---|---|---|
| severity | uint16_t | Severity 1-1000 |
| message | std::string | LocalizedText.text |
| source_name | std::string | |
| time | int64_t | FileTime(UTC 100ns since 1601) |
| event_type | std::string | Currently, 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:
| EventType | BrowsePath | Meaning | Can it be caught right now? |
|---|---|---|---|
| BaseEventType (i=2041) | {"Severity"} | Severity 1-1000 | Can (Fixed SelectClause) |
| BaseEventType | {"Message"} | Message Text | Can (Fixed SelectClause) |
| BaseEventType | {"SourceName"} | Source Name | Capable (Fixed SelectClause) |
| BaseEventType | {"Time"} | Event Time | Can (Fixed SelectClause) |
| BaseEventType | {"EventId"} | Unique Event ID | Can't |
| BaseEventType | {"EventType"} | Event Type NodeId | Can't |
| ConditionType (i=2782) | {"ConditionId"} | Conditions NodeId | Can't |
| AcknowledgeableConditionType (i=2881) | {"AckedState", "Id"} | bool Is Ack | Can't |
| AlarmConditionType (i=2915) | {"ActiveState", "Id"} | bool IsActive | Can't |
Implementation Notes
- There are always 4 fields to extract SelectClause:Severity / Message / SourceName / Time, not 5—use 4 as the standard
where_clauseNot implemented; leave blank- Failure to catch EventId / ConditionId, directly affects Alarm and Confirmation 's
Acknowledge/Confirm/AddComment(they need toevent_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
| Item | C# | Python | Java | C++ | Rust | C |
|---|---|---|---|---|---|---|
| EventFilter | EventFilter | EventFilter | EventFilterDef.Filter | EventFilter | EventFilter | DarraUa_EventFilter |
| SimpleAttributeOperand | SimpleAttributeOperand | SimpleAttributeOperand | EventFilterDef.Operand | SimpleAttributeOperand | SimpleAttributeOperand | DarraUa_SimpleAttributeOperand |
| Event Subscription with a Filter | subscribe(..., filter) | subscribe(..., filter) | subscribe(..., Filter) | None | subscribe(..., 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."