-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGUIToClient.h
More file actions
84 lines (73 loc) · 2.99 KB
/
Copy pathGUIToClient.h
File metadata and controls
84 lines (73 loc) · 2.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#pragma once
#include "Logger.h"
#include "FileInputOutput.h"
#include "Instance.h"
#include "Utility.h"
#include "Globals.h"
class GUIToClient
{
public:
GUIToClient() {} // default constructor
GUIToClient( std::string basePath )
{
Initialize( basePath );
}
void Initialize( std::string basePath )
{
requestPath = basePath + FILE_REQUESTS;
std::string configBasePath = CONFIG_FILEPATH;
std::vector<std::string> configVec = FIO_ReadFromFileToVector( configBasePath + FILE_CONFIG );
//m_params = configVec[ 0 ] + " " + configVec[ 1 ] + " " + configVec[ 2 ] + " " + configVec[ 3 ];
m_delimiter = configVec[ 2 ][ 0 ];
m_clientID = configVec[ 3 ];
}
void FetchRequests()
{
m_requests.clear();
m_requests = FIO_ReadFromFileToVector( requestPath );
}
void GetInstancesByOS()
{
m_instances.clear();
//std::vector<std::string> instanceStrings = StringToVec( Utility::ExecuteCommand( "boostclient " + m_params + " " + m_requests[ 0 ] ) );
std::vector<std::string> instanceStrings = StringToVec( Utility::ExecuteCommand( "./boostclient " + m_requests[ 0 ] ) );
for( unsigned int i = 0; i < instanceStrings.size() - 2; i+=3 )
{
m_instances.push_back( Instance( instanceStrings[ i ],instanceStrings[ i+1 ],instanceStrings[ i+2 ] ) );
}
}
void ConnectToInstance( int instanceIndex )
{
//std::vector<std::string> idIpPort = StringToVec( Utility::ExecuteCommand( "boostclient " + m_params + " " + m_requests[ 1 ] + m_instances[ instanceIndex ].GetTemplateID() + "#" + m_clientID ) );
std::vector<std::string> idIpPort = StringToVec( Utility::ExecuteCommand( "./boostclient " + m_requests[ 1 ] + m_instances[ instanceIndex ].GetTemplateID() + "#" + m_clientID ) );
m_instanceID = std::to_string( std::stoi( idIpPort[ 0 ] ) ); // little hack because it seems like there is something like a newline in front
Logger::__instance().LogLine( Utility::ExecuteCommand( "./Connect.sh " + idIpPort[ 1 ] + " " + idIpPort[ 2 ] ) );
}
void DisconnectFromInstance()
{
//Utility::ExecuteCommand( "client/boostclient " + m_params + " " + m_requests[ 2 ] + m_instanceID );
Utility::ExecuteCommand( "./boostclient " + m_requests[ 2 ] + m_instanceID );
}
private:
std::vector<std::string> StringToVec( std::string str )
{
std::vector<std::string> strVec;
std::string s = "";
std::istringstream ss( str );
while( std::getline( ss,s,m_delimiter ) )
{
strVec.push_back( s );
}
return strVec;
}
public:
std::vector<Instance> m_instances;
private:
std::string requestPath;
std::vector<std::string> m_requests;
//std::vector<Instance> m_instances;
std::string m_instanceID;
//std::string m_params;
std::string m_clientID;
char m_delimiter;
};