|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef WIN32 |
|
|
#include <unistd.h> |
|
|
#endif |
|
|
#include <cassert> |
|
|
#include <iostream> |
|
|
#include <signal.h> |
|
|
|
|
|
using namespace std; |
|
|
|
|
|
#include <xmlrpc-c/base.hpp> |
|
|
#include <xmlrpc-c/registry.hpp> |
|
|
#include <xmlrpc-c/server_pstream.hpp> |
|
|
|
|
|
|
|
|
class sampleAddMethod : public xmlrpc_c::method { |
|
|
public: |
|
|
sampleAddMethod() { |
|
|
|
|
|
|
|
|
|
|
|
this->_signature = "i:ii"; |
|
|
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) { |
|
|
|
|
|
#ifndef _WIN32 |
|
|
|
|
|
|
|
|
|
|
|
signal(SIGPIPE, SIG_IGN); |
|
|
#endif |
|
|
|
|
|
try { |
|
|
xmlrpc_c::registry myRegistry; |
|
|
|
|
|
xmlrpc_c::methodPtr const sampleAddMethodP(new sampleAddMethod); |
|
|
|
|
|
myRegistry.addMethod("sample.add", sampleAddMethodP); |
|
|
|
|
|
xmlrpc_c::serverPstream server( |
|
|
xmlrpc_c::serverPstream::constrOpt() |
|
|
.socketFd(STDIN_FILENO) |
|
|
.registryP(&myRegistry)); |
|
|
|
|
|
server.runSerial(); |
|
|
|
|
|
} catch (exception const& e) { |
|
|
cerr << "Something threw an error: " << e.what() << endl; |
|
|
} |
|
|
return 0; |
|
|
} |
|
|
|