From 4bd523d8209f1584b2d4cdc8cc9f2668bae722b7 Mon Sep 17 00:00:00 2001 From: Keaton Sentak Date: Thu, 25 Jul 2024 14:29:54 -0400 Subject: [PATCH] fix: Make focuable interface separate --- .../codeblocks/interface-focusable.cpp | 47 +++++++++++++++++++ .../codeblocks/interface-focusable.h | 12 +++++ .../cpp/templates/codeblocks/interface.cpp | 26 ---------- .../cpp/templates/codeblocks/interface.h | 7 --- src/macrofier/engine.mjs | 21 +++++++-- src/macrofier/index.mjs | 6 +-- src/shared/modules.mjs | 4 +- 7 files changed, 82 insertions(+), 41 deletions(-) create mode 100644 languages/cpp/templates/codeblocks/interface-focusable.cpp create mode 100644 languages/cpp/templates/codeblocks/interface-focusable.h diff --git a/languages/cpp/templates/codeblocks/interface-focusable.cpp b/languages/cpp/templates/codeblocks/interface-focusable.cpp new file mode 100644 index 00000000..b62df483 --- /dev/null +++ b/languages/cpp/templates/codeblocks/interface-focusable.cpp @@ -0,0 +1,47 @@ + static void ProviderInvokeSession(std::string& methodName, JsonObject& jsonParameters, Firebolt::Error *err = nullptr) + { + Firebolt::Error status = Firebolt::Error::NotConnected; + FireboltSDK::Transport* 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(), "%s is successfully invoked", methodName.c_str()); + } + + } else { + FIREBOLT_LOG_ERROR(FireboltSDK::Logger::Category::OpenRPC, FireboltSDK::Logger::Module(), "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} diff --git a/languages/cpp/templates/codeblocks/interface-focusable.h b/languages/cpp/templates/codeblocks/interface-focusable.h new file mode 100644 index 00000000..5a6032f0 --- /dev/null +++ b/languages/cpp/templates/codeblocks/interface-focusable.h @@ -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} +}; diff --git a/languages/cpp/templates/codeblocks/interface.cpp b/languages/cpp/templates/codeblocks/interface.cpp index b62df483..abab1e57 100644 --- a/languages/cpp/templates/codeblocks/interface.cpp +++ b/languages/cpp/templates/codeblocks/interface.cpp @@ -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} diff --git a/languages/cpp/templates/codeblocks/interface.h b/languages/cpp/templates/codeblocks/interface.h index 5a6032f0..5d4f4056 100644 --- a/languages/cpp/templates/codeblocks/interface.h +++ b/languages/cpp/templates/codeblocks/interface.h @@ -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; diff --git a/src/macrofier/engine.mjs b/src/macrofier/engine.mjs index 8f4522c7..969d47a1 100644 --- a/src/macrofier/engine.mjs +++ b/src/macrofier/engine.mjs @@ -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) diff --git a/src/macrofier/index.mjs b/src/macrofier/index.mjs index e6da1cce..298241f6 100644 --- a/src/macrofier/index.mjs +++ b/src/macrofier/index.mjs @@ -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() diff --git a/src/shared/modules.mjs b/src/shared/modules.mjs index 5fa64c6a..58fc7261 100644 --- a/src/shared/modules.mjs +++ b/src/shared/modules.mjs @@ -91,8 +91,8 @@ 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 })) - + 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'])