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

feat: CPP App-Passthrough Logic #196

Merged
merged 21 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
1bfdfcd
fix: Added app-passthrough functionality for cpp sdk
ksentak Jun 27, 2024
952a861
cPP: Updates based on provider schema changes
HaseenaSainul Jun 28, 2024
34313c7
CPP: Updates based on provider schema changes
HaseenaSainul Jul 1, 2024
09740b3
Merge remote-tracking branch 'origin/dev/cpp' into feature/cpp-app-pa…
ksentak Jul 1, 2024
b39da1e
Merge remote-tracking branch 'origin/dev/cpp' into feature/cpp-app-pa…
ksentak Jul 1, 2024
7187fa2
fix: Make small adjustment to interface template and engine logic
ksentak Jul 1, 2024
ad20db1
fix: Revert changes that were being tested
ksentak Jul 1, 2024
61bc94c
feat: Pass config flag to types.mjs to modify schema title
ksentak Jul 3, 2024
9e94431
fix: Update cpp templates for discoverySDK WIP
ksentak Jul 3, 2024
db4d928
fix: Added support for players and fixed few provider issues
kevinshahfws Jul 9, 2024
7d44dbc
fix: Commented file permission code for debug
kevinshahfws Jul 9, 2024
2609ea1
Merge branch 'next' into feature/cpp-app-passthrough
ksentak Jul 18, 2024
82022de
fix: Update templates to be more verbose
ksentak Jul 23, 2024
2f1e2df
fix: Added version opt in include.sh
kevinshahfws Jul 24, 2024
f86b483
fix: Added set -e in build.sh
kevinshahfws Jul 25, 2024
4bd523d
fix: Make focuable interface separate
ksentak Jul 25, 2024
c5faee9
Merge branch 'feature/cpp-app-passthrough' of github.com:rdkcentral/f…
ksentak Jul 25, 2024
90e1789
fix: Comment out side-effect ridden code
ksentak Jul 25, 2024
36a05e8
fix: Added IModule.h in firebolt.cpp
kevinshahfws Jul 29, 2024
04cbec1
Merge branch 'feature/cpp-app-passthrough' of https://github.com/rdkc…
kevinshahfws Jul 29, 2024
9edd7f8
Merge branch 'next' into feature/cpp-app-passthrough
kschrief Jul 29, 2024
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
1 change: 1 addition & 0 deletions languages/cpp/language.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"createPolymorphicMethods": true,
"excludeDeclarations": true,
"extractProviderSchema": true,
"enableUnionTypes": false,
"aggregateFiles": [
"/include/firebolt.h",
"/src/firebolt.cpp"
Expand Down
2 changes: 2 additions & 0 deletions languages/cpp/src/shared/src/Logger/Logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ ENUM_CONVERSION_BEGIN(FireboltSDK::Logger::Category)
{ FireboltSDK::Logger::Category::Core, _TXT("FireboltSDK::Core") },
{ FireboltSDK::Logger::Category::Manage, _TXT("FireboltSDK::Manage") },
{ FireboltSDK::Logger::Category::Discovery, _TXT("FireboltSDK::Discovery") },
{ FireboltSDK::Logger::Category::PlayerProvider, _TXT("FireboltSDK::PlayerProvider") },
{ FireboltSDK::Logger::Category::PlayerProvider, _TXT("FireboltSDK::PlayerManager") },

ENUM_CONVERSION_END(FireboltSDK::Logger::Category)

Expand Down
4 changes: 3 additions & 1 deletion languages/cpp/src/shared/src/Logger/Logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ namespace FireboltSDK {
OpenRPC,
Core,
Manage,
Discovery
Discovery,
PlayerProvider,
PlayerManager,
};

public:
Expand Down
1 change: 1 addition & 0 deletions languages/cpp/templates/callback-initialization/tuple.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
${if.namespace.notsame}${parent.Title}::${end.if.namespace.notsame}${title} ${property};
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@
}
}${end.if.optional}${if.non.optional}auto index((*proxyResponse)${Property.dependency}.${Property}.Elements());
while (index.Next() == true) {
${if.object}${items.with.indent}${end.if.object}${if.non.object} ${base.title}${property.dependency}${if.impl.optional}.value()${end.if.impl.optional}.${property}.value().push_back(index.Current().Value());${end.if.non.object}
}${end.if.non.optional}
${if.object}${items.with.indent}${end.if.object}${if.non.object} ${base.title}${property.dependency}${if.impl.optional}.value()${end.if.impl.optional}.${property}.push_back(index.Current().Value());${end.if.non.object} }${end.if.non.optional}
47 changes: 47 additions & 0 deletions languages/cpp/templates/codeblocks/interface-focusable.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
static void ProviderInvokeSession(std::string& methodName, JsonObject& jsonParameters, Firebolt::Error *err = nullptr)
{
Firebolt::Error status = Firebolt::Error::NotConnected;
FireboltSDK::Transport<WPEFramework::Core::JSON::IElement>* transport = FireboltSDK::Accessor::Instance().GetTransport();
if (transport != nullptr) {

JsonObject jsonResult;
status = transport->Invoke(methodName, jsonParameters, jsonResult);
if (status == Firebolt::Error::None) {
FIREBOLT_LOG_INFO(FireboltSDK::Logger::Category::OpenRPC, FireboltSDK::Logger::Module<FireboltSDK::Accessor>(), "%s is successfully invoked", methodName.c_str());
}

} else {
FIREBOLT_LOG_ERROR(FireboltSDK::Logger::Category::OpenRPC, FireboltSDK::Logger::Module<FireboltSDK::Accessor>(), "Error in getting Transport err = %d", status);
}
if (err != nullptr) {
*err = status;
}
}
static void ProviderFocusSession(std::string methodName, std::string& correlationId, Firebolt::Error *err = nullptr)
{
JsonObject jsonParameters;
WPEFramework::Core::JSON::Variant CorrelationId(correlationId);
jsonParameters.Set(_T("correlationId"), CorrelationId);

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);
jsonParameters.Set(_T("correlationId"), CorrelationId);

