当前位置: 首页>>代码示例>>C++>>正文


C++ XmlRpcValue类代码示例

本文整理汇总了C++中XmlRpcValue的典型用法代码示例。如果您正苦于以下问题:C++ XmlRpcValue类的具体用法?C++ XmlRpcValue怎么用?C++ XmlRpcValue使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了XmlRpcValue类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: XmlRpcException

void SessionMethodValue::setXmlValutRts2 (rts2core::Connection *conn, std::string valueName, XmlRpcValue &x_val)
{
	int i_val;
	double d_val;
	std::string s_val;

	rts2core::Value *val = conn->getValue (valueName.c_str ());
	if (!val)
	{
		throw XmlRpcException ("Cannot find value '" + std::string (valueName) + "' on device '" + std::string (conn->getName ()) + "'.");
	}

	switch (val->getValueBaseType ())
	{
		case RTS2_VALUE_INTEGER:
		case RTS2_VALUE_LONGINT:
			if (x_val.getType () == XmlRpcValue::TypeInt)
			{
				i_val = (int) (x_val);
			}
			else
			{
				s_val = (std::string) (x_val);
				i_val = atoi (s_val.c_str ());
			}
			conn->queCommand (new rts2core::CommandChangeValue (conn->getOtherDevClient (), valueName, '=', i_val));
			break;
		case RTS2_VALUE_DOUBLE:
			if (x_val.getType () == XmlRpcValue::TypeDouble)
			{
				d_val = (double) (x_val);
			}
			else
			{
				s_val = (std::string) (x_val);
				d_val = atof (s_val.c_str ());
			}
			conn->queCommand (new rts2core::CommandChangeValue (conn->getOtherDevClient (), valueName, '=', d_val));
			break;

		case RTS2_VALUE_FLOAT:
			if (x_val.getType () == XmlRpcValue::TypeDouble)
			{
				d_val = (double) (x_val);
			}
			else
			{
				s_val = (std::string) (x_val);
				d_val = atof (s_val.c_str ());
			}
			conn->queCommand (new rts2core::CommandChangeValue (conn->getOtherDevClient (), valueName, '=', (float) d_val));
			break;
		case RTS2_VALUE_STRING:
			conn->queCommand (new rts2core::CommandChangeValue (conn->getOtherDevClient (), valueName, '=', (std::string) (x_val)));
			break;
		default:
			conn->queCommand (new rts2core::CommandChangeValue (conn->getOtherDevClient (), valueName, '=', (std::string) (x_val), true));
			break;
	}
}
开发者ID:shaoguangleo,项目名称:rts2,代码行数:60,代码来源:xmlapi.cpp

示例2:

// 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;
}
开发者ID:dllizhen,项目名称:pr-downloader,代码行数:33,代码来源:XmlRpcCurlClient.cpp

示例3: testArray

void testArray(XmlRpcValue const& d)
{
  // Array
  XmlRpcValue a;
  a.setSize(4);
  a[0] = 1;
  a[1] = std::string("two");
  a[2] = 43.7;
  a[3] = "four";
  assert(int(a[0]) == 1);
  assert(a[2] == d);

  char csaXml[] =
    "<value><array>\n"
    "  <data>\n"
    "    <value><i4>1</i4></value> \n"
    "    <value> <string>two</string></value>\n"
    "    <value><double>43.7</double></value>\n"
    "    <value>four</value>\n"
    "  </data>\n"
    "</array></value>";
    
  int offset = 0;
  XmlRpcValue aXml(csaXml, &offset);
  assert(a == aXml);
}
开发者ID:jaredsburrows,项目名称:xml-rpcpp,代码行数:26,代码来源:TestValuesWin32.cpp

示例4:

