Skip to content

Commit

Permalink
detach setter declaration from property template and add setter templ… (
Browse files Browse the repository at this point in the history
#118)

Detach setter declaration from property template and add setter template, remove unredundant warnings
Cleanup changes, add separator between prefix and subSchema name generation
Introduce excludeDeclarations flag to handle declaration exclusion specific to language
Alignement changes + cleanup + OUT params support added to differentiate method signature parameters
Update in static code
  • Loading branch information
HaseenaSainul committed Aug 11, 2023
1 parent a6eb5df commit f8faf1f
Show file tree
Hide file tree
Showing 29 changed files with 103 additions and 126 deletions.
28 changes: 9 additions & 19 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, 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 @@ -199,11 +199,7 @@ function getMethodSignature(method, module, { destination, isInterface = false }
let paramList = getParamList(method, module)
let resultType = method.result && getSchemaType(method.result.schema, module, { title: true, name: method.result.name, resultSchema: true}) || ''

signature = getPropertyGetterSignature(method, module, resultType, paramList) + ';\n\n'

if (hasTag(method, 'property')) {
signature += getPropertySetterSignature(method, module, resultType, paramList) + ';\n\n'
}
signature = getPropertyGetterSignature(method, module, resultType, paramList) + ';\n'
}
return signature
}
Expand Down Expand Up @@ -408,10 +404,10 @@ function getSchemaShapeInfo(json, module, schemas = {}, { name = '', prefix = ''
shape = ''
}
else if (json.properties && (validJsonObjectProperties(json) === true)) {
let c_shape = description(capitalize(name), json.description)
let c_shape = '\n' + 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 @@ -461,9 +457,6 @@ function getSchemaShapeInfo(json, module, schemas = {}, { name = '', prefix = ''
let property = getJsonType(prop, module, { name : pname, prefix })
props.push({name: `${pname}`, type: `${property}`})
}
else {
console.log(`b. WARNING: Type undetermined for ${name}:${pname}`)
}
}
})

Expand All @@ -488,21 +481,18 @@ function getSchemaShapeInfo(json, module, schemas = {}, { name = '', prefix = ''
}

let tName = getTypeName(getModuleName(module), name, prefix)
let t = description(capitalize(name), json.description) + '\n'
let t = '\n' + description(capitalize(name), json.description)
let containerType = 'WPEFramework::Core::JSON::VariantContainer'

let subModuleProperty = getJsonTypeInfo(module, info.json, info.name, module['x-schemas'])
if (isCPP && ((info.json.type === 'object' && info.json.properties) || info.json.type === 'array')) {
// 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
}
else if (json.patternProperties) {
console.log(`WARNING: patternProperties are not supported by Firebolt(inside getModuleName(module):${name})`)
}
}
else if (json.anyOf) {
if (level > 0) {
Expand Down Expand Up @@ -554,8 +544,8 @@ function getSchemaShapeInfo(json, module, schemas = {}, { name = '', prefix = ''
let subModuleProperty = getJsonTypeInfo(module, j, j.title || name, schemas, 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' + description(capitalize(info.name), json.description)
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
3 changes: 2 additions & 1 deletion languages/c/language.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@
"/src/jsondata_module.h"
],
"persistPermission": true,
"createPolymorphicMethods": true
"createPolymorphicMethods": true,
"excludeDeclarations":true
}
3 changes: 3 additions & 0 deletions languages/c/src/shared/include/firebolt.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
extern "C" {
#endif

#define IN
#define OUT

/**
* @brief Intitialize the Firebolt SDK
*
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
7 changes: 5 additions & 2 deletions languages/c/src/shared/src/Logger/Logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,14 @@ namespace FireboltSDK {
char formattedMsg[Logger::MaxBufSize];
const string time = WPEFramework::Core::Time::Now().ToTimeOnly(true);
const string categoryName = WPEFramework::Core::EnumerateType<Logger::Category>(category).Data();
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat-truncation"
if (categoryName.empty() != true) {
sprintf(formattedMsg, "--->\033[1;32m[%s]:[%s]:[%s][%s:%d](%s)<PID:%d><TID:%ld> : %s\n", time.c_str(), categoryName.c_str(), module.c_str(), WPEFramework::Core::File::FileName(file).c_str(), line, function.c_str(), TRACE_PROCESS_ID, TRACE_THREAD_ID, msg);
snprintf(formattedMsg, sizeof(formattedMsg), "--->\033[1;32m[%s]:[%s]:[%s][%s:%d](%s)<PID:%d><TID:%ld> : %s\n", time.c_str(), categoryName.c_str(), module.c_str(), WPEFramework::Core::File::FileName(file).c_str(), line, function.c_str(), TRACE_PROCESS_ID, TRACE_THREAD_ID, msg);
} else {
sprintf(formattedMsg, "--->\033[1;32m[%s]:[%s][%s:%d](%s)<PID:%d><TID:%ld> : %s\n", time.c_str(), module.c_str(), WPEFramework::Core::File::FileName(file).c_str(), line, function.c_str(), TRACE_PROCESS_ID, TRACE_THREAD_ID, msg);
snprintf(formattedMsg, sizeof(formattedMsg), "--->\033[1;32m[%s]:[%s][%s:%d](%s)<PID:%d><TID:%ld> : %s\n", time.c_str(), module.c_str(), WPEFramework::Core::File::FileName(file).c_str(), line, function.c_str(), TRACE_PROCESS_ID, TRACE_THREAD_ID, msg);
}
#pragma GCC diagnostic pop
LOG_MESSAGE(formattedMsg);
}
}
Expand Down
2 changes: 1 addition & 1 deletion languages/c/src/shared/src/Transport/Transport.h
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ namespace FireboltSDK {

public:
ChannelImpl(CommunicationChannel* parent, const WPEFramework::Core::NodeId& remoteNode, const string& path, const string& query, const bool mask)
: BaseClass(5, FactoryImpl::Instance(), path, _T("JSON"), query, "", false, mask, false, remoteNode.AnyInterface(), remoteNode, 1024 * 2, 1024 * 2) //TODO Relook this size issue
: BaseClass(5, FactoryImpl::Instance(), path, _T("JSON"), query, "", false, mask, false, remoteNode.AnyInterface(), remoteNode, 512, 512)
, _parent(*parent)
{
}
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
32 changes: 16 additions & 16 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 @@ -470,13 +470,13 @@ function getCallbackResponseInstantiation(paramList, nativeType, container = '')
return impl
}

function getResultInstantiation (name, nativeType, container, indentLevel = 3) {
function getResultInstantiation (name, nativeType, container, indentLevel = 2) {

let impl = ''

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
Loading

0 comments on commit f8faf1f

Please sign in to comment.