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

calls-metrics: support added #115

Merged
merged 1 commit into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Empty file.
1 change: 1 addition & 0 deletions languages/c/templates/imports/calls-metrics.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "metrics.h"
30 changes: 30 additions & 0 deletions languages/c/templates/methods/calls-metrics.c
Original file line number Diff line number Diff line change
@@ -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<void*>(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<WPEFramework::Core::JSON::IElement>* 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<FireboltSDK::Accessor>(), "${info.Title}.${method.rpc.name} is successfully invoked");
${method.result.instantiation}

void* result = nullptr;
${if.result}result = static_cast<void*>(new ${method.result.json.type});${end.if.result}
WPEFramework::Core::ProxyType<WPEFramework::Core::IDispatch> job = WPEFramework::Core::ProxyType<WPEFramework::Core::IDispatch>(WPEFramework::Core::ProxyType<FireboltSDK::Worker>::Create(Metrics_${method.Name}Dispatcher, result));
WPEFramework::Core::IWorkerPool::Instance().Submit(job);
}

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

return status;
}
Empty file.
13 changes: 12 additions & 1 deletion src/macrofier/engine.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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)),
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions src/shared/modules.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -1148,6 +1155,7 @@ export {
isPolymorphicReducer,
isPolymorphicPullMethod,
isTemporalSetMethod,
isCallsMetricsMethod,
isExcludedMethod,
isRPCOnlyMethod,
isProviderInterfaceMethod,
Expand Down
Loading