BOSS 7.0.8
BESIII Offline Software System
Loading...
Searching...
No Matches
HelloClient.cpp File Reference
#include "XmlRpc.h"
#include <iostream>

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 8 of file HelloClient.cpp.

9{
10 if (argc != 3) {
11 std::cerr << "Usage: HelloClient serverHost serverPort\n";
12 return -1;
13 }
14 int port = atoi(argv[2]);
15 //XmlRpc::setVerbosity(5);
16
17 // Use introspection API to look up the supported methods
18 XmlRpcClient c(argv[1], port);
19 XmlRpcValue noArgs, result;
20 if (c.execute("system.listMethods", noArgs, result))
21 std::cout << "\nMethods:\n " << result << "\n\n";
22 else
23 std::cout << "Error calling 'listMethods'\n\n";
24
25 // Use introspection API to get the help string for the Hello method
26 XmlRpcValue oneArg;
27 oneArg[0] = "Hello";
28 if (c.execute("system.methodHelp", oneArg, result))
29 std::cout << "Help for 'Hello' method: " << result << "\n\n";
30 else
31 std::cout << "Error calling 'methodHelp'\n\n";
32
33 // Call the Hello method
34 if (c.execute("Hello", noArgs, result))
35 std::cout << result << "\n\n";
36 else
37 std::cout << "Error calling 'Hello'\n\n";
38
39 // Call the HelloName method
40 oneArg[0] = "Chris";
41 if (c.execute("HelloName", oneArg, result))
42 std::cout << result << "\n\n";
43 else
44 std::cout << "Error calling 'HelloName'\n\n";
45
46 // Add up an array of numbers
47 XmlRpcValue numbers;
48 numbers[0] = 33.33;
49 numbers[1] = 112.57;
50 numbers[2] = 76.1;
51 std::cout << "numbers.size() is " << numbers.size() << std::endl;
52 if (c.execute("Sum", numbers, result))
53 std::cout << "Sum = " << double(result) << "\n\n";
54 else
55 std::cout << "Error calling 'Sum'\n\n";
56
57 // Test the "no such method" fault
58 if (c.execute("NoSuchMethod", numbers, result))
59 std::cout << "NoSuchMethod call: fault: " << c.isFault() << ", result = " << result << std::endl;
60 else
61 std::cout << "Error calling 'Sum'\n";
62
63 // Test the multicall method. It accepts one arg, an array of structs
64 XmlRpcValue multicall;
65 multicall[0][0]["methodName"] = "Sum";
66 multicall[0][0]["params"][0] = 5.0;
67 multicall[0][0]["params"][1] = 9.0;
68
69 multicall[0][1]["methodName"] = "NoSuchMethod";
70 multicall[0][1]["params"][0] = "";
71
72 multicall[0][2]["methodName"] = "Sum";
73 // Missing params
74
75 multicall[0][3]["methodName"] = "Sum";
76 multicall[0][3]["params"][0] = 10.5;
77 multicall[0][3]["params"][1] = 12.5;
78
79 if (c.execute("system.multicall", multicall, result))
80 std::cout << "\nmulticall result = " << result << std::endl;
81 else
82 std::cout << "\nError calling 'system.multicall'\n";
83
84 return 0;
85}
A class to send XML RPC requests to a server and return the results.
Definition: XmlRpcClient.h:25
RPC method arguments and results are represented by Values.
Definition: XmlRpcValue.h:22
int size() const
Return the size for string, base64, array, and struct values.