Exemplo n.º 1
0
void RemoteKinematics::GetHeadMethod::execute(xmlrpc_c::paramList const& paramList, xmlrpc_c::value* const resultP) {
    paramList.verifyEnd(1);
    bool top_camera = paramList.getBoolean(0);
    SensorData<double>::Ptr data;
    data = this->m_kinematics->getHeadPosition(top_camera);

    xmlrpc_env env;
    xmlrpc_env_init(&env);

    xmlrpc_value* elem;
    xmlrpc_value* values;
    xmlrpc_value* result;

    values = xmlrpc_array_new(&env);
    for (int i = 0; i < data->data.size(); ++i) {
        elem = xmlrpc_double_new(&env, data->data[i]);
        xmlrpc_array_append_item(&env, values, elem);
        xmlrpc_DECREF(elem);
    }

    elem = xmlrpc_double_new(&env, data->timestamp);
    // Create result struct
    result = xmlrpc_struct_new(&env);
    xmlrpc_struct_set_value(&env, result, "data", values);
    xmlrpc_struct_set_value(&env, result, "timestamp", elem);
    // Apply result
    resultP->instantiate(result);
    // Clean this shit!
    xmlrpc_DECREF(elem);
    xmlrpc_DECREF(values);
    xmlrpc_DECREF(result);
    xmlrpc_env_clean(&env);
}
Exemplo n.º 2
0
 void
 execute(xmlrpc_c::paramList const& paramList,
         value *             const  retvalP) {
     
     paramList.verifyEnd(1);
     
     *retvalP = paramList[0];
 }
Exemplo n.º 3
0
void RemoteKinematics::LookAtMethod::execute(xmlrpc_c::paramList const& paramList, xmlrpc_c::value* const resultP) {
    paramList.verifyEnd(4);
    double x = paramList.getDouble(0);
    double y = paramList.getDouble(1);
    double z = paramList.getDouble(2);
    bool top_camera = paramList.getBoolean(3);
    this->m_kinematics->lookAt(x, y, z, top_camera);
    *resultP = value_nil();
}
Exemplo n.º 4
0
    void
    execute(const xmlrpc_c::paramList & paramList, xmlrpc_c::value* retvalP) {
        // Get the requested mode
        bool const hvRequested(paramList.getBoolean(0));
        paramList.verifyEnd(1);

        TheTransmitControl->setHvRequested(hvRequested);
        *retvalP = xmlrpc_c::value_nil();
    }
Exemplo n.º 5
0
 void
 execute(xmlrpc_c::paramList const& paramList,
         value *             const  retvalP) {
     
     paramList.getNil(0);
     
     paramList.verifyEnd(1);
     
     *retvalP = value_i8(7ll);
 }
Exemplo n.º 6
0
    void
    execute(const xmlrpc_c::paramList & paramList, xmlrpc_c::value* retvalP) {
        // Get the requested mode
        int const state(paramList.getInt(0));
        paramList.verifyEnd(1);

        ILOG << "Received 'setApsValveControl(" << state << ")' command";
        TheApsControl->setValveControl(static_cast<ApsControl::ValveControlState>(state));
        *retvalP = xmlrpc_c::value_nil();
    }
Exemplo n.º 7
0
 void
 execute(xmlrpc_c::paramList const& paramList,
         value *             const  retvalP) {
     
     int const addend(paramList.getInt(0));
     int const adder(paramList.getInt(1));
     
     paramList.verifyEnd(2);
     
     *retvalP = value_int(addend + adder);
 }
Exemplo n.º 8
0
    void
    execute(const xmlrpc_c::paramList & paramList, xmlrpc_c::value* retvalP) {
        paramList.verifyEnd(1);
        // Get the requested mode
        const int iMode(paramList.getInt(0));
        HcrPmc730::HmcOperationMode hmcMode =
                static_cast<HcrPmc730::HmcOperationMode>(iMode);

        ILOG << "Received 'setRequestedHmcMode(" << iMode << ")' command";
        TheTransmitControl->setRequestedHmcMode(hmcMode);
        *retvalP = xmlrpc_c::value_nil();
    }
    void
    execute(xmlrpc_c::paramList        const& paramList,
            const xmlrpc_c::callInfo * const  callInfoPtr,
            xmlrpc_c::value *          const  retvalP) {

        const xmlrpc_c::callInfo_serverAbyss * const callInfoP(
            dynamic_cast<const xmlrpc_c::callInfo_serverAbyss *>(callInfoPtr));
        
        paramList.verifyEnd(0);

        // Because this gets called via a xmlrpc_c::serverAbyss:
        assert(callInfoP != NULL);

        *retvalP = xmlrpc_c::value_string(rpcIpAddrMsg(*callInfoP));
    }