${provider.xresponse.serialization}
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);
jsonParameters.Set(_T("correlationId"), CorrelationId);

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

${methods}
12 changes: 12 additions & 0 deletions languages/cpp/templates/codeblocks/interface-focusable.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
struct I${info.Title}Session : virtual public IFocussableProviderSession {
virtual ~I${info.Title}Session() override = default;

virtual void error( ${provider.xerror.name} error, Firebolt::Error *err = nullptr ) = 0;
virtual void result( ${provider.xresponse.name} result, Firebolt::Error *err = nullptr ) = 0;
};

struct I${info.Title}Provider {
virtual ~I${info.Title}Provider() = default;

${methods}
};
26 changes: 0 additions & 26 deletions languages/cpp/templates/codeblocks/interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,5 @@
*err = status;
}
}
static void ProviderFocusSession(std::string methodName, std::string& correlationId, Firebolt::Error *err = nullptr)
{
JsonObject jsonParameters;
WPEFramework::Core::JSON::Variant CorrelationId(correlationId);
jsonParameters.Set(_T("correlationId"), CorrelationId);

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);
jsonParameters.Set(_T("correlationId"), CorrelationId);

${provider.xresponse.serialization}
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);
jsonParameters.Set(_T("correlationId"), CorrelationId);

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

${methods}
9 changes: 1 addition & 8 deletions languages/cpp/templates/codeblocks/interface.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
struct I${info.Title}Session : virtual public IFocussableProviderSession {
virtual ~I${info.Title}Session() override = default;

virtual void error( ${provider.xerror.name} error, Firebolt::Error *err = nullptr ) = 0;
virtual void result( ${provider.xresponse.name} result, Firebolt::Error *err = nullptr ) = 0;
};

