// Execute the named procedure on the remote server. // Params should be an array of the arguments for the method. // Returns true if the request was sent and a result received (although the result // might be a fault). bool XmlRpcClient::execute(const char* method, XmlRpcValue const& params, XmlRpcValue& result) { XmlRpcUtil::log(1, "XmlRpcClient::execute: method %s (_connectionState %d).", method, _connectionState); // This is not a thread-safe operation, if you want to do multithreading, use separate // clients for each thread. If you want to protect yourself from multiple threads // accessing the same client, replace this code with a real mutex. if (_executing) return false; _executing = true; ClearFlagOnExit cf(_executing); _sendAttempts = 0; _isFault = false; if ( ! setupConnection()) return false; if ( ! generateRequest(method, params)) return false; result.clear(); double msTime = -1.0; // Process until exit is called _disp.work(msTime); if (_connectionState != IDLE || ! parseResponse(result)) return false; XmlRpcUtil::log(1, "XmlRpcClient::execute: method %s completed.", method); _response = ""; return true; }
bool XmlRpcClient::executeCheckDone(XmlRpcValue& result) { result.clear(); // Are we done yet? if (_connectionState != IDLE) return false; if (! parseResponse(result)) { // Hopefully the caller can determine that parsing failed. } //XmlRpcUtil::log(1, "XmlRpcClient::execute: method %s completed.", method); _response = ""; return true; }
void testStruct() { XmlRpcValue struct1; struct1["i4"] = 1; struct1["str"] = "two"; struct1["d"] = 43.7; XmlRpcValue a; a.setSize(4); a[0] = 1; a[1] = std::string("two"); a[2] = 43.7; a[3] = "four"; assert(struct1["d"] == a[2]); char csStructXml[] = "<value><struct>\n" " <member>\n" " <name>i4</name> \n" " <value><i4>1</i4></value> \n" " </member>\n" " <member>\n" " <name>d</name> \n" " <value><double>43.7</double></value>\n" " </member>\n" " <member>\n" " <name>str</name> \n" " <value> <string>two</string></value>\n" " </member>\n" "</struct></value>"; int offset = 0; XmlRpcValue structXml(csStructXml, &offset); assert(struct1 == structXml); XmlRpcValue astruct; astruct["array"] = a; assert(astruct["array"][2] == struct1["d"]); for (int i=0; i<10; i++) { XmlRpcValue Event; Event["Name"] = "string"; Event.clear(); const int NELMTS = 100; int ii; for (ii=0; ii< NELMTS; ++ii) { char buf[40]; sprintf(buf,"%d", ii); Event[std::string(buf)] = buf; } Event.clear(); for (ii=0; ii< NELMTS; ++ii) { char buf[40]; sprintf(buf,"%d", ii); if (ii != NELMTS/2) Event[std::string(buf)] = ii; else for (int jj=0; jj< NELMTS; ++jj) { char bufj[40]; sprintf(bufj,"%d", jj); Event[std::string(buf)][std::string(bufj)] = bufj; } } for (ii=0; ii< NELMTS; ++ii) { char buf[40]; sprintf(buf,"%d", ii); if (ii != NELMTS/2) assert(Event[std::string(buf)] == XmlRpcValue(ii)); else assert(Event[std::string(buf)].size() == NELMTS); } } }