BOSS 6.6.4.p03
BESIII Offline Software System
Loading...
Searching...
No Matches
FileClient.cpp File Reference
#include "XmlRpc.h"
#include <iostream>
#include <fstream>
#include <stdlib.h>

Go to the source code of this file.

Functions

std::string parseRequest (std::string const &xml, XmlRpcValue &params)
 
int main (int argc, char *argv[])
 

Function Documentation

◆ main()

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

Definition at line 16 of file FileClient.cpp.

17{
18 if (argc != 4) {
19 std::cerr << "Usage: FileClient serverHost serverPort requestXmlFile\n";
20 return -1;
21 }
22 int port = atoi(argv[2]);
23
25 XmlRpcClient c(argv[1], port);
26
27 //
28 std::ifstream infile(argv[3]);
29 if (infile.fail()) {
30 std::cerr << "Could not open file '" << argv[3] << "'.\n";
31 return -1;
32 }
33
34 // Suck in the file. This is a one-liner in good compilers (which vc++ 6 is not)...
35 infile.seekg(0L, std::ios::end);
36 long nb = infile.tellg();
37 infile.clear();
38 infile.seekg(0L);
39 char* b = new char[nb+1];
40 infile.read(b, nb);
41 b[nb] = 0;
42
43 std::cout << "Read file.\n";
44
45 // Find the methodName and parse the params
46 std::string s(b);
47 XmlRpcValue params;
48 std::string name = parseRequest(s, params);
49
50 if (name.empty()) {
51 std::cerr << "Could not parse file\n";
52 return -1;
53 }
54
55 for (;;) {
56 XmlRpcValue result;
57 std::cout << "Calling " << name << std::endl;
58 if (c.execute(name.c_str(), params, result))
59 std::cout << result << "\n\n";
60 else
61 std::cout << "Error calling '" << name << "'\n\n";
62 std::cout << "Again? [y]: ";
63 std::string ans;
64 std::cin >> ans;
65 if (ans != "" && ans != "y") break;
66 }
67
68 return 0;
69}
std::string parseRequest(std::string const &xml, XmlRpcValue &params)
Definition: FileClient.cpp:74
XmlRpcServer s
Definition: HelloServer.cpp:11
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
void setVerbosity(int level)
Sets log message verbosity. This is short for XmlRpcLogHandler::setVerbosity(level)
Definition: XmlRpcUtil.cpp:67

◆ parseRequest()

std::string parseRequest ( std::string const &  xml,
XmlRpcValue params 
)

Definition at line 74 of file FileClient.cpp.

75{
76 const char METHODNAME_TAG[] = "<methodName>";
77 const char PARAMS_TAG[] = "<params>";
78 const char PARAMS_ETAG[] = "</params>";
79 const char PARAM_TAG[] = "<param>";
80 const char PARAM_ETAG[] = "</param>";
81
82 int offset = 0; // Number of chars parsed from the request
83
84 std::string methodName = XmlRpcUtil::parseTag(METHODNAME_TAG, xml, &offset);
85 XmlRpcUtil::log(3, "XmlRpcServerConnection::parseRequest: parsed methodName %s.", methodName.c_str());
86
87 if (! methodName.empty() && XmlRpcUtil::findTag(PARAMS_TAG, xml, &offset))
88 {
89 int nArgs = 0;
90 while (XmlRpcUtil::nextTagIs(PARAM_TAG, xml, &offset)) {
91 std::cout << "Parsing arg " << nArgs+1 << std::endl;
92 XmlRpcValue arg(xml, &offset);
93 if ( ! arg.valid()) {
94 std::cerr << "Invalid argument\n";
95 return std::string();
96 }
97 std::cout << "Adding arg " << nArgs+1 << " to params array." << std::endl;
98 params[nArgs++] = arg;
99 (void) XmlRpcUtil::nextTagIs(PARAM_ETAG, xml, &offset);
100 }
101
102 XmlRpcUtil::log(3, "XmlRpcServerConnection::parseRequest: parsed %d params.", nArgs);
103
104 (void) XmlRpcUtil::nextTagIs(PARAMS_ETAG, xml, &offset);
105 }
106
107 return methodName;
108}
double arg(const EvtComplex &c)
Definition: EvtComplex.hh:227
static bool nextTagIs(const char *tag, std::string const &xml, int *offset)
Definition: XmlRpcUtil.cpp:131
static std::string parseTag(const char *tag, std::string const &xml, int *offset)
Returns contents between <tag> and </tag>, updates offset to char after </tag>
Definition: XmlRpcUtil.cpp:98
static bool findTag(const char *tag, std::string const &xml, int *offset)
Returns true if the tag is found and updates offset to the char after the tag.
Definition: XmlRpcUtil.cpp:116
static void log(int level, const char *fmt,...)
Dump messages somewhere.
Definition: XmlRpcUtil.cpp:71

Referenced by main().