diff --git a/languages/c/Types.mjs b/languages/c/Types.mjs index edf817c9..6dd6abef 100644 --- a/languages/c/Types.mjs +++ b/languages/c/Types.mjs @@ -20,7 +20,7 @@ import deepmerge from 'deepmerge' import { getPath } from '../../src/shared/json-schema.mjs' import { getTypeName, getModuleName, description, getObjectHandleManagement, getNativeType, getPropertyAccessors, capitalize, isOptional, generateEnum, getMapAccessors, getArrayAccessors, getArrayElementSchema, getPropertyGetterSignature, getPropertyEventCallbackSignature, getPropertyEventRegisterSignature, getPropertyEventUnregisterSignature, getPropertySetterSignature, getFireboltStringType } from './src/types/NativeHelpers.mjs' import { getArrayAccessorsImpl, getMapAccessorsImpl, getObjectHandleManagementImpl, getParameterInstantiation, getPropertyAccessorsImpl, getResultInstantiation, getCallbackParametersInstantiation, getCallbackResultInstantiation, getCallbackResponseInstantiation } from './src/types/ImplHelpers.mjs' -import { getJsonContainerDefinition, getJsonDataStructName } from './src/types/JSONHelpers.mjs' +import { getJsonContainerDefinition, getJsonDataStructName, getJsonDataPrefix } from './src/types/JSONHelpers.mjs' const getSdkNameSpace = () => 'FireboltSDK' const getJsonNativeTypeForOpaqueString = () => getSdkNameSpace() + '::JSON::String' @@ -229,13 +229,13 @@ function getSchemaType(schema, module, { name, prefix = '', destination, resultS return info.type } -function getSchemaTypeInfo(module = {}, json = {}, name = '', schemas = {}, prefix = '', options = {level: 0, descriptions: true, title: false, resultSchema: false, event: false}) { +function getSchemaTypeInfo(module = {}, json = {}, name = '', schemas = {}, prefix = '', options = { level: 0, descriptions: true, title: false, resultSchema: false, event: false}) { if (json.schema) { json = json.schema } - let stringAsHandle = options.resultSchema || options.event + let fireboltString = options.resultSchema || options.event let structure = {} structure["type"] = '' @@ -259,17 +259,14 @@ function getSchemaTypeInfo(module = {}, json = {}, name = '', schemas = {}, pref structure.json = res.json structure.name = res.name structure.namespace = res.namespace - return structure } } else if (json.const) { - structure.type = getNativeType(json, stringAsHandle) + structure.type = getNativeType(json, fireboltString) structure.json = json - return structure } else if (json['x-method']) { console.log(`WARNING UNHANDLED: x-method in ${name}`) - return structure //throw "x-methods not supported yet" } else if (json.type === 'string' && json.enum) { @@ -280,13 +277,12 @@ function getSchemaTypeInfo(module = {}, json = {}, name = '', schemas = {}, pref structure.json = json structure.type = typeName structure.namespace = getModuleName(module) - return structure } else if (Array.isArray(json.type)) { let type = json.type.find(t => t !== 'null') let sch = JSON.parse(JSON.stringify(json)) sch.type = type - return getSchemaTypeInfo(module, sch, name, schemas, prefix, options) + structure = getSchemaTypeInfo(module, sch, name, schemas, prefix, options) } else if (json.type === 'array' && json.items && (validJsonObjectProperties(json) === true)) { let res = '' @@ -303,13 +299,11 @@ function getSchemaTypeInfo(module = {}, json = {}, name = '', schemas = {}, pref res = getSchemaTypeInfo(module, json.items, json.items.name || name, schemas, prefix) } - let arrayName = capitalize(res.name) + capitalize(res.json.type) - let n = getTypeName(getModuleName(module), arrayName, prefix) + let n = getTypeName(getModuleName(module), capitalize(res.name), prefix) structure.name = res.name || name && (capitalize(name)) - structure.type = n + 'ArrayHandle' + structure.type = n + 'Array_t' structure.json = json structure.namespace = getModuleName(module) - return structure } else if (json.allOf) { let title = json.title ? json.title : name @@ -317,43 +311,38 @@ function getSchemaTypeInfo(module = {}, json = {}, name = '', schemas = {}, pref union['title'] = title delete union['$ref'] - return getSchemaTypeInfo(module, union, '', schemas, '', options) + structure = getSchemaTypeInfo(module, union, '', schemas, '', options) } else if (json.oneOf) { - structure.type = 'char*' + structure.type = fireboltString ? getFireboltStringType() : 'char*' structure.json.type = 'string' - return structure } else if (json.anyOf) { let mergedSchema = getMergedSchema(module, json, name, schemas) let prefixName = ((prefix.length > 0) && (!name.startsWith(prefix))) ? prefix : capitalize(name) - return getSchemaTypeInfo(module, mergedSchema, '', schemas, prefixName, options) + structure = getSchemaTypeInfo(module, mergedSchema, '', schemas, prefixName, options) } else if (json.type === 'object') { structure.json = json if (hasProperties(json)) { - structure.type = getTypeName(getModuleName(module), json.title || name, prefix) + 'Handle' + structure.type = getTypeName(getModuleName(module), json.title || name, prefix) + '_t' structure.name = (json.name ? json.name : (json.title ? json.title : name)) structure.namespace = (json.namespace ? json.namespace : getModuleName(module)) } else { - structure.type = 'char*' + structure.type = fireboltString ? getFireboltStringType() : 'char*' } if (name) { structure.name = capitalize(name) } - - return structure } else if (json.type) { - structure.type = getNativeType(json, stringAsHandle) + structure.type = getNativeType(json, fireboltString) structure.json = json if (name || json.title) { structure.name = capitalize(name || json.title) } structure.namespace = getModuleName(module) - - return structure } return structure } @@ -367,8 +356,9 @@ function getSchemaShapeInfo(json, module, schemas = {}, { name = '', prefix = '' let shape = '' if (destination && section) { - const isHeader = (destination.includes("JsonData_") !== true) && destination.endsWith(".h") - const isCPP = ((destination.endsWith(".cpp") || destination.includes("JsonData_")) && (section.includes('accessors') !== true)) + const isHeader = (destination.includes(getJsonDataPrefix().toLowerCase()) !== true) && destination.endsWith(".h") + const isCPP = ((destination.endsWith(".cpp") || destination.includes(getJsonDataPrefix().toLowerCase())) && (section.includes('accessors') !== true)) + json = JSON.parse(JSON.stringify(json)) name = json.title || name @@ -429,14 +419,13 @@ function getSchemaShapeInfo(json, module, schemas = {}, { name = '', prefix = '' let info = getSchemaTypeInfo(module, items, items.name || pname, schemas, prefix, {level : level, descriptions: descriptions, title: true}) if (info.type && info.type.length > 0) { let objName = tName + '_' + capitalize(prop.title || pname) - let moduleName = info.namespace info.json.namespace = info.namespace let moduleProperty = getJsonTypeInfo(module, json, json.title || name, schemas, prefix) let prefixName = ((prefix.length > 0) && items['$ref']) ? '' : prefix let subModuleProperty = getJsonTypeInfo(module, info.json, info.name, schemas, prefix) let t = description(capitalize(info.name), json.description) + '\n' - t += '\n' + (isHeader ? getArrayAccessors(objName, tName, info.type) : getArrayAccessorsImpl(tName, moduleProperty.type, (tName + 'Handle'), subModuleProperty.type, capitalize(pname || prop.title), info.type, info.json)) + t += '\n' + (isHeader ? getArrayAccessors(objName, tName, info.type) : getArrayAccessorsImpl(tName, moduleProperty.type, (tName + '_t'), subModuleProperty.type, capitalize(pname || prop.title), info.type, info.json)) c_shape += '\n' + t props.push({name: `${pname}`, type: `WPEFramework::Core::JSON::ArrayType<${subModuleProperty.type}>`}) } @@ -539,10 +528,14 @@ function getSchemaShapeInfo(json, module, schemas = {}, { name = '', prefix = '' if (info.type && info.type.length > 0) { let type = getArrayElementSchema(json, module, schemas, info.name) - let arrayName = capitalize(name) + capitalize(type.type) - let objName = getTypeName(info.namespace, arrayName, prefix) + let arrayName = capitalize(info.name); + let namespace = info.namespace + if (type && type.type === 'object') { + namespace = getModuleName(module) + } + let objName = getTypeName(namespace, arrayName, prefix) let tName = objName + 'Array' - let moduleName = info.namespace + info.json.namespace = info.namespace let moduleProperty = getJsonTypeInfo(module, json, json.title || name, schemas, prefix) let subModuleProperty = getJsonTypeInfo(module, j, j.title, schemas, prefix) @@ -551,7 +544,7 @@ function getSchemaShapeInfo(json, module, schemas = {}, { name = '', prefix = '' t += description(capitalize(info.name), json.description) + '\n' t += '\n' + (isHeader ? getObjectHandleManagement(tName) : getObjectHandleManagementImpl(tName, moduleProperty.type)) } - t += '\n' + (isHeader ? getArrayAccessors(objName, tName, info.type) : getArrayAccessorsImpl(objName, moduleProperty.type, (tName + 'Handle'), subModuleProperty.type, '', info.type, info.json)) + t += '\n' + (isHeader ? getArrayAccessors(objName, tName, info.type) : getArrayAccessorsImpl(objName, moduleProperty.type, (tName + '_t'), subModuleProperty.type, '', info.type, info.json)) shape += '\n' + t } } @@ -759,7 +752,7 @@ function getSchemaInstantiation(schema, module, name, { instantiationType = '' } } else if (instantiationType === 'pull.param.name') { let resultJsonType = getJsonType(schema, module, { name: name }) || '' - return resultJsonType && resultJsonType[0].split('_')[1] || '' + return resultJsonType.length && resultJsonType[0].split('_')[1] || '' } return '' diff --git a/languages/c/language.config.json b/languages/c/language.config.json index 77cde389..ee3604d7 100644 --- a/languages/c/language.config.json +++ b/languages/c/language.config.json @@ -4,13 +4,13 @@ "createModuleDirectories": false, "extractSubSchemas": true, "templatesPerModule": [ - "/include/Module.h", - "/src/Module.cpp" + "/include/module.h", + "/src/module.cpp" ], "templatesPerSchema": [ - "/include/Common/Module.h", - "/src/Module_Common.cpp", - "/src/JsonData_Module.h" + "/include/common/module.h", + "/src/module_common.cpp", + "/src/jsondata_module.h" ], "persistPermission": true } diff --git a/languages/c/src/types/ImplHelpers.mjs b/languages/c/src/types/ImplHelpers.mjs index 6509375a..ba3aa434 100644 --- a/languages/c/src/types/ImplHelpers.mjs +++ b/languages/c/src/types/ImplHelpers.mjs @@ -4,35 +4,36 @@ const Indent = '\t' const getSdkNameSpace = () => 'FireboltSDK' const wpeJsonNameSpace = () => 'WPEFramework::Core::JSON' +const camelcase = str => str[0].toLowerCase() + str.substr(1) const getObjectHandleManagementImpl = (varName, jsonDataName) => { - let result = `${varName}Handle ${varName}Handle_Create(void) + let result = `${varName}_t ${varName}Handle_Acquire(void) { WPEFramework::Core::ProxyType<${jsonDataName}>* type = new WPEFramework::Core::ProxyType<${jsonDataName}>(); *type = WPEFramework::Core::ProxyType<${jsonDataName}>::Create(); - return (static_cast<${varName}Handle>(type)); + return (reinterpret_cast<${varName}_t>(type)); } -void ${varName}Handle_Addref(${varName}Handle handle) +void ${varName}Handle_Addref(${varName}_t handle) { ASSERT(handle != NULL); - WPEFramework::Core::ProxyType<${jsonDataName}>* var = static_cast*>(handle); + WPEFramework::Core::ProxyType<${jsonDataName}>* var = reinterpret_cast*>(handle); ASSERT(var->IsValid()); var->AddRef(); } -void ${varName}Handle_Release(${varName}Handle handle) +void ${varName}Handle_Release(${varName}_t handle) { ASSERT(handle != NULL); - WPEFramework::Core::ProxyType<${jsonDataName}>* var = static_cast*>(handle); + WPEFramework::Core::ProxyType<${jsonDataName}>* var = reinterpret_cast*>(handle); var->Release(); if (var->IsValid() != true) { delete var; } } -bool ${varName}Handle_IsValid(${varName}Handle handle) +bool ${varName}Handle_IsValid(${varName}_t handle) { ASSERT(handle != NULL); - WPEFramework::Core::ProxyType<${jsonDataName}>* var = static_cast*>(handle); + WPEFramework::Core::ProxyType<${jsonDataName}>* var = reinterpret_cast*>(handle); ASSERT(var->IsValid()); return var->IsValid(); } @@ -42,17 +43,17 @@ bool ${varName}Handle_IsValid(${varName}Handle handle) const getPropertyAccessorsImpl = (objName, modulePropertyType, subPropertyType, subPropertyName, accessorPropertyType, json = {}, options = {readonly:false, optional:false}) => { let result = '' - result += `${accessorPropertyType} ${objName}_Get_${subPropertyName}(${objName}Handle handle) + result += `${accessorPropertyType} ${objName}_Get_${subPropertyName}(${objName}_t handle) { ASSERT(handle != NULL); - WPEFramework::Core::ProxyType<${modulePropertyType}>* var = static_cast*>(handle); + WPEFramework::Core::ProxyType<${modulePropertyType}>* var = reinterpret_cast*>(handle); ASSERT(var->IsValid()); ` + '\n' if ((json.type === 'object') && (accessorPropertyType !== 'char*')) { result += ` WPEFramework::Core::ProxyType<${subPropertyType}>* element = new WPEFramework::Core::ProxyType<${subPropertyType}>(); *element = WPEFramework::Core::ProxyType<${subPropertyType}>::Create(); *(*element) = (*var)->${subPropertyName}; - return (static_cast<${accessorPropertyType}>(element));` + '\n' + return (reinterpret_cast<${accessorPropertyType}>(element));` + '\n' } else { if ((typeof json.const === 'string') || (json.type === 'string' && !json.enum) || (accessorPropertyType === 'char*')) { @@ -66,14 +67,14 @@ const getPropertyAccessorsImpl = (objName, modulePropertyType, subPropertyType, if (!options.readonly) { let type = (accessorPropertyType === getFireboltStringType()) ? 'char*' : accessorPropertyType - result += `void ${objName}_Set_${subPropertyName}(${objName}Handle handle, ${type} value)\n{ + result += `void ${objName}_Set_${subPropertyName}(${objName}_t handle, ${type} value)\n{ ASSERT(handle != NULL); - WPEFramework::Core::ProxyType<${modulePropertyType}>* var = static_cast*>(handle); + WPEFramework::Core::ProxyType<${modulePropertyType}>* var = reinterpret_cast*>(handle); ASSERT(var->IsValid()); ` + '\n' if (json.type === 'object' && (accessorPropertyType !== 'char*')) { - result += ` WPEFramework::Core::ProxyType<${subPropertyType}>* object = static_cast*>(value); + result += ` WPEFramework::Core::ProxyType<${subPropertyType}>* object = reinterpret_cast*>(value); (*var)->${subPropertyName} = *(*object);` + '\n' } else { @@ -83,16 +84,16 @@ const getPropertyAccessorsImpl = (objName, modulePropertyType, subPropertyType, } if (options.optional === true) { - result += `bool ${objName}_Has_${subPropertyName}(${objName}Handle handle)\n{ + result += `bool ${objName}_Has_${subPropertyName}(${objName}_t handle)\n{ ASSERT(handle != NULL); - WPEFramework::Core::ProxyType<${modulePropertyType}>* var = static_cast*>(handle); + WPEFramework::Core::ProxyType<${modulePropertyType}>* var = reinterpret_cast*>(handle); ASSERT(var->IsValid()); return ((*var)->${subPropertyName}.IsSet()); }` + '\n' - result += `void ${objName}_Clear_${subPropertyName}(${objName}Handle handle)\n{ + result += `void ${objName}_Clear_${subPropertyName}(${objName}_t handle)\n{ ASSERT(handle != NULL); - WPEFramework::Core::ProxyType<${modulePropertyType}>* var = static_cast*>(handle); + WPEFramework::Core::ProxyType<${modulePropertyType}>* var = reinterpret_cast*>(handle); ASSERT(var->IsValid()); ((*var)->${subPropertyName}.Clear()); }` + '\n' @@ -113,7 +114,7 @@ const getArrayAccessorsImpl = (objName, modulePropertyType, objHandleType, subPr let result = `uint32_t ${objName}Array_Size(${objHandleType} handle) { ASSERT(handle != NULL); - WPEFramework::Core::ProxyType<${modulePropertyType}>* var = static_cast*>(handle); + WPEFramework::Core::ProxyType<${modulePropertyType}>* var = reinterpret_cast*>(handle); ASSERT(var->IsValid()); return (${propertyName}.Length()); @@ -122,7 +123,7 @@ const getArrayAccessorsImpl = (objName, modulePropertyType, objHandleType, subPr result += `${accessorPropertyType} ${objName}Array_Get(${objHandleType} handle, uint32_t index) { ASSERT(handle != NULL); - WPEFramework::Core::ProxyType<${modulePropertyType}>* var = static_cast*>(handle); + WPEFramework::Core::ProxyType<${modulePropertyType}>* var = reinterpret_cast*>(handle); ASSERT(var->IsValid());` + '\n' if ((json.type === 'object') || (json.type === 'array')) { @@ -130,7 +131,7 @@ const getArrayAccessorsImpl = (objName, modulePropertyType, objHandleType, subPr *object = WPEFramework::Core::ProxyType<${subPropertyType}>::Create(); *(*object) = ${propertyName}.Get(index); - return (static_cast<${accessorPropertyType}>(object));` + '\n' + return (reinterpret_cast<${accessorPropertyType}>(object));` + '\n' } else { if ((typeof json.const === 'string') || (json.type === 'string' && !json.enum)) { @@ -146,23 +147,25 @@ const getArrayAccessorsImpl = (objName, modulePropertyType, objHandleType, subPr result += `void ${objName}Array_Add(${objHandleType} handle, ${type} value) { ASSERT(handle != NULL); - WPEFramework::Core::ProxyType<${modulePropertyType}>* var = static_cast*>(handle); + WPEFramework::Core::ProxyType<${modulePropertyType}>* var = reinterpret_cast*>(handle); ASSERT(var->IsValid());` + '\n' if ((json.type === 'object') || (json.type === 'array')) { - result += ` ${subPropertyType}& element = *(*(static_cast*>(value)));` + '\n' + result += ` ${subPropertyType} element; + element = *(*(reinterpret_cast*>(value)));` + '\n' } else { - result += ` ${subPropertyType} element(value);` + '\n' + result += ` ${subPropertyType} element;` + '\n' + result += ` element = value;` + '\n' } result += ` - ${propertyName}.Add(element); + ${propertyName}.Add() = element; }` + '\n' result += `void ${objName}Array_Clear(${objHandleType} handle) { ASSERT(handle != NULL); - WPEFramework::Core::ProxyType<${modulePropertyType}>* var = static_cast*>(handle); + WPEFramework::Core::ProxyType<${modulePropertyType}>* var = reinterpret_cast*>(handle); ASSERT(var->IsValid()); ${propertyName}.Clear(); @@ -172,10 +175,10 @@ const getArrayAccessorsImpl = (objName, modulePropertyType, objHandleType, subPr } const getMapAccessorsImpl = (objName, containerType, subPropertyType, accessorPropertyType, json = {}, options = {readonly:false, optional:false}) => { - let result = `uint32_t ${objName}_KeysCount(${objName}Handle handle) + let result = `uint32_t ${objName}_KeysCount(${objName}_t handle) { ASSERT(handle != NULL); - WPEFramework::Core::ProxyType<${containerType}>* var = static_cast*>(handle); + WPEFramework::Core::ProxyType<${containerType}>* var = reinterpret_cast*>(handle); ASSERT(var->IsValid()); ${containerType}::Iterator elements = (*var)->Variants(); uint32_t count = 0; @@ -184,10 +187,10 @@ const getMapAccessorsImpl = (objName, containerType, subPropertyType, accessorPr } return (count); }` + '\n' - result += `void ${objName}_AddKey(${objName}Handle handle, char* key, ${accessorPropertyType} value) + result += `void ${objName}_AddKey(${objName}_t handle, char* key, ${accessorPropertyType} value) { ASSERT(handle != NULL); - WPEFramework::Core::ProxyType<${containerType}>* var = static_cast*>(handle); + WPEFramework::Core::ProxyType<${containerType}>* var = reinterpret_cast*>(handle); ASSERT(var->IsValid()); ` + '\n' let elementContainer = subPropertyType @@ -196,14 +199,14 @@ const getMapAccessorsImpl = (objName, containerType, subPropertyType, accessorPr } if ((json.type === 'object') || (json.type === 'array' && json.items)) { if (containerType.includes('VariantContainer')) { - result += ` ${subPropertyType}& container = *(*(static_cast*>(value)));` + '\n' + result += ` ${subPropertyType}& container = *(*(reinterpret_cast*>(value)));` + '\n' result += ` string containerStr;` + '\n' result += ` element.ToString(containerStr);` + '\n' result += ` WPEFramework::Core::JSON::VariantContainer containerVariant(containerStr);` + '\n' result += ` WPEFramework::Core::JSON::Variant element = containerVariant;` + '\n' } else { - result += ` ${subPropertyType}& element = *(*(static_cast*>(value)));` + '\n' + result += ` ${subPropertyType}& element = *(*(reinterpret_cast*>(value)));` + '\n' } } else { result += ` ${elementContainer} element(value);` + '\n' @@ -211,19 +214,19 @@ const getMapAccessorsImpl = (objName, containerType, subPropertyType, accessorPr result += ` (*var)->Set(const_cast(key), element); }` + '\n' - result += `void ${objName}_RemoveKey(${objName}Handle handle, char* key) + result += `void ${objName}_RemoveKey(${objName}_t handle, char* key) { ASSERT(handle != NULL); - WPEFramework::Core::ProxyType<${containerType}>* var = static_cast*>(handle); + WPEFramework::Core::ProxyType<${containerType}>* var = reinterpret_cast*>(handle); ASSERT(var->IsValid()); (*var)->Remove(key); }` + '\n' - result += `${accessorPropertyType} ${objName}_FindKey(${objName}Handle handle, char* key) + result += `${accessorPropertyType} ${objName}_FindKey(${objName}_t handle, char* key) { ASSERT(handle != NULL); - WPEFramework::Core::ProxyType<${containerType}>* var = static_cast*>(handle); + WPEFramework::Core::ProxyType<${containerType}>* var = reinterpret_cast*>(handle); ASSERT(var->IsValid());` + '\n' if ((json.type === 'object') || (json.type === 'array') || ((json.type === 'string' || (typeof json.const === 'string')) && !json.enum)) { @@ -249,14 +252,14 @@ const getMapAccessorsImpl = (objName, containerType, subPropertyType, accessorPr *element = WPEFramework::Core::ProxyType<${subPropertyType}>::Create(); *(*element) = objectMap; - status = (static_cast<${accessorPropertyType}>(element));` + '\n' + status = (reinterpret_cast<${accessorPropertyType}>(element));` + '\n' } else if (json.type === 'array' && json.items) { result += ` WPEFramework::Core::ProxyType<${subPropertyType}>* element = new WPEFramework::Core::ProxyType<${subPropertyType}>(); *element = WPEFramework::Core::ProxyType<${subPropertyType}>::Create(); *(*element) = (*var)->Get(key).Array(); - status = (static_cast<${accessorPropertyType}>(element));` + '\n' + status = (reinterpret_cast<${accessorPropertyType}>(element));` + '\n' } else { if (json.type === 'string' || (typeof json.const === 'string')) { @@ -298,25 +301,41 @@ function getParameterInstantiation(paramList, container = '') { paramList.forEach(param => { impl += `\n` const jsonType = param.jsonType + const name = param.name if (jsonType.length) { if (param.required) { - if (param.nativeType.includes('FireboltTypes_StringHandle')) { - impl += ` WPEFramework::Core::JSON::Variant ${capitalize(param.name)} = *(static_cast<${jsonType}*>(${param.name}));\n` + if (param.nativeType.includes('FireboltTypes_String_t')) { + impl += ` WPEFramework::Core::JSON::Variant ${capitalize(name)} = *(reinterpret_cast<${jsonType}*>(${name}));\n` + } + else if (param.nativeType.includes('_t')) { + impl += ` ${jsonType}& ${capitalize(name)}Container = *(*(reinterpret_cast*>(${camelcase(name)})));\n` + impl += ` string ${capitalize(name)}Str;\n` + impl += ` ${capitalize(name)}Container.ToString(${capitalize(name)}Str);\n` + impl += ` WPEFramework::Core::JSON::VariantContainer ${capitalize(name)}VariantContainer(${capitalize(name)}Str);\n` + impl += ` WPEFramework::Core::JSON::Variant ${capitalize(name)} = ${capitalize(name)}VariantContainer;\n` } else { - impl += ` WPEFramework::Core::JSON::Variant ${capitalize(param.name)} = ${param.name};\n` + impl += ` WPEFramework::Core::JSON::Variant ${capitalize(name)} = ${name};\n` } - impl += ` jsonParameters.Set(_T("${param.name}"), ${capitalize(param.name)});` + impl += ` jsonParameters.Set(_T("${name}"), ${capitalize(name)});` } else { - impl += ` if (${param.name} != nullptr) {\n` + + impl += ` if (${name} != nullptr) {\n` if (param.nativeType.includes('char*')) { - impl += ` WPEFramework::Core::JSON::Variant ${capitalize(param.name)} = ${param.name};\n` + impl += ` WPEFramework::Core::JSON::Variant ${capitalize(name)} = ${name};\n` + } + else if (param.nativeType.includes('_t')) { + impl += ` ${jsonType}& ${capitalize(name)}Container = *(*(reinterpret_cast*>(*${camelcase(name)})));\n` + impl += ` string ${capitalize(name)}Str;\n` + impl += ` ${capitalize(name)}Container.ToString(${capitalize(name)}Str);\n` + impl += ` WPEFramework::Core::JSON::VariantContainer ${capitalize(name)}VariantContainer(${capitalize(name)}Str);\n` + impl += ` WPEFramework::Core::JSON::Variant ${capitalize(name)} = ${capitalize(name)}VariantContainer;\n` } else { - impl += ` WPEFramework::Core::JSON::Variant ${capitalize(param.name)} = *(${param.name});\n` + impl += ` WPEFramework::Core::JSON::Variant ${capitalize(name)} = *(${name});\n` } - impl += ` jsonParameters.Set(_T("${param.name}"), ${capitalize(param.name)});\n` + impl += ` jsonParameters.Set(_T("${name}"), ${capitalize(name)});\n` impl += ` }` } impl += '\n' @@ -347,7 +366,7 @@ function getCallbackParametersInstantiation(paramList, container = '') { } }) impl += `\n WPEFramework::Core::ProxyType<${container}>* jsonResponse;\n` - impl += ` WPEFramework::Core::ProxyType& var = *(static_cast*>(response)); + impl += ` WPEFramework::Core::ProxyType& var = *(reinterpret_cast*>(response)); ASSERT(var.IsValid() == true); if (var.IsValid() == true) { @@ -378,7 +397,7 @@ function getCallbackParametersInstantiation(paramList, container = '') { if (param.nativeType === 'char*') { contextParams += ` ${getSdkNameSpace()}::JSON::String* ${param.name}Value = new ${getSdkNameSpace()}::JSON::String(); *${param.name}Value = elements.Current().Value().c_str(); - ${param.name} = ${param.name}Value;\n` + ${param.name} = reinterpret_cast<${getFireboltStringType()}>(${param.name}Value);\n` } else if (param.nativeType === 'bool') { contextParams += ` ${param.name} = elements.Current().Boolean();\n` @@ -402,7 +421,7 @@ function getCallbackParametersInstantiation(paramList, container = '') { }\n` } else { - impl +=` WPEFramework::Core::ProxyType<${container}>* jsonResponse = static_cast*>(response);\n` + impl +=` WPEFramework::Core::ProxyType<${container}>* jsonResponse = reinterpret_cast*>(response);\n` } return impl @@ -410,7 +429,7 @@ function getCallbackParametersInstantiation(paramList, container = '') { function getCallbackResultInstantiation(nativeType, container = '') { let impl = '' - if (nativeType === 'char*' || nativeType === 'FireboltTypes_StringHandle') { + if (nativeType === 'char*' || nativeType === 'FireboltTypes_String_t') { impl +=` ${container}* jsonStrResponse = new ${container}(); *jsonStrResponse = *(*jsonResponse); @@ -426,7 +445,7 @@ function getCallbackResponseInstantiation(paramList, nativeType, container = '') paramList.forEach(param => { if (param.required !== undefined) { if (param.nativeType === 'char*') { - impl += `static_cast<${getFireboltStringType()}>(${param.name}), ` + impl += `reinterpret_cast<${getFireboltStringType()}>(${param.name}), ` } else if (param.required === true) { impl += `${param.name}, ` @@ -438,11 +457,11 @@ function getCallbackResponseInstantiation(paramList, nativeType, container = '') }) } - if (nativeType === 'char*' || nativeType === 'FireboltTypes_StringHandle') { - impl += `static_cast<${nativeType}>(jsonStrResponse)` + if (nativeType === 'char*' || nativeType === 'FireboltTypes_String_t') { + impl += `reinterpret_cast<${nativeType}>(jsonStrResponse)` } - else if (nativeType.includes('Handle')) { - impl += `static_cast<${nativeType}>(jsonResponse)` + else if (nativeType.includes('_t')) { + impl += `reinterpret_cast<${nativeType}>(jsonResponse)` } else { impl += `static_cast<${nativeType}>((*jsonResponse)->Value())` @@ -455,16 +474,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 { - impl += `${' '.repeat(indentLevel)}*${name} = jsonResult.Value();` + if (nativeType) { + impl += `${' '.repeat(indentLevel)}if (${name} != nullptr) {` + '\n' + if (nativeType === 'char*' || nativeType === 'FireboltTypes_String_t') { + impl += `${' '.repeat(indentLevel + 1)}${container}* strResult = new ${container}(jsonResult);` + '\n' + impl += `${' '.repeat(indentLevel + 1)}*${name} = reinterpret_cast<${getFireboltStringType()}>(strResult);` + '\n' + } else if (nativeType.includes('_t')) { + 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} = reinterpret_cast<${nativeType}>(resultPtr);` + '\n' + } else { + impl += `${' '.repeat(indentLevel + 1)}*${name} = jsonResult.Value();` + '\n' + } + impl += `${' '.repeat(indentLevel)}}` + '\n' + } else if (name === 'success') { + impl += `${' '.repeat(indentLevel)}status = (jsonResult.Value() == true) ? FireboltSDKErrorNone : FireboltSDKErrorNotSupported` } return impl diff --git a/languages/c/src/types/JSONHelpers.mjs b/languages/c/src/types/JSONHelpers.mjs index b2a260b5..cc31b14a 100644 --- a/languages/c/src/types/JSONHelpers.mjs +++ b/languages/c/src/types/JSONHelpers.mjs @@ -52,5 +52,6 @@ function getJsonContainerDefinition (schema, name, props) { export { getJsonContainerDefinition, - getJsonDataStructName + getJsonDataStructName, + getJsonDataPrefix } diff --git a/languages/c/src/types/NativeHelpers.mjs b/languages/c/src/types/NativeHelpers.mjs index 022437e8..7bfef987 100644 --- a/languages/c/src/types/NativeHelpers.mjs +++ b/languages/c/src/types/NativeHelpers.mjs @@ -29,7 +29,7 @@ const { isObject, isArray, propEq, pathSatisfies, hasProp, propSatisfies } = pre const getModuleName = json => getPathOr(null, ['info', 'title'], json) || json.title || 'missing' -const getFireboltStringType = () => 'FireboltTypes_StringHandle' +const getFireboltStringType = () => 'FireboltTypes_String_t' const getHeaderText = () => { return `/* @@ -42,40 +42,6 @@ const getHeaderText = () => { ` } -const getIncludeGuardOpen = (json, prefix=null) => { - prefix = prefix ? `${prefix.toUpperCase()}_` : '' - return ` -#ifndef _${prefix}${getModuleName(json).toUpperCase()}_H -#define _${prefix}${getModuleName(json).toUpperCase()}_H - -` -} - -const getStyleGuardOpen = () => { - return ` -#ifdef __cplusplus -extern "C" { -#endif - -` -} - -const getStyleGuardClose = () => { - return ` - -#ifdef __cplusplus -} -#endif - -` -} - -const getIncludeGuardClose = () => { - return ` -#endif // Header Include Guard -` -} - const capitalize = str => str[0].toUpperCase() + str.substr(1) const description = (title, str='') => '/* ' + title + (str.length > 0 ? ' - ' + str : '') + ' */' const isOptional = (prop, json) => (!json.required || !json.required.includes(prop)) @@ -115,12 +81,12 @@ const getArrayElementSchema = (json, module, schemas = {}, name) => { return result } -const getNativeType = (json, stringAsHandle = false) => { +const getNativeType = (json, fireboltString = false) => { let type let jsonType = json.const ? typeof json.const : json.type if (jsonType === 'string') { type = 'char*' - if (stringAsHandle) { + if (fireboltString) { type = getFireboltStringType() } } @@ -142,26 +108,26 @@ const getNativeType = (json, stringAsHandle = false) => { const getObjectHandleManagement = varName => { - let result = `typedef void* ${varName}Handle; -${varName}Handle ${varName}Handle_Create(void); -void ${varName}Handle_Addref(${varName}Handle handle); -void ${varName}Handle_Release(${varName}Handle handle); -bool ${varName}Handle_IsValid(${varName}Handle handle); + let result = `typedef struct ${varName}_s* ${varName}_t; +${varName}_t ${varName}Handle_Acquire(void); +void ${varName}Handle_Addref(${varName}_t handle); +void ${varName}Handle_Release(${varName}_t handle); +bool ${varName}Handle_IsValid(${varName}_t handle); ` return result } const getPropertyAccessors = (objName, propertyName, propertyType, options = {level:0, readonly:false, optional:false}) => { - let result = `${Indent.repeat(options.level)}${propertyType} ${objName}_Get_${propertyName}(${objName}Handle handle);` + '\n' + let result = `${Indent.repeat(options.level)}${propertyType} ${objName}_Get_${propertyName}(${objName}_t handle);` + '\n' if (!options.readonly) { let type = (propertyType === getFireboltStringType()) ? 'char*' : propertyType - result += `${Indent.repeat(options.level)}void ${objName}_Set_${propertyName}(${objName}Handle handle, ${type} ${propertyName.toLowerCase()});` + '\n' + result += `${Indent.repeat(options.level)}void ${objName}_Set_${propertyName}(${objName}_t handle, ${type} ${propertyName.toLowerCase()});` + '\n' } if (options.optional === true) { - result += `${Indent.repeat(options.level)}bool ${objName}_Has_${propertyName}(${objName}Handle handle);` + '\n' - result += `${Indent.repeat(options.level)}void ${objName}_Clear_${propertyName}(${objName}Handle handle);` + '\n' + result += `${Indent.repeat(options.level)}bool ${objName}_Has_${propertyName}(${objName}_t handle);` + '\n' + result += `${Indent.repeat(options.level)}void ${objName}_Clear_${propertyName}(${objName}_t handle);` + '\n' } return result @@ -171,10 +137,10 @@ const getMapAccessors = (typeName, accessorPropertyType, level = 0) => { let res - res = `${Indent.repeat(level)}uint32_t ${typeName}_KeysCount(${typeName}Handle handle);` + '\n' - res += `${Indent.repeat(level)}void ${typeName}_AddKey(${typeName}Handle handle, char* key, ${accessorPropertyType} value);` + '\n' - res += `${Indent.repeat(level)}void ${typeName}_RemoveKey(${typeName}Handle handle, char* key);` + '\n' - res += `${Indent.repeat(level)}${accessorPropertyType} ${typeName}_FindKey(${typeName}Handle handle, char* key);` + '\n' + res = `${Indent.repeat(level)}uint32_t ${typeName}_KeysCount(${typeName}_t handle);` + '\n' + res += `${Indent.repeat(level)}void ${typeName}_AddKey(${typeName}_t handle, char* key, ${accessorPropertyType} value);` + '\n' + res += `${Indent.repeat(level)}void ${typeName}_RemoveKey(${typeName}_t handle, char* key);` + '\n' + res += `${Indent.repeat(level)}${accessorPropertyType} ${typeName}_FindKey(${typeName}_t handle, char* key);` + '\n' return res } @@ -193,10 +159,10 @@ const getTypeName = (moduleName, varName, prefix = '', upperCase = false, capita const getArrayAccessors = (arrayName, propertyType, valueType) => { - let res = `uint32_t ${arrayName}Array_Size(${propertyType}Handle handle);` + '\n' - res += `${valueType} ${arrayName}Array_Get(${propertyType}Handle handle, uint32_t index);` + '\n' - res += `void ${arrayName}Array_Add(${propertyType}Handle handle, ${valueType} value);` + '\n' - res += `void ${arrayName}Array_Clear(${propertyType}Handle handle);` + '\n' + let res = `uint32_t ${arrayName}Array_Size(${propertyType}_t handle);` + '\n' + res += `${valueType} ${arrayName}Array_Get(${propertyType}_t handle, uint32_t index);` + '\n' + res += `void ${arrayName}Array_Add(${propertyType}_t handle, ${valueType} value);` + '\n' + res += `void ${arrayName}Array_Clear(${propertyType}_t handle);` + '\n' return res } @@ -270,10 +236,6 @@ function getPropertyEventUnregisterSignature(property, module) { export { getHeaderText, - getIncludeGuardOpen, - getStyleGuardOpen, - getStyleGuardClose, - getIncludeGuardClose, getNativeType, getModuleName, getPropertyGetterSignature, diff --git a/languages/c/templates/imports/default.cpp b/languages/c/templates/imports/default.cpp index 69e241f9..dd80010a 100644 --- a/languages/c/templates/imports/default.cpp +++ b/languages/c/templates/imports/default.cpp @@ -1 +1 @@ -#include "JsonData_${info.title}.h" +#include "jsondata_${module.title}.h" diff --git a/languages/c/templates/imports/default.h b/languages/c/templates/imports/default.h index a38b58ef..d3aeb558 100644 --- a/languages/c/templates/imports/default.h +++ b/languages/c/templates/imports/default.h @@ -1 +1 @@ -#include "Common/${info.title}.h" +#include "common/${module.title}.h" diff --git a/languages/c/templates/imports/default.jsondata b/languages/c/templates/imports/default.jsondata index 69e241f9..dd80010a 100644 --- a/languages/c/templates/imports/default.jsondata +++ b/languages/c/templates/imports/default.jsondata @@ -1 +1 @@ -#include "JsonData_${info.title}.h" +#include "jsondata_${module.title}.h" diff --git a/languages/c/templates/modules/include/Module.h b/languages/c/templates/modules/include/module.h similarity index 92% rename from languages/c/templates/modules/include/Module.h rename to languages/c/templates/modules/include/module.h index a202f643..00c5d595 100644 --- a/languages/c/templates/modules/include/Module.h +++ b/languages/c/templates/modules/include/module.h @@ -16,10 +16,10 @@ * SPDX-License-Identifier: Apache-2.0 */ -#ifndef _${info.TITLE}_H -#define _${info.TITLE}_H +#ifndef ${info.TITLE}_H +#define ${info.TITLE}_H -#include "Firebolt.h" +#include /* ${IMPORTS} */ #ifdef __cplusplus diff --git a/languages/c/templates/modules/src/Module.cpp b/languages/c/templates/modules/src/module.cpp similarity index 93% rename from languages/c/templates/modules/src/Module.cpp rename to languages/c/templates/modules/src/module.cpp index 65721f1e..1669dad7 100644 --- a/languages/c/templates/modules/src/Module.cpp +++ b/languages/c/templates/modules/src/module.cpp @@ -18,10 +18,10 @@ #include "FireboltSDK.h" /* ${IMPORTS} */ -#include "${info.title}.h" +#include "${module.title}.h" namespace FireboltSDK { - namespace ${info.title} { + namespace ${info.Title} { // Types /* ${TYPES} */ } diff --git a/languages/c/templates/schemas/include/Common/Module.h b/languages/c/templates/schemas/include/common/module.h similarity index 90% rename from languages/c/templates/schemas/include/Common/Module.h rename to languages/c/templates/schemas/include/common/module.h index ff037fba..939b3988 100644 --- a/languages/c/templates/schemas/include/Common/Module.h +++ b/languages/c/templates/schemas/include/common/module.h @@ -16,10 +16,10 @@ * SPDX-License-Identifier: Apache-2.0 */ -#ifndef _COMMON_${info.TITLE}_H -#define _COMMON_${info.TITLE}_H +#ifndef COMMON_${info.TITLE}_H +#define COMMON_${info.TITLE}_H -#include "Firebolt.h" +#include /* ${IMPORTS} */ #ifdef __cplusplus diff --git a/languages/c/templates/schemas/src/JsonData_Module.h b/languages/c/templates/schemas/src/jsondata_module.h similarity index 92% rename from languages/c/templates/schemas/src/JsonData_Module.h rename to languages/c/templates/schemas/src/jsondata_module.h index d0ecbbac..ac8ce2ef 100644 --- a/languages/c/templates/schemas/src/JsonData_Module.h +++ b/languages/c/templates/schemas/src/jsondata_module.h @@ -19,10 +19,10 @@ #pragma once /* ${IMPORTS} */ -#include "Common/${info.title}.h" +#include "common/${module.title}.h" namespace FireboltSDK { - namespace ${info.title} { + namespace ${info.Title} { // Types /* ${SCHEMAS} */ diff --git a/languages/c/templates/schemas/src/Module_Common.cpp b/languages/c/templates/schemas/src/module_common.cpp similarity index 95% rename from languages/c/templates/schemas/src/Module_Common.cpp rename to languages/c/templates/schemas/src/module_common.cpp index 0ccdfc28..53b79972 100644 --- a/languages/c/templates/schemas/src/Module_Common.cpp +++ b/languages/c/templates/schemas/src/module_common.cpp @@ -18,7 +18,7 @@ #include "FireboltSDK.h" /* ${IMPORTS} */ -#include "JsonData_${info.title}.h" +#include "jsondata_${module.title}.h" /* ${ENUMS} */ diff --git a/languages/c/templates/sdk/include/Error.h b/languages/c/templates/sdk/include/error.h similarity index 93% rename from languages/c/templates/sdk/include/Error.h rename to languages/c/templates/sdk/include/error.h index 87cda9dd..07d6268a 100644 --- a/languages/c/templates/sdk/include/Error.h +++ b/languages/c/templates/sdk/include/error.h @@ -16,8 +16,8 @@ * SPDX-License-Identifier: Apache-2.0 */ -#ifndef _FIREBOLT_ERROR_H -#define _FIREBOLT_ERROR_H +#ifndef FIREBOLT_ERROR_H +#define FIREBOLT_ERROR_H #ifdef __cplusplus extern "C" { @@ -38,4 +38,4 @@ typedef enum FireboltSDKError { } #endif -#endif // _FIREBOLT_ERROR_H +#endif // FIREBOLT_ERROR_H diff --git a/languages/c/templates/sdk/include/Firebolt.h b/languages/c/templates/sdk/include/firebolt.h similarity index 93% rename from languages/c/templates/sdk/include/Firebolt.h rename to languages/c/templates/sdk/include/firebolt.h index 2223bad3..0957973f 100644 --- a/languages/c/templates/sdk/include/Firebolt.h +++ b/languages/c/templates/sdk/include/firebolt.h @@ -16,11 +16,11 @@ * SPDX-License-Identifier: Apache-2.0 */ -#ifndef _FIREBOLT_H -#define _FIREBOLT_H +#ifndef FIREBOLT_H +#define FIREBOLT_H -#include "Error.h" -#include "Types.h" +#include "error.h" +#include "types.h" #ifdef __cplusplus extern "C" { @@ -62,4 +62,4 @@ uint32_t FireboltSDK_Deinitialize(void); #endif -#endif // _FIREBOLT_H +#endif // FIREBOLT_H diff --git a/languages/c/templates/sdk/include/Types.h b/languages/c/templates/sdk/include/types.h similarity index 73% rename from languages/c/templates/sdk/include/Types.h rename to languages/c/templates/sdk/include/types.h index 4fd16256..26efc54f 100644 --- a/languages/c/templates/sdk/include/Types.h +++ b/languages/c/templates/sdk/include/types.h @@ -16,8 +16,8 @@ * SPDX-License-Identifier: Apache-2.0 */ -#ifndef _FIREBOLT_TYPES_H -#define _FIREBOLT_TYPES_H +#ifndef FIREBOLT_TYPES_H +#define FIREBOLT_TYPES_H #include #include @@ -26,12 +26,12 @@ extern "C" { #endif -typedef void* FireboltTypes_StringHandle; -const char* FireboltTypes_String(FireboltTypes_StringHandle handle); -void FireboltTypes_StringHandle_Release(FireboltTypes_StringHandle handle); +typedef struct FireboltTypes_String_s* FireboltTypes_String_t; +const char* FireboltTypes_String(FireboltTypes_String_t handle); +void FireboltTypes_StringHandle_Release(FireboltTypes_String_t handle); #ifdef __cplusplus } #endif -#endif // _FIREBOLT_TYPES_H +#endif // FIREBOLT_TYPES_H diff --git a/languages/c/templates/sdk/scripts/build.sh b/languages/c/templates/sdk/scripts/build.sh index e9b01f20..d50295a6 100755 --- a/languages/c/templates/sdk/scripts/build.sh +++ b/languages/c/templates/sdk/scripts/build.sh @@ -1,11 +1,37 @@ #!/bin/bash -SDK_PATH="." -if [ "$1" != "" ] +usage() +{ + echo "options:" + echo " -p sdk path" + echo " -s sysroot path" + echo " -t enable test" + echo " -c clear build" + echo " -h : help" + echo + echo "usage: " + echo " ./build.sh -p path -tc" +} + +SdkPath="." +EnableTest="OFF" +SysrootPath=${SYSROOT_PATH} +ClearBuild="N" +while getopts p:s:tch flag +do + case "${flag}" in + p) SdkPath="${OPTARG}";; + s) SysrootPath="${OPTARG}";; + t) EnableTest="ON";; + c) ClearBuild="Y";; + h) usage && exit 1;; + esac +done + +if [ "${ClearBuild}" == "Y" ]; then - SDK_PATH=$1 - echo "inside ${1}" + rm -rf ${SdkPath}/build fi -echo ${SDK_PATH} -rm -rf ${SDK_PATH}/build -cmake -B${SDK_PATH}/build -S${SDK_PATH} -DSYSROOT_PATH=${SYSROOT_PATH} -cmake --build ${SDK_PATH}/build + +cmake -B${SdkPath}/build -S${SdkPath} -DSYSROOT_PATH=${SysrootPath} -DENABLE_TESTS=${EnableTest} +cmake --build ${SdkPath}/build +cmake --install ${SdkPath}/build --prefix=${SdkPath}/build/Firebolt diff --git a/languages/c/templates/sdk/src/CMakeLists.txt b/languages/c/templates/sdk/src/CMakeLists.txt index 2f00bdf1..b565d6b1 100644 --- a/languages/c/templates/sdk/src/CMakeLists.txt +++ b/languages/c/templates/sdk/src/CMakeLists.txt @@ -20,7 +20,6 @@ project(FireboltSDK) project_version(1.0.0) set(TARGET ${PROJECT_NAME}) message("Setup ${TARGET} v${PROJECT_VERSION}") -file(GLOB GENERATED_SOURCES "${GENERATED_CODE_PATH}/src/*.cpp") file(GLOB SOURCES *.cpp) add_library(${TARGET} ${FIREBOLT_LIBRARY_TYPE} @@ -41,8 +40,6 @@ target_link_libraries(${TARGET} target_include_directories(${TARGET} PRIVATE - $ - $ $ $ ) @@ -64,8 +61,6 @@ install( ) InstallHeaders(TARGET ${TARGET} HEADERS . NAMESPACE ${FIREBOLT_NAMESPACE} DESTINATION ${FIREBOLT_NAMESPACE}SDK) -InstallHeaders(TARGET ${TARGET} EXCLUDE_ROOT_DIR HEADERS . NAMESPACE ${FIREBOLT_NAMESPACE} - SOURCE ${GENERATED_CODE_PATH}/include DESTINATION ${FIREBOLT_NAMESPACE}/generated) InstallHeaders(TARGET ${TARGET} HEADERS . NAMESPACE ${FIREBOLT_NAMESPACE} SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/../include DESTINATION ${FIREBOLT_NAMESPACE}) diff --git a/languages/c/templates/sdk/src/FireboltSDK.h b/languages/c/templates/sdk/src/FireboltSDK.h index 19946126..d78687dc 100644 --- a/languages/c/templates/sdk/src/FireboltSDK.h +++ b/languages/c/templates/sdk/src/FireboltSDK.h @@ -23,4 +23,4 @@ #include "Accessor/Accessor.h" #include "Logger/Logger.h" #include "TypesPriv.h" -#include "Types.h" +#include "types.h" diff --git a/languages/c/templates/sdk/src/Logger/Logger.cpp b/languages/c/templates/sdk/src/Logger/Logger.cpp index 0e49dfce..a9750a6e 100644 --- a/languages/c/templates/sdk/src/Logger/Logger.cpp +++ b/languages/c/templates/sdk/src/Logger/Logger.cpp @@ -17,7 +17,7 @@ */ #include "Module.h" -#include "Error.h" +#include "error.h" #include "Logger.h" namespace WPEFramework { diff --git a/languages/c/templates/sdk/src/Logger/Logger.h b/languages/c/templates/sdk/src/Logger/Logger.h index cffeff54..2c864c7b 100644 --- a/languages/c/templates/sdk/src/Logger/Logger.h +++ b/languages/c/templates/sdk/src/Logger/Logger.h @@ -18,7 +18,7 @@ #pragma once -#include "Types.h" +#include "types.h" namespace FireboltSDK { diff --git a/languages/c/templates/sdk/src/Transport/Transport.h b/languages/c/templates/sdk/src/Transport/Transport.h index 2aff350d..2b78a5b3 100644 --- a/languages/c/templates/sdk/src/Transport/Transport.h +++ b/languages/c/templates/sdk/src/Transport/Transport.h @@ -19,7 +19,7 @@ #pragma once #include "Module.h" -#include "Error.h" +#include "error.h" namespace FireboltSDK { diff --git a/languages/c/templates/sdk/src/Types.cpp b/languages/c/templates/sdk/src/Types.cpp index f19cfe63..b9620436 100644 --- a/languages/c/templates/sdk/src/Types.cpp +++ b/languages/c/templates/sdk/src/Types.cpp @@ -17,7 +17,7 @@ */ #include "Module.h" -#include "Types.h" +#include "types.h" #include "TypesPriv.h" #ifdef __cplusplus @@ -25,14 +25,14 @@ extern "C" { #endif // String Type Handler Interfaces -const char* FireboltTypes_String(FireboltTypes_StringHandle handle) +const char* FireboltTypes_String(FireboltTypes_String_t handle) { - return ((static_cast(handle))->Value().c_str()); + return ((reinterpret_cast(handle))->Value().c_str()); } -void FireboltTypes_StringHandle_Release(FireboltTypes_StringHandle handle) +void FireboltTypes_StringHandle_Release(FireboltTypes_String_t handle) { - delete static_cast(handle); + delete reinterpret_cast(handle); } #ifdef __cplusplus diff --git a/languages/c/templates/sdk/src/Firebolt.cpp b/languages/c/templates/sdk/src/firebolt.cpp similarity index 100% rename from languages/c/templates/sdk/src/Firebolt.cpp rename to languages/c/templates/sdk/src/firebolt.cpp diff --git a/languages/c/templates/sdk/test/CMakeLists.txt b/languages/c/templates/sdk/test/CMakeLists.txt index a56ca20a..21ee1f55 100644 --- a/languages/c/templates/sdk/test/CMakeLists.txt +++ b/languages/c/templates/sdk/test/CMakeLists.txt @@ -57,7 +57,7 @@ install( InstallCMakeConfig(TARGETS ${TESTLIB}) InstallCMakeConfigs(TARGET ${TESTLIB} DESTINATION ${FIREBOLT_NAMESPACE}) InstallHeaders(TARGET ${TESTLIB} HEADERS . NAMESPACE ${FIREBOLT_NAMESPACE} DESTINATION FireboltTest) -InstallLibraries(TARGET ${TESTLIB} LIBRARIES ${TESTLIB} DESTINATION ${FIREBOLT_NAMESPACE}) +InstallLibraries(TARGET ${TESTLIB} STATIC LIBRARIES ${TESTLIB} DESTINATION ${FIREBOLT_NAMESPACE}) set(TESTAPP "FireboltSDKTestApp") diff --git a/languages/c/templates/sdk/test/Main.c b/languages/c/templates/sdk/test/Main.c index 7c4c94a5..6161792e 100644 --- a/languages/c/templates/sdk/test/Main.c +++ b/languages/c/templates/sdk/test/Main.c @@ -35,6 +35,7 @@ int main() EXECUTE("test_properties_set", test_properties_set); EXECUTE("test_eventregister_by_providing_callback", test_eventregister_by_providing_callback); EXECUTE("test_eventregister", test_eventregister); + EXECUTE("test_eventregister_with_same_callback", test_eventregister_with_same_callback); EXECUTE("test_string_set_get_value", test_string_set_get_value); test_firebolt_dispose_instance(); diff --git a/languages/c/templates/sdk/test/Module.h b/languages/c/templates/sdk/test/Module.h index d5340b68..a147ff75 100644 --- a/languages/c/templates/sdk/test/Module.h +++ b/languages/c/templates/sdk/test/Module.h @@ -23,7 +23,6 @@ #endif #include -#include #undef EXTERNAL #define EXTERNAL diff --git a/languages/c/templates/sdk/test/OpenRPCCTests.h b/languages/c/templates/sdk/test/OpenRPCCTests.h index 7f2fb59e..4fe5eb5b 100644 --- a/languages/c/templates/sdk/test/OpenRPCCTests.h +++ b/languages/c/templates/sdk/test/OpenRPCCTests.h @@ -16,8 +16,8 @@ * SPDX-License-Identifier: Apache-2.0 */ -#ifndef _OPENRPC_C_TESTS_H -#define _OPENRPC_C_TESTS_H +#ifndef OPENRPC_C_TESTS_H +#define OPENRPC_C_TESTS_H #include "TestUtils.h" @@ -25,13 +25,14 @@ extern "C" { #endif -uint32_t test_firebolt_create_instance(); -uint32_t test_firebolt_dispose_instance(); +void test_firebolt_create_instance(); +void test_firebolt_dispose_instance(); uint32_t test_firebolt_main(); uint32_t test_properties_get_device_id(); uint32_t test_properties_set(); uint32_t test_eventregister(); +uint32_t test_eventregister_with_same_callback(); uint32_t test_eventregister_by_providing_callback(); uint32_t test_string_set_get_value(); @@ -39,4 +40,4 @@ uint32_t test_string_set_get_value(); } #endif -#endif // _OPENRPC_C_TESTS_H +#endif // OPENRPC_C_TESTS_H diff --git a/languages/c/templates/sdk/test/OpenRPCTests.cpp b/languages/c/templates/sdk/test/OpenRPCTests.cpp index cf9ea5a0..b74f17ae 100644 --- a/languages/c/templates/sdk/test/OpenRPCTests.cpp +++ b/languages/c/templates/sdk/test/OpenRPCTests.cpp @@ -38,11 +38,20 @@ ENUM_CONVERSION_BEGIN(TestEnum) { TestEnum::Test4, _TXT("Test4ValueCheck") }, ENUM_CONVERSION_END(TestEnum) } + +typedef void (*OnNotifyDeviceNameChanged)(const void* userData, const char* data); +static void NotifyEvent(const void* userData, const char* data) +{ + printf("NotifyEvent data : %s\n", data); +} + namespace FireboltSDK { Tests::Tests() { _functionMap.emplace(std::piecewise_construct, std::forward_as_tuple("SubscribeEventWithMultipleCallback"), std::forward_as_tuple(&SubscribeEventWithMultipleCallback)); + _functionMap.emplace(std::piecewise_construct, std::forward_as_tuple("SubscribeEventwithSameCallback"), + std::forward_as_tuple(&SubscribeEventwithSameCallback)); _functionMap.emplace(std::piecewise_construct, std::forward_as_tuple("SubscribeEvent"), std::forward_as_tuple(&SubscribeEvent)); @@ -147,25 +156,55 @@ namespace FireboltSDK { return status; } - static void deviceNameChangeCallback(const void* userData, void* response) + static void deviceNameChangeCallback(void* userCB, const void* userData, void* response) { - WPEFramework::Core::ProxyType& jsonResponse = *(static_cast*>(response)); + WPEFramework::Core::ProxyType& jsonResponse = *(reinterpret_cast*>(response)); FIREBOLT_LOG_INFO(Logger::Category::OpenRPC, Logger::Module(), "Received a new event: %s", jsonResponse->Value().c_str()); - jsonResponse.Release(); FireboltSDK::Tests::EventControl* eventControl = reinterpret_cast(const_cast(userData)); + OnNotifyDeviceNameChanged notifyDeviceNameChanged = reinterpret_cast(userCB); + notifyDeviceNameChanged(userData, jsonResponse->Value().c_str()); eventControl->NotifyEvent(); + jsonResponse.Release(); } /* static */ uint32_t Tests::SubscribeEvent() { - FireboltSDK::Tests::EventControl* eventControl = new FireboltSDK::Tests::EventControl(); + FireboltSDK::Tests::EventControl* eventControl = new FireboltSDK::Tests::EventControl("EventControl"); const string eventName = _T("device.Name"); const void* userdata = static_cast(eventControl); - uint32_t id = 0; + eventControl->ResetEvent(); + + JsonObject jsonParameters; + uint32_t status = Properties::Subscribe(eventName, jsonParameters, deviceNameChangeCallback,reinterpret_cast(NotifyEvent), userdata); + + EXPECT_EQ(status, FireboltSDKErrorNone); + if (status != FireboltSDKErrorNone) { + FIREBOLT_LOG_ERROR(Logger::Category::OpenRPC, Logger::Module(), + "Set %s status = %d", eventName.c_str(), status); + } else { + FIREBOLT_LOG_INFO(Logger::Category::OpenRPC, Logger::Module(), + "%s Yes registered successfully, Waiting for event...", __func__); + + eventControl->WaitForEvent(WPEFramework::Core::infinite); + } + + EXPECT_EQ(Properties::Unsubscribe(eventName, reinterpret_cast(NotifyEvent)), FireboltSDKErrorNone); + delete eventControl; + + return status; + } + + /* static */ uint32_t Tests::SubscribeEventwithSameCallback() + { + FireboltSDK::Tests::EventControl* eventControl = new FireboltSDK::Tests::EventControl("EventControl"); + const string eventName = _T("device.Name"); + const void* userdata = static_cast(eventControl); eventControl->ResetEvent(); - uint32_t status = Properties::Subscribe(eventName, deviceNameChangeCallback, userdata, id); + + JsonObject jsonParameters; + uint32_t status = Properties::Subscribe(eventName, jsonParameters, deviceNameChangeCallback,reinterpret_cast(NotifyEvent), userdata); EXPECT_EQ(status, FireboltSDKErrorNone); if (status != FireboltSDKErrorNone) { @@ -174,40 +213,71 @@ namespace FireboltSDK { } else { FIREBOLT_LOG_INFO(Logger::Category::OpenRPC, Logger::Module(), "%s Yes registered successfully", __func__); - eventControl->WaitForEvent(WPEFramework::Core::infinite); + + status = Properties::Subscribe(eventName, jsonParameters, deviceNameChangeCallback, reinterpret_cast(NotifyEvent), userdata); + EXPECT_EQ(status, FireboltSDKErrorInUse); + if (status == FireboltSDKErrorInUse) { + FIREBOLT_LOG_INFO(Logger::Category::OpenRPC, Logger::Module(), + "%s Yes this device.name event is already registered with same callback", __func__); + } + status = ((status == FireboltSDKErrorInUse) ? FireboltSDKErrorNone : status); } - EXPECT_EQ(Properties::Unsubscribe(eventName, id), FireboltSDKErrorNone); + EXPECT_EQ(Properties::Unsubscribe(eventName, reinterpret_cast(NotifyEvent)), FireboltSDKErrorNone); delete eventControl; return status; } + + static void NotifyEvent1(const void* userData, const char* data) + { + FIREBOLT_LOG_INFO(Logger::Category::OpenRPC, Logger::Module(), + "NotifyEvent1 data : %s", data); + if (userData) { + FIREBOLT_LOG_INFO(Logger::Category::OpenRPC, Logger::Module(), + "NotifyEvent1 userData : %s\n", reinterpret_cast(userData)->Name().c_str()); + } + } + static void NotifyEvent2(const void* userData, const char* data) + { + FIREBOLT_LOG_INFO(Logger::Category::OpenRPC, Logger::Module(), + "NotifyEvent2 data : %s", data); + if (userData) { + FIREBOLT_LOG_INFO(Logger::Category::OpenRPC, Logger::Module(), + "NotifyEvent2 userData : %s\n", reinterpret_cast(userData)->Name().c_str()); + } + } + template - /* static */ uint32_t Tests::SubscribeEventForC(const string& eventName, CALLBACK& callbackFunc, const void* userdata, uint32_t& id) + /* static */ uint32_t Tests::SubscribeEventForC(const string& eventName, JsonObject& jsonParameters, CALLBACK& callbackFunc, void* usercb, const void* userdata) { - return Properties::Subscribe(eventName, callbackFunc, userdata, id);; + return Properties::Subscribe(eventName, jsonParameters, callbackFunc, usercb, userdata); } - static void deviceNameChangeMultipleCallback(const void* userData, void* response) + static void deviceNameChangeMultipleCallback(void* userCB, const void* userData, void* response) { - WPEFramework::Core::ProxyType& jsonResponse = *(static_cast*>(response)); + WPEFramework::Core::ProxyType& jsonResponse = *(reinterpret_cast*>(response)); FIREBOLT_LOG_INFO(Logger::Category::OpenRPC, Logger::Module(), "Received a new event from deviceNameChangeMultipleCallback: %s", jsonResponse->Value().c_str()); - jsonResponse.Release(); FireboltSDK::Tests::EventControl* eventControl = reinterpret_cast(const_cast(userData)); + OnNotifyDeviceNameChanged notifyDeviceNameChanged = reinterpret_cast(userCB); + notifyDeviceNameChanged(userData, jsonResponse->Value().c_str()); + eventControl->NotifyEvent(); + jsonResponse.Release(); } /* static */ uint32_t Tests::SubscribeEventWithMultipleCallback() { - FireboltSDK::Tests::EventControl* eventControl1 = new FireboltSDK::Tests::EventControl(); + FireboltSDK::Tests::EventControl* eventControl1 = new FireboltSDK::Tests::EventControl("EventControl1"); const string eventName = _T("device.Name"); const void* userdata = static_cast(eventControl1); - uint32_t id1 = 0, id2 = 0; eventControl1->ResetEvent(); - uint32_t status = Properties::Subscribe(eventName, deviceNameChangeCallback, userdata, id1); + + JsonObject jsonParameters; + uint32_t status = Properties::Subscribe(eventName, jsonParameters, deviceNameChangeMultipleCallback, reinterpret_cast(NotifyEvent1), userdata); EXPECT_EQ(status, FireboltSDKErrorNone); if (status != FireboltSDKErrorNone) { @@ -215,28 +285,33 @@ namespace FireboltSDK { "Set %s status = %d", eventName.c_str(), status); } else { FIREBOLT_LOG_INFO(Logger::Category::OpenRPC, Logger::Module(), - "%s Yes registered successfully", __func__); + "%s Yes registered successfully, Waiting for event...", __func__); } if (status == FireboltSDKErrorNone) { - FireboltSDK::Tests::EventControl* eventControl2 = new FireboltSDK::Tests::EventControl(); + FireboltSDK::Tests::EventControl* eventControl2 = new FireboltSDK::Tests::EventControl("EventControl2"); userdata = static_cast(eventControl2); - status = Properties::Subscribe(eventName, deviceNameChangeMultipleCallback, userdata, id2); + status = Properties::Subscribe(eventName, jsonParameters, deviceNameChangeMultipleCallback, reinterpret_cast(NotifyEvent2), userdata); EXPECT_EQ(status, FireboltSDKErrorNone); if (status != FireboltSDKErrorNone) { FIREBOLT_LOG_ERROR(Logger::Category::OpenRPC, Logger::Module(), "Set %s status = %d", eventName.c_str(), status); } else { + status = Properties::Subscribe(eventName, jsonParameters, deviceNameChangeMultipleCallback, reinterpret_cast(NotifyEvent2), userdata); + EXPECT_EQ(status, FireboltSDKErrorInUse); + status = ((status == FireboltSDKErrorInUse) ? FireboltSDKErrorNone : status); + FIREBOLT_LOG_INFO(Logger::Category::OpenRPC, Logger::Module(), - "%s Yes registered second callback also successfully", __func__); + "%s Yes registered second callback also successfully, waiting for events...\n", __func__); + eventControl1->WaitForEvent(WPEFramework::Core::infinite); eventControl2->WaitForEvent(WPEFramework::Core::infinite); } - EXPECT_EQ(Properties::Unsubscribe(eventName, id1), FireboltSDKErrorNone); + EXPECT_EQ(Properties::Unsubscribe(eventName, reinterpret_cast(NotifyEvent2)), FireboltSDKErrorNone); delete eventControl2; } - EXPECT_EQ(Properties::Unsubscribe(eventName, id2), FireboltSDKErrorNone); + EXPECT_EQ(Properties::Unsubscribe(eventName, reinterpret_cast(NotifyEvent1)), FireboltSDKErrorNone); delete eventControl1; return status; @@ -248,12 +323,21 @@ namespace FireboltSDK { extern "C" { #endif -uint32_t test_firebolt_create_instance() +void test_firebolt_create_instance() { - FireboltSDK::Accessor::Instance(); + const std::string config = _T("{\ + \"waitTime\": 1000,\ + \"logLevel\": \"Info\",\ + \"workerPool\":{\ + \"queueSize\": 8,\ + \"threadCount\": 3\ + },\ + \"wsUrl\": \"ws://127.0.0.1:9998\"\ +}"); + FireboltSDK::Accessor::Instance(config); } -uint32_t test_firebolt_dispose_instance() +void test_firebolt_dispose_instance() { FireboltSDK::Accessor::Dispose(); } @@ -297,28 +381,27 @@ uint32_t test_properties_set() return status; } -static void deviceNameChangeCallbackForC(const void* userData, void* response) +static void deviceNameChangeCallbackForC(void* userCB, const void* userData, void* response) { - WPEFramework::Core::ProxyType& jsonResponse = *(static_cast*>(response)); + WPEFramework::Core::ProxyType& jsonResponse = *(reinterpret_cast*>(response)); FIREBOLT_LOG_INFO(FireboltSDK::Logger::Category::OpenRPC, "ctest", "Received a new event--->: %s", jsonResponse->Value().c_str()); - jsonResponse.Release(); FireboltSDK::Tests::EventControl* eventControl = reinterpret_cast(const_cast(userData)); eventControl->NotifyEvent(); + jsonResponse.Release(); } uint32_t test_eventregister() { FireboltSDK::Tests::EventControl* eventControl = new FireboltSDK::Tests::EventControl(); - JsonObject parameters; - const string eventName = _T("device.Name"); const void* userdata = static_cast(eventControl); - uint32_t id = 0; eventControl->ResetEvent(); - uint32_t status = FireboltSDK::Properties::Subscribe(eventName, deviceNameChangeCallbackForC, userdata, id); + + JsonObject jsonParameters; + uint32_t status = FireboltSDK::Properties::Subscribe(eventName, jsonParameters, deviceNameChangeCallbackForC, reinterpret_cast(NotifyEvent), userdata); EXPECT_EQ(status, FireboltSDKErrorNone); if (status != FireboltSDKErrorNone) { @@ -326,26 +409,60 @@ uint32_t test_eventregister() "%s Set %s status = %d", __func__, eventName.c_str(), status); } else { FIREBOLT_LOG_INFO(FireboltSDK::Logger::Category::OpenRPC, "ctest", - "%s Yes registered successfully", __func__); + "%s Yes registered successfully, Waiting for event...", __func__); eventControl->WaitForEvent(WPEFramework::Core::infinite); } delete eventControl; - EXPECT_EQ(FireboltSDK::Properties::Unsubscribe(eventName, id), FireboltSDKErrorNone); + EXPECT_EQ(FireboltSDK::Properties::Unsubscribe(eventName, reinterpret_cast(NotifyEvent)), FireboltSDKErrorNone); return status; } +uint32_t test_eventregister_with_same_callback() +{ + FireboltSDK::Tests::EventControl* eventControl = new FireboltSDK::Tests::EventControl(); + const string eventName = _T("device.Name"); + const void* userdata = static_cast(eventControl); + + eventControl->ResetEvent(); + + JsonObject jsonParameters; + uint32_t status = FireboltSDK::Properties::Subscribe(eventName, jsonParameters, deviceNameChangeCallbackForC, reinterpret_cast(NotifyEvent), userdata); + + EXPECT_EQ(status, FireboltSDKErrorNone); + if (status != FireboltSDKErrorNone) { + FIREBOLT_LOG_ERROR(FireboltSDK::Logger::Category::OpenRPC, "ctest", + "%s Set %s status = %d", __func__, eventName.c_str(), status); + } else { + FIREBOLT_LOG_INFO(FireboltSDK::Logger::Category::OpenRPC, "ctest", + "%s Yes registered successfully", __func__); + + status = FireboltSDK::Properties::Subscribe(eventName, jsonParameters, deviceNameChangeCallbackForC, reinterpret_cast(NotifyEvent), userdata); + EXPECT_EQ(status, FireboltSDKErrorInUse); + if (status == FireboltSDKErrorInUse) { + FIREBOLT_LOG_INFO(FireboltSDK::Logger::Category::OpenRPC, "ctest", + "%s Yes this device.name event is already registered with same callback", __func__); + } + status = ((status == FireboltSDKErrorInUse) ? FireboltSDKErrorNone : status); + } + + delete eventControl; + EXPECT_EQ(FireboltSDK::Properties::Unsubscribe(eventName, reinterpret_cast(NotifyEvent)), FireboltSDKErrorNone); + + return status; +} uint32_t test_eventregister_by_providing_callback() { FireboltSDK::Tests::EventControl* eventControl = new FireboltSDK::Tests::EventControl(); const string eventName = _T("device.Name"); const void* userdata = static_cast(eventControl); - uint32_t id = 0; eventControl->ResetEvent(); - uint32_t status = FireboltSDK::Tests::SubscribeEventForC(eventName, deviceNameChangeCallbackForC, userdata, id); + + JsonObject jsonParameters; + uint32_t status = FireboltSDK::Tests::SubscribeEventForC(eventName, jsonParameters, deviceNameChangeCallbackForC, reinterpret_cast(NotifyEvent), userdata); EXPECT_EQ(status, FireboltSDKErrorNone); if (status != FireboltSDKErrorNone) { @@ -353,20 +470,22 @@ uint32_t test_eventregister_by_providing_callback() "%s Set %s status = %d", __func__, eventName.c_str(), status); } else { FIREBOLT_LOG_INFO(FireboltSDK::Logger::Category::OpenRPC, "ctest", - "%s Yes registered successfully", __func__); + "%s Yes registered successfully, Waiting for event...", __func__); eventControl->WaitForEvent(WPEFramework::Core::infinite); } delete eventControl; - EXPECT_EQ(FireboltSDK::Properties::Unsubscribe(eventName, id), FireboltSDKErrorNone); + EXPECT_EQ(FireboltSDK::Properties::Unsubscribe(eventName, reinterpret_cast(NotifyEvent)), FireboltSDKErrorNone); + return status; } #include "TypesPriv.h" uint32_t test_string_set_get_value() { uint32_t status = FireboltSDKErrorNone; - FireboltSDK::String* str = new FireboltSDK::String("testString"); - void* handle = static_cast(str); + FireboltSDK::JSON::String* str = new FireboltSDK::JSON::String(); + WPEFramework::Core::JSON::String wpeJsonStr("TestString"); + FireboltTypes_String_t handle = reinterpret_cast(str); const char* value = FireboltTypes_String(handle); EXPECT_EQ(strncmp(value, str->Value().c_str(), str->Value().length()), 0); diff --git a/languages/c/templates/sdk/test/OpenRPCTests.h b/languages/c/templates/sdk/test/OpenRPCTests.h index 00abd364..e82665d0 100644 --- a/languages/c/templates/sdk/test/OpenRPCTests.h +++ b/languages/c/templates/sdk/test/OpenRPCTests.h @@ -18,8 +18,15 @@ #pragma once +#include "FireboltSDK.h" #include "TestUtils.h" -#include "Firebolt.h" + +typedef enum { + Test1, + Test2, + Test3, + Test4 +} TestEnum; namespace FireboltSDK { typedef uint32_t (*Func)(); @@ -30,6 +37,12 @@ namespace FireboltSDK { public: EventControl() : _event(false, true) + , _name("EventControl") + { + } + EventControl(string name) + : _event(false, true) + , _name(name) { } ~EventControl() = default; @@ -47,8 +60,13 @@ namespace FireboltSDK { { _event.ResetEvent(); } + string Name() const + { + return _name; + } private: WPEFramework::Core::Event _event; + string _name; }; private: @@ -84,10 +102,11 @@ namespace FireboltSDK { static uint32_t SetUnKnownMethod(); static uint32_t SubscribeEvent(); + static uint32_t SubscribeEventwithSameCallback(); static uint32_t SubscribeEventWithMultipleCallback(); template - static uint32_t SubscribeEventForC(const string& eventName, CALLBACK& callbackFunc, const void* userdata, uint32_t& id); + static uint32_t SubscribeEventForC(const string& eventName, JsonObject& jsonParameters, CALLBACK& callbackFunc, void* usercb, const void* userdata); protected: static void PrintJsonObject(const JsonObject::Iterator& iterator); diff --git a/languages/c/templates/sdk/test/TestUtils.h b/languages/c/templates/sdk/test/TestUtils.h index 8c3cb732..c54db9f0 100644 --- a/languages/c/templates/sdk/test/TestUtils.h +++ b/languages/c/templates/sdk/test/TestUtils.h @@ -1,5 +1,5 @@ -#ifndef _TEST_UTILS_H -#define _TEST_UTILS_H +#ifndef TEST_UTILS_H +#define TEST_UTILS_H #include #include @@ -8,8 +8,8 @@ #define MAX(x, y) (((x) > (y)) ? (x) : (y)) #define MIN(x, y) (((x) < (y)) ? (x) : (y)) -#define _RESULT(expr, exprorig, result) if (expr) { printf(" SUCCESS: %s\n", #exprorig); __pass++; } else printf(" FAILED: %s, actual: %u\n", #exprorig, result) -#define _EVAL(result, expected, op) do { __cnt++; uint32_t resval = ((uint32_t)(result)); uint32_t expval = ((uint32_t)(expected)); _RESULT(resval op expval, result op expected, resval); } while(0) +#define _RESULT(expr, exprorig, result) if (expr) { printf("TestStatus: SUCCESS: %s\n", #exprorig); __pass++; } else printf("TestStatus: FAILED: %s, actual: %lu\n", #exprorig, result) +#define _EVAL(result, expected, op) do { __cnt++; long resval = ((long)(result)); long expval = ((long)(expected)); _RESULT(resval op expval, result op expected, resval); } while(0) #define _HEAD(name) printf("\n======== %s\n", name); __cnt = 0; __pass = 0 #define _FOOT(name) printf("\n======== %s - %i PASSED, %i FAILED\n", name, __pass, (__cnt - __pass)); TotalTests += __cnt; TotalTestsPassed += __pass; @@ -35,4 +35,4 @@ extern int TotalTestsPassed; } #endif -#endif // _TEST_UTILS_H +#endif // TEST_UTILS_H diff --git a/languages/c/templates/types/enum.cpp b/languages/c/templates/types/enum.cpp index ddda2ae9..9c98f888 100644 --- a/languages/c/templates/types/enum.cpp +++ b/languages/c/templates/types/enum.cpp @@ -1,4 +1,4 @@ /* ${title} ${description} */ - ENUM_CONVERSION_BEGIN(${info.title}_${name}) + ENUM_CONVERSION_BEGIN(${info.Title}_${name}) { ${info.TITLE}_${NAME}_${key}, _T("${value}") }, - ENUM_CONVERSION_END(${info.title}_${name}) + ENUM_CONVERSION_END(${info.Title}_${name}) diff --git a/languages/c/templates/types/enum.h b/languages/c/templates/types/enum.h index 6926fa77..906d908d 100644 --- a/languages/c/templates/types/enum.h +++ b/languages/c/templates/types/enum.h @@ -1,4 +1,4 @@ /* ${title} ${description} */ typedef enum { ${info.TITLE}_${NAME}_${key}, -} ${info.title}_${name}; +} ${info.Title}_${name}; diff --git a/src/macrofier/engine.mjs b/src/macrofier/engine.mjs index 18091b7e..6352dab3 100644 --- a/src/macrofier/engine.mjs +++ b/src/macrofier/engine.mjs @@ -506,6 +506,8 @@ const insertMacros = (fContents = '', macros = {}) => { fContents = fContents.replace(/\$\{minor\}/g, macros.version.minor) fContents = fContents.replace(/\$\{patch\}/g, macros.version.patch) fContents = fContents.replace(/\$\{info\.title\}/g, macros.title) + fContents = fContents.replace(/\$\{module\.title\}/g, macros.title.toLowerCase()) + fContents = fContents.replace(/\$\{info\.Title\}/g, capitalize(macros.title)) fContents = fContents.replace(/\$\{info\.TITLE\}/g, macros.title.toUpperCase()) fContents = fContents.replace(/\$\{info\.description\}/g, macros.description) fContents = fContents.replace(/\$\{info\.version\}/g, macros.version.readable) diff --git a/src/macrofier/index.mjs b/src/macrofier/index.mjs index 3db5d17a..dc5f30e8 100644 --- a/src/macrofier/index.mjs +++ b/src/macrofier/index.mjs @@ -167,7 +167,7 @@ const macrofy = async ( content = engine.insertMacros(content, macros) content = engine.insertAggregateMacros(content, aggregateMacros) - const location = createModuleDirectories ? path.join(output, module.info.title, t) : path.join(output, t.replace(/Module/, module.info.title).replace(/index/, module.info.title)) + const location = createModuleDirectories ? path.join(output, module.info.title, t) : path.join(output, t.replace(/module/, module.info.title.toLowerCase()).replace(/index/, module.info.title)) outputFiles[location] = content logSuccess(`Generated macros for module ${path.relative(output, location)}`) @@ -262,7 +262,7 @@ const macrofy = async ( // NOTE: whichever insert is called first also needs to be called again last, so each phase can insert recursive macros from the other content = engine.insertMacros(content, macros) - const location = createModuleDirectories ? path.join(output, document.info.title, t) : path.join(output, t.replace(/Module/, document.info.title).replace(/index/, document.info.title)) + const location = createModuleDirectories ? path.join(output, document.info.title, t) : path.join(output, t.replace(/module/, document.info.title.toLowerCase()).replace(/index/, document.info.title)) outputFiles[location] = content logSuccess(`Generated macros for schema ${path.relative(output, location)}`)