JBus
JoyBus communication server
Listener.hpp
Go to the documentation of this file.
1 #ifndef JBUS_LISTENER_HPP
2 #define JBUS_LISTENER_HPP
3 
4 #include "Common.hpp"
5 #include "Socket.hpp"
6 #include <thread>
7 #include <queue>
8 #include <mutex>
9 
10 namespace jbus
11 {
12 
14 class Listener
15 {
16  net::Socket m_dataServer = {false};
17  net::Socket m_clockServer = {false};
18  std::thread m_listenerThread;
19  std::mutex m_queueLock;
20  std::queue<std::unique_ptr<Endpoint>> m_endpointQueue;
21  bool m_running = false;
22 
23  static const uint32_t DataPort = 0xd6ba;
24  static const uint32_t ClockPort = 0xc10c;
25 
26  void listenerProc();
27 
28 public:
30  void start();
31 
33  void stop();
34 
37  std::unique_ptr<Endpoint> accept();
38 
39  ~Listener();
40 };
41 
42 }
43 
44 #endif // JBUS_LISTENER_HPP
Definition: Listener.hpp:14
void start()
Start listener thread.
Definition: Common.hpp:8
Definition: Socket.hpp:104
std::unique_ptr< Endpoint > accept()
Pop jbus::Endpoint off Listener&#39;s queue.
void stop()
Request stop of listener thread and block until joined.