본문으로 건너뛰기

이벤트 구독

OPC UA 이벤트(Alarms & Conditions)는 구독을 s.SubscribeEvents(...) 통해 확인할 수 있습니다. 이는 OPC UA 프로토콜 이벤트, 및 SDK 내부 s.Events().* 같은 말이 아닙니다.

차이점
  • s.SubscribeEvents(...) — OPC UA 프로토콜 이벤트 (알람 / 조건, 서버 푸시, 본 절)
  • s.Events().on_* — SDK 내부 사건 (세션 수명 주기, 프로토콜과 무관)

서명​

EventSubscription SubscribeEvents(
std::string const& node_id = "",
Subscription* existing = nullptr);
매개변수기본값설명
node_id"" (Server, i=2253)이벤트 소스 노드
existingnullptr기존의 Subscription을 재사용하며, nullptr인 경우 자동으로 새로운 1000ms 컨테이너를 생성합니다.

EventSubscription​

EventSubscription Move-only 스택 객체이며, 소멸 시:

  • 자동으로 생성된 컨테이너인 경우: 컨테이너 삭제 (DarraUa_Subscription_Delete)
  • 외부 컨테이너를 사용하는 경우: 해당 이벤트만 제거합니다. MI
구성원설명
SetOnEvent(cb)이벤트 콜백 설정
on_event() = cbSetOnEvent와 유사한 구문 단축형

EventArrivedEventArgs​

struct EventArrivedEventArgs {
uint16_t severity = 0; // 1-1000 (OPC UA Part 9 §5.4)
std::string message;
std::string source_name;
int64_t time = 0; // FileTime (UTC 100ns since 1601)
std::string event_type; // 현재 헝은 공석입니다 (아래 참조).
};
event_type 현재 가져올 수 없음

이벤트 구독반드시 4개만 선택하세요 SelectClause: 심각도 / 메시지 / SourceName / 시간 (opcua_event.h).EventType 선택 항목에 포함되지 않으므로, 디코딩 측에서 직접 NULL로 설정하므로 event_type 는 항상 빈 문자열입니다. 마찬가지로 EventArrivedEventArgs 내에서도해당 EventId 필드가 없습니다., 알람 확인에 필요한 것조차 EventId 구할 수 없다.

사용법​

기본 구독 서버 노드​

auto ev_sub = s.SubscribeEvents();
ev_sub.SetOnEvent([](EventArrivedEventArgs const& e) {
std::cout << "[" << e.severity << "] " << e.source_name << ": " << e.message
<< " ft=" << e.time << "\n"; // 4개의 문장 선택 필드, event_type 헝공은 인쇄되지 않음
});

std::this_thread::sleep_for(std::chrono::minutes(5));
// ev_sub 스코프에서 벗어나면: 이벤트 자동 제거 MI + 자동으로 생성된 컨테이너 파기

지정된 노드의 이벤트 구독​

auto ev_sub = s.SubscribeEvents("ns=2;s=Line1");
// Line1 반드시 ~이어야 한다 EventNotifier

기존 구독 컨테이너 재사용​

auto sub = s.CreateSubscription(500.0);
sub.AddNode("ns=2;s=Counter", [](DataValue const& dv) { /* 데이터 구독 */ });

// Event를 같은 컨테이너에 MI 연결하기 (빌리기)
auto ev_sub = s.SubscribeEvents("ns=2;s=Line1", &sub);
ev_sub.SetOnEvent([](EventArrivedEventArgs const& e) { /* ... */ });

// ev_sub 소멸: Event만 제거하고 MI, sub는 소멸시키지 않음

EventNotifier​

EventNotifier 속성(12)이 0이 아닌 노드만 이벤트를 생성할 수 있습니다. 기본 Server(i=2253)는 EventNotifier입니다. 사용자 정의 노드가 이벤트 소스 기능을 갖는지 여부는 서버 구현에 따라 다릅니다.

EventFilter (고급)​

SubscribeEvents 필터 미장착 —— 4개 고정 SelectClause (중요도 / 메시지 / SourceName / 시간), whereClause 비어 있는 경우, 서버의 모든 이벤트가 보고됩니다.

어떤 필드를 선택할지는 직접 결정해야 하며, C 편의 계층에서 C/include/opcua_filter.h 선언된 DarraUa_EventSubscription_SubscribeWithFilter: 전달 DarraUa_EventFilter (select_clauses 배열 + where_clause)만 가능합니다. NULL을 filter 전달하면 기본 4개 필드 필터로 축소됩니다. where_clause (ContentFilter 표현식) 현재 구현되지 않았으므로 NULL을 전달하면 됩니다. C++ 측에서는 이 진입점을 래핑하지 않았으며, event_filter.hpp 내부의 EventFilter / SimpleAttributeOperand 는 단지 유형 정의일 뿐이며, SubscribeEvents 이들에도 연결되어 있지 않습니다.

알람 처리 (확인 / 승인)​

AlarmConditionType 이벤트를 수신한 후, 운영자는 일반적으로 이를 Acknowledge(확인)해야 합니다. 표준 방법의 절차는 고정되어 있습니다 NodeId (제9부), 혼자서 조합하지 마세요 condition_id + ".Acknowledge" —— 미리 alarm_condition.hpp 캡슐화된 자유 함수를 직접 사용하는 방법:

#include <darra/opcua/alarm_condition.hpp>

std::vector<uint8_t> event_id = {/* 사건의 EventId 바이트 */};
std::string condition_id = "ns=2;s=Line1.Alarm1";

// Acknowledge (i=9111) / Confirm (i=9113) / AddComment (i=9029) 동족
Status st = darra::opcua::alarm::Acknowledge(s, condition_id, event_id, "Operator confirmed");
if (st != Status::Good) { /* 사용자에게 다시 시도하도록 안내 */ }

입력 매개변수의 EventId 유형은 입니다 ByteString. C++ Variant 없음 SetByteString, alarm_condition.hpp ISO-8859-1 인코딩을 사용하여 전체 바이트를 보존한다 (detail::BuildEventId).

EventId 현재 가져올 수 없습니다.

EventArrivedEventArgs 해당 EventId 필드가 없으므로(위 참조) 콜백을 반환할 수 없습니다 event_id. Acknowledge/Confirm을 사용하려면 서버 측의 다른 곳에서 가져오거나 EventId, C 계층을 DarraUa_EventSubscription_SubscribeWithFilter 사용하여 해당 필드를 EventId 추가해야 합니다 SelectClauses.

다음 단계​