mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
[cscore] Add USB camera change event (#3123)
This commit is contained in:
@@ -36,7 +36,10 @@ static void def_log_func(unsigned int level, const char* file,
|
||||
wpi::errs() << oss.str();
|
||||
}
|
||||
|
||||
Instance::Instance() : telemetry(notifier), networkListener(logger, notifier) {
|
||||
Instance::Instance()
|
||||
: telemetry(notifier),
|
||||
networkListener(logger, notifier),
|
||||
usbCameraListener(logger, notifier) {
|
||||
SetDefaultLogger();
|
||||
}
|
||||
|
||||
@@ -52,6 +55,7 @@ void Instance::Shutdown() {
|
||||
m_sinks.FreeAll();
|
||||
m_sources.FreeAll();
|
||||
networkListener.Stop();
|
||||
usbCameraListener.Stop();
|
||||
telemetry.Stop();
|
||||
notifier.Stop();
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include "SourceImpl.h"
|
||||
#include "Telemetry.h"
|
||||
#include "UnlimitedHandleResource.h"
|
||||
#include "UsbCameraListener.h"
|
||||
|
||||
namespace cs {
|
||||
|
||||
@@ -54,6 +55,7 @@ class Instance {
|
||||
Notifier notifier;
|
||||
Telemetry telemetry;
|
||||
NetworkListener networkListener;
|
||||
UsbCameraListener usbCameraListener;
|
||||
|
||||
private:
|
||||
UnlimitedHandleResource<Handle, SourceData, Handle::kSource> m_sources;
|
||||
|
||||
@@ -94,3 +94,7 @@ void Notifier::NotifyNetworkInterfacesChanged() {
|
||||
void Notifier::NotifyTelemetryUpdated() {
|
||||
Send(UINT_MAX, RawEvent::kTelemetryUpdated);
|
||||
}
|
||||
|
||||
void Notifier::NotifyUsbCamerasChanged() {
|
||||
Send(UINT_MAX, RawEvent::kUsbCamerasChanged);
|
||||
}
|
||||
|
||||
@@ -83,6 +83,7 @@ class Notifier : public wpi::CallbackManager<Notifier, impl::NotifierThread> {
|
||||
const wpi::Twine& valueStr);
|
||||
void NotifyNetworkInterfacesChanged();
|
||||
void NotifyTelemetryUpdated();
|
||||
void NotifyUsbCamerasChanged();
|
||||
};
|
||||
|
||||
} // namespace cs
|
||||
|
||||
31
cscore/src/main/native/cpp/UsbCameraListener.h
Normal file
31
cscore/src/main/native/cpp/UsbCameraListener.h
Normal file
@@ -0,0 +1,31 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
#ifndef CSCORE_USBCAMERALISTENER_H_
|
||||
#define CSCORE_USBCAMERALISTENER_H_
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <wpi/Logger.h>
|
||||
|
||||
namespace cs {
|
||||
|
||||
class Notifier;
|
||||
|
||||
class UsbCameraListener {
|
||||
public:
|
||||
UsbCameraListener(wpi::Logger& logger, Notifier& notifier);
|
||||
~UsbCameraListener();
|
||||
|
||||
void Start();
|
||||
void Stop();
|
||||
|
||||
private:
|
||||
class Impl;
|
||||
std::unique_ptr<Impl> m_impl;
|
||||
};
|
||||
|
||||
} // namespace cs
|
||||
|
||||
#endif // CSCORE_USBCAMERALISTENER_H_
|
||||
@@ -718,6 +718,13 @@ static void StartBackground(int eventMask, bool immediateNotify) {
|
||||
inst.notifier.NotifyNetworkInterfacesChanged();
|
||||
}
|
||||
}
|
||||
if ((eventMask & CS_USB_CAMERAS_CHANGED) != 0) {
|
||||
// start network interface event listener
|
||||
inst.usbCameraListener.Start();
|
||||
if (immediateNotify) {
|
||||
inst.notifier.NotifyUsbCamerasChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CS_Listener AddListener(std::function<void(const RawEvent& event)> callback,
|
||||
|
||||
Reference in New Issue
Block a user