EventFilter
개요
OPC UA Part 4 §7.18 EventFilter:
- select_clauses — 어떤 필드를 추출할 것인가
- where_clause — 필터 조건 (현재 구현되지 않았으므로 비워 두시면 됩니다)
SimpleAttributeOperand 필드: type_definition_id / browse_path / attribute_id / index_range.
Session::SubscribeEvents(std::string const& node_id = "", Subscription* existing = nullptr) 연결되어 있지 않습니다.EventFilter 매개변수가 없습니다., 어떤 필드를 가져올지는고정된 4개 SelectClause:Severity / Message / SourceName / Time.
따라서 C++ 측면에서는 현재고칠 수 없다어떤 필드를 추출할지 설정할 수도 없습니다 WhereClause. 사용자 정의 필터를 적용하려면 C 편의 계층을 거쳐야 하며 DarraUa_EventSubscription_SubscribeWithFilter(sub, object_node_id, filter, cb, ctx, &out_mi), NULL filter를 전달하면 이 4개의 기본 필터가 반환됩니다.
API
namespace darra::opcua {
/// SimpleAttributeOperand (Part 4 §7.4.4.5)
struct SimpleAttributeOperand {
std::string type_definition_id; // 이벤트 유형 NodeId, 예: "i=2041"; 빈 값 = 와일드카드 BaseEventType
std::vector<std::string> browse_path; // 예: ["Severity"] / ["EnabledState","Id"]; 빈 값 = 전체 선택
AttributeId attribute_id = AttributeId::Value;
std::string index_range; // NumericRange 열; 빈 값 = 전체
};
/// EventFilter (Part 4 §7.18)
struct EventFilter {
std::vector<SimpleAttributeOperand> select_clauses;
std::string where_clause; // V1 미실현, 공란
};
}
둘 다 struct 필드, 방법이 없습니다.SDK C++17을 준수하며, 예제에서는 위치 초기화를 사용합니다(지정 .field = 초기화는 작성하지 마세요. 이는 C++20의 기능입니다).
코드 예시
#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) 필터 유형 생성 (현재는 생성만 가능하며, 전달할 수는 없음 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) 실제 구독 —— 매개변수가 두 개뿐이며, filter는 없습니다.
EventSubscription ev = s.SubscribeEvents("i=2253", &sub);
// 3) 콜백을 통해 반환되는 것은 이름이 지정된 5개의 필드이며, fields[] 배열이 아닙니다.
ev.on_event() = [](EventArrivedEventArgs const& e) {
std::cout << "sev=" << e.severity << " " << e.message
<< " src=" << e.source_name << "\n";
};
필드 빠른 참조
콜백 매개변수는 EventArrivedEventArgs 다음과 같습니다.이름 필드, 배열이 아니며, fields[] / AsByteString() / AsDateTime() / 와 같은 값을 가져오는 AsUInt16() 방법도 AsBoolean() 없습니다:
| 필드 | 유형 | 설명 |
|---|---|---|
| severity | uint16_t | 심각도 1-1000 |
| message | std::string | LocalizedText.text |
| source_name | std::string | |
| time | int64_t | FileTime(UTC 100ns since 1601) |
| event_type | std::string | 현재 항상 빈 문자열입니다.(SelectClauses 미포함 EventType) |
다음은 참고용으로 제공되는 표준 OPC UA BaseEventType / ConditionType 필드 표입니다.이 4개 이외의 필드는 현재 SDK 가져올 수 없습니다.:
| EventType | BrowsePath | 의미 | 지금 잡을 수 있을까 |
|---|---|---|---|
| BaseEventType (i=2041) | {"Severity"} | 심각도 1-1000 | 가능 (고정 SelectClause) |
| BaseEventType | {"Message"} | 메시지 본문 | 가능 (고정 SelectClause) |
| BaseEventType | {"SourceName"} | 출처명 | 가능 (고정 SelectClause) |
| BaseEventType | {"Time"} | 사건 발생 시간 | 가능 (고정 SelectClause) |
| BaseEventType | {"EventId"} | 이벤트의 고유 ID | 안 돼 |
| BaseEventType | {"EventType"} | 사건 유형 NodeId | 안 돼 |
| ConditionType (i=2782) | {"ConditionId"} | 조건 NodeId | 안 돼 |
| AcknowledgeableConditionType (i=2881) | {"AckedState", "Id"} | bool Ack 여부 | 안 돼 |
| AlarmConditionType (i=2915) | {"ActiveState", "Id"} | bool 활성화 여부 | 안 돼 |
구현 설명
- 추출 필드는 SelectClause 4개로 고정입니다: Severity / Message / SourceName / Time, 5개가 아니라 —— 4개를 기준으로 한다
where_clause미실현, 비워둠- EventId / ConditionId는 잡을 수 없으며, 이는 알람 및 확인의
Acknowledge/Confirm/AddComment(이들은event_id가 필요합니다)에 직접 영향을 미칩니다 — 해당 페이지의 역량 격차 설명을 참조하십시오
모범 사례
- 필드/필터를 사용자 정의하려면 C 계층으로 이동하세요
DarraUa_EventSubscription_SubscribeWithFilter - 콜백은 Publish 스레드에서 동기식으로 실행되며, 재시도는 큐로 넘겨집니다.
다국어 대조
| 항목 | C# | Python | Java | C++ | Rust | C |
|---|---|---|---|---|---|---|
| EventFilter | EventFilter | EventFilter | EventFilterDef.Filter | EventFilter | EventFilter | DarraUa_EventFilter |
| SimpleAttributeOperand | SimpleAttributeOperand | SimpleAttributeOperand | EventFilterDef.Operand | SimpleAttributeOperand | SimpleAttributeOperand | DarraUa_SimpleAttributeOperand |
| filter가 포함된 이벤트 구독 | subscribe(..., filter) | subscribe(..., filter) | subscribe(..., Filter) | 없음 | subscribe(..., filter) | DarraUa_EventSubscription_SubscribeWithFilter |
Java의 타입 이름이 다릅니다: 예 EventFilterDef.Filter / EventFilterDef.Operand(EventFilterDef.java), 아니오 EventFilter / SimpleAttributeOperand. C++은 ‘filter를 사용하는 이벤트 구독 진입점’이 없는 유일한 언어입니다.