1
2
3
4
5
6 #include <cmajor/build/SocketClient.hpp>
7 #include <cmajor/build/ServerConfig.hpp>
8 #include <cmajor/symbols/GlobalFlags.hpp>
9 #include <soulng/util/Log.hpp>
10
11 namespace cmajor { namespace build {
12
13 using namespace cmajor::symbols;
14 using namespace soulng::util;
15
16 SocketClient::SocketClient(Log* log_, const std::string& serverName_) : log(log_), name("socket client"), serverName(serverName_), socket()
17 {
18 }
19
20 const std::string& SocketClient::Name() const
21 {
22 return name;
23 }
24
25 void SocketClient::Run()
26 {
27 ServerInfo* serverInfo = ServerConfig::Instance().GetServerInfo(serverName, true, true);
28 if (serverInfo)
29 {
30 std::string node = "localhost";
31 std::string service = std::to_string(serverInfo->Port());
32 std::string hostPortStr;
33 if (!serverInfo->Host().empty() && serverInfo->Host() != "localhost" && serverInfo->Host() != "127.0.0.1")
34 {
35 node = serverInfo->Host();
36 hostPortStr = "host " + serverInfo->Host() + " port " + std::to_string(serverInfo->Port());
37 }
38 else
39 {
40 hostPortStr = "port " + std::to_string(serverInfo->Port());
41 }
42 if (GetGlobalFlag(GlobalFlags::verbose))
43 {
44 LogMessage(-1, "socket client: connecting to server '" + serverName + "' in " + hostPortStr + "...");
45 }
46 socket.Connect(node, service);
47 if (GetGlobalFlag(GlobalFlags::verbose))
48 {
49 LogMessage(-1, "socket client: connected");
50 }
51 }
52 else
53 {
54 throw std::runtime_error("socket client: server name '" + serverName + "' not found");
55 }
56 connection.reset(new SocketConnection(log, this, std::move(socket)));
57 connection->SetServerAlive(true);
58 buildClient.reset(new BuildClient(connection.get()));
59 buildClient->SetDefaultToolChain(serverInfo->DefaultToolChain());
60 }
61
62 void SocketClient::Exit()
63 {
64 }
65
66 } }