diff --git a/src/CvSinkImpl.cpp b/src/CvSinkImpl.cpp index e2639fc122..27b5cb5da3 100644 --- a/src/CvSinkImpl.cpp +++ b/src/CvSinkImpl.cpp @@ -16,6 +16,7 @@ #include "c_util.h" #include "Handle.h" #include "Log.h" +#include "Notifier.h" using namespace cs; @@ -97,14 +98,18 @@ namespace cs { CS_Sink CreateCvSink(llvm::StringRef name, CS_Status* status) { auto sink = std::make_shared(name); - return Sinks::GetInstance().Allocate(CS_SINK_CV, sink); + auto handle = Sinks::GetInstance().Allocate(CS_SINK_CV, sink); + Notifier::GetInstance().NotifySink(name, handle, CS_SINK_CREATED); + return handle; } CS_Sink CreateCvSinkCallback(llvm::StringRef name, std::function processFrame, CS_Status* status) { auto sink = std::make_shared(name, processFrame); - return Sinks::GetInstance().Allocate(CS_SINK_CV, sink); + auto handle = Sinks::GetInstance().Allocate(CS_SINK_CV, sink); + Notifier::GetInstance().NotifySink(name, handle, CS_SINK_CREATED); + return handle; } void SetSinkDescription(CS_Sink sink, llvm::StringRef description, diff --git a/src/CvSourceImpl.cpp b/src/CvSourceImpl.cpp index 3ebde6ea0d..bc3eb7236c 100644 --- a/src/CvSourceImpl.cpp +++ b/src/CvSourceImpl.cpp @@ -16,6 +16,7 @@ #include "c_util.h" #include "Handle.h" #include "Log.h" +#include "Notifier.h" using namespace cs; @@ -157,7 +158,9 @@ namespace cs { CS_Source CreateCvSource(llvm::StringRef name, const VideoMode& mode, CS_Status* status) { auto source = std::make_shared(name, mode); - return Sources::GetInstance().Allocate(CS_SOURCE_CV, source); + auto handle = Sources::GetInstance().Allocate(CS_SOURCE_CV, source); + Notifier::GetInstance().NotifySource(name, handle, CS_SOURCE_CREATED); + return handle; } void PutSourceFrame(CS_Source source, cv::Mat& image, CS_Status* status) { diff --git a/src/MJPEGServerImpl.cpp b/src/MJPEGServerImpl.cpp index 69cc3a004a..027413a70d 100644 --- a/src/MJPEGServerImpl.cpp +++ b/src/MJPEGServerImpl.cpp @@ -18,6 +18,7 @@ #include "cscore_cpp.h" #include "Handle.h" #include "Log.h" +#include "Notifier.h" #include "SourceImpl.h" using namespace cs; @@ -696,7 +697,9 @@ CS_Sink CreateMJPEGServer(llvm::StringRef name, llvm::StringRef listenAddress, name, desc.str(), std::unique_ptr( new wpi::TCPAcceptor(port, str.c_str(), Logger::GetInstance()))); - return Sinks::GetInstance().Allocate(CS_SINK_MJPEG, sink); + auto handle = Sinks::GetInstance().Allocate(CS_SINK_MJPEG, sink); + Notifier::GetInstance().NotifySink(name, handle, CS_SINK_CREATED); + return handle; } } // namespace cs diff --git a/src/USBCameraImpl.cpp b/src/USBCameraImpl.cpp index 1445610f78..b0fe529b2a 100644 --- a/src/USBCameraImpl.cpp +++ b/src/USBCameraImpl.cpp @@ -37,6 +37,7 @@ #include "c_util.h" #include "Handle.h" #include "Log.h" +#include "Notifier.h" using namespace cs; @@ -1360,7 +1361,9 @@ CS_Source CreateUSBCameraDev(llvm::StringRef name, int dev, CS_Status* status) { CS_Source CreateUSBCameraPath(llvm::StringRef name, llvm::StringRef path, CS_Status* status) { auto source = std::make_shared(name, path); - return Sources::GetInstance().Allocate(CS_SOURCE_USB, source); + auto handle = Sources::GetInstance().Allocate(CS_SOURCE_USB, source); + Notifier::GetInstance().NotifySource(name, handle, CS_SOURCE_CREATED); + return handle; } std::vector EnumerateUSBCameras(CS_Status* status) { diff --git a/src/cscore_cpp.cpp b/src/cscore_cpp.cpp index 21b7003787..a2d397285e 100644 --- a/src/cscore_cpp.cpp +++ b/src/cscore_cpp.cpp @@ -13,6 +13,7 @@ #include "SinkImpl.h" #include "SourceImpl.h" #include "Handle.h" +#include "Notifier.h" using namespace cs; @@ -341,7 +342,11 @@ void ReleaseSource(CS_Source source, CS_Status* status) { *status = CS_INVALID_HANDLE; return; } - if (data->refCount-- == 0) inst.Free(source); + if (data->refCount-- == 0) { + Notifier::GetInstance().NotifySource(data->source->GetName(), source, + CS_SOURCE_DESTROYED); + inst.Free(source); + } } // @@ -450,7 +455,11 @@ void ReleaseSink(CS_Sink sink, CS_Status* status) { *status = CS_INVALID_HANDLE; return; } - if (data->refCount-- == 0) inst.Free(sink); + if (data->refCount-- == 0) { + Notifier::GetInstance().NotifySink(data->sink->GetName(), sink, + CS_SINK_DESTROYED); + inst.Free(sink); + } } //