]> git.sesse.net Git - ultimatescore/blob - client/acmp_client.h
Activate tiebreak rules #3 and #5 only if everybody in the tiebreak group have played.
[ultimatescore] / client / acmp_client.h
1 #ifndef _ACMP_CLIENT_H
2 #define _ACMP_CLIENT_H 1
3
4 #include <functional>
5 #include <mutex>
6 #include <string>
7 #include <thread>
8 #include <vector>
9
10 class ACMPClient {
11 public:
12         ACMPClient(const std::string &host, int port);
13
14         void add_init_command(const std::string &cmd);
15         void start();
16         void end();
17         void send_command(const std::string &cmd);  // Thread-safe.
18         void change_server(const std::string &host, int port);  // Thread-safe.
19         void set_connection_callback(const std::function<void(bool)> &callback);
20
21 private:
22         void thread_func();
23
24         std::thread t;
25         std::vector<std::string> init_commands;
26         std::function<void(bool)> connection_callback;
27
28         std::mutex mu;
29         std::string host;  // Protected by mu.
30         int port;  // Protected by mu.
31         std::vector<std::string> queued_commands;  // Protected by mu.
32 };
33
34 #endif  // !defined(_ACMP_CLIENT_H)