BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
Validator.cpp
Go to the documentation of this file.
1// Validator.cpp : XMLRPC server based on the compliancy test at validator.xmlrpc.com.
2//
3#include "XmlRpc.h"
4using namespace XmlRpc;
5
6#include <iostream>
7
9
10// One argument is passed, an array of structs, each with a member named curly with
11// an integer value. Return the sum of those values.
12
14public:
16 : XmlRpcServerMethod( "validator1.arrayOfStructsTest", s ) {}
17
18 void execute( XmlRpcValue& params, XmlRpcValue& result ) {
19 std::cerr << "ArrayOfStructsTest\n";
20 XmlRpcValue& arg1 = params[0];
21 int n = arg1.size(), sum = 0;
22 for ( int i = 0; i < n; ++i ) sum += int( arg1[i]["curly"] );
23
24 result = sum;
25 }
26} arrayOfStructsTest( &s );
27
28// This handler takes a single parameter, a string, that contains any number of predefined
29// entities, namely <, >, &, ' and ".
30// The handler must return a struct that contains five fields, all numbers:
31// ctLeftAngleBrackets, ctRightAngleBrackets, ctAmpersands, ctApostrophes, ctQuotes. To
32// validate, the numbers must be correct.
33
35public:
37 : XmlRpcServerMethod( "validator1.countTheEntities", s ) {}
38
39 void execute( XmlRpcValue& params, XmlRpcValue& result ) {
40 std::cerr << "CountTheEntities\n";
41 std::string& arg = params[0];
42 int ctLeftAngleBrackets = 0;
43 int ctRightAngleBrackets = 0;
44 int ctAmpersands = 0;
45 int ctApostrophes = 0;
46 int ctQuotes = 0;
47
48 int n = int( arg.length() );
49 for ( int i = 0; i < n; ++i ) switch ( arg[i] )
50 {
51 case '<': ++ctLeftAngleBrackets; break;
52 case '>': ++ctRightAngleBrackets; break;
53 case '&': ++ctAmpersands; break;
54 case '\'': ++ctApostrophes; break;
55 case '\"': ++ctQuotes; break;
56 }
57
58 result["ctLeftAngleBrackets"] = ctLeftAngleBrackets;
59 result["ctRightAngleBrackets"] = ctRightAngleBrackets;
60 result["ctAmpersands"] = ctAmpersands;
61 result["ctApostrophes"] = ctApostrophes;
62 result["ctQuotes"] = ctQuotes;
63 }
64} countTheEntities( &s );
65
66// This handler takes a single parameter, a struct, containing at least three elements
67// named moe, larry and curly, all <i4>s. Your handler must add the three numbers and
68// return the result.
69
71public:
72 EasyStructTest( XmlRpcServer* s ) : XmlRpcServerMethod( "validator1.easyStructTest", s ) {}
73
74 void execute( XmlRpcValue& params, XmlRpcValue& result ) {
75 std::cerr << "EasyStructTest\n";
76 XmlRpcValue& arg1 = params[0];
77 int sum = int( arg1["moe"] ) + int( arg1["larry"] ) + int( arg1["curly"] );
78 result = sum;
79 }
80} easyStructTest( &s );
81
82// This handler takes a single parameter, a struct. Your handler must return the struct.
83
85public:
86 EchoStructTest( XmlRpcServer* s ) : XmlRpcServerMethod( "validator1.echoStructTest", s ) {}
87
88 void execute( XmlRpcValue& params, XmlRpcValue& result ) {
89 std::cerr << "EchoStructTest\n";
90 result = params[0];
91 }
92} echoStructTest( &s );
93
94// This handler takes six parameters, and returns an array containing all the parameters.
95
97public:
98 ManyTypesTest( XmlRpcServer* s ) : XmlRpcServerMethod( "validator1.manyTypesTest", s ) {}
99
100 void execute( XmlRpcValue& params, XmlRpcValue& result ) {
101 std::cerr << "ManyTypesTest\n";
102 result = params;
103 }
104} manyTypesTest( &s );
105
106// This handler takes a single parameter, which is an array containing between 100 and
107// 200 elements. Each of the items is a string, your handler must return a string
108// containing the concatenated text of the first and last elements.
109
111public:
113 : XmlRpcServerMethod( "validator1.moderateSizeArrayCheck", s ) {}
114
115 void execute( XmlRpcValue& params, XmlRpcValue& result ) {
116 std::cerr << "ModerateSizeArrayCheck\n";
117 std::string s = params[0][0];
118 s += params[0][params[0].size() - 1];
119 result = s;
120 }
121} moderateSizeArrayCheck( &s );
122
123// This handler takes a single parameter, a struct, that models a daily calendar.
124// At the top level, there is one struct for each year. Each year is broken down
125// into months, and months into days. Most of the days are empty in the struct
126// you receive, but the entry for April 1, 2000 contains a least three elements
127// named moe, larry and curly, all <i4>s. Your handler must add the three numbers
128// and return the result.
129
131public:
133 : XmlRpcServerMethod( "validator1.nestedStructTest", s ) {}
134
135 void execute( XmlRpcValue& params, XmlRpcValue& result ) {
136 std::cerr << "NestedStructTest\n";
137 XmlRpcValue& dayStruct = params[0]["2000"]["04"]["01"];
138 int sum = int( dayStruct["moe"] ) + int( dayStruct["larry"] ) + int( dayStruct["curly"] );
139 result = sum;
140 }
141} nestedStructTest( &s );
142
143// This handler takes one parameter, and returns a struct containing three elements,
144// times10, times100 and times1000, the result of multiplying the number by 10, 100 and 1000.
145
147public:
149 : XmlRpcServerMethod( "validator1.simpleStructReturnTest", s ) {}
150
151 void execute( XmlRpcValue& params, XmlRpcValue& result ) {
152 std::cerr << "SimpleStructReturnTest\n";
153 int n = params[0];
154 result["times10"] = n * 10;
155 result["times100"] = n * 100;
156 result["times1000"] = n * 1000;
157 }
158} simpleStructReturnTest( &s );
159
160int main( int argc, char* argv[] ) {
161 if ( argc != 2 )
162 {
163 std::cerr << "Usage: Validator port\n";
164 return -1;
165 }
166 int port = atoi( argv[1] );
167
169
170 // Create the server socket on the specified port
171 s.bindAndListen( port );
172
173 // Wait for requests indefinitely
174 s.work( -1.0 );
175
176 return 0;
177}
const Int_t n
double arg(const EvtComplex &c)
XmlRpcServer s
XmlRpcServer s
Definition Validator.cpp:8
ArrayOfStructsTest(XmlRpcServer *s)
Definition Validator.cpp:15
void execute(XmlRpcValue &params, XmlRpcValue &result)
Execute the method. Subclasses must provide a definition for this method.
Definition Validator.cpp:18
void execute(XmlRpcValue &params, XmlRpcValue &result)
Execute the method. Subclasses must provide a definition for this method.
Definition Validator.cpp:39
CountTheEntities(XmlRpcServer *s)
Definition Validator.cpp:36
EasyStructTest(XmlRpcServer *s)
Definition Validator.cpp:72
void execute(XmlRpcValue &params, XmlRpcValue &result)
Execute the method. Subclasses must provide a definition for this method.
Definition Validator.cpp:74
EchoStructTest(XmlRpcServer *s)
Definition Validator.cpp:86
void execute(XmlRpcValue &params, XmlRpcValue &result)
Execute the method. Subclasses must provide a definition for this method.
Definition Validator.cpp:88
ManyTypesTest(XmlRpcServer *s)
Definition Validator.cpp:98
void execute(XmlRpcValue &params, XmlRpcValue &result)
Execute the method. Subclasses must provide a definition for this method.
ModerateSizeArrayCheck(XmlRpcServer *s)
void execute(XmlRpcValue &params, XmlRpcValue &result)
Execute the method. Subclasses must provide a definition for this method.
void execute(XmlRpcValue &params, XmlRpcValue &result)
Execute the method. Subclasses must provide a definition for this method.
NestedStructTest(XmlRpcServer *s)
void execute(XmlRpcValue &params, XmlRpcValue &result)
Execute the method. Subclasses must provide a definition for this method.
SimpleStructReturnTest(XmlRpcServer *s)
XmlRpcServerMethod(std::string const &name, XmlRpcServer *server=0)
Constructor.
A class to handle XML RPC requests.
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.
void setVerbosity(int level)
Sets log message verbosity. This is short for XmlRpcLogHandler::setVerbosity(level).
int main()
Definition phokhara.cc:42