WPILibC++  unspecified
Notifier.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2015-2018 FIRST. All Rights Reserved. */
3 /* Open Source Software - may be modified and shared by FRC teams. The code */
4 /* must be accompanied by the FIRST BSD license file in the root directory of */
5 /* the project. */
6 /*----------------------------------------------------------------------------*/
7 
8 #ifndef CSCORE_NOTIFIER_H_
9 #define CSCORE_NOTIFIER_H_
10 
11 #include <functional>
12 
13 #include <support/SafeThread.h>
14 
15 #include "cscore_cpp.h"
16 
17 namespace cs {
18 
19 class SinkImpl;
20 class SourceImpl;
21 
22 class Notifier {
23  friend class NotifierTest;
24 
25  public:
26  static Notifier& GetInstance() {
27  static Notifier instance;
28  return instance;
29  }
30  ~Notifier();
31 
32  void Start();
33  void Stop();
34 
35  static bool destroyed() { return s_destroyed; }
36 
37  void SetOnStart(std::function<void()> on_start) { m_on_start = on_start; }
38  void SetOnExit(std::function<void()> on_exit) { m_on_exit = on_exit; }
39 
40  int AddListener(std::function<void(const RawEvent& event)> callback,
41  int eventMask);
42  void RemoveListener(int uid);
43 
44  // Notification events
45  void NotifySource(llvm::StringRef name, CS_Source source, CS_EventKind kind);
46  void NotifySource(const SourceImpl& source, CS_EventKind kind);
47  void NotifySourceVideoMode(const SourceImpl& source, const VideoMode& mode);
48  void NotifySourceProperty(const SourceImpl& source, CS_EventKind kind,
49  llvm::StringRef propertyName, int property,
50  CS_PropertyKind propertyKind, int value,
51  llvm::StringRef valueStr);
52  void NotifySink(llvm::StringRef name, CS_Sink sink, CS_EventKind kind);
53  void NotifySink(const SinkImpl& sink, CS_EventKind kind);
54  void NotifySinkSourceChanged(llvm::StringRef name, CS_Sink sink,
55  CS_Source source);
56  void NotifyNetworkInterfacesChanged();
57  void NotifyTelemetryUpdated();
58 
59  private:
60  Notifier();
61 
62  class Thread;
64 
65  std::function<void()> m_on_start;
66  std::function<void()> m_on_exit;
67  static bool s_destroyed;
68 };
69 
70 } // namespace cs
71 
72 #endif // CSCORE_NOTIFIER_H_
Definition: SinkImpl.h:19
Definition: SinkImpl.h:23
Listener event.
Definition: cscore_cpp.h:71
Definition: SourceImpl.h:30
Definition: Notifier.h:22
Definition: Notifier.cpp:66
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:42
Video mode.
Definition: cscore_cpp.h:46