initial load of upstream version 1.06.32
[xmlrpc-c] / examples / cpp / xmlrpc_sample_add_server.cpp
1 #include <cassert>
2 #include <stdexcept>
3 #include <iostream>
4
5 #include <xmlrpc-c/base.hpp>
6 #include <xmlrpc-c/registry.hpp>
7 #include <xmlrpc-c/server_abyss.hpp>
8
9 using namespace std;
10
11 class sampleAddMethod : public xmlrpc_c::method {
12 public:
13     sampleAddMethod() {
14         // signature and help strings are documentation -- the client
15         // can query this information with a system.methodSignature and
16         // system.methodHelp RPC.
17         this->_signature = "i:ii";
18             // method's result and two arguments are integers
19         this->_help = "This method adds two integers together";
20     }
21     void
22     execute(xmlrpc_c::paramList const& paramList,
23             xmlrpc_c::value *   const  retvalP) {
24         
25         int const addend(paramList.getInt(0));
26         int const adder(paramList.getInt(1));
27         
28         paramList.verifyEnd(2);
29         
30         *retvalP = xmlrpc_c::value_int(addend + adder);
31     }
32 };
33
34
35
36 int 
37 main(int           const, 
38      const char ** const) {
39
40     try {
41         xmlrpc_c::registry myRegistry;
42
43         xmlrpc_c::methodPtr const sampleAddMethodP(new sampleAddMethod);
44
45         myRegistry.addMethod("sample.add", sampleAddMethodP);
46         
47         xmlrpc_c::serverAbyss myAbyssServer(
48             myRegistry,
49             8080,              // TCP port on which to listen
50             "/tmp/xmlrpc_log"  // Log file
51             );
52         
53         myAbyssServer.run();
54         // xmlrpc_c::serverAbyss.run() never returns
55         assert(false);
56     } catch (exception const& e) {
57         cerr << "Something failed.  " << e.what() << endl;
58     }
59     return 0;
60 }