BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
FileClient.cpp File Reference
#include "XmlRpc.h"
#include <fstream>
#include <iostream>
#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 15 of file FileClient.cpp.

15 {
16 if ( argc != 4 )
17 {
18 std::cerr << "Usage: FileClient serverHost serverPort requestXmlFile\n";
19 return -1;
20 }
21 int port = atoi( argv[2] );
22
24 XmlRpcClient c( argv[1], port );
25
26 //
27 std::ifstream infile( argv[3] );
28 if ( infile.fail() )
29 {
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 {
52 std::cerr << "Could not parse file\n";
53 return -1;
54 }
55
56 for ( ;; )
57 {
58 XmlRpcValue result;
59 std::cout << "Calling " << name << std::endl;
60 if ( c.execute( name.c_str(), params, result ) ) std::cout << result << "\n\n";
61 else 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)
XmlRpcServer s
A class to send XML RPC requests to a server and return the results.
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).

◆ parseRequest()

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

Definition at line 72 of file FileClient.cpp.

72 {
73 const char METHODNAME_TAG[] = "<methodName>";
74 const char PARAMS_TAG[] = "<params>";
75 const char PARAMS_ETAG[] = "</params>";
76 const char PARAM_TAG[] = "<param>";
77 const char PARAM_ETAG[] = "</param>";
78
79 int offset = 0; // Number of chars parsed from the request
80
81 std::string methodName = XmlRpcUtil::parseTag( METHODNAME_TAG, xml, &offset );
82 XmlRpcUtil::log( 3, "XmlRpcServerConnection::parseRequest: parsed methodName %s.",
83 methodName.c_str() );
84
85 if ( !methodName.empty() && XmlRpcUtil::findTag( PARAMS_TAG, xml, &offset ) )
86 {
87 int nArgs = 0;
88 while ( XmlRpcUtil::nextTagIs( PARAM_TAG, xml, &offset ) )
89 {
90 std::cout << "Parsing arg " << nArgs + 1 << std::endl;
91 XmlRpcValue arg( xml, &offset );
92 if ( !arg.valid() )
93 {
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)
static bool nextTagIs(const char *tag, std::string const &xml, int *offset)
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>.
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.
static void log(int level, const char *fmt,...)
Dump messages somewhere.

Referenced by main().