Exemplo n.º 10
0
  void 
  CloseSession::
  execute(xmlrpc_c::paramList const& paramList,
	  xmlrpc_c::value *   const  retvalP)
  {
    typedef std::map<std::string, xmlrpc_c::value> params_t;
    paramList.verifyEnd(1); // ??? UG
    params_t const& params = paramList.getStruct(0);
    params_t::const_iterator si = params.find("session-id");
    if (si != params.end())
      {
	uint64_t session_id = xmlrpc_c::value_int(si->second);
	m_server.delete_session(session_id);
	*retvalP = xmlrpc_c::value_string("Session closed");
      }
  }
    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);

        // Sometimes, make it look hard (so client can see what it's like
        // to do an RPC that takes a while).
        if (adder == 1)
            SLEEP(2);
    }
Exemplo n.º 12
0
void RemoteAccelerometer::AccelerationMethod::execute(xmlrpc_c::paramList const &paramList,
                                                         xmlrpc_c::value *const resultP) {
    paramList.verifyEnd(0);
    SensorData<double>::Ptr data = m_accelerometer->getAcceleration();

    // TODO Check for memory leaks
    // Some optimisation by using C library of xmlrpc-c
    xmlrpc_env env;
    xmlrpc_env_init(&env);

    xmlrpc_value *elem;
    xmlrpc_value *values;
    xmlrpc_value *result;

    // Init result array
    values = xmlrpc_array_new(&env);
    for (int i = 0; i < data->data.size(); ++i) {
        elem = xmlrpc_double_new(&env, data->data[i]);
        xmlrpc_array_append_item(&env, values, elem);
        xmlrpc_DECREF(elem);
    }

    // XMLRPC-C timestamp
    elem = xmlrpc_double_new(&env, data->timestamp);

    // Create result struct
    result = xmlrpc_struct_new(&env);
    xmlrpc_struct_set_value(&env, result, "data", values);
    xmlrpc_struct_set_value(&env, result, "timestamp", elem);

    // Apply result
    resultP->instantiate(result);

    // Clean this shit!
    xmlrpc_DECREF(elem);
    xmlrpc_DECREF(values);
    xmlrpc_DECREF(result);
    xmlrpc_env_clean(&env);
}
Exemplo n.º 13
0
void RemoteKinematics::JointsLookAtMethodLookAtMethod::execute(xmlrpc_c::paramList const& paramList,
                                                               xmlrpc_c::value* const resultP) {
    paramList.verifyEnd(4);
    double x = paramList.getDouble(0);
    double y = paramList.getDouble(1);
    double z = paramList.getDouble(2);
    bool top_camera = paramList.getBoolean(3);
    ValuesVectorPtr data = this->m_kinematics->jointsLookAt(x, y, z, top_camera);

    xmlrpc_env env;
    xmlrpc_env_init(&env);
    xmlrpc_value* elem;
    xmlrpc_value* values;
    values = xmlrpc_array_new(&env);
    for (int i = 0; i < data->size(); ++i) {
        elem = xmlrpc_double_new(&env, data->at(i));
        xmlrpc_array_append_item(&env, values, elem);
        xmlrpc_DECREF(elem);
    }
    resultP->instantiate(values);
    // Clean this shit!
    xmlrpc_DECREF(values);
    xmlrpc_env_clean(&env);
}
Exemplo n.º 14
0
    void
    execute(xmlrpc_c::paramList const& paramList,
            xmlrpc_c::value *   const  retvalP) {

        const params_t params = paramList.getStruct(0);
        paramList.verifyEnd(1);
        params_t::const_iterator si = params.find("text");
        if (si == params.end()) {
            throw xmlrpc_c::fault(
                "Missing source text",
                xmlrpc_c::fault::CODE_PARSE);
        }
        const string source(
            (xmlrpc_c::value_string(si->second)));

        cerr << "Input: " << source << endl;
        si = params.find("align");
        bool addAlignInfo = (si != params.end());
        si = params.find("sg");
        bool addGraphInfo = (si != params.end());
        si = params.find("topt");
        bool addTopts = (si != params.end());
        si = params.find("report-all-factors");
        bool reportAllFactors = (si != params.end());
        si = params.find("nbest");
        int nbest_size = (si == params.end()) ? 0 : int(xmlrpc_c::value_int(si->second));
        si = params.find("nbest-distinct");
        bool nbest_distinct = (si != params.end());

        vector<float> multiModelWeights;
        si = params.find("lambda");
        if (si != params.end()) {
            xmlrpc_c::value_array multiModelArray = xmlrpc_c::value_array(si->second);
            vector<xmlrpc_c::value> multiModelValueVector(multiModelArray.vectorValueValue());
            for (size_t i=0; i < multiModelValueVector.size(); i++) {
                multiModelWeights.push_back(xmlrpc_c::value_double(multiModelValueVector[i]));
            }
        }

        const StaticData &staticData = StaticData::Instance();

        if (addGraphInfo) {
            (const_cast<StaticData&>(staticData)).SetOutputSearchGraph(true);
        }

        if (multiModelWeights.size() > 0) {
            PhraseDictionaryMultiModel* pdmm = (PhraseDictionaryMultiModel*) staticData.GetPhraseDictionaries()[0]; //TODO: only works if multimodel is first phrase table
            pdmm->SetTemporaryMultiModelWeightsVector(multiModelWeights);
        }

        stringstream out, graphInfo, transCollOpts;
        map<string, xmlrpc_c::value> retData;

        if (staticData.IsChart()) {
            TreeInput tinput;
            const vector<FactorType> &inputFactorOrder =
                staticData.GetInputFactorOrder();
            stringstream in(source + "\n");
            tinput.Read(in,inputFactorOrder);
            ChartManager manager(tinput);
            manager.ProcessSentence();
            const ChartHypothesis *hypo = manager.GetBestHypothesis();
            outputChartHypo(out,hypo);
        } else {
            Sentence sentence;
            const vector<FactorType> &inputFactorOrder =
                staticData.GetInputFactorOrder();
            stringstream in(source + "\n");
            sentence.Read(in,inputFactorOrder);
            size_t lineNumber = 0; // TODO: Include sentence request number here?
            Manager manager(lineNumber, sentence, staticData.GetSearchAlgorithm());
            manager.ProcessSentence();
            const Hypothesis* hypo = manager.GetBestHypothesis();

            vector<xmlrpc_c::value> alignInfo;
            outputHypo(out,hypo,addAlignInfo,alignInfo,reportAllFactors);
            if (addAlignInfo) {
                retData.insert(pair<string, xmlrpc_c::value>("align", xmlrpc_c::value_array(alignInfo)));
            }

            if(addGraphInfo) {
                insertGraphInfo(manager,retData);
                (const_cast<StaticData&>(staticData)).SetOutputSearchGraph(false);
            }
            if (addTopts) {
                insertTranslationOptions(manager,retData);
            }
            if (nbest_size>0) {
                outputNBest(manager, retData, nbest_size, nbest_distinct, reportAllFactors);
            }
        }
        pair<string, xmlrpc_c::value>
        text("text", xmlrpc_c::value_string(out.str()));
        retData.insert(text);
        cerr << "Output: " << out.str() << endl;
        *retvalP = xmlrpc_c::value_struct(retData);
    }