struct I${info.Title}Provider {
virtual ~I${info.Title}Provider() = default;

${methods}
};
};
17 changes: 13 additions & 4 deletions languages/cpp/templates/interfaces/default.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,17 @@
};
static void ${info.Title}${method.Name}SessionInnerCallback( void* provider, const void* userData, void* jsonResponse )
{
//TODO: code to convert jsonResponse to ${method.name} session
I${info.Title}Provider& ${info.title.lowercase}Provider = *(reinterpret_cast<I${info.Title}Provider*>(provider));
${info.title.lowercase}Provider.${method.name}( parameters, session );
}
${event.callback.serialization}
ASSERT(proxyResponse.IsValid() == true);

if (proxyResponse.IsValid() == true) {
${event.callback.initialization}

${event.callback.instantiation}
proxyResponse.Release();

std::unique_ptr<IProviderSession> ${info.title.lowercase}${method.Name}Session = std::make_unique<${info.Title}${method.Name}Session>();
I${info.Title}Provider& ${info.title.lowercase}Provider = *(reinterpret_cast<I${info.Title}Provider*>(provider));
${info.title.lowercase}Provider.${method.name}(${method.result.name}.parameters, std::move(${info.title.lowercase}${method.Name}Session));
}
}
2 changes: 1 addition & 1 deletion languages/cpp/templates/interfaces/default.h
Original file line number Diff line number Diff line change
@@ -1 +1 @@
virtual void ${method.name}( ${method.signature.params}, IProviderSession& session ) = 0;
virtual void ${method.name}( ${method.signature.params}, std::unique_ptr<IProviderSession> session ) = 0;
10 changes: 5 additions & 5 deletions languages/cpp/templates/methods/default.cpp
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
/* ${method.name} - ${method.description} */
${method.signature.result} ${info.Title}Impl::${method.name}( ${method.signature.params}${if.params}, ${end.if.params}Firebolt::Error *err ) ${if.result.nonvoid}${if.params.empty} const${end.if.params.empty}${end.if.result.nonvoid}
{
Firebolt::Error status = Firebolt::Error::NotConnected;
Firebolt::Error statusError = Firebolt::Error::NotConnected;
${if.result.nonvoid}${method.result.initialization}${end.if.result.nonvoid}
FireboltSDK::Transport<WPEFramework::Core::JSON::IElement>* transport = FireboltSDK::Accessor::Instance().GetTransport();
if (transport != nullptr) {

JsonObject jsonParameters;
${method.params.serialization.with.indent}
${method.result.json.type} jsonResult;
status = transport->Invoke("${info.title.lowercase}.${method.name}", jsonParameters, jsonResult);
if (status == Firebolt::Error::None) {
statusError = transport->Invoke("${info.title.lowercase}.${method.name}", jsonParameters, jsonResult);
if (statusError == Firebolt::Error::None) {
FIREBOLT_LOG_INFO(FireboltSDK::Logger::Category::OpenRPC, FireboltSDK::Logger::Module<FireboltSDK::Accessor>(), "${info.Title}.${method.name} is successfully invoked");
${if.result.nonvoid}${method.result.instantiation.with.indent}${end.if.result.nonvoid}
}

} else {
FIREBOLT_LOG_ERROR(FireboltSDK::Logger::Category::OpenRPC, FireboltSDK::Logger::Module<FireboltSDK::Accessor>(), "Error in getting Transport err = %d", status);
FIREBOLT_LOG_ERROR(FireboltSDK::Logger::Category::OpenRPC, FireboltSDK::Logger::Module<FireboltSDK::Accessor>(), "Error in getting Transport err = %d", statusError);
}
if (err != nullptr) {
*err = status;
*err = statusError;
}

return${if.result.nonvoid} ${method.result.name}${end.if.result.nonvoid};
Expand Down
8 changes: 4 additions & 4 deletions languages/cpp/templates/parameter-serialization/enum.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
${if.optional}if (${property}.has_value()) {
${if.namespace.notsame}Firebolt::${info.Title}::${end.if.namespace.notsame}JsonData_${title} jsonValue = ${property}.value();
WPEFramework::Core::JSON::Variant ${property}Variant(jsonValue.Data());
${if.namespace.notsame}Firebolt::${info.Title}::${end.if.namespace.notsame}JsonData_${title} json${Property} = ${property}.value();
WPEFramework::Core::JSON::Variant ${property}Variant(json${Property}.Data());
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());
}${end.if.optional}${if.non.optional}${if.namespace.notsame}Firebolt::${info.Title}::${end.if.namespace.notsame}JsonData_${title} json${Property} = ${property};
WPEFramework::Core::JSON::Variant ${property}Variant(json${Property}.Data());
jsonParameters.Set(_T("${property}"), ${property}Variant);${end.if.non.optional}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
${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}
${if.optional}if (jsonResult${Property.dependency}.${Property}.IsSet()) {
${base.title}Result${level}${property.dependency}${if.impl.optional}.value()${end.if.impl.optional}.${property} = std::make_optional<${type}>();
auto ${property}Index(jsonResult${Property.dependency}.${Property}.Elements());
while (${property}Index.Next() == true) {
${if.object}${items.with.indent}${end.if.object}${if.non.object} ${base.title}Result${level}.${property}.value().push_back(${property}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}.push_back(index.Current().Value());${end.if.non.object}
}${end.if.optional}${if.non.optional}auto ${property}Index(jsonResult.${Property}.Elements());
while (${property}Index.Next() == true) {
${if.object}${items.with.indent}${end.if.object}${if.non.object} ${base.title}Result${level}.${property}.push_back(${property}Index.Current().Value());${end.if.non.object}
}${end.if.non.optional}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
${type} ${property}Result${level};
${if.namespace.notsame}Firebolt::${info.Title}::${end.if.namespace.notsame}JsonData_${title} jsonResult = index.Current();
${if.namespace.notsame}Firebolt::${info.Title}::${end.if.namespace.notsame}JsonData_${title} jsonResult = ${property}Index.Current();
{
${properties}
}
${property}Result.${property}${if.impl.array.optional}.value()${end.if.impl.array.optional}.push_back(${property}Result${level});
${base.title}Result${property.dependency}${if.impl.optional}.value()${end.if.impl.optional}.${property}.push_back(${property}Result${level});
1 change: 1 addition & 0 deletions languages/cpp/templates/sdk/scripts/build.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
set -e
usage()
{
echo "options:"
Expand Down
9 changes: 6 additions & 3 deletions languages/cpp/templates/sdk/scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ usage()
echo " -i install path"
echo " -s sdk path"
echo " -m module name. i.e, core/manage"
echo " -v sdk version. i.e, 1.3.0"
echo
echo "usage: "
echo " ./install.sh -i path -s sdk path -m core"
Expand All @@ -13,12 +14,15 @@ usage()
SdkPath=".."
InstallPath=".."
ModuleName="core"
while getopts i:s:m:h flag
Version=1.3.0-next.1

while getopts i:s:m:v:h flag
do
case "${flag}" in
i) InstallPath="${OPTARG}";;
s) SdkPath="${OPTARG}";;
m) ModuleName="${OPTARG}";;
v) Version="${OPTARG}";;
h) usage && exit 1;;
esac
done
Expand All @@ -40,8 +44,7 @@ GetVersion()
Version=${array[2]}
}

