Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CPPSDK: check jsonrpc response values are set or not before assigning for optional types and fixing alignment issue #157

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion languages/cpp/src/shared/cmake/HelperFunctions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function(InstallHeaders)
if (headers)
install(
DIRECTORY "${source}/${directory}/${subdir}"
DESTINATION include/${dest}
DESTINATION include/${dest}
FILES_MATCHING PATTERN "*.h")
endif()
endif()
Expand Down
2 changes: 1 addition & 1 deletion languages/cpp/src/shared/src/Logger/Logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ namespace FireboltSDK {
static void Log(LogLevel logLevel, Category category, const std::string& module, const std::string file, const std::string function, const uint16_t line, const std::string& format, ...);

public:
template<typename CLASS>
template<typename CLASS>
static const string Module()
{
return WPEFramework::Core::ClassNameOnly(typeid(CLASS).name()).Text();
Expand Down
2 changes: 1 addition & 1 deletion languages/cpp/src/shared/src/Properties/Properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ namespace FireboltSDK {
}


template <typename RESPONSETYPE>
template <typename RESPONSETYPE>
static Firebolt::Error Get(const string& propertyName, RESPONSETYPE& response)
{
Firebolt::Error status = Firebolt::Error::General;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
${if.impl.optional}
${base.title}${property.dependency} = std::make_optional<${type}>();${end.if.impl.optional}
${properties}
${if.impl.optional} ${base.title}${property.dependency} = std::make_optional<${type}>();${end.if.impl.optional}
{
${properties}
}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
${property} = proxyResponse->Value();
${property} = proxyResponse->Value();
Original file line number Diff line number Diff line change
@@ -1 +1 @@
${properties}
${properties}
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
${shape} ${if.non.const}${if.non.anyOf}${if.non.array}${if.non.object}${base.title}.${property} = proxyResponse->${Property};${end.if.non.object}${end.if.non.array}${end.if.non.anyOf}${end.if.non.const}
${shape} ${if.non.const}${if.non.anyOf}${if.non.array}${if.non.object}${if.optional}if (proxyResponse->${Property}.IsSet()) {
${base.title}.${property} = proxyResponse->${Property};
}${end.if.optional}${if.non.optional}${base.title}.${property} = proxyResponse->${Property};${end.if.non.optional}${end.if.non.object}${end.if.non.array}${end.if.non.anyOf}${end.if.non.const}
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
string ${property}Str;
${if.optional}if (proxyResponse->${Property.dependency}${Property}.IsSet()) {
string ${property}Str;
proxyResponse->${Property.dependency}${Property}.ToString(${property}Str);
${base.title}${property.dependency}${if.impl.optional}.value()${end.if.impl.optional}.${property} = ${property}Str;
}${end.if.optional}${if.non.optional}string ${property}Str;
proxyResponse->${Property.dependency}${Property}.ToString(${property}Str);
${base.title}${property.dependency}${if.impl.optional}.value()${end.if.impl.optional}.${property} = ${property}Str;
${base.title}${property.dependency}.${property} = ${property}Str;${end.if.non.optional}
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
${if.impl.array.optional}${base.title}.${property} = std::make_optional<${type}>();${end.if.impl.array.optional}
auto index(proxyResponse->${Property}.Elements());
${if.optional}if (proxyResponse->${Property}.IsSet()) {
${base.title}.${property} = std::make_optional<${type}>();
auto index(proxyResponse->${Property}.Elements());
while (index.Next() == true) {
${if.object}${items.with.indent}${end.if.object}${if.non.object} ${base.title}.${property}.value().push_back(index.Current().Value());${end.if.non.object}
}
}${end.if.optional}${if.non.optional}auto index(proxyResponse->${Property}.Elements());
while (index.Next() == true) {
${if.object}${items.with.indent}${end.if.object}${if.non.object} ${base.title}.${property}${if.impl.array.optional}.value()${end.if.impl.array.optional}.push_back(index.Current().Value());${end.if.non.object}
}
${if.object}${items.with.indent}${end.if.object}${if.non.object} ${base.title}.${property}.value().push_back(index.Current().Value());${end.if.non.object}
}${end.if.non.optional}
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
${base.title}${property.dependency}${if.impl.optional}.value()${end.if.impl.optional}.${property} = proxyResponse->${Property.dependency}${Property};
${if.optional}if (proxyResponse->${Property.dependency}${Property}.IsSet()) {
${base.title}${property.dependency}${if.impl.optional}.value()${end.if.impl.optional}.${property} = proxyResponse->${Property.dependency}${Property};
}${end.if.optional}${if.non.optional}${base.title}${property.dependency}${if.impl.optional}.value()${end.if.impl.optional}.${property} = proxyResponse->${Property.dependency}${Property};${end.if.non.optional}
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
${if.impl.optional}
${base.title}${property.dependency} = std::make_optional<${type}>();${end.if.impl.optional}
${properties}
${if.optional} if (proxyResponse->${Property.dependency}IsSet()) {
${base.title}${property.dependency} = std::make_optional<${type}>();
${properties}
}${end.if.optional}${if.non.optional} {
${properties}
}${end.if.non.optional}
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
${shape} ${if.non.const}${if.non.anyOf}${if.non.array}${if.non.object}${base.title}${property.dependency}${if.impl.optional}.value()${end.if.impl.optional}.${property} = proxyResponse->${Property.dependency}${Property};${end.if.non.object}${end.if.non.array}${end.if.non.anyOf}${end.if.non.const}
${shape} ${if.non.const}${if.non.anyOf}${if.non.array}${if.non.object}${if.optional}if (proxyResponse->${Property.dependency}${Property}.IsSet()) {
${base.title}${property.dependency}${if.impl.optional}.value()${end.if.impl.optional}.${property} = proxyResponse->${Property.dependency}${Property};
}${end.if.optional}${if.non.optional}${base.title}${property.dependency}${if.impl.optional}.value()${end.if.impl.optional}.${property} = proxyResponse->${Property.dependency}${Property};${end.if.non.optional}${end.if.non.object}${end.if.non.array}${end.if.non.anyOf}${end.if.non.const}
10 changes: 5 additions & 5 deletions languages/cpp/templates/codeblocks/interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,25 @@
WPEFramework::Core::JSON::Variant CorrelationId(correlationId);
jsonParameters.Set(_T("correlationId"), CorrelationId);

ProviderInvokeSession(methodName, jsonParameters, err);
ProviderInvokeSession(methodName, jsonParameters, err);
}
static void ProviderResultSession(std::string methodName, std::string& correlationId, ${provider.xresponse.name} result, Firebolt::Error *err = nullptr)
{
JsonObject jsonParameters;
WPEFramework::Core::JSON::Variant CorrelationId(correlationId);
WPEFramework::Core::JSON::Variant CorrelationId(correlationId);
jsonParameters.Set(_T("correlationId"), CorrelationId);

${provider.xresponse.serialization}
ProviderInvokeSession(methodName, jsonParameters, err);
ProviderInvokeSession(methodName, jsonParameters, err);
}
static void ProviderErrorSession(std::string methodName, std::string& correlationId, ${provider.xerror.name} result, Firebolt::Error *err = nullptr)
{
JsonObject jsonParameters;
WPEFramework::Core::JSON::Variant CorrelationId(correlationId);
WPEFramework::Core::JSON::Variant CorrelationId(correlationId);
jsonParameters.Set(_T("correlationId"), CorrelationId);

${provider.xerror.serialization}
ProviderInvokeSession(methodName, jsonParameters, err);
ProviderInvokeSession(methodName, jsonParameters, err);
}

${methods}
4 changes: 2 additions & 2 deletions languages/cpp/templates/codeblocks/module-init.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
${if.modules} ${info.Title}::I${info.Title}& ${info.Title}Interface() const override
{
auto module = _moduleMap.find("${info.Title}");
${info.Title}::I${info.Title}* ${info.title.lowercase} = nullptr;
${info.Title}::I${info.Title}* ${info.title.lowercase} = nullptr;

if (module != _moduleMap.end()) {
${info.title.lowercase} = reinterpret_cast<${info.Title}::I${info.Title}*>(module->second);
} else {
${info.title.lowercase} = reinterpret_cast<${info.Title}::I${info.Title}*>(new ${info.Title}::${info.Title}Impl());
_moduleMap.emplace("${info.Title}", reinterpret_cast<IModule*>(${info.title.lowercase}));
}
}
return *${info.title.lowercase};
}

