-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.cpp
52 lines (41 loc) · 1.35 KB
/
client.cpp
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
#include <string>
#include <fstream>
#include <iostream>
#include "upTime.h"
int main(int argc, char *argv[]) {
try {
CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
ifstream iorFile("ior.dat");
if (!iorFile) {
std::cerr << "Failed to open ior.dat file" << std::endl;
throw 0;
}
std::string iorString;
iorFile >> iorString;
iorFile.close();
CORBA::Object_var obj = orb->string_to_object(iorString.c_str());
if (CORBA::is_nil(obj.in())) {
std::cerr << "Nil server reference" << std::endl;
throw 0;
}
upTime_var uptime = upTime::_narrow(obj.in());
if (CORBA::is_nil(uptime.in())) {
std::cerr << "Reference string does not refer to a CPULoad server" <<std:: endl;
throw 0;
}
CORBA::Float systemHasBeenUp;
CORBA::Float systemHasSpentIdle;
uptime->getUpTime(systemHasBeenUp, systemHasSpentIdle);
std::cout << "Time:\n"
<< " system has been up: " << systemHasBeenUp
<< " system has spent idle: " << systemHasSpentIdle<<std::endl;
}
catch (const CORBA::Exception &x) {
std::cerr << "Uncaught CORBA exception" << std::endl;
return 1;
}
catch (...) {
return 1;
}
return 0;
}