diff --git a/src/Notifier.cpp b/src/Notifier.cpp index 52985c1839..c3123799f9 100644 --- a/src/Notifier.cpp +++ b/src/Notifier.cpp @@ -11,6 +11,8 @@ #include #include "Handle.h" +#include "SinkImpl.h" +#include "SourceImpl.h" using namespace cs; @@ -151,37 +153,54 @@ void Notifier::RemoveListener(int uid) { } void Notifier::NotifySource(llvm::StringRef name, CS_Source source, - RawEvent::Kind kind) { + CS_EventKind kind) { auto thr = m_owner.GetThread(); if (!thr) return; - thr->m_notifications.emplace(name, source, kind); + thr->m_notifications.emplace(name, source, static_cast(kind)); thr->m_cond.notify_one(); } -void Notifier::NotifySourceVideoMode(llvm::StringRef name, CS_Source source, +void Notifier::NotifySource(const SourceImpl& source, CS_EventKind kind) { + auto handleData = Sources::GetInstance().Find(source); + NotifySource(source.GetName(), handleData.first, kind); +} + +void Notifier::NotifySourceVideoMode(const SourceImpl& source, const VideoMode& mode) { auto thr = m_owner.GetThread(); if (!thr) return; - thr->m_notifications.emplace(name, source, mode); + + auto handleData = Sources::GetInstance().Find(source); + + thr->m_notifications.emplace(source.GetName(), handleData.first, mode); thr->m_cond.notify_one(); } -void Notifier::NotifySourceProperty(llvm::StringRef name, CS_Source source, - RawEvent::Kind kind, int property, - CS_PropertyKind propertyKind, int value, - llvm::StringRef valueStr) { +void Notifier::NotifySourceProperty(const SourceImpl& source, CS_EventKind kind, + int property, CS_PropertyKind propertyKind, + int value, llvm::StringRef valueStr) { auto thr = m_owner.GetThread(); if (!thr) return; - thr->m_notifications.emplace(name, source, kind, - Handle{source, property, Handle::kProperty}, - propertyKind, value, valueStr); + + auto handleData = Sources::GetInstance().Find(source); + + thr->m_notifications.emplace( + source.GetName(), handleData.first, static_cast(kind), + Handle{handleData.first, property, Handle::kProperty}, propertyKind, + value, valueStr); thr->m_cond.notify_one(); } void Notifier::NotifySink(llvm::StringRef name, CS_Sink sink, - RawEvent::Kind kind) { + CS_EventKind kind) { auto thr = m_owner.GetThread(); if (!thr) return; - thr->m_notifications.emplace(name, sink, kind); + + thr->m_notifications.emplace(name, sink, static_cast(kind)); thr->m_cond.notify_one(); } + +void Notifier::NotifySink(const SinkImpl& sink, CS_EventKind kind) { + auto handleData = Sinks::GetInstance().Find(sink); + NotifySink(sink.GetName(), handleData.first, kind); +} diff --git a/src/Notifier.h b/src/Notifier.h index 7e240f00ca..3ec0203a3e 100644 --- a/src/Notifier.h +++ b/src/Notifier.h @@ -16,6 +16,9 @@ namespace cs { +class SinkImpl; +class SourceImpl; + class Notifier { friend class NotifierTest; @@ -39,15 +42,14 @@ class Notifier { void RemoveListener(int uid); // Notification events - void NotifySource(llvm::StringRef name, CS_Source source, - RawEvent::Kind kind); - void NotifySourceVideoMode(llvm::StringRef name, CS_Source source, - const VideoMode& mode); - void NotifySourceProperty(llvm::StringRef name, CS_Source source, - RawEvent::Kind kind, int property, - CS_PropertyKind propertyKind, int value, - llvm::StringRef valueStr); - void NotifySink(llvm::StringRef name, CS_Sink sink, RawEvent::Kind kind); + void NotifySource(llvm::StringRef name, CS_Source source, CS_EventKind kind); + void NotifySource(const SourceImpl& source, CS_EventKind kind); + void NotifySourceVideoMode(const SourceImpl& source, const VideoMode& mode); + void NotifySourceProperty(const SourceImpl& source, CS_EventKind kind, + int property, CS_PropertyKind propertyKind, + int value, llvm::StringRef valueStr); + void NotifySink(llvm::StringRef name, CS_Sink sink, CS_EventKind kind); + void NotifySink(const SinkImpl& sink, CS_EventKind kind); private: Notifier();