Exemplo n.º 15
0
void METHOD_MESSAGE_SEND::execute(xmlrpc_c::paramList const & paramList,
                                  xmlrpc_c::value *   const   retvalPtr)
{
std::string cookie = paramList.getString(0);
std::vector<xmlrpc_c::value> logins(paramList.getArray(1));
std::map<std::string, xmlrpc_c::value> msgInfo(paramList.getStruct(2));
paramList.verifyEnd(3);

ADMIN_INFO adminInfo;

if (config->GetAdminInfo(cookie, &adminInfo))
    {
    *retvalPtr = xmlrpc_c::value_boolean(false);
    return;
    }

STG_MSG message;

std::map<std::string, xmlrpc_c::value>::iterator it;

if ((it = msgInfo.find("version")) == msgInfo.end())
    {
    message.header.ver = 1; // Default value
    }
else
    {
    message.header.ver = xmlrpc_c::value_int(it->second);
    }

if ((it = msgInfo.find("type")) == msgInfo.end())
    {
    message.header.type = 1; // default value
    }
else
    {
    message.header.type = xmlrpc_c::value_int(it->second);
    }

if ((it = msgInfo.find("repeat")) == msgInfo.end())
    {
    *retvalPtr = xmlrpc_c::value_boolean(false);
    return;
    }
message.header.repeat = xmlrpc_c::value_int(it->second);

if ((it = msgInfo.find("repeat_period")) == msgInfo.end())
    {
    *retvalPtr = xmlrpc_c::value_boolean(false);
    return;
    }
message.header.repeatPeriod = xmlrpc_c::value_int(it->second);

if ((it = msgInfo.find("show_time")) == msgInfo.end())
    {
    *retvalPtr = xmlrpc_c::value_boolean(false);
    return;
    }
message.header.showTime = xmlrpc_c::value_int(it->second);

if ((it = msgInfo.find("text")) == msgInfo.end())
    {
    *retvalPtr = xmlrpc_c::value_boolean(false);
    return;
    }
message.text = IconvString(xmlrpc_c::value_string(it->second), "UTF-8", "CP1251");

message.header.creationTime = static_cast<int>(stgTime);
message.header.lastSendTime = 0;

std::vector<xmlrpc_c::value>::iterator lit;
for (lit = logins.begin(); lit != logins.end(); ++lit)
    {
    USER_PTR ui;
    if (users->FindByName(xmlrpc_c::value_string(*lit), &ui))
        {
        printfd(__FILE__, "METHOD_MESSAGE_SEND::execute(): 'User '%s' not found'\n", std::string(xmlrpc_c::value_string(*lit)).c_str());
        }
    else
        {
        ui->AddMessage(&message);
        }
    }

*retvalPtr = xmlrpc_c::value_boolean(true);
}