WPILibC++  unspecified
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Pages
Notifier.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) FIRST 2015. 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 NT_NOTIFIER_H_
9 #define NT_NOTIFIER_H_
10 
11 #include <functional>
12 
13 #include "support/atomic_static.h"
14 #include "support/SafeThread.h"
15 #include "ntcore_cpp.h"
16 
17 namespace nt {
18 
19 class Notifier {
20  friend class NotifierTest;
21 
22  public:
23  static Notifier& GetInstance() {
24  ATOMIC_STATIC(Notifier, instance);
25  return instance;
26  }
27  ~Notifier();
28 
29  void Start();
30  void Stop();
31 
32  bool local_notifiers() const { return m_local_notifiers; }
33  static bool destroyed() { return s_destroyed; }
34 
35  void SetOnStart(std::function<void()> on_start) { m_on_start = on_start; }
36  void SetOnExit(std::function<void()> on_exit) { m_on_exit = on_exit; }
37 
38  unsigned int AddEntryListener(llvm::StringRef prefix,
39  EntryListenerCallback callback,
40  unsigned int flags);
41  void RemoveEntryListener(unsigned int entry_listener_uid);
42 
43  void NotifyEntry(StringRef name, std::shared_ptr<Value> value,
44  unsigned int flags, EntryListenerCallback only = nullptr);
45 
46  unsigned int AddConnectionListener(ConnectionListenerCallback callback);
47  void RemoveConnectionListener(unsigned int conn_listener_uid);
48 
49  void NotifyConnection(bool connected, const ConnectionInfo& conn_info,
50  ConnectionListenerCallback only = nullptr);
51 
52  private:
53  Notifier();
54 
55  class Thread;
56  wpi::SafeThreadOwner<Thread> m_owner;
57 
58  std::atomic_bool m_local_notifiers;
59 
60  std::function<void()> m_on_start;
61  std::function<void()> m_on_exit;
62 
63  ATOMIC_STATIC_DECL(Notifier)
64  static bool s_destroyed;
65 };
66 
67 } // namespace nt
68 
69 #endif // NT_NOTIFIER_H_
NetworkTables Connection Information.
Definition: ntcore_cpp.h:43
Definition: Notifier.h:19
Definition: Notifier.cpp:63