2016-11-05 13:13:09 -07:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2017-08-25 17:48:06 -07:00
|
|
|
/* Copyright (c) 2015-2017 FIRST. All Rights Reserved. */
|
2016-11-05 13:13:09 -07:00
|
|
|
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
|
|
|
|
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
|
|
|
|
/* the project. */
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
2017-08-25 17:48:06 -07:00
|
|
|
#ifndef CSCORE_NOTIFIER_H_
|
|
|
|
|
#define CSCORE_NOTIFIER_H_
|
2016-11-05 13:13:09 -07:00
|
|
|
|
|
|
|
|
#include <functional>
|
|
|
|
|
|
2017-08-25 17:48:06 -07:00
|
|
|
#include <support/SafeThread.h>
|
|
|
|
|
|
2016-11-05 22:11:55 -07:00
|
|
|
#include "cscore_cpp.h"
|
2016-11-05 13:13:09 -07:00
|
|
|
|
|
|
|
|
namespace cs {
|
|
|
|
|
|
2016-11-18 07:49:33 -08:00
|
|
|
class SinkImpl;
|
|
|
|
|
class SourceImpl;
|
|
|
|
|
|
2016-11-05 13:13:09 -07:00
|
|
|
class Notifier {
|
|
|
|
|
friend class NotifierTest;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
static Notifier& GetInstance() {
|
2017-11-17 09:29:20 -08:00
|
|
|
static Notifier instance;
|
2016-11-05 13:13:09 -07:00
|
|
|
return instance;
|
|
|
|
|
}
|
|
|
|
|
~Notifier();
|
|
|
|
|
|
|
|
|
|
void Start();
|
|
|
|
|
void Stop();
|
|
|
|
|
|
|
|
|
|
static bool destroyed() { return s_destroyed; }
|
|
|
|
|
|
|
|
|
|
void SetOnStart(std::function<void()> on_start) { m_on_start = on_start; }
|
|
|
|
|
void SetOnExit(std::function<void()> on_exit) { m_on_exit = on_exit; }
|
|
|
|
|
|
|
|
|
|
int AddListener(std::function<void(const RawEvent& event)> callback,
|
|
|
|
|
int eventMask);
|
|
|
|
|
void RemoveListener(int uid);
|
|
|
|
|
|
|
|
|
|
// Notification events
|
2016-11-18 07:49:33 -08:00
|
|
|
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,
|
2017-01-02 19:43:04 -08:00
|
|
|
llvm::StringRef propertyName, int property,
|
|
|
|
|
CS_PropertyKind propertyKind, int value,
|
|
|
|
|
llvm::StringRef valueStr);
|
2016-11-18 07:49:33 -08:00
|
|
|
void NotifySink(llvm::StringRef name, CS_Sink sink, CS_EventKind kind);
|
|
|
|
|
void NotifySink(const SinkImpl& sink, CS_EventKind kind);
|
2016-11-18 08:56:24 -08:00
|
|
|
void NotifySinkSourceChanged(llvm::StringRef name, CS_Sink sink,
|
|
|
|
|
CS_Source source);
|
2016-11-18 12:38:54 -08:00
|
|
|
void NotifyNetworkInterfacesChanged();
|
2016-11-05 13:13:09 -07:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
Notifier();
|
|
|
|
|
|
|
|
|
|
class Thread;
|
|
|
|
|
wpi::SafeThreadOwner<Thread> m_owner;
|
|
|
|
|
|
|
|
|
|
std::function<void()> m_on_start;
|
|
|
|
|
std::function<void()> m_on_exit;
|
|
|
|
|
static bool s_destroyed;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace cs
|
|
|
|
|
|
2017-08-25 17:48:06 -07:00
|
|
|
#endif // CSCORE_NOTIFIER_H_
|