1
2
3
4
5
6 #include <cmajor/build/ClientExecutionContext.hpp>
7 #include <cmajor/build/BuildServerMessage.hpp>
8 #include <stdexcept>
9
10 namespace cmajor { namespace build {
11
12 ClientExecutionContext::ClientExecutionContext(const std::string& serverName) : ExecutionContext()
13 {
14 socketClient.reset(new SocketClient(GetLog(), serverName));
15 socketClient->Run();
16 }
17
18 ClientExecutionContext::~ClientExecutionContext()
19 {
20 try
21 {
22 Connection* connection = socketClient->GetConnection();
23 if (connection)
24 {
25 if (connection->ServerAlive())
26 {
27 connection->SetServerAlive(false);
28 if (connection->GetLog())
29 {
30 connection->GetLog()->Write("closing connection\n", nullptr);
31 }
32 CloseConnectionRequest closeConnectionRequest;
33 closeConnectionRequest.SendTo(*connection);
34 }
35 }
36 }
37 catch (const std::exception&;)
38 {
39 }
40 }
41
42 BuildClient* ClientExecutionContext::GetClient()
43 {
44 return socketClient->GetClient();
45 }
46
47 Connection* ClientExecutionContext::GetConnection()
48 {
49 return socketClient->GetConnection();
50 }
51
52 } }