jbus/include/jbus/Listener.hpp

45 lines
994 B
C++
Raw Normal View History

2017-01-06 19:13:23 -08:00
#ifndef JBUS_LISTENER_HPP
#define JBUS_LISTENER_HPP
#include "Common.hpp"
#include "Socket.hpp"
#include <thread>
#include <queue>
2017-01-07 00:24:16 -08:00
#include <mutex>
2017-01-06 19:13:23 -08:00
namespace jbus
{
2017-01-07 15:55:41 -08:00
/** Server interface for accepting incoming connections from GBA emulator instances. */
2017-01-06 19:13:23 -08:00
class Listener
{
net::Socket m_dataServer = {false};
net::Socket m_clockServer = {false};
std::thread m_listenerThread;
std::mutex m_queueLock;
std::queue<std::unique_ptr<Endpoint>> m_endpointQueue;
bool m_running = false;
static const uint32_t DataPort = 0xd6ba;
static const uint32_t ClockPort = 0xc10c;
void listenerProc();
public:
2017-01-07 15:55:41 -08:00
/** @brief Start listener thread. */
2017-01-06 19:13:23 -08:00
void start();
2017-01-07 15:55:41 -08:00
/** @brief Request stop of listener thread and block until joined. */
2017-01-06 19:13:23 -08:00
void stop();
2017-01-07 15:55:41 -08:00
/** @brief Pop jbus::Endpoint off Listener's queue.
* @return Endpoint instance, ready to issue commands. */
2017-01-06 19:13:23 -08:00
std::unique_ptr<Endpoint> accept();
2017-01-07 15:55:41 -08:00
2017-01-06 19:13:23 -08:00
~Listener();
};
}
#endif // JBUS_LISTENER_HPP