BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
HelloServer.cpp
Go to the documentation of this file.
1// HelloServer.cpp : Simple XMLRPC server example. Usage: HelloServer serverPort
2//
3#include "XmlRpc.h"
4
5#include <iostream>
6#include <stdlib.h>
7
8using namespace XmlRpc;
9
10// The server
12
13// No arguments, result is "Hello".
14class Hello : public XmlRpcServerMethod {
15public:
17
18 void execute( XmlRpcValue& params, XmlRpcValue& result ) { result = "Hello"; }
19
20 std::string help() { return std::string( "Say hello" ); }
21
22} hello( &s ); // This constructor registers the method with the server
23
24// One argument is passed, result is "Hello, " + arg.
26public:
27 HelloName( XmlRpcServer* s ) : XmlRpcServerMethod( "HelloName", s ) {}
29 void execute( XmlRpcValue& params, XmlRpcValue& result ) {
30 std::string resultString = "Hello, ";
31 resultString += std::string( params[0] );
32 result = resultString;
33 }
34} helloName( &s );
35
36// A variable number of arguments are passed, all doubles, result is their sum.
37class Sum : public XmlRpcServerMethod {
38public:
40
41 void execute( XmlRpcValue& params, XmlRpcValue& result ) {
42 int nArgs = params.size();
43 double sum = 0.0;
44 for ( int i = 0; i < nArgs; ++i ) sum += double( params[i] );
45 result = sum;
46 }
47} sum( &s );
48
49int main( int argc, char* argv[] ) {
50 if ( argc != 2 )
51 {
52 std::cerr << "Usage: HelloServer serverPort\n";
53 return -1;
54 }
55 int port = atoi( argv[1] );
56
58
59 // Create the server socket on the specified port
60 s.bindAndListen( port );
61
62 // Enable introspection
63 s.enableIntrospection( true );
64
65 // Wait for requests indefinitely
66 s.work( -1.0 );
67
68 return 0;
69}
XmlRpcServer s
HelloName(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.
Hello(XmlRpcServer *s)
std::string help()
Sum(XmlRpcServer *s)
void execute(XmlRpcValue &params, XmlRpcValue &result)
Execute the method. Subclasses must provide a definition for this method.
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