WPILibC++  unspecified
ConnectionNotifier.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_CONNECTIONNOTIFIER_H_
9 #define NT_CONNECTIONNOTIFIER_H_
10 
11 #include "ntcore_cpp.h"
12 
13 #include "CallbackManager.h"
14 #include "Handle.h"
15 #include "IConnectionNotifier.h"
16 
17 namespace nt {
18 
19 namespace impl {
20 
22  : public CallbackThread<ConnectionNotifierThread, ConnectionNotification> {
23  public:
24  ConnectionNotifierThread(int inst) : m_inst(inst) {}
25 
26  bool Matches(const ListenerData& listener,
27  const ConnectionNotification& data) {
28  return true;
29  }
30 
31  void SetListener(ConnectionNotification* data, unsigned int listener_uid) {
32  data->listener =
33  Handle(m_inst, listener_uid, Handle::kConnectionListener).handle();
34  }
35 
36  void DoCallback(
37  std::function<void(const ConnectionNotification& event)> callback,
38  const ConnectionNotification& data) {
39  callback(data);
40  }
41 
42  int m_inst;
43 };
44 
45 } // namespace impl
46 
48  : public IConnectionNotifier,
49  public CallbackManager<ConnectionNotifier,
50  impl::ConnectionNotifierThread> {
51  friend class ConnectionNotifierTest;
52  friend class CallbackManager<ConnectionNotifier,
53  impl::ConnectionNotifierThread>;
54 
55  public:
56  explicit ConnectionNotifier(int inst);
57 
58  void Start();
59 
60  unsigned int Add(std::function<void(const ConnectionNotification& event)>
61  callback) override;
62  unsigned int AddPolled(unsigned int poller_uid) override;
63 
64  void NotifyConnection(bool connected, const ConnectionInfo& conn_info,
65  unsigned int only_listener = UINT_MAX) override;
66 
67  private:
68  int m_inst;
69 };
70 
71 } // namespace nt
72 
73 #endif // NT_CONNECTIONNOTIFIER_H_
Definition: ConnectionNotifier.h:21
Definition: CallbackManager.h:52
NT_ConnectionListener listener
Listener that was triggered.
Definition: ntcore_cpp.h:214
Definition: IConnectionNotifier.h:17
Definition: Handle.h:20
Definition: IEntryNotifier.h:15
NetworkTables Connection Notification.
Definition: ntcore_cpp.h:206
Definition: CallbackManager.h:166
Definition: ConnectionNotifier.h:47