From 282891e032f816c6da7fc8765b94148eefb9ca9f Mon Sep 17 00:00:00 2001 From: HaseenaSainul Date: Mon, 17 Jul 2023 10:29:08 -0400 Subject: [PATCH] calls-metrics: support added --- languages/c/templates/declarations/rpc-only.c | 0 .../c/templates/imports/calls-metrics.cpp | 1 + languages/c/templates/methods/calls-metrics.c | 30 +++++++++++++++++++ languages/c/templates/methods/rpc-only.c | 0 src/macrofier/engine.mjs | 13 +++++++- src/shared/modules.mjs | 8 +++++ 6 files changed, 51 insertions(+), 1 deletion(-) delete mode 100644 languages/c/templates/declarations/rpc-only.c create mode 100644 languages/c/templates/imports/calls-metrics.cpp create mode 100644 languages/c/templates/methods/calls-metrics.c delete mode 100644 languages/c/templates/methods/rpc-only.c diff --git a/languages/c/templates/declarations/rpc-only.c b/languages/c/templates/declarations/rpc-only.c deleted file mode 100644 index e69de29b..00000000 diff --git a/languages/c/templates/imports/calls-metrics.cpp b/languages/c/templates/imports/calls-metrics.cpp new file mode 100644 index 00000000..4ba289b3 --- /dev/null +++ b/languages/c/templates/imports/calls-metrics.cpp @@ -0,0 +1 @@ +#include "metrics.h" diff --git a/languages/c/templates/methods/calls-metrics.c b/languages/c/templates/methods/calls-metrics.c new file mode 100644 index 00000000..91831a3c --- /dev/null +++ b/languages/c/templates/methods/calls-metrics.c @@ -0,0 +1,30 @@ +/* ${method.rpc.name} - ${method.description} */ +void Metrics_${method.Name}Dispatcher(const void*${if.result} result${end.if.result}) { + Metrics_${method.Name}(${if.result}(static_cast<${method.result.json.type}>(const_cast(result)))${end.if.result}); +} + +uint32_t ${info.Title}_${method.Name}( ${method.signature.params}${if.result}${if.params}, ${end.if.params}${method.result.type}* ${method.result.name}${end.if.result}${if.signature.empty}void${end.if.signature.empty} ) { + + uint32_t status = FireboltSDKErrorUnavailable; + FireboltSDK::Transport* transport = FireboltSDK::Accessor::Instance().GetTransport(); + if (transport != nullptr) { + + ${method.params.serialization.with.indent} + ${method.result.json.type} jsonResult; + status = transport->Invoke("${info.title}.${method.rpc.name}", jsonParameters, jsonResult); + if (status == FireboltSDKErrorNone) { + FIREBOLT_LOG_INFO(FireboltSDK::Logger::Category::OpenRPC, FireboltSDK::Logger::Module(), "${info.Title}.${method.rpc.name} is successfully invoked"); +${method.result.instantiation} + + void* result = nullptr; + ${if.result}result = static_cast(new ${method.result.json.type});${end.if.result} + WPEFramework::Core::ProxyType job = WPEFramework::Core::ProxyType(WPEFramework::Core::ProxyType::Create(Metrics_${method.Name}Dispatcher, result)); + WPEFramework::Core::IWorkerPool::Instance().Submit(job); + } + + } else { + FIREBOLT_LOG_ERROR(FireboltSDK::Logger::Category::OpenRPC, FireboltSDK::Logger::Module(), "Error in getting Transport err = %d", status); + } + + return status; +} diff --git a/languages/c/templates/methods/rpc-only.c b/languages/c/templates/methods/rpc-only.c deleted file mode 100644 index e69de29b..00000000 diff --git a/src/macrofier/engine.mjs b/src/macrofier/engine.mjs index 61eebd3d..9a2da33f 100644 --- a/src/macrofier/engine.mjs +++ b/src/macrofier/engine.mjs @@ -29,7 +29,7 @@ import isString from 'crocks/core/isString.js' import predicates from 'crocks/predicates/index.js' const { isObject, isArray, propEq, pathSatisfies, propSatisfies } = predicates -import { isRPCOnlyMethod, isProviderInterfaceMethod, getProviderInterface, getPayloadFromEvent, providerHasNoParameters, isTemporalSetMethod, hasMethodAttributes, getMethodAttributes, isEventMethodWithContext, getSemanticVersion, getSetterFor, getProvidedCapabilities, isPolymorphicPullMethod, hasPublicAPIs } from '../shared/modules.mjs' +import { isRPCOnlyMethod, isProviderInterfaceMethod, getProviderInterface, getPayloadFromEvent, providerHasNoParameters, isTemporalSetMethod, isCallsMetricsMethod, isExcludedMethod, hasMethodAttributes, getMethodAttributes, isEventMethodWithContext, getSemanticVersion, getSetterFor, getProvidedCapabilities, isPolymorphicPullMethod, hasPublicAPIs } from '../shared/modules.mjs' import isEmpty from 'crocks/core/isEmpty.js' import { getLinkedSchemaPaths, getSchemaConstraints, isSchema, localizeDependencies, isDefinitionReferencedBySchema } from '../shared/json-schema.mjs' @@ -282,6 +282,13 @@ const temporalSets = compose( getMethods ) +const callsMetrics = compose( + option([]), + map(filter(not(isExcludedMethod))), + map(filter(isCallsMetricsMethod)), + getMethods +) + const methodsWithXMethodsInResult = compose( option([]), map(filter(hasMethodAttributes)), @@ -830,6 +837,10 @@ const generateImports = (json, templates, options = { destination: '' }) => { const suffix = options.destination.split('.').pop() const prefix = options.destination.split('/').pop().split('_')[0].toLowerCase() + if (callsMetrics(json).length) { + imports += getTemplate(suffix ? `/imports/calls-metrics.${suffix}` : '/imports/calls-metrics', templates) + } + let template = prefix ? getTemplate(`/imports/default.${prefix}`, templates) : '' if (!template) { template = getTemplate(suffix ? `/imports/default.${suffix}` : '/imports/default', templates) diff --git a/src/shared/modules.mjs b/src/shared/modules.mjs index 386b9d6d..a91c076b 100644 --- a/src/shared/modules.mjs +++ b/src/shared/modules.mjs @@ -227,6 +227,13 @@ const isTemporalSetMethod = compose( getPath(['tags']) ) +const isCallsMetricsMethod = compose( + option(false), + map(_ => true), + chain(find(propEq('name', 'calls-metrics'))), + getPath(['tags']) +) + const getMethodAttributes = compose( option(null), map(props => props.reduce( (val, item) => { @@ -1148,6 +1155,7 @@ export { isPolymorphicReducer, isPolymorphicPullMethod, isTemporalSetMethod, + isCallsMetricsMethod, isExcludedMethod, isRPCOnlyMethod, isProviderInterfaceMethod,