void devTcp4Client_Interface::client_create(xmlrpc_c::paramList const& paramList, xmlrpc_c::value* retvalP) { ACE_TRACE("devTcp4Client_Interface::create"); std::string devname = static_cast<std::string>(paramList.getString(0)); if (devices::instance()->exists(devname)) { throw Exception("Device with that name already exists."); } std::string address = IPv4Addr::IPv4_Any; int port = 0; devTcp4Client* tcp4_dev = new devTcp4Client(devname, this); devices::instance()->add(tcp4_dev); if (paramList.size() > 1) { address = static_cast<std::string>(paramList.getString(2)); tcp4_dev->setAddress(address); } if (paramList.size() > 2) { port = static_cast<int>(paramList.getInt(3)); tcp4_dev->setPort(port); if (port > 0) tcp4_dev->openConnection(); } *retvalP = xmlrpc_c::value_nil(); }
void Log::print(const xmlrpc_c::paramList & params) { for(unsigned i=0; i < params.size(); i++) { std::clog<<"param["<<i<<"]\n"; printValues(params.getStruct(i)); } }
void ElementMethodCl::execute(xmlrpc_c::paramList const& paramList,xmlrpc_c::value * const retvalP) { if (paramList.size() == 0) { /* return list of element */ *retvalP = xmlrpc_c::value_string("empty"); } }
virtual void get_rate_limit(xmlrpc_c::paramList const& paramList, xmlrpc_c::value* retvalP) { ACE_TRACE("modEmulateRate_Interface::get_rate"); int rate = 0; if (paramList.size() > 2 ) { rate = find_handler(paramList)->getRateLimitAtTime(paramList.getDouble(2)); } else { rate = find_handler(paramList)->getRateLimit(); } *retvalP = xmlrpc_c::value_double(rate); }
void RemoteKinematics::PositionMethod::execute(xmlrpc_c::paramList const& paramList, xmlrpc_c::value* const resultP) { // n:AA if (paramList.size() == 2) { vector<value> keys = paramList.getArray(0); vector<value> values = paramList.getArray(1); // Size check if (keys.size() != values.size()) throw girerr::error("Keys vector and values vector doesn't have same size"); // Empty check if (keys.empty()) return; bool integer_keys = keys[0].type() == xmlrpc_c::value::TYPE_INT; vector<double> data(values.size()); for (int i = 0; i < values.size(); ++i) data[i] = value_double(values[i]); if (integer_keys) { vector<int> joint_names(keys.size()); for (int i = 0; i < keys.size(); ++i) joint_names[i] = value_int(keys[i]); this->m_kinematics->setPosition(joint_names, data); } else { vector<string> joint_names(keys.size()); for (int i = 0; i < keys.size(); ++i) joint_names[i] = value_string(keys[i]); this->m_kinematics->setPosition(joint_names, data); } *resultP = value_nil(); return; } // S: SensorData<double>::Ptr data; if (paramList.size() == 0) { data = this->m_kinematics->getPosition(); // S:A } else if (paramList.size() == 1) { // Empty check vector<value> keys = paramList.getArray(0); if (keys.empty()) return; bool integer_keys = keys[0].type() == xmlrpc_c::value::TYPE_INT; if (integer_keys) { vector<int> joint_names(keys.size()); for (int i = 0; i < keys.size(); ++i) joint_names[i] = (int) value_int(keys[i]); data = this->m_kinematics->getPosition(joint_names); } else { vector<string> joint_names(keys.size()); for (int i = 0; i < keys.size(); ++i) joint_names[i] = (string) value_string(keys[i]); data = this->m_kinematics->getPosition(joint_names); } } else throw girerr::error("Unknown signature for hardness function"); // 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); }