Skip to content

Commit

Permalink
CPPSDK: parameter/result handling for method and events + inner objec…
Browse files Browse the repository at this point in the history
…t handlings
  • Loading branch information
HaseenaSainul committed Oct 13, 2023
1 parent b7a27f0 commit 9babd2f
Show file tree
Hide file tree
Showing 102 changed files with 159 additions and 98 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
WPEFramework::Core::ProxyType<${method.result.json}>* proxyResponse = reinterpret_cast<WPEFramework::Core::ProxyType<${method.result.json}>*>(jsonResponse);
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
${type}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
response
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
${type}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
${shape}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
${if.namespace.notsame}Firebolt::${info.Title}::${end.if.namespace.notsame}JsonData_${title} elements = (*proxyResponse)->Variants();
${if.namespace.notsame}${info.Title}::${end.if.namespace.notsame}${title} response;
while (elements.Next()) {
response.insert(elements.Label(), elements.Current().${additional.type}.Value());
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
auto index((*proxyResponse)->Elements());
${type} response;
while (index.Next() == true) {
response.push_back(index.Current().Value());
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
${if.namespace.notsame}${info.Title}::${end.if.namespace.notsame}${title} response = (*proxyResponse)->Value();
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
${type} response = (*proxyResponse)->Value();
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
${title} response;
${properties}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
${type}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
${shape} ${if.non.object}response.${property} = (*proxyResponse)->${Property};${end.if.non.object}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
${shape}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
${properties}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
${shape} ${if.non.object}response.${property.dependency}${property} = (*proxyResponse)->${Property.dependency}${Property};${end.if.non.object}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
${shape}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
${Title}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
${Title}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
auto index((*proxyResponse)->Elements());
${if.namespace.notsame}${info.Title}::${end.if.namespace.notsame}${title} response;
response.first = index.Get(0);
response.second = index.Get(1);
1 change: 0 additions & 1 deletion languages/cpp/templates/json-types/additionalProperties.c

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
using ${title} = WPEFramework::Core::JSON::VariantContainer;
1 change: 0 additions & 1 deletion languages/cpp/templates/json-types/anyOf.c

This file was deleted.

1 change: 1 addition & 0 deletions languages/cpp/templates/json-types/anyOf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
WPEFramework::Core::JSON::VariantContainer
1 change: 1 addition & 0 deletions languages/cpp/templates/json-types/anyOfSchemaShape.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* anyOf schema shape is supported right now */
4 changes: 0 additions & 4 deletions languages/cpp/templates/json-types/array.c

This file was deleted.

1 change: 1 addition & 0 deletions languages/cpp/templates/json-types/array.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
WPEFramework::Core::JSON::ArrayType<${json.type}>
File renamed without changes.
5 changes: 1 addition & 4 deletions languages/cpp/templates/json-types/enum.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
/* ${title} ${description} */
ENUM_CONVERSION_BEGIN(${name})
{ ${NAME}_${key}, _T("${value}") },
ENUM_CONVERSION_END(${name})
using JsonData_${type} = WPEFramework::Core::JSON::EnumType<${type}>;
4 changes: 0 additions & 4 deletions languages/cpp/templates/json-types/enum.h

This file was deleted.

1 change: 0 additions & 1 deletion languages/cpp/templates/json-types/namespace.c

This file was deleted.

1 change: 1 addition & 0 deletions languages/cpp/templates/json-types/namespace.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Firebolt::${info.Title}::
File renamed without changes.
8 changes: 4 additions & 4 deletions languages/cpp/templates/json-types/object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@
${title}()
: WPEFramework::Core::JSON::Container()
{
${properties.register}
${properties.register}
}

${title}(const ${title}& other)
{
${properties.assign}
${properties.assign}
}

${title}& operator=(const ${title}& other)
{
${properties.assign}
${properties.assign}
return (*this);
}

public:
${properties}
${properties}
};
Empty file.
1 change: 1 addition & 0 deletions languages/cpp/templates/json-types/primitive.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
${type}
4 changes: 2 additions & 2 deletions languages/cpp/templates/json-types/property-assign.cpp
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Add(_T("${property}"), &${Property});
${Property} = other.${Property}
Add(_T("${property}"), &${Property});
${Property} = other.${Property};
3 changes: 1 addition & 2 deletions languages/cpp/templates/json-types/property-register.cpp
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
Add(_T("${property}"), &${Property});

Add(_T("${property}"), &${Property});
1 change: 1 addition & 0 deletions languages/cpp/templates/json-types/ref.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
${shape}
File renamed without changes.
File renamed without changes.
25 changes: 0 additions & 25 deletions languages/cpp/templates/json-types/tuple.c

This file was deleted.

1 change: 1 addition & 0 deletions languages/cpp/templates/json-types/tuple.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
using ${title} = WPEFramework::Core::JSON::ArrayType<${json.type}>;
Empty file.
File renamed without changes.
File renamed without changes.
7 changes: 7 additions & 0 deletions languages/cpp/templates/parameter-serialization/array.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
WPEFramework::Core::JSON::ArrayType<WPEFramework::Core::JSON::Variant> ${Property};
for (auto& element: ${property}) {
${Property}.Add() = element;
}
WPEFramework::Core::JSON::Variant ${Property}Variant;
${Property}Variant.Array(${Property});
jsonParameters.Set(_T("${property}"), ${Property}Variant);
3 changes: 3 additions & 0 deletions languages/cpp/templates/parameter-serialization/enum.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
${if.namespace.notsame}Firebolt::${info.Title}::${end.if.namespace.notsame}JsonData_${title} jsonValue = ${property};
WPEFramework::Core::JSON::Variant ${Property}(jsonValue.Data());
jsonParameters.Set(_T("${property}"), ${Property});
2 changes: 2 additions & 0 deletions languages/cpp/templates/parameter-serialization/generic.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
WPEFramework::Core::JSON::Variant ${Property}(${property});
jsonParameters.Set(_T("${property}"), ${Property});
7 changes: 6 additions & 1 deletion languages/cpp/templates/parameter-serialization/object.cpp
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
WPEFramework::Core::JSON::Variant ${Property} = ${property};
${if.namespace.notsame}Firebolt::${info.Title}::${end.if.namespace.notsame}JsonData_${title} ${Property}Container;
${properties}
string ${Property}Str;
${Property}Container.ToString(${Property}Str);
WPEFramework::Core::JSON::VariantContainer ${Property}VariantContainer(${Property}Str);
WPEFramework::Core::JSON::Variant ${Property} = ${Property}VariantContainer;
jsonParameters.Set(_T("${property}"), ${Property});
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
WPEFramework::Core::JSON::Variant ${Property} = ${property};
jsonParameters.Set(_T("${property}"), ${Property});
${type}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
${shape} ${if.non.object}${title}.${Property} = ${base.title}.${property};${end.if.non.object}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
${properties}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
${shape} ${if.non.object}${title}.${Property.dependency}${Property} = ${base.title}.${property.dependency}${property};${end.if.non.object}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
${shape}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
${Title}
File renamed without changes.
2 changes: 1 addition & 1 deletion languages/cpp/templates/parameters/optional.h
Original file line number Diff line number Diff line change
@@ -1 +1 @@
std::optional<${method.param.type}> ${method.param.name}
const std::optional<${method.param.type}>& ${method.param.name}
Empty file.
1 change: 0 additions & 1 deletion languages/cpp/templates/parameters/result.h

This file was deleted.

1 change: 1 addition & 0 deletions languages/cpp/templates/result-initialization/boolean.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
${type} ${property} = false;
1 change: 1 addition & 0 deletions languages/cpp/templates/result-initialization/generic.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
${type} ${property};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
${if.namespace.notsame}${parent.Title}::${end.if.namespace.notsame}
1 change: 1 addition & 0 deletions languages/cpp/templates/result-initialization/number.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
${type} ${property} = 0;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
${type}
1 change: 1 addition & 0 deletions languages/cpp/templates/result-initialization/string.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
${type} ${property};
1 change: 1 addition & 0 deletions languages/cpp/templates/result-initialization/title.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
${Title}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
while (jsonResult.Variants().Next()) {
${property}.insert(elements.Label(), elements.Current().${additional.type}.Value());
}
4 changes: 4 additions & 0 deletions languages/cpp/templates/result-instantiation/array.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
auto index(jsonResult.Elements());
while (index.Next() == true) {
${property}.push_back(index.Current().Value());
}
1 change: 1 addition & 0 deletions languages/cpp/templates/result-instantiation/generic.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
${property} = jsonResult.Value();
5 changes: 1 addition & 4 deletions languages/cpp/templates/result-instantiation/object.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
WPEFramework::Core::ProxyType<FireboltSDK::${info.Title}::${title}>* resultPtr = new WPEFramework::Core::ProxyType<FireboltSDK::${info.Title}::${title}>();
*resultPtr = WPEFramework::Core::ProxyType<FireboltSDK::${info.Title}::${title}>::Create();
*(*resultPtr) = jsonResult;
*${property} = static_cast<${info.Title}_${title}>(resultPtr);
${properties}
1 change: 1 addition & 0 deletions languages/cpp/templates/result-instantiation/property.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
${shape} ${if.non.object}${base.title}.${property} = jsonResult.${Property}.Value();${end.if.non.object}
3 changes: 1 addition & 2 deletions languages/cpp/templates/result-instantiation/string.cpp
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
FireboltSDK::JSON::String* strResult = new FireboltSDK::JSON::String(jsonResult);
*value = static_cast<FireboltTypes_StringHandle>(strResult);
${property} = jsonResult.Value().c_str();
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
${properties}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
${shape} ${if.non.object}${base.title}.${property.dependency}${property} = jsonResult.${Property.dependency}${Property};${end.if.non.object}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
${shape}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
${Title}
1 change: 1 addition & 0 deletions languages/cpp/templates/result-instantiation/title.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
${Title}
3 changes: 3 additions & 0 deletions languages/cpp/templates/result-instantiation/tuple.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
auto index(jsonResult.Elements());
${property}.first = index.Get(0);
${property}.second = index.Get(1);
2 changes: 1 addition & 1 deletion languages/cpp/templates/types/additionalProperties.h
Original file line number Diff line number Diff line change
@@ -1 +1 @@
${title} value;
using ${title} = std::unordered_map<${key}, ${type}>;
1 change: 1 addition & 0 deletions languages/cpp/templates/types/additionalPropertiesKey.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
std::string
1 change: 0 additions & 1 deletion languages/cpp/templates/types/anyOf.c

This file was deleted.

1 change: 1 addition & 0 deletions languages/cpp/templates/types/anyOf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
std::string
1 change: 1 addition & 0 deletions languages/cpp/templates/types/anyOfSchemaShape.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* anyOf schema shape is supported right now */
1 change: 1 addition & 0 deletions languages/cpp/templates/types/const.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
std::string
4 changes: 0 additions & 4 deletions languages/cpp/templates/types/default.cpp

This file was deleted.

1 change: 1 addition & 0 deletions languages/cpp/templates/types/default.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
${shape}
1 change: 1 addition & 0 deletions languages/cpp/templates/types/items.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
${title}${delimiter}, ${end.delimiter}
1 change: 1 addition & 0 deletions languages/cpp/templates/types/null.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
void
2 changes: 0 additions & 2 deletions languages/cpp/templates/types/object.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
struct ${title} {

${properties}

};
2 changes: 1 addition & 1 deletion languages/cpp/templates/types/tuple.h
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
/* ${title} */
std::pair<${type},${type}> ${title};
std::pair<${items}> ${title};
11 changes: 6 additions & 5 deletions src/macrofier/engine.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1193,13 +1193,14 @@ function insertMethodMacros(template, methodObj, json, templates, examples = {})
const pullsParamsType = pullsParams ? types.getSchemaShape(pullsParams, json, { destination: state.destination, templateDir: state.typeTemplateDir, section: state.section }) : ''
const serializedParams = flattenedMethod.params.map(param => types.getSchemaShape(param.schema, json, { templateDir: 'parameter-serialization', property: param.name, destination: state.destination, section: state.section, level: 1, skipTitleOnce: true })).join('\n')
const resultInst = types.getSchemaShape(flattenedMethod.result.schema, json, { templateDir: 'result-instantiation', property: flattenedMethod.result.name, destination: state.destination, section: state.section, level: 1, skipTitleOnce: true }) // w/out level: 1, getSchemaShape skips anonymous types, like primitives
const resultInit = types.getSchemaShape(flattenedMethod.result.schema, json, { templateDir: 'result-initialization', property: flattenedMethod.result.name, destination: state.destination, section: state.section, level: 1, skipTitleOnce: true }) // w/out level: 1, getSchemaShape skips anonymous types, like primitives
const serializedEventParams = event ? flattenedMethod.params.filter(p => p.name !== 'listen').map(param => types.getSchemaShape(param.schema, json, {templateDir: 'parameter-serialization', property: param.name, destination: state.destination, section: state.section, level: 1, skipTitleOnce: true })).join('\n') : ''
// this was wrong... check when we merge if it was fixed
const callbackSerializedParams = event ? types.getSchemaShape(event.result.schema, json, { templateDir: 'parameter-serialization', property: result.name, destination: state.destination, section: state.section, level: 1, skipTitleOnce: true }) : ''
const callbackResultInst = event ? types.getSchemaShape(event, json, { name: event.name, templateDir: 'result-instantiation' }) : ''
// const callbackResponseInst = event ? types.getSchemaInstantiation(event, json, event.name, { instantiationType: 'callback.response' }) : ''
const callbackSerializedParams = event ? types.getSchemaShape(event.result.schema, json, { templateDir: 'callback-parameter-serialization', property: result.name, destination: state.destination, section: state.section, level: 1, skipTitleOnce: true }) : ''

const callbackResultInst = event ? types.getSchemaShape(event.result.schema, json, { templateDir: 'callback-result-instantiation', property: result.name, destination: state.destination, section: state.section, level: 1, skipTitleOnce: true }) : ''
// hmm... how is this different from callbackSerializedParams? i guess they get merged?
const callbackResponseInst = event ? types.getSchemaShape(event.result.schema, json, { templateDir: 'parameter-serialization', property: result.name, destination: state.destination, section: state.section, level: 1, skipTitleOnce: true }) : ''
const callbackResponseInst = event ? types.getSchemaShape(event.result.schema, json, { templateDir: 'callback-response-instantiation', property: result.name, destination: state.destination, section: state.section, level: 1, skipTitleOnce: true }) : ''
const resultType = result.schema ? types.getSchemaType(result.schema, json, { name: result.name, templateDir: state.typeTemplateDir }) : ''
const resultJsonType = result.schema ? types.getSchemaType(result.schema, json, { name: result.name, templateDir: 'json-types' }) : ''
const resultParams = generateResultParams(result.schema, json, templates, { name: result.name})
Expand Down Expand Up @@ -1306,7 +1307,7 @@ function insertMethodMacros(template, methodObj, json, templates, examples = {})
.replace(/\$\{method\.pulls\.params.type\}/g, pullsParams ? pullsParams.title : '')
.replace(/\$\{method\.pulls\.params\}/g, pullsParamsType)
.replace(/\$\{method\.pulls\.param\.type\}/g, pullsForParamType)
.replace(/\$\{method\.pulls\.param\.json.type\}/g, pullsForParamJsonType)
.replace(/\$\{method\.pulls\.param\.json\.type\}/g, pullsForParamJsonType)
.replace(/\$\{method\.setter\.for\}/g, setterFor)
.replace(/\$\{method\.puller\}/g, pullerTemplate) // must be last!!
.replace(/\$\{method\.setter\}/g, setterTemplate) // must be last!!
Expand Down
Loading

0 comments on commit 9babd2f

Please sign in to comment.