]> git.sesse.net Git - cubemap/blob - serverpool.h
Some small refactoring of main().
[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         // Accessor. Only to be used in rare situations, really.
17         // The ServerPool retains ownership.
18         Server *get_server(int num) { return &servers[num]; }
19
20         // Picks a server (round-robin) and allocates the given client to it.
21         void add_client(int sock);
22         void add_client_from_serialized(const ClientProto &client);
23
24         // Adds the given stream to all the servers.
25         void add_stream(const std::string &stream_id);
26         void add_stream_from_serialized(const StreamProto &stream);
27
28         // Adds the given data to all the servers.
29         void set_header(const std::string &stream_id, const std::string &header);
30         void add_data(const std::string &stream_id, const char *data, size_t bytes);
31
32         // Connects the given stream to the given mark pool for all the servers.
33         void set_mark_pool(const std::string &stream_id, MarkPool *mark_pool);
34
35         // Starts all the servers.
36         void run();
37
38         std::vector<ClientStats> get_client_stats() const;
39
40 private:
41         Server *servers;
42         int num_servers, clients_added;
43
44         ServerPool(const ServerPool &);
45 };
46
47 #endif  // !defined(_SERVERPOOL_H)