port_zero_server.cpp
Go to the documentation of this file.
1 // HelloServer.cpp : Simple XMLRPC server example. Usage: HelloServer serverPort
2 //
3 #include "xmlrpcpp/XmlRpc.h"
4 
5 #include <iostream>
6 #include <stdlib.h>
7 
8 using namespace XmlRpc;
9 
10 // The server
12 
13 // No arguments, result is "Hello".
14 class Hello : public XmlRpcServerMethod
15 {
16 public:
18 
19  void execute(XmlRpcValue& params, XmlRpcValue& result)
20  {
21  result = "Hello";
22  }
23 
24  std::string help() { return std::string("Say hello"); }
25 
26 } hello(&s); // This constructor registers the method with the server
27 
28 
29 // One argument is passed, result is "Hello, " + arg.
30 class HelloName : public XmlRpcServerMethod
31 {
32 public:
34 
35  void execute(XmlRpcValue& params, XmlRpcValue& result)
36  {
37  std::string resultString = "Hello, ";
38  resultString += std::string(params[0]);
39  result = resultString;
40  }
41 } helloName(&s);
42 
43 
44 // A variable number of arguments are passed, all doubles, result is their sum.
45 class Sum : public XmlRpcServerMethod
46 {
47 public:
49 
50  void execute(XmlRpcValue& params, XmlRpcValue& result)
51  {
52  int nArgs = params.size();
53  double sum = 0.0;
54  for (int i=0; i<nArgs; ++i)
55  sum += double(params[i]);
56  result = sum;
57  }
58 } sum(&s);
59 
60 
61 int main(int argc, char* argv[])
62 {
64 
65  // Create the server socket on the specified port
66  s.bindAndListen(0);
67 
68  // Enable introspection
69  s.enableIntrospection(true);
70 
71  // Wait for requests indefinitely
72  s.work(-1.0);
73 
74  return 0;
75 }
76 
XmlRpc::XmlRpcValue::size
int size() const
Return the size for string, base64, array, and struct values.
Definition: XmlRpcValue.cpp:211
XmlRpc::XmlRpcServer::enableIntrospection
void enableIntrospection(bool enabled=true)
Specify whether introspection is enabled or not. Default is not enabled.
Definition: XmlRpcServer.cpp:351
HelloName::execute
void execute(XmlRpcValue &params, XmlRpcValue &result)
Execute the method. Subclasses must provide a definition for this method.
Definition: port_zero_server.cpp:35
XmlRpc::setVerbosity
XMLRPCPP_DECL void setVerbosity(int level)
Sets log message verbosity. This is short for XmlRpcLogHandler::setVerbosity(level)
Definition: XmlRpcUtil.cpp:77
Sum::Sum
Sum(XmlRpcServer *s)
Definition: port_zero_server.cpp:48
XmlRpc::XmlRpcServer
A class to handle XML RPC requests.
Definition: XmlRpcServer.h:41
HelloName
Definition: HelloServer.cpp:30
Sum
Definition: HelloServer.cpp:45
XmlRpc
Definition: XmlRpcClient.h:20
Hello::Hello
Hello(XmlRpcServer *s)
Definition: port_zero_server.cpp:17
XmlRpc::XmlRpcServerMethod
Abstract class representing a single RPC method.
Definition: XmlRpcServerMethod.h:26
XmlRpc.h
main
int main(int argc, char *argv[])
Definition: port_zero_server.cpp:61
Hello::execute
void execute(XmlRpcValue &params, XmlRpcValue &result)
Definition: port_zero_server.cpp:19
XmlRpc::XmlRpcServer::bindAndListen
bool bindAndListen(int port, int backlog=5)
Definition: XmlRpcServer.cpp:107
Hello
Definition: HelloServer.cpp:14
Hello::help
std::string help()
Definition: port_zero_server.cpp:24
XmlRpc::XmlRpcServer::work
void work(double msTime)
Process client requests for the specified time.
Definition: XmlRpcServer.cpp:163
HelloName::HelloName
HelloName(XmlRpcServer *s)
Definition: port_zero_server.cpp:33
XmlRpc::XmlRpcValue
RPC method arguments and results are represented by Values.
Definition: XmlRpcValue.h:24
s
XmlRpcServer s
Definition: port_zero_server.cpp:11
Sum::execute
void execute(XmlRpcValue &params, XmlRpcValue &result)
Execute the method. Subclasses must provide a definition for this method.
Definition: port_zero_server.cpp:50


xmlrpcpp
Author(s): Chris Morley, Konstantin Pilipchuk, Morgan Quigley, Austin Hendrix, Dirk Thomas , Jacob Perron
autogenerated on Thu Nov 23 2023 04:01:41