Skip to content

Commit

Permalink
Merge branch 'feature/cpp-app-passthrough' of https://github.com/rdkc…
Browse files Browse the repository at this point in the history
…entral/firebolt-openrpc into feature/cpp-app-passthrough
  • Loading branch information
kevinshahfws committed Jul 29, 2024
2 parents 36a05e8 + 90e1789 commit 04cbec1
Show file tree
Hide file tree
Showing 16 changed files with 119 additions and 63 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# [3.0.0-next.7](https://github.com/rdkcentral/firebolt-openrpc/compare/v3.0.0-next.6...v3.0.0-next.7) (2024-07-10)


### Bug Fixes

* Added x-response-name in EventTag ([#200](https://github.com/rdkcentral/firebolt-openrpc/issues/200)) ([d2130a8](https://github.com/rdkcentral/firebolt-openrpc/commit/d2130a8bfa88a4a43c033596c9a8aa4d7b1864fa))

# [3.0.0-next.6](https://github.com/rdkcentral/firebolt-openrpc/compare/v3.0.0-next.5...v3.0.0-next.6) (2024-07-10)


### Bug Fixes

* SchemasMatch handling null ([#199](https://github.com/rdkcentral/firebolt-openrpc/issues/199)) ([07c47db](https://github.com/rdkcentral/firebolt-openrpc/commit/07c47db16ca2a533ee29e6586703834658928bc4))

# [3.0.0-next.5](https://github.com/rdkcentral/firebolt-openrpc/compare/v3.0.0-next.4...v3.0.0-next.5) (2024-06-13)


Expand Down
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}
7 changes: 0 additions & 7 deletions languages/cpp/templates/codeblocks/interface.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
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;

Expand Down
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
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
${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 index(jsonResult${Property.dependency}.${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}
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}
}
${base.title}Result${property.dependency}${if.impl.optional}.value()${end.if.impl.optional}.${property}->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
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 @@ -16,7 +16,7 @@ InstallPath=".."
ModuleName="core"
Version=1.3.0-next.1

while getopts i:s:m:h flag
while getopts i:s:m:v:h flag
do
case "${flag}" in
i) InstallPath="${OPTARG}";;
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@firebolt-js/openrpc",
"version": "3.0.0-next.5",
"version": "3.0.0-next.7",
"description": "The Firebolt SDK Code & Doc Generator",
"main": "languages/javascript/src/sdk.mjs",
"type": "module",
Expand Down
21 changes: 18 additions & 3 deletions src/macrofier/engine.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1813,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
6 changes: 3 additions & 3 deletions src/macrofier/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -314,9 +314,9 @@ const macrofy = async (
}

await writeFiles(outputFiles)
// if (persistPermission) {
// await writeFilesPermissions(templatesPermission)
// }
if (persistPermission) {
await writeFilesPermissions(templatesPermission)
}
logSuccess(`Wrote ${Object.keys(outputFiles).length} files.`)

resolve()
Expand Down
2 changes: 1 addition & 1 deletion src/shared/modules.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const getProviderInterfaceMethods = (capability, json) => {
function getProviderInterface(capability, module, extractProviderSchema = false) {
module = JSON.parse(JSON.stringify(module))
const iface = getProviderInterfaceMethods(capability, module)//.map(method => localizeDependencies(method, module, null, { mergeAllOfs: true }))

iface.forEach(method => {
const payload = getPayloadFromEvent(method)
const focusable = method.tags.find(t => t['x-allow-focus'])
Expand Down
12 changes: 6 additions & 6 deletions src/validate/validator/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ const addFailingMethodSchema = (error, json, schema) => {
const i = parseInt(error.schemaPath.split("/")[2])
error.params.failingSchema = schema.definitions.Method.allOf[i].then.$ref
}
}

}
}
}

Expand All @@ -61,7 +61,7 @@ export const pruneErrors = (errors = []) => {

Object.values(groups).forEach( group => {
const paths = []
pruned.push(group.sort( (a, b) => b.schemaPath.split('/').length - a.schemaPath.split('/').length ).pop())
pruned.push(group.sort( (a, b) => b.schemaPath.split('/').length - a.schemaPath.split('/').length ).pop())
})

return pruned
Expand Down Expand Up @@ -163,7 +163,7 @@ export const validate = (json = {}, schemas = {}, ajv, validator, additionalPack
validator.errors.forEach(error => error.source = 'OpenRPC')

errors.push(...pruneErrors(validator.errors))
}
}

return { valid: valid, title: json.title || json.info.title, errors: errors }
}
Expand Down Expand Up @@ -235,7 +235,7 @@ export const validatePasshtroughs = (json) => {

if (!schemasMatch(source, destination)) {
const properties = getPropertiesInSchema(destination, json)

// follow $refs so we can see the schemas
source = getPropertySchema(source, '.', json)
destination = getPropertySchema(destination, '.', json)
Expand Down Expand Up @@ -276,4 +276,4 @@ export const validatePasshtroughs = (json) => {

return result

}
}

0 comments on commit 04cbec1

Please sign in to comment.