BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
HelloClient.cpp
Go to the documentation of this file.
1// HelloClient.cpp : A simple xmlrpc client. Usage: HelloClient serverHost serverPort
2// Link against xmlrpc lib and whatever socket libs your system needs (ws2_32.lib
3// on windows)
4#include "XmlRpc.h"
5#include <iostream>
6using namespace XmlRpc;
7
8int main( int argc, char* argv[] ) {
9 if ( argc != 3 )
10 {
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 std::cout << "Error calling 'listMethods'\n\n";
23
24 // Use introspection API to get the help string for the Hello method
25 XmlRpcValue oneArg;
26 oneArg[0] = "Hello";
27 if ( c.execute( "system.methodHelp", oneArg, result ) )
28 std::cout << "Help for 'Hello' method: " << result << "\n\n";
29 else std::cout << "Error calling 'methodHelp'\n\n";
30
31 // Call the Hello method
32 if ( c.execute( "Hello", noArgs, result ) ) std::cout << result << "\n\n";
33 else std::cout << "Error calling 'Hello'\n\n";
34
35 // Call the HelloName method
36 oneArg[0] = "Chris";
37 if ( c.execute( "HelloName", oneArg, result ) ) std::cout << result << "\n\n";
38 else std::cout << "Error calling 'HelloName'\n\n";
39
40 // Add up an array of numbers
41 XmlRpcValue numbers;
42 numbers[0] = 33.33;
43 numbers[1] = 112.57;
44 numbers[2] = 76.1;
45 std::cout << "numbers.size() is " << numbers.size() << std::endl;
46 if ( c.execute( "Sum", numbers, result ) )
47 std::cout << "Sum = " << double( result ) << "\n\n";
48 else std::cout << "Error calling 'Sum'\n\n";
49
50 // Test the "no such method" fault
51 if ( c.execute( "NoSuchMethod", numbers, result ) )
52 std::cout << "NoSuchMethod call: fault: " << c.isFault() << ", result = " << result
53 << std::endl;
54 else std::cout << "Error calling 'Sum'\n";
55
56 // Test the multicall method. It accepts one arg, an array of structs
57 XmlRpcValue multicall;
58 multicall[0][0]["methodName"] = "Sum";
59 multicall[0][0]["params"][0] = 5.0;
60 multicall[0][0]["params"][1] = 9.0;
61
62 multicall[0][1]["methodName"] = "NoSuchMethod";
63 multicall[0][1]["params"][0] = "";
64
65 multicall[0][2]["methodName"] = "Sum";
66 // Missing params
67
68 multicall[0][3]["methodName"] = "Sum";
69 multicall[0][3]["params"][0] = 10.5;
70 multicall[0][3]["params"][1] = 12.5;
71
72 if ( c.execute( "system.multicall", multicall, result ) )
73 std::cout << "\nmulticall result = " << result << std::endl;
74 else std::cout << "\nError calling 'system.multicall'\n";
75
76 return 0;
77}
A class to send XML RPC requests to a server and return the results.
bool execute(const char *method, XmlRpcValue const &params, XmlRpcValue &result)
bool isFault() const
Returns true if the result of the last execute() was a fault response.
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.
int main()
Definition phokhara.cc:42