本文整理汇总了C++中XmlRpcValue::valid方法的典型用法代码示例。如果您正苦于以下问题:C++ XmlRpcValue::valid方法的具体用法?C++ XmlRpcValue::valid怎么用?C++ XmlRpcValue::valid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XmlRpcValue
的用法示例。
在下文中一共展示了XmlRpcValue::valid方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
// 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();
}
示例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;
}
示例3: 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;
}
示例4: 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);
};
}
}
}
示例5: executeMethod
// Execute a named method with the specified params.
bool XmlRpcServerConnection::executeMethod(const std::string& methodName, XmlRpcValue& params, XmlRpcValue& result)
{
XmlRpcServerMethod* method = _server->findMethod(methodName);
if ( ! method) return false;
method->setAuthorization(_authorization);
method->execute(&_saddr, params, result);
// Ensure a valid result value
if ( ! result.valid ())
result = std::string ();
return true;
}
示例6: if
// Convert the response xml into a result value
bool
XmlRpcClient::parseResponse(XmlRpcValue& result)
{
std::string r;
_response.swap(r);
// Parse response xml into result
bool emptyParam;
int offset = 0;
if ( ! XmlRpcUtil::findTag("methodResponse",r,&offset,&emptyParam) || emptyParam)
{
XmlRpcUtil::error("Error in XmlRpcClient::parseResponse: Invalid response - no methodResponse. Response:\n%s", r.c_str());
return false;
}
// Expect either <params><param>... or <fault>...
if (XmlRpcUtil::nextTagIs("params",r,&offset,&emptyParam) &&
XmlRpcUtil::nextTagIs("param",r,&offset,&emptyParam))
{
if (emptyParam)
{
result = 0; // No result?
}
else if ( ! result.fromXml(r, &offset))
{
XmlRpcUtil::error("Error in XmlRpcClient::parseResponse: Invalid response value. Response:\n%s", r.c_str());
return false;
}
}
else if (XmlRpcUtil::nextTagIs("fault",r,&offset,&emptyParam))
{
_isFault = true;
if (emptyParam || ! result.fromXml(r, &offset))
{
result = 0; // No result?
return false;
}
}
else
{
XmlRpcUtil::error("Error in XmlRpcClient::parseResponse: Invalid response - no param or fault tag. Response:\n%s", r.c_str());
return false;
}
return result.valid();
}
示例7: findMethod
// Execute a named method with the specified params.
bool
XmlRpcServer::executeMethod(const std::string& methodName,
XmlRpcValue& params,
XmlRpcValue& result)
{
XmlRpcServerMethod* method = findMethod(methodName);
if ( ! method) return false;
method->execute(params, result);
// Ensure a valid result value
if ( ! result.valid())
result = std::string();
return true;
}
示例8: TriggerValueGet
bool HmValue::TriggerValueGet()
{
if( _sendingChannel )
{
XmlRpcValue value = _channel->GetValue(_valueId);
if( value.valid() )
{
HandleXmlRpcEvent( value );
return true;
}else{
_sendingChannel->MarkAsUndefined();
LOG( Logger::LOG_WARNING, "Error getting value %s.%s", _channel->GetSerial().c_str(), _valueId.c_str());
return false;
}
}else{
return true;
}
}
示例9: 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);
};
}
}
}
示例10: ReceivingSetValue
void HmValue::ReceivingSetValue( unsigned long value )
{
XmlRpcValue& description = _channel->GetValueDescription( _valueId );
if( !description.valid() )return;
XmlRpcValue v;
switch( description["DEFAULT"].getType() )
{
case XmlRpcValue::TypeBoolean:
(bool&)v = ((value & 0x01) != 0) != _boolInvert;
break;
case XmlRpcValue::TypeDouble:
(double&)v = double(value) / _floatScale;
break;
case XmlRpcValue::TypeInt:
(int&)v = value;
break;
default:
break;
}
if( v.valid() )
{
_channel->SetValue( _valueId, v );
}
}