-
Notifications
You must be signed in to change notification settings - Fork 6
/
SampleMain.cpp
101 lines (82 loc) · 2.41 KB
/
SampleMain.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
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include <iostream>
#include "TimXmlRpc.h"
// main.cpp: includes both a little unit test and a sample client program.
static void BasicTest()
{
// Replace this URL with your own URL:
XmlRpcClient Connection("http://web.edval.com.au/rpc");
Connection.setIgnoreCertificateAuthority();
//Connection.setBasicAuth_Callback(PopUpAPrettyDialog);
Connection.setBasicAuth_UsernameAndPassword("foo", "goo");
// Call: arumate.getKilowatts(string, integer) :
XmlRpcValue args, result;
args[0] = "test";
args[1] = 1;
//
double g = 3.14159;
XmlRpcValue binary(&g, sizeof(g));
args[2] = binary;
XmlRpcValue::BinaryData bdata = binary;
// Replace this function name with your own:
if (! Connection.execute("getKilowatts", args, result)) {
std::cout << Connection.getError();
}
else if (result.getType() == XmlRpcValue::TypeString)
std::cout << result.GetStdString();
else std::cout << "Success\n";
}
static void AdvancedTest()
{
XmlRpcValue args, result;
// Passing datums:
args[0] = "a string";
args[1] = 1;
args[2] = true;
args[3] = 3.14159;
struct tm timeNow;
args[4] = XmlRpcValue(&timeNow);
// Passing an array:
XmlRpcValue array;
array[0] = 4;
array[1] = 5;
array[2] = 6;
args[5] = array;
// Note: if there's a chance that the array contains zero elements,
// you'll need to call:
// array.initAsArray();
// ...because otherwise the type will never get set to "TypeArray" and
// the value will be a "TypeInvalid".
// Passing a struct:
XmlRpcValue record;
record["SOURCE"] = "a";
record["DESTINATION"] = "b";
record["LENGTH"] = 5;
args[6] = record;
// We don't support zero-size struct's...Surely no-one needs these?
// Make the call:
XmlRpcClient Connection("https://61.95.191.232:9600/arumate/rpc/xmlRpcServer.php");
Connection.setIgnoreCertificateAuthority();
if (! Connection.execute("arumate.getMegawatts", args, result)) {
std::cout << Connection.getError();
return;
}
// Pull the data out:
if (result.getType() != XmlRpcValue::TypeStruct) {
std::cout << "I was expecting a struct.";
return;
}
int i = result["n"];
std::string s = result["name"];
array = result["A"];
for (int i=0; i < array.size(); i++)
std::cout << (int)array[i] << "\n";
record = result["subStruct"];
std::cout << (std::string)record["foo"] << "\n";
}
//---------------------------- main(): -------------------------
int main(int argc, char* argv[])
{
BasicTest();
AdvancedTest();
return 0;
}