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 "atomic_static.h"
14 #include "ntcore_cpp.h"
15 #include "SafeThread.h"
16 
17 namespace nt {
18 
19 class Notifier {
20  friend class NotifierTest;
21  public:
22  static Notifier& GetInstance() {
23  ATOMIC_STATIC(Notifier, instance);
24  return instance;
25  }
26  ~Notifier();
27 
28  void Start();
29  void Stop();
30 
31  bool local_notifiers() const { return m_local_notifiers; }
32  static bool destroyed() { return s_destroyed; }
33 
34  void SetOnStart(std::function<void()> on_start) { m_on_start = on_start; }
35  void SetOnExit(std::function<void()> on_exit) { m_on_exit = on_exit; }
36 
37  unsigned int AddEntryListener(StringRef prefix,
38  EntryListenerCallback callback,
39  unsigned int flags);
40  void RemoveEntryListener(unsigned int entry_listener_uid);
41 
42  void NotifyEntry(StringRef name, std::shared_ptr<Value> value,
43  unsigned int flags, EntryListenerCallback only = nullptr);
44 
45  unsigned int AddConnectionListener(ConnectionListenerCallback callback);
46  void RemoveConnectionListener(unsigned int conn_listener_uid);
47 
48  void NotifyConnection(bool connected, const ConnectionInfo& conn_info,
49  ConnectionListenerCallback only = nullptr);
50 
51  private:
52  Notifier();
53 
54  class Thread;
56 
57  std::atomic_bool m_local_notifiers;
58 
59  std::function<void()> m_on_start;
60  std::function<void()> m_on_exit;
61 
62  ATOMIC_STATIC_DECL(Notifier)
63  static bool s_destroyed;
64 };
65 
66 } // namespace nt
67 
68 #endif // NT_NOTIFIER_H_
NetworkTables Connection Information.
Definition: ntcore_cpp.h:43
Definition: Notifier.h:19
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:39