Skip to content

Commit

Permalink
fix: Make focuable interface separate
Browse files Browse the repository at this point in the history
  • Loading branch information
ksentak committed Jul 25, 2024
1 parent 82022de commit 4bd523d
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 41 deletions.
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
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
4 changes: 2 additions & 2 deletions src/shared/modules.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand Down

0 comments on commit 4bd523d

Please sign in to comment.