10 #ifndef PLAYD_IO_CORE_HPP 11 #define PLAYD_IO_CORE_HPP 20 #define _SSIZE_T_DEFINED 63 void Run(
const std::string &host,
const std::string &port);
114 std::vector<std::shared_ptr<Connection>>
pool;
127 void InitAcceptor(
const std::string &address,
const std::string &port);
221 void Read(ssize_t nread,
const uv_buf_t *buf);
266 Response RunCommand(
const std::vector<std::string> &msg);
269 #endif // PLAYD_IO_CORE_HPP size_t NextConnectionID()
Acquires the next available connection ID.
Player & player
The Player to which finished commands should be sent.
void UpdatePlayer()
Performs a player update cycle.
std::vector< size_t > free_list
A list of free 1-indexed slots inside pool.
IoCore & parent
The pool on which this connection is running.
void Broadcast(const Response &response) const
Sends the given response to all connections.
void InitSignals()
Initialises playd's signal handling.
size_t id
The Connection's ID in the connection pool.
uv_signal_t sigint
The libuv handle for the Ctrl-C signal.
Abstract class for anything that can be sent a response.
Player & player
The player.
void Unicast(size_t id, const Response &response) const
Sends the given response to the identified connection.
void Respond(size_t id, const Response &response) const override
Outputs a response.
void Accept(uv_stream_t *server)
Accepts a new connection.
void InitAcceptor(const std::string &address, const std::string &port)
Initialises a TCP acceptor on the given address and port.
void Run(const std::string &host, const std::string &port)
Runs the reactor.
uv_tcp_t server
The libuv handle for the TCP server.
IoCore & operator=(const IoCore &)=delete
Deleted copy-assignment.
void InitUpdateTimer()
Sets up a periodic timer to run the playd update loop.
Declaration of the Player class, and associated types.
std::vector< std::shared_ptr< Connection > > pool
The set of connections inside this IoCore.
void ExpandPool()
Adds a new connection slot to the connection pool.
Declaration of classes pertaining to responses to the client.
uv_tcp_t * tcp
The libuv handle for the TCP connection.
void Shutdown()
Shuts down the IoCore by terminating all IO loop tasks.
IoCore(Player &player)
Constructs an IoCore.
Declaration of the Tokeniser class.
Tokeniser tokeniser
The Tokeniser to which data read on this connection should be sent.
A TCP connection from a client.
uv_loop_t * loop
The loop this IoCore is using.
A Player contains a loaded audio file and a command API for manipulating it.
void Remove(size_t id)
Removes a connection.
The IO core, which services input, routes responses, and executes the Player update routine periodica...
static const uint16_t PLAYER_UPDATE_PERIOD
The period between player updates.
uv_timer_t updater
The libuv handle for the update timer.