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