jbus/include/jbus/Listener.hpp

40 lines
848 B
C++
Raw Normal View History

2018-10-06 20:42:04 -07:00
#pragma once
2017-01-06 19:13:23 -08:00
#include <memory>
2017-01-07 00:24:16 -08:00
#include <mutex>
#include <queue>
#include <thread>
#include "jbus/Socket.hpp"
2017-01-06 19:13:23 -08:00
2018-12-07 21:20:55 -08:00
namespace jbus {
class Endpoint;
2017-01-06 19:13:23 -08:00
2017-01-07 15:55:41 -08:00
/** Server interface for accepting incoming connections from GBA emulator instances. */
2018-12-07 21:20:55 -08:00
class Listener {
net::Socket m_dataServer{false};
net::Socket m_clockServer{false};
2018-12-07 21:20:55 -08:00
std::thread m_listenerThread;
std::mutex m_queueLock;
std::queue<std::unique_ptr<Endpoint>> m_endpointQueue;
bool m_running = false;
2017-01-06 19:13:23 -08:00
2018-12-07 21:20:55 -08:00
void listenerProc();
2017-01-06 19:13:23 -08:00
public:
2018-12-07 21:20:55 -08:00
/** @brief Start listener thread. */
void start();
2017-01-07 15:55:41 -08:00
2018-12-07 21:20:55 -08:00
/** @brief Request stop of listener thread and block until joined. */
void stop();
2017-01-07 15:55:41 -08:00
2018-12-07 21:20:55 -08:00
/** @brief Pop jbus::Endpoint off Listener's queue.
* @return Endpoint instance, ready to issue commands. */
std::unique_ptr<Endpoint> accept();
2017-01-07 15:55:41 -08:00
Listener();
2018-12-07 21:20:55 -08:00
~Listener();
2017-01-06 19:13:23 -08:00
};
2018-12-07 21:20:55 -08:00
} // namespace jbus