diff --git a/languages/c/Types.mjs b/languages/c/Types.mjs index 70fb91b5..d73ce06d 100644 --- a/languages/c/Types.mjs +++ b/languages/c/Types.mjs @@ -170,6 +170,9 @@ const hasTag = (method, tag) => { return method.tags && method.tags.filter(t => t.name === tag).length > 0 } +const IsResultConstSuccess = (schema, name) => (name === 'success' && schema.const) +const IsResultBooleanSuccess = (schema, name) => (name === 'success' && schema.type === 'boolean') + function getParamList(schema, module) { let paramList = [] if (schema.params.length > 0) { @@ -346,14 +349,14 @@ function getSchemaTypeInfo(module = {}, json = {}, name = '', schemas = {}, pref return structure } else if (json.type) { - structure.type = getNativeType(json, fireboltString) - structure.json = json - if (name || json.title) { - structure.name = capitalize(name || json.title) + if (!IsResultBooleanSuccess(json, name) && !IsResultConstSuccess(json, name)) { + structure.type = getNativeType(json, fireboltString) + structure.json = json + if (name || json.title) { + structure.name = capitalize(name || json.title) + } + structure.namespace = getModuleName(module) } - structure.namespace = getModuleName(module) - - return structure } return structure } @@ -744,9 +747,16 @@ function getSchemaInstantiation(schema, module, name, { instantiationType = '' } return getParameterInstantiation(getParamList(schema, module)) } else if (instantiationType === 'result') { - let resultType = getSchemaType(schema, module, { title: true, name: name, resultSchema: true}) || '' - let resultJsonType = getJsonType(schema, module, {name: name}) || '' - return getResultInstantiation(name, resultType, resultJsonType) + let result = '' + if (!IsResultConstSuccess(schema, name)) { + let resultJsonType = getJsonType(schema, module, {name: name}) || '' + let resultType = '' + if (!IsResultBooleanSuccess(schema, name)) { + resultType = getSchemaType(schema, module, { title: true, name: name, resultSchema: true}) || '' + } + result = getResultInstantiation(name, resultType, resultJsonType) + } + return result } else if (instantiationType === 'callback.params') { let resultJsonType = getJsonType(schema.result.schema, module, { name: schema.result.name }) || '' diff --git a/languages/c/src/types/ImplHelpers.mjs b/languages/c/src/types/ImplHelpers.mjs index 8bd950c2..e2b87eb5 100644 --- a/languages/c/src/types/ImplHelpers.mjs +++ b/languages/c/src/types/ImplHelpers.mjs @@ -455,16 +455,22 @@ function getResultInstantiation (name, nativeType, container, indentLevel = 3) { let impl = '' - if (nativeType === 'char*' || nativeType === 'FireboltTypes_StringHandle') { - impl += `${' '.repeat(indentLevel)}${container}* strResult = new ${container}(jsonResult);` + '\n' - impl += `${' '.repeat(indentLevel)}*${name} = static_cast<${getFireboltStringType()}>(strResult);` - } else if (nativeType.includes('Handle')) { - impl += `${' '.repeat(indentLevel)}WPEFramework::Core::ProxyType<${container}>* resultPtr = new WPEFramework::Core::ProxyType<${container}>();\n` - impl += `${' '.repeat(indentLevel)}*resultPtr = WPEFramework::Core::ProxyType<${container}>::Create();\n` - impl += `${' '.repeat(indentLevel)}*(*resultPtr) = jsonResult;\n` - impl += `${' '.repeat(indentLevel)}*${name} = static_cast<${nativeType}>(resultPtr);` - } else if (nativeType) { - impl += `${' '.repeat(indentLevel)}*${name} = jsonResult.Value();` + if (nativeType) { + impl += `${' '.repeat(indentLevel)}if (${name} != nullptr) {` + '\n' + if (nativeType === 'char*' || nativeType === 'FireboltTypes_StringHandle') { + impl += `${' '.repeat(indentLevel + 1)}${container}* strResult = new ${container}(jsonResult);` + '\n' + impl += `${' '.repeat(indentLevel + 1)}*${name} = static_cast<${getFireboltStringType()}>(strResult);` + } else if (nativeType.includes('Handle')) { + impl += `${' '.repeat(indentLevel + 1)}WPEFramework::Core::ProxyType<${container}>* resultPtr = new WPEFramework::Core::ProxyType<${container}>();\n` + impl += `${' '.repeat(indentLevel + 1)}*resultPtr = WPEFramework::Core::ProxyType<${container}>::Create();\n` + impl += `${' '.repeat(indentLevel + 1)}*(*resultPtr) = jsonResult;\n` + impl += `${' '.repeat(indentLevel + 1)}*${name} = static_cast<${nativeType}>(resultPtr);` + } else { + impl += `${' '.repeat(indentLevel + 1)}*${name} = jsonResult.Value();` + } + impl += `${' '.repeat(indentLevel)}}` + '\n' + } else if (name === 'success') { + impl += `${' '.repeat(indentLevel)}status = (jsonResult.Value() == true) ? FireboltSDKErrorNone : FireboltSDKErrorNotSupported` } return impl diff --git a/src/macrofier/engine.mjs b/src/macrofier/engine.mjs index 069fc640..b4f4f9c8 100644 --- a/src/macrofier/engine.mjs +++ b/src/macrofier/engine.mjs @@ -1146,7 +1146,7 @@ function insertMethodMacros(template, methodObj, json, templates, examples = {}) .replace(/\$\{event\.callback\.params\.serialization\}/g, callbackSerializedParams) .replace(/\$\{event\.callback\.result\.instantiation\}/g, callbackResultInst) .replace(/\$\{event\.callback\.response\.instantiation\}/g, callbackResponseInst) - .replace(/\$\{info\.title\}/g, info.title.toLowerCase()) + .replace(/\$\{info\.title\}/g, info.title) .replace(/\$\{info\.Title\}/g, capitalize(info.title)) .replace(/\$\{info\.TITLE\}/g, info.title.toUpperCase()) .replace(/\$\{method\.property\.immutable\}/g, hasTag(methodObj, 'property:immutable'))