From 883fd5b062d8b0a4c3c4180c3c2b8168aa3ffe7e Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Mon, 2 Jan 2017 19:43:04 -0800 Subject: [PATCH] For property events, provide property name rather than source name. This is much more useful. --- include/cscore_c.h | 2 +- include/cscore_cpp.h | 2 +- java/src/edu/wpi/cscore/VideoEvent.java | 2 +- src/CvSourceImpl.cpp | 7 ++++--- src/HttpCameraImpl.cpp | 10 +++++----- src/Notifier.cpp | 7 ++++--- src/Notifier.h | 5 +++-- src/SourceImpl.cpp | 13 +++++++------ 8 files changed, 26 insertions(+), 22 deletions(-) diff --git a/include/cscore_c.h b/include/cscore_c.h index 3377e078ae..c75d3cc7f7 100644 --- a/include/cscore_c.h +++ b/include/cscore_c.h @@ -164,7 +164,7 @@ struct CS_Event { CS_Source source; CS_Sink sink; - // Source/sink name + // Source/sink/property name const char *name; // Fields for CS_SOURCE_VIDEOMODE_CHANGED event diff --git a/include/cscore_cpp.h b/include/cscore_cpp.h index 3a408e8362..5ede8d6b98 100644 --- a/include/cscore_cpp.h +++ b/include/cscore_cpp.h @@ -119,7 +119,7 @@ struct RawEvent { CS_Source sourceHandle = CS_INVALID_HANDLE; CS_Sink sinkHandle = CS_INVALID_HANDLE; - // Source/sink name + // Source/sink/property name std::string name; // Fields for kSourceVideoModeChanged event diff --git a/java/src/edu/wpi/cscore/VideoEvent.java b/java/src/edu/wpi/cscore/VideoEvent.java index ba6b514282..cb78b8dae6 100644 --- a/java/src/edu/wpi/cscore/VideoEvent.java +++ b/java/src/edu/wpi/cscore/VideoEvent.java @@ -79,7 +79,7 @@ public class VideoEvent { public int sourceHandle; public int sinkHandle; - // Source/sink name + // Source/sink/property name public String name; // Fields for kSourceVideoModeChanged event diff --git a/src/CvSourceImpl.cpp b/src/CvSourceImpl.cpp index b4bd45f111..0ed34d03e8 100644 --- a/src/CvSourceImpl.cpp +++ b/src/CvSourceImpl.cpp @@ -188,7 +188,8 @@ int CvSourceImpl::CreateProperty(llvm::StringRef name, CS_PropertyKind kind, value = prop->value; } Notifier::GetInstance().NotifySourceProperty( - *this, CS_SOURCE_PROPERTY_CREATED, ndx, kind, value, llvm::StringRef{}); + *this, CS_SOURCE_PROPERTY_CREATED, name, ndx, kind, value, + llvm::StringRef{}); return ndx; } @@ -215,8 +216,8 @@ void CvSourceImpl::SetEnumPropertyChoices(int property, } prop->enumChoices = choices; Notifier::GetInstance().NotifySourceProperty( - *this, CS_SOURCE_PROPERTY_CHOICES_UPDATED, property, CS_PROP_ENUM, - prop->value, llvm::StringRef{}); + *this, CS_SOURCE_PROPERTY_CHOICES_UPDATED, prop->name, property, + CS_PROP_ENUM, prop->value, llvm::StringRef{}); } namespace cs { diff --git a/src/HttpCameraImpl.cpp b/src/HttpCameraImpl.cpp index 4d134fbbbb..bcfe625418 100644 --- a/src/HttpCameraImpl.cpp +++ b/src/HttpCameraImpl.cpp @@ -335,8 +335,8 @@ void HttpCameraImpl::CreateProperty(llvm::StringRef name, value)); Notifier::GetInstance().NotifySourceProperty( - *this, CS_SOURCE_PROPERTY_CREATED, m_propertyData.size() + 1, kind, value, - llvm::StringRef{}); + *this, CS_SOURCE_PROPERTY_CREATED, name, m_propertyData.size() + 1, kind, + value, llvm::StringRef{}); } template @@ -353,11 +353,11 @@ void HttpCameraImpl::CreateEnumProperty( for (const auto& choice : choices) enumChoices.emplace_back(choice); Notifier::GetInstance().NotifySourceProperty( - *this, CS_SOURCE_PROPERTY_CREATED, m_propertyData.size() + 1, + *this, CS_SOURCE_PROPERTY_CREATED, name, m_propertyData.size() + 1, CS_PROP_ENUM, value, llvm::StringRef{}); Notifier::GetInstance().NotifySourceProperty( - *this, CS_SOURCE_PROPERTY_CHOICES_UPDATED, m_propertyData.size() + 1, - CS_PROP_ENUM, value, llvm::StringRef{}); + *this, CS_SOURCE_PROPERTY_CHOICES_UPDATED, name, + m_propertyData.size() + 1, CS_PROP_ENUM, value, llvm::StringRef{}); } std::unique_ptr HttpCameraImpl::CreateEmptyProperty( diff --git a/src/Notifier.cpp b/src/Notifier.cpp index de81fa300a..1ec9a4f8a6 100644 --- a/src/Notifier.cpp +++ b/src/Notifier.cpp @@ -177,15 +177,16 @@ void Notifier::NotifySourceVideoMode(const SourceImpl& source, } void Notifier::NotifySourceProperty(const SourceImpl& source, CS_EventKind kind, - int property, CS_PropertyKind propertyKind, - int value, llvm::StringRef valueStr) { + llvm::StringRef propertyName, int property, + CS_PropertyKind propertyKind, int value, + llvm::StringRef valueStr) { auto thr = m_owner.GetThread(); if (!thr) return; auto handleData = Sources::GetInstance().Find(source); thr->m_notifications.emplace( - source.GetName(), handleData.first, static_cast(kind), + propertyName, handleData.first, static_cast(kind), Handle{handleData.first, property, Handle::kProperty}, propertyKind, value, valueStr); thr->m_cond.notify_one(); diff --git a/src/Notifier.h b/src/Notifier.h index f0a88a8b45..95bf6acf8a 100644 --- a/src/Notifier.h +++ b/src/Notifier.h @@ -46,8 +46,9 @@ class Notifier { 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); + llvm::StringRef propertyName, 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); void NotifySinkSourceChanged(llvm::StringRef name, CS_Sink sink, diff --git a/src/SourceImpl.cpp b/src/SourceImpl.cpp index 09462985b8..a792e26ed5 100644 --- a/src/SourceImpl.cpp +++ b/src/SourceImpl.cpp @@ -337,13 +337,14 @@ void SourceImpl::PutError(llvm::StringRef msg, Frame::Time time) { void SourceImpl::NotifyPropertyCreated(int propIndex, PropertyImpl& prop) { auto& notifier = Notifier::GetInstance(); - notifier.NotifySourceProperty(*this, CS_SOURCE_PROPERTY_CREATED, propIndex, - prop.propKind, prop.value, prop.valueStr); + notifier.NotifySourceProperty(*this, CS_SOURCE_PROPERTY_CREATED, prop.name, + propIndex, prop.propKind, prop.value, + prop.valueStr); // also notify choices updated event for enum types if (prop.propKind == CS_PROP_ENUM) notifier.NotifySourceProperty(*this, CS_SOURCE_PROPERTY_CHOICES_UPDATED, - propIndex, prop.propKind, prop.value, - llvm::StringRef{}); + prop.name, propIndex, prop.propKind, + prop.value, llvm::StringRef{}); } void SourceImpl::UpdatePropertyValue(int property, bool setString, int value, @@ -359,8 +360,8 @@ void SourceImpl::UpdatePropertyValue(int property, bool setString, int value, // Only notify updates after we've notified created if (m_properties_cached) Notifier::GetInstance().NotifySourceProperty( - *this, CS_SOURCE_PROPERTY_VALUE_UPDATED, property, prop->propKind, - prop->value, prop->valueStr); + *this, CS_SOURCE_PROPERTY_VALUE_UPDATED, prop->name, property, + prop->propKind, prop->value, prop->valueStr); } void SourceImpl::ReleaseImage(std::unique_ptr image) {