Skip to content

Commit

Permalink
cleanup changes, add separator between prefix and subSchema name gene…
Browse files Browse the repository at this point in the history
…ration
  • Loading branch information
HaseenaSainul committed Jul 25, 2023
1 parent 02d19ad commit f607e16
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 38 deletions.
10 changes: 5 additions & 5 deletions languages/c/Types.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

import deepmerge from 'deepmerge'
import { getPath } from '../../src/shared/json-schema.mjs'
import { getTypeName, getModuleName, description, getObjectHandleManagement, getNativeType, getPropertyAccessors, capitalize, isOptional, generateEnum, getMapAccessors, getArrayAccessors, 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 { getTypeName, getModuleName, description, getObjectManagement, getNativeType, getPropertyAccessors, capitalize, isOptional, generateEnum, getMapAccessors, getArrayAccessors, getPropertyGetterSignature, getPropertyEventCallbackSignature, getPropertyEventRegisterSignature, getPropertyEventUnregisterSignature, getPropertySetterSignature, getFireboltStringType } from './src/types/NativeHelpers.mjs'
import { getArrayAccessorsImpl, getMapAccessorsImpl, getObjectManagementImpl, getParameterInstantiation, getPropertyAccessorsImpl, getResultInstantiation, getCallbackParametersInstantiation, getCallbackResultInstantiation, getCallbackResponseInstantiation } from './src/types/ImplHelpers.mjs'
import { getJsonContainerDefinition, getJsonDataStructName, getJsonDataPrefix } from './src/types/JSONHelpers.mjs'

const getSdkNameSpace = () => 'FireboltSDK'
Expand Down Expand Up @@ -407,7 +407,7 @@ function getSchemaShapeInfo(json, module, schemas = {}, { name = '', prefix = ''
let c_shape = description(capitalize(name), json.description)
let cpp_shape = ''
let tName = getTypeName(getModuleName(module), name, prefix)
c_shape += '\n' + (isHeader ? getObjectHandleManagement(tName) : getObjectHandleManagementImpl(tName, getJsonType(json, module, { name })))
c_shape += '\n' + (isHeader ? getObjectManagement(tName) : getObjectManagementImpl(tName, getJsonType(json, module, { name })))
let props = []
let containerName = ((prefix.length > 0) && (!name.startsWith(prefix))) ? (prefix + '_' + capitalize(name)) : capitalize(name)
Object.entries(json.properties).forEach(([pname, prop]) => {
Expand Down Expand Up @@ -489,7 +489,7 @@ function getSchemaShapeInfo(json, module, schemas = {}, { name = '', prefix = ''
// Handle Container generation here
}

t += '\n' + (isHeader ? getObjectHandleManagement(tName) : getObjectHandleManagementImpl(tName, containerType))
t += '\n' + (isHeader ? getObjectManagement(tName) : getObjectManagementImpl(tName, containerType))
t += (isHeader ? getMapAccessors(tName, info.type, { descriptions: descriptions, level: level }) : getMapAccessorsImpl(tName, containerType, subModuleProperty.type, info.type, info.json, { readonly: true, optional: false }))
shape += '\n' + t
}
Expand Down Expand Up @@ -545,7 +545,7 @@ function getSchemaShapeInfo(json, module, schemas = {}, { name = '', prefix = ''
let t = ''
if (level === 0) {
t += description(capitalize(info.name), json.description) + '\n'
t += '\n' + (isHeader ? getObjectHandleManagement(tName) : getObjectHandleManagementImpl(tName, moduleProperty.type))
t += '\n' + (isHeader ? getObjectManagement(tName) : getObjectManagementImpl(tName, moduleProperty.type))
}
t += '\n' + (isHeader ? getArrayAccessors(objName, tName, info.type) : getArrayAccessorsImpl(objName, moduleProperty.type, (tName + '_t'), subModuleProperty.type, '', info.type, info.json))
shape += '\n' + t
Expand Down
6 changes: 3 additions & 3 deletions languages/c/src/shared/include/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
extern "C" {
#endif

typedef struct FireboltTypes_String_s* FireboltTypes_String_t;
const char* FireboltTypes_String(FireboltTypes_String_t handle);
void FireboltTypes_StringHandle_Release(FireboltTypes_String_t handle);
typedef struct Firebolt_String_s* Firebolt_String_t;
const char* Firebolt_String(Firebolt_String_t handle);
void Firebolt_String_Release(Firebolt_String_t handle);

#ifdef __cplusplus
}
Expand Down
4 changes: 2 additions & 2 deletions languages/c/src/shared/src/Types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ extern "C" {
#endif

// String Type Handler Interfaces
const char* FireboltTypes_String(FireboltTypes_String_t handle)
const char* Firebolt_String(Firebolt_String_t handle)
{
return ((reinterpret_cast<FireboltSDK::JSON::String*>(handle))->Value().c_str());
}

void FireboltTypes_StringHandle_Release(FireboltTypes_String_t handle)
void Firebolt_String_Release(Firebolt_String_t handle)
{
delete reinterpret_cast<FireboltSDK::JSON::String*>(handle);
}
Expand Down
6 changes: 3 additions & 3 deletions languages/c/src/shared/test/OpenRPCTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -485,17 +485,17 @@ uint32_t test_string_set_get_value()
uint32_t status = FireboltSDKErrorNone;
FireboltSDK::JSON::String* str = new FireboltSDK::JSON::String();
WPEFramework::Core::JSON::String wpeJsonStr("TestString");
FireboltTypes_String_t handle = reinterpret_cast<FireboltTypes_String_t>(str);
Firebolt_String_t handle = reinterpret_cast<Firebolt_String_t>(str);

const char* value = FireboltTypes_String(handle);
const char* value = Firebolt_String(handle);
EXPECT_EQ(strncmp(value, str->Value().c_str(), str->Value().length()), 0);
FIREBOLT_LOG_INFO(FireboltSDK::Logger::Category::OpenRPC, "ctest",
" ---> type name = %s %s", str->Value().c_str(), value);

WPEFramework::Core::JSON::EnumType<::TestEnum> testEnum = Test4;
FIREBOLT_LOG_INFO(FireboltSDK::Logger::Category::OpenRPC, "ctest",
" EnumTest = %d %s", testEnum.Value(), testEnum.Data());
FireboltTypes_StringHandle_Release(handle);
Firebolt_String_Release(handle);
return status;
}

Expand Down
30 changes: 15 additions & 15 deletions languages/c/src/types/ImplHelpers.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@ const getSdkNameSpace = () => 'FireboltSDK'
const wpeJsonNameSpace = () => 'WPEFramework::Core::JSON'
const camelcase = str => str[0].toLowerCase() + str.substr(1)

const getObjectHandleManagementImpl = (varName, jsonDataName) => {
const getObjectManagementImpl = (varName, jsonDataName) => {

let result = `${varName}_t ${varName}Handle_Acquire(void)
let result = `${varName}_t ${varName}_Acquire(void)
{
WPEFramework::Core::ProxyType<${jsonDataName}>* type = new WPEFramework::Core::ProxyType<${jsonDataName}>();
*type = WPEFramework::Core::ProxyType<${jsonDataName}>::Create();
return (reinterpret_cast<${varName}_t>(type));
}
void ${varName}Handle_Addref(${varName}_t handle)
void ${varName}_Addref(${varName}_t handle)
{
ASSERT(handle != NULL);
WPEFramework::Core::ProxyType<${jsonDataName}>* var = reinterpret_cast<WPEFramework::Core::ProxyType<${jsonDataName}>*>(handle);
ASSERT(var->IsValid());
var->AddRef();
}
void ${varName}Handle_Release(${varName}_t handle)
void ${varName}_Release(${varName}_t handle)
{
ASSERT(handle != NULL);
WPEFramework::Core::ProxyType<${jsonDataName}>* var = reinterpret_cast<WPEFramework::Core::ProxyType<${jsonDataName}>*>(handle);
Expand All @@ -30,7 +30,7 @@ void ${varName}Handle_Release(${varName}_t handle)
delete var;
}
}
bool ${varName}Handle_IsValid(${varName}_t handle)
bool ${varName}_IsValid(${varName}_t handle)
{
ASSERT(handle != NULL);
WPEFramework::Core::ProxyType<${jsonDataName}>* var = reinterpret_cast<WPEFramework::Core::ProxyType<${jsonDataName}>*>(handle);
Expand Down Expand Up @@ -101,7 +101,7 @@ const getPropertyAccessorsImpl = (objName, modulePropertyType, subPropertyType,

return result
}
const getArrayAccessorsImpl = (objName, modulePropertyType, objHandleType, subPropertyType, subPropertyName, accessorPropertyType, json = {}) => {
const getArrayAccessorsImpl = (objName, modulePropertyType, objType, subPropertyType, subPropertyName, accessorPropertyType, json = {}) => {

let propertyName
if (subPropertyName) {
Expand All @@ -112,15 +112,15 @@ const getArrayAccessorsImpl = (objName, modulePropertyType, objHandleType, subPr
propertyName = '(*(*var))'
}

let result = `uint32_t ${objName}Array_Size(${objHandleType} handle) {
let result = `uint32_t ${objName}Array_Size(${objType} handle) {
ASSERT(handle != NULL);
WPEFramework::Core::ProxyType<${modulePropertyType}>* var = reinterpret_cast<WPEFramework::Core::ProxyType<${modulePropertyType}>*>(handle);
ASSERT(var->IsValid());
return (${propertyName}.Length());
}` + '\n'

result += `${accessorPropertyType} ${objName}Array_Get(${objHandleType} handle, uint32_t index)
result += `${accessorPropertyType} ${objName}Array_Get(${objType} handle, uint32_t index)
{
ASSERT(handle != NULL);
WPEFramework::Core::ProxyType<${modulePropertyType}>* var = reinterpret_cast<WPEFramework::Core::ProxyType<${modulePropertyType}>*>(handle);
Expand All @@ -144,7 +144,7 @@ const getArrayAccessorsImpl = (objName, modulePropertyType, objHandleType, subPr
result += `}` + '\n'

let type = (accessorPropertyType === getFireboltStringType()) ? 'char*' : accessorPropertyType
result += `void ${objName}Array_Add(${objHandleType} handle, ${type} value)
result += `void ${objName}Array_Add(${objType} handle, ${type} value)
{
ASSERT(handle != NULL);
WPEFramework::Core::ProxyType<${modulePropertyType}>* var = reinterpret_cast<WPEFramework::Core::ProxyType<${modulePropertyType}>*>(handle);
Expand All @@ -162,7 +162,7 @@ const getArrayAccessorsImpl = (objName, modulePropertyType, objHandleType, subPr
${propertyName}.Add() = element;
}` + '\n'

result += `void ${objName}Array_Clear(${objHandleType} handle)
result += `void ${objName}Array_Clear(${objType} handle)
{
ASSERT(handle != NULL);
WPEFramework::Core::ProxyType<${modulePropertyType}>* var = reinterpret_cast<WPEFramework::Core::ProxyType<${modulePropertyType}>*>(handle);
Expand Down Expand Up @@ -304,7 +304,7 @@ function getParameterInstantiation(paramList, container = '') {
const name = param.name
if (jsonType.length) {
if (param.required) {
if (param.nativeType.includes('FireboltTypes_String_t')) {
if (param.nativeType.includes('Firebolt_String_t')) {
impl += ` WPEFramework::Core::JSON::Variant ${capitalize(name)} = *(reinterpret_cast<${jsonType}*>(${name}));\n`
}
else if (param.nativeType.includes('_t')) {
Expand Down Expand Up @@ -429,7 +429,7 @@ function getCallbackParametersInstantiation(paramList, container = '') {

function getCallbackResultInstantiation(nativeType, container = '') {
let impl = ''
if (nativeType === 'char*' || nativeType === 'FireboltTypes_String_t') {
if (nativeType === 'char*' || nativeType === 'Firebolt_String_t') {
impl +=`
${container}* jsonStrResponse = new ${container}();
*jsonStrResponse = *(*jsonResponse);
Expand Down Expand Up @@ -457,7 +457,7 @@ function getCallbackResponseInstantiation(paramList, nativeType, container = '')
})
}

if (nativeType === 'char*' || nativeType === 'FireboltTypes_String_t') {
if (nativeType === 'char*' || nativeType === 'Firebolt_String_t') {
impl += `reinterpret_cast<${nativeType}>(jsonStrResponse)`
}
else if (nativeType.includes('_t')) {
Expand All @@ -476,7 +476,7 @@ function getResultInstantiation (name, nativeType, container, indentLevel = 3) {

if (nativeType) {
impl += `${' '.repeat(indentLevel)}if (${name} != nullptr) {` + '\n'
if (nativeType === 'char*' || nativeType === 'FireboltTypes_String_t') {
if (nativeType === 'char*' || nativeType === 'Firebolt_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')) {
Expand All @@ -500,7 +500,7 @@ function getResultInstantiation (name, nativeType, container, indentLevel = 3) {
export {
getArrayAccessorsImpl,
getMapAccessorsImpl,
getObjectHandleManagementImpl,
getObjectManagementImpl,
getPropertyAccessorsImpl,
getParameterInstantiation,
getCallbackParametersInstantiation,
Expand Down
2 changes: 1 addition & 1 deletion languages/c/src/types/JSONHelpers.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const getJsonDataPrefix = () => 'JsonData_'
const wpeJsonNameSpace = () => 'WPEFramework::Core::JSON'

const getJsonDataStructName = (modName, name, prefix = '') => {
let result =((prefix && prefix.length > 0) && (prefix !== name)) ? `${capitalize(modName)}::${getJsonDataPrefix()}${capitalize(prefix)}${capitalize(name)}` : `${capitalize(modName)}::${getJsonDataPrefix()}${capitalize(name)}`
let result =((prefix && prefix.length > 0) && (prefix !== name)) ? `${capitalize(modName)}::${getJsonDataPrefix()}${capitalize(prefix)}_${capitalize(name)}` : `${capitalize(modName)}::${getJsonDataPrefix()}${capitalize(name)}`

return ((result.includes(wpeJsonNameSpace()) === true) ? result : `${getSdkNameSpace()}::${result}`)
}
Expand Down
16 changes: 8 additions & 8 deletions languages/c/src/types/NativeHelpers.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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_String_t'
const getFireboltStringType = () => 'Firebolt_String_t'

const capitalize = str => str[0].toUpperCase() + str.substr(1)
const description = (title, str='') => '/* ' + title + (str.length > 0 ? ' - ' + str : '') + ' */'
Expand Down Expand Up @@ -64,13 +64,13 @@ const getNativeType = (json, fireboltString = false) => {
return type
}

const getObjectHandleManagement = varName => {
const getObjectManagement = varName => {

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);
${varName}_t ${varName}_Acquire(void);
void ${varName}_Addref(${varName}_t handle);
void ${varName}_Release(${varName}_t handle);
bool ${varName}_IsValid(${varName}_t handle);
`
return result
}
Expand Down Expand Up @@ -111,7 +111,7 @@ const getTypeName = (moduleName, varName, prefix = '', upperCase = false, capita
prefix = (prefix !== varName) ? (upperCase ? prefix.toUpperCase() : capitalize(prefix)) : ''
}
prefix = (prefix && prefix.length > 0) ?(upperCase ? prefix.toUpperCase() : capitalize(prefix)) : prefix
let name = (prefix && prefix.length > 0) ? `${mName}_${prefix}${vName}` : `${mName}_${vName}`
let name = (prefix && prefix.length > 0) ? `${mName}_${prefix}_${vName}` : `${mName}_${vName}`
return name
}

Expand Down Expand Up @@ -205,7 +205,7 @@ export {
capitalize,
description,
getTypeName,
getObjectHandleManagement,
getObjectManagement,
getPropertyAccessors,
isOptional,
generateEnum,
Expand Down
2 changes: 1 addition & 1 deletion src/macrofier/engine.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ const addContentDescriptorSubSchema = (descriptor, prefix, obj) => {
else {
let descriptorName = capitalize(descriptor.name)
let prefixName = capitalize(prefix)
title = (prefixName !== descriptorName) ? prefixName + descriptorName : descriptorName
title = (prefixName !== descriptorName) ? prefixName + '_' +descriptorName : descriptorName
if (obj.components.schemas[title]) {
throw 'Generated name `' + title + '` already exists...'
}
Expand Down

0 comments on commit f607e16

Please sign in to comment.