
#include "XmlRpc.h"

#include <iostream>
#include <stdlib.h>

using namespace XmlRpc;

// Servidor XML-RPC definit a 'Comunicacio_Terra'
extern XmlRpcServer s;

class Comunicacio_Activa : public XmlRpcServerMethod
{
public:
   Comunicacio_Activa(XmlRpcServer* s) : XmlRpcServerMethod("Comunicacio_Activa", s) {}

   void execute(XmlRpcValue& params, XmlRpcValue& result)
   {
      result = "Canal de comunicacio actiu";
   }

   std::string help() { return std::string("Verifica el comunicacio entre la Terra i Mart"); }

} comunicacio_Activa(&s);    // This constructor registers the method with the server


// One argument is passed, result is "Hello, " + arg.
class HelloName : public XmlRpcServerMethod
{
public:
  HelloName(XmlRpcServer* s) : XmlRpcServerMethod("HelloName", s) {}

  void execute(XmlRpcValue& params, XmlRpcValue& result)
  {
    std::string resultString = "Hello, ";
    resultString += std::string(params[0]);
    result = resultString;
  }
} helloName(&s);


// A variable number of arguments are passed, all doubles, result is their sum.
class Sum : public XmlRpcServerMethod
{
public:
  Sum(XmlRpcServer* s) : XmlRpcServerMethod("Sum", s) {}

  void execute(XmlRpcValue& params, XmlRpcValue& result)
  {
    int nArgs = params.size();
    double sum = 0.0;
    for (int i=0; i<nArgs; ++i)
      sum += double(params[i]);
    result = sum;
  }
} sum(&s);


