Skip to content

Commit

Permalink
reverted info.title lower case change + added logic to verify jsonRes…
Browse files Browse the repository at this point in the history
…ult value
  • Loading branch information
HaseenaSainul committed Jul 11, 2023
1 parent 6beeadf commit 92be1ec
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 21 deletions.
30 changes: 20 additions & 10 deletions languages/c/Types.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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 }) || ''
Expand Down
26 changes: 16 additions & 10 deletions languages/c/src/types/ImplHelpers.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/macrofier/engine.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand Down

0 comments on commit 92be1ec

Please sign in to comment.