EventFilter
개요
OPC UA Part 4 §7.18 EventFilter:
- select_clauses — 어떤 필드를 추출할 것인가
- where_clause — 필터 조건 (V1 NULL로 두면 됩니다)
DarraUa_SimpleAttributeOperand 필드: type_definition_id / browse_path / attribute_id / index_range.
이벤트 필터링 SDK 확장 헤더(프로토콜 스택 ABI 헤더가 아님) API 에서:
#include <opcua/opcua.h>
#include "../include/opcua_filter.h"
API
typedef struct {
/** 이벤트 유형 NodeId 문자열, 예: "i=2041" (BaseEventType). NULL = 와일드카드 BaseEventType. */
const char* type_definition_id;
/** 필드 BrowsePath (각 구간 BrowseName). NULL 또는 count == 0은 전체 이벤트를 선택함을 의미합니다. */
const char* const* browse_path;
size_t browse_path_count;
/** 속성 ID, 기본값 UA_ATTR_VALUE. */
DarraUa_AttributeId attribute_id;
/** 배열 인덱스 범위 (NumericRange 문자열). NULL = 지정하지 않음. */
const char* index_range;
} DarraUa_SimpleAttributeOperand;
typedef struct {
const DarraUa_SimpleAttributeOperand* select_clauses;
size_t select_clauses_count;
const char* where_clause; /* NULL = where 없음 */
} DarraUa_EventFilter;
| 함수 | 분류 | 읽기 및 쓰기 | 설명 |
|---|---|---|---|
| DarraUa_EventSubscription_SubscribeWithFilter(sub, object_node_id, filter, cb, user_context, out_mi) | 함수 | 쓰기 | 사용자 정의 필터를 사용하여 이벤트 생성 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 = 기본 4개 필드 사용 */
DarraUa_OnEvent cb,
void* user_context,
DarraUa_MonitoredItemHandle* out_mi);
이벤트 콜백 서명은 다음을 참조하십시오. 이벤트 구독 DarraUa_OnEvent.
코드 예시
#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);
// 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
의 DarraUa_Event
페이로드 필드는 SDK
고정된 해로 구해지며
severity
/ message
/ source_name
/ time
/ event_type
, select_clauses
각 항의 전개에 따라 변하지 않음; 사용자 정의 select_clauses에 의해 결정됨서버 측에서 어떤 필드를 전송하나요?.
필드 빠른 참조
| EventType | BrowsePath | 의미 |
|---|---|---|
| BaseEventType (i=2041) | ["EventId"] | 이벤트의 고유 ID |
| BaseEventType | ["Severity"] | 심각도 1-1000 |
| ConditionType (i=2782) | ["ConditionId"] | 조건 NodeId |
| AcknowledgeableConditionType (i=2881) | ["AckedState", "Id"] | Ack 여부 |
| AlarmConditionType (i=2915) | ["ActiveState", "Id"] | 활성화되었는지 여부 |
구현 설명
- 모든 필드는 borrowed이며, SDK가 RPC 진입점 전에 딥 복사합니다.
SubscribeWithFilter반환 후에는 struct를 해제하거나 스코프 밖으로 빠져나오면 됩니다. - Stack은 사용자 정의 SelectClauses 시 그레이스풀 다운그레이드를 지원하지 않습니다: 롤백기본 4개 필드 (중요도 / 메시지 / SourceName / 시간), 그리고 info 로그를 기록합니다
모범 사례
- 명시적 열 필드
- 알람 패널은 반드시 확보해야 한다 ConditionId
다국어 대조
| C# | Python | Java | C++ | Rust | C |
|---|---|---|---|---|---|
| EventFilter | EventFilter | EventFilter | EventFilter | EventFilter | DarraUa_EventFilter |
| SimpleAttributeOperand | SimpleAttributeOperand | SimpleAttributeOperand | SimpleAttributeOperand | SimpleAttributeOperand | DarraUa_SimpleAttributeOperand |