// Convert the response xml into a result value
bool
XmlRpcClient::parseResponse(XmlRpcValue& result)
{
  // Parse response xml into result
  int offset = 0;
  if ( ! XmlRpcUtil::findTag(METHODRESPONSE_TAG,_response,&offset)) {
    XmlRpcUtil::error("Error in XmlRpcClient::parseResponse: Invalid response - no methodResponse. Response:\n%s", _response.c_str());
    return false;
  }

  // Expect either <params><param>... or <fault>...
  if ((XmlRpcUtil::nextTagIs(PARAMS_TAG,_response,&offset) &&
       XmlRpcUtil::nextTagIs(PARAM_TAG,_response,&offset)) ||
      XmlRpcUtil::nextTagIs(FAULT_TAG,_response,&offset) && (_isFault = true))
  {
    if ( ! result.fromXml(_response, &offset)) {
      XmlRpcUtil::error("Error in XmlRpcClient::parseResponse: Invalid response value. Response:\n%s", _response.c_str());
      _response = "";
      return false;
    }
  } else {
    XmlRpcUtil::error("Error in XmlRpcClient::parseResponse: Invalid response - no param or fault tag. Response:\n%s", _response.c_str());
    _response = "";
    return false;
  }

  _response = "";
  return result.valid();
}
开发者ID:shaikhkh,项目名称:fcc_files,代码行数:30,代码来源:XmlRpcClient.cpp

示例5: findDataType

const DataType& XmlRpcFunction::parameterType (size_t synopsis_index,
					       size_t parameter_index)
{
    XmlRpcValue func_synop = mSynopsis.arrayGetItem(synopsis_index);
    XmlRpcValue param = func_synop.arrayGetItem(parameter_index + 1);
    return findDataType(param.getString());
}
开发者ID:BenedictHiddleston,项目名称:xmlrpc-c-1.06.30,代码行数:7,代码来源:XmlRpcFunction.cpp

示例6: 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;
}
开发者ID:ampereira,项目名称:F2Dock,代码行数:34,代码来源:XmlRpcClient.cpp

示例7: 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";
}
开发者ID:drtimcooper,项目名称:XmlRpc4Win,代码行数:53,代码来源:SampleMain.cpp

示例8: 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);
      };
    }
  } 
}
开发者ID:BackupTheBerlios,项目名称:sems-svn,代码行数:14,代码来源:XMLRPC2DI.cpp

示例9: arrayFromXml

  // Array
  bool XmlRpcValue::arrayFromXml(std::string const& valueXml, int* offset)
  {
    if ( ! XmlRpcUtil::nextTagIs(DATA_TAG, valueXml, offset))
      return false;

    _type = TypeArray;
    _value.asArray = new ValueArray;
    XmlRpcValue v;
    while (v.fromXml(valueXml, offset))
      _value.asArray->push_back(v);       // copy...

    // Skip the trailing </data>
    (void) XmlRpcUtil::nextTagIs(DATA_ETAG, valueXml, offset);
    return true;
  }
开发者ID:KinKir,项目名称:codeblocks-python,代码行数:16,代码来源:XmlRpcValue.cpp

示例10: XmlRpcException

// 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;
}
开发者ID:RTS2,项目名称:rts2,代码行数:49,代码来源:XmlRpcServerConnection.cpp

示例11: 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;
	}
}
开发者ID:shaoguangleo,项目名称:rts2,代码行数:31,代码来源:xmlapi.cpp

示例12: 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]);
}
开发者ID:shaoguangleo,项目名称:rts2,代码行数:7,代码来源:xmlapi.cpp

示例13: cf

// 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;
}
开发者ID:shaikhkh,项目名称:fcc_files,代码行数:38,代码来源:XmlRpcClient.cpp

示例14: generateFaultResponse

void XmlRpcServerConnection::generateFaultResponse(std::string const& errorMsg, int errorCode)
{
	const char RESPONSE_1[] =
		"<?xml version=\"1.0\"?>\r\n"
		"<methodResponse><fault>\r\n\t";
	const char RESPONSE_2[] =
		"\r\n</fault></methodResponse>\r\n";

	XmlRpcValue faultStruct;
	faultStruct[FAULTCODE] = errorCode;
	faultStruct[FAULTSTRING] = errorMsg;
	std::string body = RESPONSE_1 + faultStruct.toXml() + RESPONSE_2;
	std::string header = generateHeader(body);

	_response = header + body;
}
开发者ID:RTS2,项目名称:rts2,代码行数:16,代码来源:XmlRpcServerConnection.cpp

示例15: 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";
	}
开发者ID:hjgode,项目名称:ITE_xml_rpc,代码行数:33,代码来源:ITEScreenWatch.cpp


注:本文中的XmlRpcValue类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。