EventFilter
Overview
OPC UA Part 4 §7.18 EventFilter:
- select_clauses — Which fields to capture
- where_clause — Filter criteria (V1 leave as NULL)
DarraUa_SimpleAttributeOperand Fields: type_definition_id / browse_path / attribute_id / index_range.
Event filtering API in the extension SDK header (not the protocol stack header ABI):
#include <opcua/opcua.h>
#include "../include/opcua_filter.h"
API
typedef struct {
/** Event Type NodeId String, such as "i=2041" (BaseEventType). NULL = Wildcard BaseEventType. */
const char* type_definition_id;
/** Field BrowsePath (each segment BrowseName). NULL Or count == 0 indicates that all events are selected. */
const char* const* browse_path;
size_t browse_path_count;
/** Property ID, Default UA_ATTR_VALUE. */
DarraUa_AttributeId attribute_id;
/** Array index range (NumericRange string). NULL = None. */
const char* index_range;
} DarraUa_SimpleAttributeOperand;
typedef struct {
const DarraUa_SimpleAttributeOperand* select_clauses;
size_t select_clauses_count;
const char* where_clause; /* NULL = None where */
} DarraUa_EventFilter;
| Function | Category | Reading and Writing | Note |
|---|---|---|---|
| DarraUa_EventSubscription_SubscribeWithFilter(sub, object_node_id, filter, cb, user_context, out_mi) | Function | Write | Create an event with a custom filter MI |
UA_SDK_API DarraUa_Status UA_SDK_CALL DarraUa_EventSubscription_SubscribeWithFilter(
DarraUa_SubscriptionHandle sub,
const char* object_node_id, /* NULL = "i=2253" */
const DarraUa_EventFilter* filter, /* NULL = Use the default 4 fields */
DarraUa_OnEvent cb,
void* user_context,
DarraUa_MonitoredItemHandle* out_mi);
See the event callback signature at Event Subscription DarraUa_OnEvent.
Code Example
#include <opcua/opcua.h>
#include "../include/opcua_filter.h"
DarraUa_SessionConfig cfg;
DarraUa_SessionConfig_Init(&cfg);
cfg.endpoint_url = "opc.tcp://localhost:4840";
cfg.security_mode = UA_MSG_SECURITY_MODE_NONE;
cfg.security_policy_uri = "http://opcfoundation.org/UA/SecurityPolicy#None";
cfg.user_token_type = UA_USER_TOKEN_ANONYMOUS;
DarraUa_SessionHandle h = UA_INVALID_SESSION_HANDLE;
DarraUa_Session_Create(&cfg, &h);
DarraUa_Session_Connect(h);
DarraUa_SubscriptionConfig sc;
DarraUa_SubscriptionConfig_Init(&sc);
sc.publishing_interval_ms = 500.0;
sc.publishing_enabled = 1;
DarraUa_SubscriptionHandle sub = UA_INVALID_SUBSCRIPTION_HANDLE;
DarraUa_Subscription_Create(h, &sc, &sub);
// Create a filter
const char* event_id_path[] = { "EventId" };
const char* source_path[] = { "SourceName" };
const char* time_path[] = { "Time" };
const char* msg_path[] = { "Message" };
const char* sev_path[] = { "Severity" };
const char* cond_id_path[] = { "ConditionId" };
const char* active_state_path[] = { "ActiveState", "Id" };
DarraUa_SimpleAttributeOperand selects[7] = {
{ "i=2041", event_id_path, 1, UA_ATTR_VALUE, NULL },
{ "i=2041", source_path, 1, UA_ATTR_VALUE, NULL },
{ "i=2041", time_path, 1, UA_ATTR_VALUE, NULL },
{ "i=2041", msg_path, 1, UA_ATTR_VALUE, NULL },
{ "i=2041", sev_path, 1, UA_ATTR_VALUE, NULL },
{ "i=2782", cond_id_path, 1, UA_ATTR_VALUE, NULL },
{ "i=2915", active_state_path, 2, UA_ATTR_VALUE, NULL },
};
DarraUa_EventFilter filter = {
.select_clauses = selects,
.select_clauses_count = 7,
.where_clause = NULL,
};
DarraUa_MonitoredItemHandle ev_mi = UA_INVALID_MONITORED_ITEM_HANDLE;
DarraUa_Status st = DarraUa_EventSubscription_SubscribeWithFilter(
sub, "i=2253", &filter, on_event, NULL, &ev_mi);
on_event
The load DarraUa_Event
fields are determined by the fixed SDK
solution
severity
/ message
/ source_name
/ time
/ event_type
, and do not depend on select_clauses
term-by-term expansion; they are determined by the custom select_clauses.Which fields should the server send?。
Field Quick Reference
| EventType | BrowsePath | Meaning |
|---|---|---|
| BaseEventType (i=2041) | ["EventId"] | Unique Event ID |
| BaseEventType | ["Severity"] | Severity 1–1000 |
| ConditionType (i=2782) | ["ConditionId"] | Conditions NodeId |
| AcknowledgeableConditionType (i=2881) | ["AckedState", "Id"] | Ack or Not |
| AlarmConditionType (i=2915) | ["ActiveState", "Id"] | Is it activated? |
Implementation Notes
- All fields are borrowed; SDK perform a deep copy before RPC entry; after returning
SubscribeWithFilter, the struct can be released or go out of scope. - Stack does not support custom SelectClauses graceful degradation: fallbackDefault: 4 fields (Severity / Message / SourceName / Time), and log to the "info" file
Best Practices
- Explicitly List Fields
- Alarm Panels Must Be Captured ConditionId
Cross-Language Comparison
| C# | Python | Java | C++ | Rust | C |
|---|---|---|---|---|---|
| EventFilter | EventFilter | EventFilter | EventFilter | EventFilter | DarraUa_EventFilter |
| SimpleAttributeOperand | SimpleAttributeOperand | SimpleAttributeOperand | SimpleAttributeOperand | SimpleAttributeOperand | DarraUa_SimpleAttributeOperand |