1
2
3
4
5
6 #ifndef CMAJOR_BUILD_SERVER_CONFIG_INCLUDED
7 #define CMAJOR_BUILD_SERVER_CONFIG_INCLUDED
8 #include <cmajor/build/BuildApi.hpp>
9 #include <soulng/util/CodeFormatter.hpp>
10 #include <string>
11 #include <map>
12 #include <vector>
13 #include <memory>
14
15 namespace cmajor { namespace build {
16
17 using soulng::util::CodeFormatter;
18
19 std::string GetDefaultToolChainForCurrentPlatform();
20 int GetDefaultLocalPort();
21
22 class ServerInfo
23 {
24 public:
25 ServerInfo(const std::string& serverName_, const std::string& host, int port_, const std::string& defaultToolChain_);
26 ServerInfo(const ServerInfo&) = delete;
27 ServerInfo& operator=(const ServerInfo&) = delete;
28 const std::string& ServerName() const { return serverName; }
29 const std::string& Host() const { return host; }
30 void SetHost(const std::string& host_) { host = host_; }
31 int Port() const { return port; }
32 void SetPort(int port_) { port = port_; }
33 const std::string& DefaultToolChain() const { return defaultToolChain; }
34 void SetDefaultToolChain(const std::string& defaultToolChain_);
35 void Print(CodeFormatter& formatter);
36 private:
37 std::string serverName;
38 std::string host;
39 int port;
40 std::string defaultToolChain;
41 };
42
43 class ServerConfig
44 {
45 public:
46 static void Init();
47 static void Done();
48 static ServerConfig& Instance() { return *instance; }
49 void Read();
50 void Write();
51 ServerConfig(const ServerConfig&) = delete;
52 ServerConfig& operator=(const ServerConfig&) = delete;
53 void Add(const std::string& serverName, const std::string& hostName, int port, const std::string& defaultToolChain, bool force, bool read, bool write);
54 void Remove(const std::string& serverName);
55 void Show();
56 ServerInfo* GetServerInfo(const std::string& serverName, bool failIfNotExist, bool read);
57 private:
58 ServerConfig();
59 static std::unique_ptr<ServerConfig> instance;
60 std::map<std::string, ServerInfo*> serverMap;
61 std::vector<std::std::unique_ptr<ServerInfo>>serverInfos;
62 std::map<std::std::pair<std::string, int>, std::string>hostPortMap;
63 };
64
65 void ServerInit();
66 void ServerDone();
67
68 } }
69
70 #endif // CMAJOR_BUILD_SERVER_CONFIG_INCLUDED