initial load of upstream version 1.06.32
[xmlrpc-c] / examples / cpp / xmlrpc_inetd_server.cpp
1 /* A simple standalone XML-RPC server based on Abyss that contains a
2    simple one-thread request processing loop.  
3
4    xmlrpc_sample_add_server.cpp is a server that does the same thing, but
5    does it by running a full Abyss daemon in the background, so it has
6    less control over how the requests are served.
7 */
8
9 #ifndef WIN32
10 #include <unistd.h>
11 #endif
12 #include <cassert>
13
14 #include <xmlrpc-c/base.hpp>
15 #include <xmlrpc-c/registry.hpp>
16 #include <xmlrpc-c/server_abyss.hpp>
17
18 using namespace std;
19
20 class sampleAddMethod : public xmlrpc_c::method {
21 public:
22     sampleAddMethod() {
23         // signature and help strings are documentation -- the client
24         // can query this information with a system.methodSignature and
25         // system.methodHelp RPC.
26         this->_signature = "ii";  // method's arguments are two integers
27         this->_help = "This method adds two integers together";
28     }
29     void
30     execute(xmlrpc_c::paramList const& paramList,
31             xmlrpc_c::value *   const  retvalP) {
32         
33         int const addend(paramList.getInt(0));
34         int const adder(paramList.getInt(1));
35         
36         paramList.verifyEnd(2);
37         
38         *retvalP = xmlrpc_c::value_int(addend + adder);
39     }
40 };
41
42
43
44 int 
45 main(int           const, 
46      const char ** const) {
47
48     xmlrpc_c::registry myRegistry;
49
50     xmlrpc_c::methodPtr const sampleAddMethodP(new sampleAddMethod);
51
52     myRegistry.addMethod("sample.add", sampleAddMethodP);
53
54     xmlrpc_c::serverAbyss myAbyssServer(
55         myRegistry,
56         8080,              // TCP port on which to listen
57         "/tmp/xmlrpc_log"  // Log file
58         );
59
60     myAbyssServer.runConn(STDIN_FILENO);
61         /* This reads the HTTP POST request from Standard Input and
62            executes the indicated RPC.
63         */
64     return 0;
65 }