aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormontellese <montellese@xbmc.org>2011-06-09 15:40:40 +0200
committermontellese <montellese@xbmc.org>2011-06-11 16:08:50 +0200
commit787890946aec4cdf3a6ec839f175c360b5ba9fdd (patch)
tree5510d23b0c76e8ff6da2817d673a2e046dac04b2
parentb8ccedcb56abbcc107043825729a4a457e0a7a03 (diff)
added parsing of "returns" to CJSONServiceDescription
-rw-r--r--xbmc/interfaces/json-rpc/JSONServiceDescription.cpp74
-rw-r--r--xbmc/interfaces/json-rpc/JSONServiceDescription.h5
2 files changed, 49 insertions, 30 deletions
diff --git a/xbmc/interfaces/json-rpc/JSONServiceDescription.cpp b/xbmc/interfaces/json-rpc/JSONServiceDescription.cpp
index cd103a3d7c..1c4df3e19f 100644
--- a/xbmc/interfaces/json-rpc/JSONServiceDescription.cpp
+++ b/xbmc/interfaces/json-rpc/JSONServiceDescription.cpp
@@ -495,13 +495,15 @@ JSON_STATUS CJSONServiceDescription::Print(CVariant &result, ITransportLayer *tr
for (typeIterator = types.begin(); typeIterator != typeIteratorEnd; typeIterator++)
getReferencedTypes(typeIterator->second, referencedTypes);
- // Loop through all printed method's parameters to get all referenced types
+ // Loop through all printed method's parameters and return value to get all referenced types
CJsonRpcMethodMap::JsonRpcMethodIterator methodIterator;
CJsonRpcMethodMap::JsonRpcMethodIterator methodIteratorEnd = methods.end();
for (methodIterator = methods.begin(); methodIterator != methodIteratorEnd; methodIterator++)
{
for (unsigned int index = 0; index < methodIterator->second.parameters.size(); index++)
getReferencedTypes(methodIterator->second.parameters.at(index), referencedTypes);
+
+ getReferencedTypes(methodIterator->second.returns, referencedTypes);
}
for (unsigned int index = 0; index < referencedTypes.size(); index++)
@@ -560,7 +562,7 @@ JSON_STATUS CJSONServiceDescription::Print(CVariant &result, ITransportLayer *tr
currentMethod["params"].append(param);
}
- currentMethod["returns"] = methodIterator->second.returns;
+ printType(methodIterator->second.returns, false, false, false, printDescriptions, currentMethod["returns"]);
result["methods"][methodIterator->second.name] = currentMethod;
}
@@ -1135,29 +1137,7 @@ bool CJSONServiceDescription::parseTypeDefinition(const CVariant &value, JSONSch
}
// Get the defined type of the parameter
- if (value["type"].isArray())
- {
- int parsedType = 0;
- // If the defined type is an array, we have
- // to handle a union type
- for (unsigned int typeIndex = 0; typeIndex < value["type"].size(); typeIndex++)
- {
- // If the type is a string try to parse it
- if (value["type"][typeIndex].isString())
- parsedType |= StringToSchemaValueType(value["type"][typeIndex].asString());
- else
- CLog::Log(LOGWARNING, "JSONRPC: Invalid type in union type definition of type %s", type.name.c_str());
- }
-
- type.type = (JSONSchemaType)parsedType;
-
- // If the type has not been set yet
- // set it to "any"
- if (type.type == 0)
- type.type = AnyValue;
- }
- else
- type.type = value["type"].isString() ? StringToSchemaValueType(value["type"].asString()) : AnyValue;
+ type.type = parseJSONSchemaType(value["type"]);
if (type.type == ObjectValue)
{
@@ -1349,11 +1329,49 @@ bool CJSONServiceDescription::parseTypeDefinition(const CVariant &value, JSONSch
return true;
}
-void CJSONServiceDescription::parseReturn(const CVariant &value, CVariant &returns)
+void CJSONServiceDescription::parseReturn(const CVariant &value, JSONSchemaTypeDefinition &returns)
{
// Only parse the "returns" definition if there is one
- if (value.isMember("returns"))
- returns = value["returns"];
+ if (!value.isMember("returns"))
+ {
+ returns.type = NullValue;
+ return;
+ }
+
+ // If the type of the return value is defined as a simple string we can parse it directly
+ if (value["returns"].isString())
+ {
+ returns.type = parseJSONSchemaType(value["returns"]);
+ }
+ // otherwise we have to parse the whole type definition
+ else
+ parseTypeDefinition(value["returns"], returns, false);
+}
+
+JSONSchemaType CJSONServiceDescription::parseJSONSchemaType(const CVariant &value)
+{
+ if (value.isArray())
+ {
+ int parsedType = 0;
+ // If the defined type is an array, we have
+ // to handle a union type
+ for (unsigned int typeIndex = 0; typeIndex < value.size(); typeIndex++)
+ {
+ // If the type is a string try to parse it
+ if (value[typeIndex].isString())
+ parsedType |= StringToSchemaValueType(value[typeIndex].asString());
+ else
+ CLog::Log(LOGWARNING, "JSONRPC: Invalid type in union type definition");
+ }
+
+ // If the type has not been set yet set it to "any"
+ if (parsedType == 0)
+ return AnyValue;
+
+ return (JSONSchemaType)parsedType;
+ }
+ else
+ return value.isString() ? StringToSchemaValueType(value.asString()) : AnyValue;
}
void CJSONServiceDescription::addReferenceTypeDefinition(JSONSchemaTypeDefinition &typeDefinition)
diff --git a/xbmc/interfaces/json-rpc/JSONServiceDescription.h b/xbmc/interfaces/json-rpc/JSONServiceDescription.h
index 116904c491..6b30eed190 100644
--- a/xbmc/interfaces/json-rpc/JSONServiceDescription.h
+++ b/xbmc/interfaces/json-rpc/JSONServiceDescription.h
@@ -205,7 +205,7 @@ namespace JSONRPC
/*!
\brief Definition of the return value
*/
- CVariant returns;
+ JSONSchemaTypeDefinition returns;
} JsonRpcMethod;
/*!
@@ -322,7 +322,8 @@ namespace JSONRPC
static bool parseMethod(const CVariant &value, JsonRpcMethod &method);
static bool parseParameter(CVariant &value, JSONSchemaTypeDefinition &parameter);
static bool parseTypeDefinition(const CVariant &value, JSONSchemaTypeDefinition &type, bool isParameter);
- static void parseReturn(const CVariant &value, CVariant &returns);
+ static void parseReturn(const CVariant &value, JSONSchemaTypeDefinition &returns);
+ static JSONSchemaType parseJSONSchemaType(const CVariant &value);
static void addReferenceTypeDefinition(JSONSchemaTypeDefinition &typeDefinition);
static void getReferencedTypes(const JSONSchemaTypeDefinition &type, std::vector<std::string> &referencedTypes);