Version=0.0
GetVersion
#GetVersion
ReleaseName=firebolt-${ModuleName}-native-sdk-${Version}
ReleasePath=${InstallPath}/${ReleaseName}

Expand Down
1 change: 1 addition & 0 deletions languages/cpp/templates/sdk/src/firebolt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include <firebolt.h>
#include "FireboltSDK.h"
#include "IModule.h"
${module.includes.private}

namespace Firebolt {
Expand Down
39 changes: 31 additions & 8 deletions src/macrofier/engine.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1775,16 +1775,24 @@ function getProviderXValues(method) {
return xValues
}

function insertProviderXValues(template, moduleJson, xValues) {
function insertProviderXValues(template, module, xValues) {
if (xValues['x-response']) {
const xResponseInst = types.getSchemaShape(xValues['x-response'], moduleJson, { templateDir: 'parameter-serialization', property: 'result', required: true, destination: state.destination, section: state.section, primitive: true, skipTitleOnce: true })
let schema = localizeDependencies(xValues['x-response'], module)
const moduleTitle = types.getXSchemaGroup(schema, module)
const xResponseInst = types.getSchemaShape(schema, module, { templateDir: 'parameter-serialization', property: 'result', required: true, destination: state.destination, section: state.section, primitive: true, skipTitleOnce: true })
const type = types.getSchemaType(schema, module, { moduleTitle: moduleTitle, result: true, namespace: true})
template = template.replace(/\$\{provider\.xresponse\.serialization\}/gms, xResponseInst)
.replace(/\$\{provider\.xresponse\.name\}/gms, xValues['x-response'].title)
.replace(/\$\{provider\.xresponse\.name\}/gms, type)
.replace(/\$\{parent\.Title\}/g, capitalize(moduleTitle))
}
if (xValues['x-error']) {
const xErrorInst = types.getSchemaShape(xValues['x-error'], moduleJson, { templateDir: 'parameter-serialization', property: 'result', required: true, destination: state.destination, section: state.section, primitive: true, skipTitleOnce: true })
let schema = localizeDependencies(xValues['x-error'], module)
const moduleTitle = types.getXSchemaGroup(schema, module)
const xErrorInst = types.getSchemaShape(schema, module, { templateDir: 'parameter-serialization', property: 'result', required: true, destination: state.destination, section: state.section, primitive: true, skipTitleOnce: true })
const type = types.getSchemaType(schema, module, { moduleTitle: moduleTitle, result: true, namespace: true})
template = template.replace(/\$\{provider\.xerror\.serialization\}/gms, xErrorInst)
.replace(/\$\{provider\.xerror\.name\}/gms, xValues['x-error'].title)
.replace(/\$\{provider\.xerror\.name\}/gms, type)
.replace(/\$\{parent\.Title\}/g, capitalize(moduleTitle))
}
return template
}
Expand All @@ -1805,9 +1813,24 @@ function insertProviderInterfaceMacros(template, capability, moduleJson = {}, te
let name = getProviderInterfaceName(iface, capability, moduleJson)
let xValues
const suffix = state.destination ? state.destination.split('.').pop() : ''
let interfaceShape = getTemplate(suffix ? `/codeblocks/interface.${suffix}` : '/codeblocks/interface', templates)
if (!interfaceShape) {
interfaceShape = getTemplate('/codeblocks/interface', templates)

// Determine if any method has the 'x-allow-focus' tag set to true
const hasFocusableMethods = iface.some(method =>
method.tags.some(tag => tag['x-allow-focus'] === true)
)

// Determine the appropriate template based on hasFocusableMethods and suffix
let interfaceShape;
if (hasFocusableMethods) {
interfaceShape = getTemplate(suffix ? `/codeblocks/interface-focusable.${suffix}` : '/codeblocks/interface-focusable', templates);
if (!interfaceShape) {
interfaceShape = getTemplate('/codeblocks/interface-focusable', templates);
}
} else {
interfaceShape = getTemplate(suffix ? `/codeblocks/interface.${suffix}` : '/codeblocks/interface', templates);
if (!interfaceShape) {
interfaceShape = getTemplate('/codeblocks/interface', templates);
}
}

interfaceShape = interfaceShape.replace(/\$\{name\}/g, name)
Expand Down
Loading
Loading