1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- /* A CGI script that effects a simple XML-RPC server, written in C++.
- See the identically named C program source code for hints on running
- this example.
- */
- #include <cassert>
- #include <iostream>
- #include <xmlrpc-c/base.hpp>
- #include <xmlrpc-c/registry.hpp>
- #include <xmlrpc-c/server_cgi.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 = "i:ii"; // method's arguments, result are 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) {
- try {
- xmlrpc_c::registry myRegistry;
- xmlrpc_c::methodPtr const sampleAddMethodP(new sampleAddMethod);
- myRegistry.addMethod("sample.add", sampleAddMethodP);
- xmlrpc_c::serverCgi myServer(
- xmlrpc_c::serverCgi::constrOpt()
- .registryP(&myRegistry));
- myServer.processCall();
- } catch (exception const& e) {
- cerr << "Something failed. " << e.what() << endl;
- }
- return 0;
- }
|