initial load of upstream version 1.06.32
[xmlrpc-c] / examples / cpp / xmlrpc_inetd_server.cpp
diff --git a/examples/cpp/xmlrpc_inetd_server.cpp b/examples/cpp/xmlrpc_inetd_server.cpp
new file mode 100644 (file)
index 0000000..fd97424
--- /dev/null
@@ -0,0 +1,65 @@
+/* A simple standalone XML-RPC server based on Abyss that contains a
+   simple one-thread request processing loop.  
+
+   xmlrpc_sample_add_server.cpp is a server that does the same thing, but
+   does it by running a full Abyss daemon in the background, so it has
+   less control over how the requests are served.
+*/
+
+#ifndef WIN32
+#include <unistd.h>
+#endif
+#include <cassert>
+
+#include <xmlrpc-c/base.hpp>
+#include <xmlrpc-c/registry.hpp>
+#include <xmlrpc-c/server_abyss.hpp>
+
+using namespace std;
+
+class sampleAddMethod : public xmlrpc_c::method {
+public:
+    sampleAddMethod() {
+        // signature and help strings are documentation -- the client
+        // can query this information with a system.methodSignature and
+        // system.methodHelp RPC.
+        this->_signature = "ii";  // method's arguments are two integers
+        this->_help = "This method adds two integers together";
+    }
+    void
+    execute(xmlrpc_c::paramList const& paramList,
+            xmlrpc_c::value *   const  retvalP) {
+        
+        int const addend(paramList.getInt(0));
+        int const adder(paramList.getInt(1));
+        
+        paramList.verifyEnd(2);
+        
+        *retvalP = xmlrpc_c::value_int(addend + adder);
+    }
+};
+
+
+
+int 
+main(int           const, 
+     const char ** const) {
+
+    xmlrpc_c::registry myRegistry;
+
+    xmlrpc_c::methodPtr const sampleAddMethodP(new sampleAddMethod);
+
+    myRegistry.addMethod("sample.add", sampleAddMethodP);
+
+    xmlrpc_c::serverAbyss myAbyssServer(
+        myRegistry,
+        8080,              // TCP port on which to listen
+        "/tmp/xmlrpc_log"  // Log file
+        );
+
+    myAbyssServer.runConn(STDIN_FILENO);
+        /* This reads the HTTP POST request from Standard Input and
+           executes the indicated RPC.
+        */
+    return 0;
+}