]> git.sesse.net Git - cubemap/blob - serverpool.h
Move Client and Stream into their own files.
[cubemap] / serverpool.h
1 #ifndef _SERVERPOOL_H
2 #define _SERVERPOOL_H 1
3
4 #include "server.h"
5
6 #include <vector>
7
8 class MarkPool;
9
10 // Provides services such as load-balancing between a number of Server instances.
11 class ServerPool {
12 public:
13         ServerPool(int num_servers);
14         ~ServerPool();
15
16         // Fills streams() and clients().
17         CubemapStateProto serialize();
18
19         // Picks a server (round-robin) and allocates the given client to it.
20         void add_client(int sock);
21         void add_client_from_serialized(const ClientProto &client);
22
23         // Adds the given stream to all the servers.
24         void add_stream(const std::string &stream_id, size_t backlog_size);
25         void add_stream_from_serialized(const StreamProto &stream);
26
27         // Adds the given data to all the servers.
28         void set_header(const std::string &stream_id, const std::string &header);
29         void add_data(const std::string &stream_id, const char *data, size_t bytes);
30
31         // Connects the given stream to the given mark pool for all the servers.
32         void set_mark_pool(const std::string &stream_id, MarkPool *mark_pool);
33
34         // Starts all the servers.
35         void run();
36
37         // Stops all the servers.
38         void stop();
39
40         std::vector<ClientStats> get_client_stats() const;
41
42 private:
43         Server *servers;
44         int num_servers, clients_added;
45
46         ServerPool(const ServerPool &);
47 };
48
49 #endif  // !defined(_SERVERPOOL_H)