Expand Down
2 changes: 1 addition & 1 deletion languages/cpp/templates/methods/polymorphic-pull-event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
Firebolt::Error status = Firebolt::Error::NotConnected;
FireboltSDK::Transport<WPEFramework::Core::JSON::IElement>* transport = FireboltSDK::Accessor::Instance().GetTransport();
if (transport != nullptr) {
JsonObject jsonParameters;
JsonObject jsonParameters;
WPEFramework::Core::JSON::Variant CorrelationId = proxyResponse->CorrelationId.Value();
jsonParameters.Set(_T("correlationId"), CorrelationId);
${method.pulls.json.type} ${method.pulls.result.title}Container;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
jsonContainer.Set(element.first.c_str(), jsonElement);
${property}Variant = jsonContainer;
}
jsonParameters.Set(_T("${property}"), ${property}Variant);
jsonParameters.Set(_T("${property}"), ${property}Variant);
2 changes: 1 addition & 1 deletion languages/cpp/templates/parameter-serialization/enum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
jsonParameters.Set(_T("${property}"), ${property}Variant);
}${end.if.optional}${if.non.optional}${if.namespace.notsame}Firebolt::${info.Title}::${end.if.namespace.notsame}JsonData_${title} jsonValue = ${property};
WPEFramework::Core::JSON::Variant ${property}Variant(jsonValue.Data());
jsonParameters.Set(_T("${property}"), ${property}Variant);${end.if.non.optional}
jsonParameters.Set(_T("${property}"), ${property}Variant);${end.if.non.optional}
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
WPEFramework::Core::JSON::Variant ${property}Variant(${property}.value());
jsonParameters.Set(_T("${property}"), ${property}Variant);
}${end.if.optional}${if.non.optional}WPEFramework::Core::JSON::Variant ${property}Variant(${property});
jsonParameters.Set(_T("${property}"), ${property}Variant);${end.if.non.optional}
jsonParameters.Set(_T("${property}"), ${property}Variant);${end.if.non.optional}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
${property}Container.ToString(${property}Str);
WPEFramework::Core::JSON::VariantContainer ${property}VariantContainer(${property}Str);
WPEFramework::Core::JSON::Variant ${property}Variant = ${property}VariantContainer;
${property}Array.Add() = ${property}Variant;
${property}Array.Add() = ${property}Variant;
2 changes: 1 addition & 1 deletion languages/cpp/templates/parameter-serialization/object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
${property}Container.ToString(${property}Str);
WPEFramework::Core::JSON::VariantContainer ${property}VariantContainer(${property}Str);
WPEFramework::Core::JSON::Variant ${property}Variant = ${property}VariantContainer;
jsonParameters.Set(_T("${property}"), ${property}Variant);${end.if.impl.non.optional}
jsonParameters.Set(_T("${property}"), ${property}Variant);${end.if.impl.non.optional}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
for (auto& element : ${property}) {
${if.object}${items.with.indent}${end.if.object}${if.non.object} ${property}Array.Add() = element;${end.if.non.object}
}
${base.title}Container.${Property.dependency}Add(_T("${property}"), &${property}Array);${end.if.impl.array.non.optional}
${base.title}Container.${Property.dependency}Add(_T("${property}"), &${property}Array);${end.if.impl.array.non.optional}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
${if.optional}if (element${property.dependency}.${property}.has_value()) {
${base.title}Container.${Property.dependency}${Property} = element${property.dependency}.${property}.value();
}${end.if.optional}${if.non.optional}${base.title}Container.${Property.dependency}${Property} = element${property.dependency}.${property};${end.if.non.optional}
}${end.if.optional}${if.non.optional}${base.title}Container.${Property.dependency}${Property} = element${property.dependency}.${property};${end.if.non.optional}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
${if.namespace.notsame}Firebolt::${info.Title}::${end.if.namespace.notsame}JsonData_${title} ${property}Container;
{
${properties}
}
${property}Array.Add() = ${property}Container;
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
{
${properties}
}
2 changes: 1 addition & 1 deletion languages/cpp/templates/result-instantiation/array.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
auto index(jsonResult.Elements());
while (index.Next() == true) {
${if.object}${items.with.indent}${end.if.object}${if.non.object} ${property}.push_back(index.Current().Value());${end.if.non.object}
${if.object}${items}${end.if.object}${if.non.object} ${property}.push_back(index.Current().Value());${end.if.non.object}
}
6 changes: 3 additions & 3 deletions languages/cpp/templates/result-instantiation/object-array.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
${type} ${property}Result${level};
${if.namespace.notsame}Firebolt::${info.Title}::${end.if.namespace.notsame}JsonData_${title} jsonResult = index.Current();
${type} ${property}Result${level};
${if.namespace.notsame}Firebolt::${info.Title}::${end.if.namespace.notsame}JsonData_${title} jsonResult = index.Current();
${properties}
${property}.push_back(${property}Result${level});
${property}.push_back(${property}Result${level});
4 changes: 3 additions & 1 deletion languages/cpp/templates/result-instantiation/property.cpp
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
${shape} ${if.non.anyOf}${if.non.array}${if.non.object}${base.title}Result${level}.${property} = jsonResult.${Property}.Value();${end.if.non.object}${end.if.non.array}${end.if.non.anyOf}
${shape} ${if.non.anyOf}${if.non.array}${if.non.object}${if.optional}if (jsonResult.${Property}.IsSet()) {
${base.title}Result${level}.${property} = jsonResult.${Property}.Value();
}${end.if.optional}${if.non.optional}${base.title}Result${level}.${property} = jsonResult.${Property}.Value();${end.if.non.optional}${end.if.non.object}${end.if.non.array}${end.if.non.anyOf}
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
string ${property}Str;
${if.optional}if (jsonResult.${Property.dependency}${Property}.IsSet()) {
string ${property}Str;
jsonResult.${Property.dependency}${Property}.ToString(${property}Str);
${base.title}Result${level}${property.dependency}${if.impl.optional}.value()${end.if.impl.optional}.${property} = ${property}Str;
}${end.if.optional}${if.non.optional}string ${property}Str;
jsonResult.${Property.dependency}${Property}.ToString(${property}Str);
${base.title}Result${level}${property.dependency}${if.impl.optional}.value()${end.if.impl.optional}.${property} = ${property}Str;
${base.title}Result${level}${property.dependency}${if.impl.optional}.value()${end.if.impl.optional}.${property} = ${property}Str;${end.if.non.optional}
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
${if.impl.array.optional}${base.title}Result${level}.${property} = std::make_optional<${type}>();${end.if.impl.array.optional}
auto index(jsonResult.${Property}.Elements());
${if.optional}if (jsonResult.${Property}.IsSet()) {
${base.title}Result${level}.${property} = std::make_optional<${type}>();
auto index(jsonResult.${Property}.Elements());
while (index.Next() == true) {
${if.object}${items.with.indent}${end.if.object}${if.non.object} ${base.title}Result${level}.${property}.value().push_back(index.Current().Value());${end.if.non.object}
}
}${end.if.optional}${if.non.optional}auto index(jsonResult.${Property}.Elements());
while (index.Next() == true) {
${if.object}${items.with.indent}${end.if.object}${if.non.object} ${base.title}Result${level}.${property}${if.impl.array.optional}.value()${end.if.impl.array.optional}.push_back(index.Current().Value());${end.if.non.object}
}
${if.object}${items.with.indent}${end.if.object}${if.non.object} ${base.title}Result${level}.${property}.push_back(index.Current().Value());${end.if.non.object}
}${end.if.non.optional}
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
${type} ${property}Result${level};
${if.namespace.notsame}Firebolt::${info.Title}::${end.if.namespace.notsame}JsonData_${title} jsonResult = index.Current();
{
${properties}
}
${property}Result.${property}${if.impl.array.optional}.value()${end.if.impl.array.optional}.push_back(${property}Result${level});
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
${if.impl.optional}
${base.title}Result${level}${property.dependency} = std::make_optional<${type}>();${end.if.impl.optional}
${properties}
${if.optional} if (jsonResult.${Property.dependency}IsSet()) {
${base.title}Result${level}${property.dependency} = std::make_optional<${type}>();
${properties}
}${end.if.optional}${if.non.optional} {
${properties}
}${end.if.non.optional}
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
${shape} ${if.non.anyOf}${if.non.array}${if.non.object}${base.title}Result${level}${property.dependency}${if.impl.optional}.value()${end.if.impl.optional}.${property} = jsonResult.${Property.dependency}${Property};${end.if.non.object}${end.if.non.array}${end.if.non.anyOf}
${shape} ${if.non.anyOf}${if.non.array}${if.non.object}${if.optional}if (jsonResult.${Property.dependency}${Property}.IsSet()) {
${base.title}Result${level}${property.dependency}${if.impl.optional}.value()${end.if.impl.optional}.${property} = jsonResult.${Property.dependency}${Property};
}${end.if.optional}${if.non.optional}${base.title}Result${level}${property.dependency}${if.impl.optional}.value()${end.if.impl.optional}.${property} = jsonResult.${Property.dependency}${Property};${end.if.non.optional}${end.if.non.object}${end.if.non.array}${end.if.non.anyOf}
2 changes: 1 addition & 1 deletion languages/cpp/templates/sdk/scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ do
case "${flag}" in
i) InstallPath="${OPTARG}";;
s) SdkPath="${OPTARG}";;
m) ModuleName="${OPTARG}";;
m) ModuleName="${OPTARG}";;
h) usage && exit 1;;
esac
done
Expand Down
2 changes: 1 addition & 1 deletion languages/cpp/templates/types/object.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
struct ${title} {
${properties}
${properties}
};
2 changes: 1 addition & 1 deletion languages/cpp/templates/types/property.h
Original file line number Diff line number Diff line change
@@ -1 +1 @@
${if.optional}std::optional<${end.if.optional}${title}${if.optional}>${end.if.optional} ${property};
${if.optional}std::optional<${end.if.optional}${title}${if.optional}>${end.if.optional} ${property};
2 changes: 1 addition & 1 deletion languages/javascript/templates/types/object.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
${properties}
${properties}
}
2 changes: 1 addition & 1 deletion languages/javascript/templates/types/property.mjs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
${property}${if.optional}?${end.if.optional}: ${title} // ${summary}
${property}${if.optional}?${end.if.optional}: ${title} // ${summary}
Loading
Loading