-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServiceManagerUI.cpp
More file actions
82 lines (73 loc) · 1.86 KB
/
Copy pathServiceManagerUI.cpp
File metadata and controls
82 lines (73 loc) · 1.86 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
#include "ServiceManager/ServiceManagerUI.h"
namespace ServiceManagerSpace
{
// -------------------------------------------------------
// class ServiceManagerUI
// -------------------------------------------------------
ServiceManagerUI::ServiceManagerUI(ServiceManager &ls) : serviceManager(ls)
{
start();
}
ServiceManagerUI::~ServiceManagerUI()
{
}
// -------------------------------------------------------
// the UI
// -------------------------------------------------------
void ServiceManagerUI::printCommand()
{
cout << "ServiceManager commands: print-info (p), clear-services (c), quit (q), help (h)." << endl;
}
void ServiceManagerUI::run()
{
printCommand();
while(true)
{
string command;
try
{
istream &ret = getline(cin, command);
if(ret.eof() == true || ret.bad() == true || ret.good() == false)
{
throw string("End of file!");
break;
}
}
catch(...)
{
//cout << "ServiceManagerCommand: WARNING! getline returned End of file! Stopping command line!" << endl;
cout << "ServiceManagerCommand::run(): WARNING! ServiceManager user interface (UI) is off." << endl;
break;
}
if(strncmp(command.c_str(), "quit", 1) == 0)
{
cerr << "Do you really want to quit (y/n)? " ;
string confirm;
getline(cin, confirm);
if(strncmp(confirm.c_str(), "yes", 1) == 0)
{
cerr << "Quitting ServiceManager..." << endl;
serviceManager.Quit();
break;
}
else printCommand();
}
else if(strncmp(command.c_str(), "clear-services", 1) == 0)
{
serviceManager.ClearServices();
}
else if(strncmp(command.c_str(), "print-info", 1) == 0)
{
serviceManager.cmdPrintHostInformation(cerr);
}
else if(strncmp(command.c_str(), "help", 1) == 0)
{
printCommand();
}
else if(!command.empty())
{
cerr << "Command: " << command << " is not supported" << endl;
}
}
}
} // namespace ServiceManagerSpace