X-Git-Url: http://git.maemo.org/git/?p=xmlrpc-c;a=blobdiff_plain;f=examples%2Fcpp%2Fxmlrpc_sample_add_server.cpp;fp=examples%2Fcpp%2Fxmlrpc_sample_add_server.cpp;h=9658f6d7cc100a5923120d04b94223466d1afdb1;hp=0000000000000000000000000000000000000000;hb=ce67d0cdeaa37c3e856e23ae4010480887165630;hpb=e355d4e7962400470f467b88f5568de9c8324475 diff --git a/examples/cpp/xmlrpc_sample_add_server.cpp b/examples/cpp/xmlrpc_sample_add_server.cpp new file mode 100644 index 0000000..9658f6d --- /dev/null +++ b/examples/cpp/xmlrpc_sample_add_server.cpp @@ -0,0 +1,60 @@ +#include +#include +#include + +#include +#include +#include + +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 result and two arguments 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::serverAbyss myAbyssServer( + myRegistry, + 8080, // TCP port on which to listen + "/tmp/xmlrpc_log" // Log file + ); + + myAbyssServer.run(); + // xmlrpc_c::serverAbyss.run() never returns + assert(false); + } catch (exception const& e) { + cerr << "Something failed. " << e.what() << endl; + } + return 0; +}