本文整理汇总了C++中XmlRpcValue::size方法的典型用法代码示例。如果您正苦于以下问题:C++ XmlRpcValue::size方法的具体用法?C++ XmlRpcValue::size怎么用?C++ XmlRpcValue::size使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XmlRpcValue
的用法示例。
在下文中一共展示了XmlRpcValue::size方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sessionExecute
void TargetAltitude::sessionExecute (XmlRpcValue& params, XmlRpcValue& result)
{
if (params.size () != 4)
throw XmlRpcException ("Invalid number of parameters");
if (((int) params[0]) < 0)
throw XmlRpcException ("Target id < 0");
rts2db::Target *tar = createTarget ((int) params[0], Configuration::instance ()->getObserver (), Configuration::instance ()->getObservatoryAltitude ());
if (tar == NULL)
{
throw XmlRpcException ("Cannot create target");
}
time_t tfrom = (int)params[1];
double jd_from = ln_get_julian_from_timet (&tfrom);
time_t tto = (int)params[2];
double jd_to = ln_get_julian_from_timet (&tto);
double stepsize = ((double)params[3]) / 86400;
// test for insane request
if ((jd_to - jd_from) / stepsize > 10000)
{
throw XmlRpcException ("Too many points");
}
int i;
double j;
for (i = 0, j = jd_from; j < jd_to; i++, j += stepsize)
{
result[i][0] = j;
ln_hrz_posn hrz;
tar->getAltAz (&hrz, j);
result[i][1] = hrz.alt;
}
}
示例2: generateRequest
// Encode the request to call the specified method with the specified parameters into xml
bool XmlRpcClient::generateRequest(const char* methodName, XmlRpcValue const& params)
{
std::string body = REQUEST_BEGIN;
body += methodName;
body += REQUEST_END_METHODNAME;
// If params is an array, each element is a separate parameter
if (params.valid())
{
body += PARAMS_TAG;
if (params.getType() == XmlRpcValue::TypeArray)
{
for (int i=0; i<params.size(); ++i)
{
body += PARAM_TAG;
body += params[i].toXml();
body += PARAM_ETAG;
}
}
else
{
body += PARAM_TAG;
body += params.toXml();
body += PARAM_ETAG;
}
body += PARAMS_ETAG;
}
body += REQUEST_END;
std::string header = generateHeader(body);
XmlRpcUtil::log(4, "XmlRpcClient::generateRequest: header is %d bytes, content-length is %d.",
header.length(), body.length());
_request = header + body;
return true;
}
示例3:
// Encode the request to call the specified method with the specified parameters into xml
bool
XmlRpcCurlClient::generateRequest(const char* methodName, XmlRpcValue const& params)
{
std::string body = REQUEST_BEGIN;
body += methodName;
body += REQUEST_END_METHODNAME;
// If params is an array, each element is a separate parameter
if (params.valid()) {
body += PARAMS_TAG;
if (params.getType() == XmlRpcValue::TypeArray)
{
for (int i=0; i<params.size(); ++i) {
body += PARAM_TAG;
body += params[i].toXml();
body += PARAM_ETAG;
}
}
else
{
body += PARAM_TAG;
body += params.toXml();
body += PARAM_ETAG;
}
body += PARAMS_ETAG;
}
body += REQUEST_END;
_request = body;
return true;
}
示例4: execute
void execute(XmlRpcValue& params, XmlRpcValue& result)
{
int nArgs = params.size();
int requiredSize;
wchar_t wFieldText[129];
bool ShowMsg=false;
Log(2,L"RX: %d",nArgs);
for (int i=0; i<nArgs; i++)
{
int y = (int) (params[i]["Row"]);
int x = (int) (params[i]["Column"]);
std::string& fieldText = params[i]["Field"];
int attribute = params[i]["Attribute"];
requiredSize = mbstowcs(NULL, fieldText.c_str(), 0); // C4996
if (requiredSize>127)
requiredSize=127;
mbstowcs(wFieldText,fieldText.c_str(),requiredSize+1);
//row updated?
if (0 != wcsncmp(ScreenContent[y]+x, wFieldText, wcslen(wFieldText)))
{
wcsncpy(ScreenContent[y]+x, wFieldText, wcslen(wFieldText));
Log(2,L"R:%d C:%d <%s>",y,x,wFieldText);
}
}
DumpScreenContent();
result = "OK";
}
示例5: execute
void UserLogin::execute (struct sockaddr_in *saddr, XmlRpcValue& params, XmlRpcValue& result)
{
if (params.size() != 2)
throw XmlRpcException ("Invalid number of parameters");
result = verifyUser (params[0], params[1]);
}
示例6: validateXmlrpcResponse
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;
}
示例7: execute
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;
}
示例8: execute
void execute(XmlRpcValue& params, XmlRpcValue& result)
{
string tmp = params[0];
vector<string> list = chat.Listar();
for(int i = 0; i < list.size(); i++)
result[i] = (string)list[i];
cout << "Listando: " << result.size() << endl;
}
示例9: AdvancedTest
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";
}
示例10: switch
void XMLRPC2DIServer::xmlrpcval2amarg(XmlRpcValue& v, AmArg& a,
unsigned int start_index) {
if (v.valid()) {
for (int i=start_index; i<v.size();i++) {
switch (v[i].getType()) {
case XmlRpcValue::TypeInt: { a.push(AmArg((int)v[i])); } break;
case XmlRpcValue::TypeDouble:{ a.push(AmArg((double)v[i])); } break;
case XmlRpcValue::TypeString:{ a.push(AmArg(((string)v[i]).c_str())); } break;
// TODO: support more types (datetime, struct, ...)
default: throw XmlRpcException("unsupported parameter type", 400);
};
}
}
}
示例11: XmlRpcException
void XMLRPC2DIServerDIMethod::execute(XmlRpcValue& params, XmlRpcValue& result) {
try {
if (params.size() < 2) {
DBG("XMLRPC2DI: ERROR: need at least factory name"
" and function name to call\n");
throw XmlRpcException("need at least factory name"
" and function name to call", 400);
}
string fact_name = params[0];
string fct_name = params[1];
DBG("XMLRPC2DI: factory '%s' function '%s'\n",
fact_name.c_str(), fct_name.c_str());
// get args
AmArg args;
XMLRPC2DIServer::xmlrpcval2amarg(params, args, 2);
AmDynInvokeFactory* di_f = AmPlugIn::instance()->getFactory4Di(fact_name);
if(!di_f){
throw XmlRpcException("could not get factory", 500);
}
AmDynInvoke* di = di_f->getInstance();
if(!di){
throw XmlRpcException("could not get instance from factory", 500);
}
AmArg ret;
di->invoke(fct_name, args, ret);
XMLRPC2DIServer::amarg2xmlrpcval(ret, result);
} catch (const XmlRpcException& e) {
throw;
} catch (const AmDynInvoke::NotImplemented& e) {
throw XmlRpcException("Exception: AmDynInvoke::NotImplemented: "
+ e.what, 504);
} catch (const AmArg::OutOfBoundsException& e) {
throw XmlRpcException("Exception: AmArg out of bounds - paramter number mismatch.", 300);
} catch (const AmArg::TypeMismatchException& e) {
throw XmlRpcException("Exception: Type mismatch in arguments.", 300);
} catch (const string& e) {
throw XmlRpcException("Exception: "+e, 500);
} catch (...) {
throw XmlRpcException("Exception occured.", 500);
}
}
示例12: executeMulticall
// Execute multiple calls and return the results in an array.
bool XmlRpcServerConnection::executeMulticall(const std::string& in_methodName, XmlRpcValue& params, XmlRpcValue& result)
{
if (in_methodName != SYSTEM_MULTICALL) return false;
// There ought to be 1 parameter, an array of structs
if (params.size() != 1 || params[0].getType() != XmlRpcValue::TypeArray)
throw XmlRpcException(SYSTEM_MULTICALL + ": Invalid argument (expected an array)");
int nc = params[0].size();
result.setSize(nc);
for (int i=0; i<nc; ++i)
{
if ( ! params[0][i].hasMember(METHODNAME) ||
! params[0][i].hasMember(PARAMS))
{
result[i][FAULTCODE] = -1;
result[i][FAULTSTRING] = SYSTEM_MULTICALL +
": Invalid argument (expected a struct with members methodName and params)";
continue;
}
const std::string& methodName = params[0][i][METHODNAME];
XmlRpcValue& methodParams = params[0][i][PARAMS];
XmlRpcValue resultValue;
resultValue.setSize(1);
try
{
if ( ! executeMethod(methodName, methodParams, resultValue[0]) &&
! executeMulticall(methodName, params, resultValue[0]))
{
result[i][FAULTCODE] = -1;
result[i][FAULTSTRING] = methodName + ": unknown method name";
}
else
result[i] = resultValue;
}
catch (const XmlRpcException& fault)
{
result[i][FAULTCODE] = fault.getCode();
result[i][FAULTSTRING] = fault.getMessage();
}
}
return true;
}
示例13: switch
void XMLRPC2DIServer::xmlrpcval2amarg(XmlRpcValue& v, AmArg& a,
unsigned int start_index) {
if (v.valid()) {
for (int i=start_index; i<v.size();i++) {
switch (v[i].getType()) {
case XmlRpcValue::TypeInt: { /* DBG("X->A INT\n");*/ a.push(AmArg((int)v[i])); } break;
case XmlRpcValue::TypeDouble:{ /* DBG("X->A DBL\n");*/ a.push(AmArg((double)v[i])); } break;
case XmlRpcValue::TypeString:{ /* DBG("X->A STR\n");*/ a.push(AmArg(((string)v[i]).c_str())); } break;
case XmlRpcValue::TypeArray: {
// DBG("X->A ARR\n");
a.push(AmArg());
a[a.size()-1].assertArray(0);
AmArg arr;
xmlrpcval2amarg(v[i], a[a.size()-1], 0);
} break;
// TODO: support more types (datetime, struct, ...)
default: throw XmlRpcException("unsupported parameter type", 400);
};
}
}
}
示例14: validateXmlrpcResponse
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() != 3)
{
ROSCPP_LOG_DEBUG("XML-RPC call [%s] didn't return a 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;
}
payload = response[2];
return true;
}
示例15: main
int main(int argc, char* argv[])
{
string server = "localhost";
string port = "11088";
string service = def_service;
string method = def_method;
bool serviceSet = false;
bool methodSet = false;
int extraArgs = argc;
// a kindergarten cmdline parser
for (int i = 1; i < argc; ) {
string arg = argv[i++];
if (arg == "-h") {
Usage();
} else if (arg == "-d") {
debug = true;
quiet = false;
} else if (arg == "-q") {
quiet = true;
debug = false;
} else if (arg == "-s") {
if (i >= argc) {
cerr << "Error: -s missing hostname" << endl;
Usage();
} else {
server = argv[i++];
}
} else if (arg == "-p") {
if (i >= argc) {
cerr << "Error: -p missing port number" << endl;
Usage();
} else {
port = argv[i++];
}
} else if (arg[0] == '-') {
cerr << "Error: don't understand flag '" << arg << "'" << endl;
Usage();
} else if ( ! serviceSet) {
service = arg;
method = def_method2;
serviceSet = true;
} else if ( ! methodSet) {
method = arg;
methodSet = true;
} else {
extraArgs = i - 1;
break;
}
}
int portnum = strtol(port.c_str(), NULL, 0);
//XmlRpc::setVerbosity(5);
cout << "Connecting to " << server << ":" << portnum << " ... " << flush;
Tarati::Client client(server, portnum, debug);
cout << "done" << endl;
XmlRpcValue noArgs, result;
try {
if (service == "client") {
if (method == "directory") {
if (extraArgs != argc) {
cerr << "Error: too many arguments on command line" << endl;
Usage();
}
string service = "Server";
string method = "ServiceDirectory";
cout << "Service: " << service << "::" << method << "()" << endl;
XmlRpcValue services;
if (client.execute(service, method, noArgs, services)) {
for (int i = 0; i < services.size(); i++) {
XmlRpcValue version;
string service = services[i];
string method = "MethodDirectory";
client.execute(service, "Version", noArgs, version);
cout << " Service: "
<< service << "(v" << version << ")::"
<< method << "()" << endl;
XmlRpcValue methods;
if (client.execute(service, method, noArgs, methods)) {
for (int i = 0; i < methods.size(); i++) {
cout << " Method: " << methods[i] << endl;
}
}
}
}
} else if (method == "stats") {
if (extraArgs != argc) {
cerr << "Error: too many arguments on command line" << endl;
Usage();
}
string service = "Stats";
string method = "States";
cout << "Service: " << service << "::" << method << "()" << endl;
XmlRpcValue states;
if (client.execute(service, method, noArgs, states)) {
for (int i = 0; i < states.size(); i++) {
XmlRpcValue args = states[i];
//.........这里部分代码省略.........