inline XmlRpcValue XmlRpcClient::call (std::string method_name, XmlRpcValue param_array) { XmlRpcEnv env; xmlrpc_value *result = xmlrpc_client_call_params(env, mServerUrl.c_str(), method_name.c_str(), param_array.borrowReference()); env.throwIfFaultOccurred(); return XmlRpcValue(result, XmlRpcValue::CONSUME_REFERENCE); }
static void AdvancedTest() { XmlRpcValue args, result; // Passing datums: args[0] = "a string"; args[1] = 1; args[2] = true; args[3] = 3.14159; struct tm timeNow; args[4] = XmlRpcValue(&timeNow); // Passing an array: XmlRpcValue array; array[0] = 4; array[1] = 5; array[2] = 6; args[5] = array; // Note: if there's a chance that the array contains zero elements, // you'll need to call: // array.initAsArray(); // ...because otherwise the type will never get set to "TypeArray" and // the value will be a "TypeInvalid". // Passing a struct: XmlRpcValue record; record["SOURCE"] = "a"; record["DESTINATION"] = "b"; record["LENGTH"] = 5; args[6] = record; // We don't support zero-size struct's...Surely no-one needs these? // Make the call: XmlRpcClient Connection("https://61.95.191.232:9600/arumate/rpc/xmlRpcServer.php"); Connection.setIgnoreCertificateAuthority(); if (! Connection.execute("arumate.getMegawatts", args, result)) { std::cout << Connection.getError(); return; } // Pull the data out: if (result.getType() != XmlRpcValue::TypeStruct) { std::cout << "I was expecting a struct."; return; } int i = result["n"]; std::string s = result["name"]; array = result["A"]; for (int i=0; i < array.size(); i++) std::cout << (int)array[i] << "\n"; record = result["subStruct"]; std::cout << (std::string)record["foo"] << "\n"; }
bool XMLRPCManager::validateXmlrpcResponse(const std::string& method, XmlRpcValue &response, XmlRpcValue &payload) { if (response.getType() != XmlRpcValue::TypeArray) { ROSCPP_LOG_DEBUG("XML-RPC call [%s] didn't return an array", method.c_str()); return false; } if (response.size() != 2 && response.size() != 3) { ROSCPP_LOG_DEBUG("XML-RPC call [%s] didn't return a 2 or 3-element array", method.c_str()); return false; } if (response[0].getType() != XmlRpcValue::TypeInt) { ROSCPP_LOG_DEBUG("XML-RPC call [%s] didn't return a int as the 1st element", method.c_str()); return false; } int status_code = response[0]; if (response[1].getType() != XmlRpcValue::TypeString) { ROSCPP_LOG_DEBUG("XML-RPC call [%s] didn't return a string as the 2nd element", method.c_str()); return false; } std::string status_string = response[1]; if (status_code != 1) { ROSCPP_LOG_DEBUG("XML-RPC call [%s] returned an error (%d): [%s]", method.c_str(), status_code, status_string.c_str()); return false; } if (response.size() > 2) { payload = response[2]; } else { std::string empty_array = "<value><array><data></data></array></value>"; int offset = 0; payload = XmlRpcValue(empty_array, &offset); } return true; }