WPILibC++  unspecified
Notifier.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2015-2017 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 #include <support/atomic_static.h>
15 
16 #include "cscore_cpp.h"
17 
18 namespace cs {
19 
20 class SinkImpl;
21 class SourceImpl;
22 
23 class Notifier {
24  friend class NotifierTest;
25 
26  public:
27  static Notifier& GetInstance() {
28  ATOMIC_STATIC(Notifier, instance);
29  return instance;
30  }
31  ~Notifier();
32 
33  void Start();
34  void Stop();
35 
36  static bool destroyed() { return s_destroyed; }
37 
38  void SetOnStart(std::function<void()> on_start) { m_on_start = on_start; }
39  void SetOnExit(std::function<void()> on_exit) { m_on_exit = on_exit; }
40 
41  int AddListener(std::function<void(const RawEvent& event)> callback,
42  int eventMask);
43  void RemoveListener(int uid);
44 
45  // Notification events
46  void NotifySource(llvm::StringRef name, CS_Source source, CS_EventKind kind);
47  void NotifySource(const SourceImpl& source, CS_EventKind kind);
48  void NotifySourceVideoMode(const SourceImpl& source, const VideoMode& mode);
49  void NotifySourceProperty(const SourceImpl& source, CS_EventKind kind,
50  llvm::StringRef propertyName, int property,
51  CS_PropertyKind propertyKind, int value,
52  llvm::StringRef valueStr);
53  void NotifySink(llvm::StringRef name, CS_Sink sink, CS_EventKind kind);
54  void NotifySink(const SinkImpl& sink, CS_EventKind kind);
55  void NotifySinkSourceChanged(llvm::StringRef name, CS_Sink sink,
56  CS_Source source);
57  void NotifyNetworkInterfacesChanged();
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 
68  ATOMIC_STATIC_DECL(Notifier)
69  static bool s_destroyed;
70 };
71 
72 } // namespace cs
73 
74 #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:23
Definition: Notifier.cpp:67
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:42
Video mode.
Definition: cscore_cpp.h:46