Skip to content

Commit

Permalink
Remove unused or redundant helpers from src/app/zap-templates/templat…
Browse files Browse the repository at this point in the history
…es/app/helper.js (#8141)
  • Loading branch information
vivien-apple authored and pull[bot] committed Aug 19, 2021
1 parent e2b5828 commit 5505089
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 88 deletions.
7 changes: 0 additions & 7 deletions src/app/zap-templates/common/ChipTypesHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,7 @@ function asBasicType(type)
}
}

const signedTypes = [ 'INT8S', 'INT16S', 'INT32S', 'INT64S' ];
function isSigned(type)
{
return signedTypes.includes(type);
}

//
// Module exports
//
exports.asBasicType = asBasicType;
exports.isSigned = isSigned;
87 changes: 11 additions & 76 deletions src/app/zap-templates/templates/app/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,65 +16,15 @@
*/

// Import helpers from zap core
const zapPath = '../../../../../third_party/zap/repo/src-electron/';
const templateUtil = require(zapPath + 'generator/template-util.js')
const queryEndpoint = require(zapPath + 'db/query-endpoint.js')
const zclHelper = require(zapPath + 'generator/helper-zcl.js')
const zclQuery = require(zapPath + 'db/query-zcl.js')
const cHelper = require(zapPath + 'generator/helper-c.js')
const zapPath = '../../../../../third_party/zap/repo/src-electron/';
const templateUtil = require(zapPath + 'generator/template-util.js')
const zclHelper = require(zapPath + 'generator/helper-zcl.js')
const zclQuery = require(zapPath + 'db/query-zcl.js')
const cHelper = require(zapPath + 'generator/helper-c.js')

const StringHelper = require('../../common/StringHelper.js');
const ChipTypesHelper = require('../../common/ChipTypesHelper.js');

/**
* Check if the cluster (name) has any enabled manufacturer commands. This works only inside
* cluster block helpers.
*
* @param {*} name : Cluster name
* @param {*} side : Cluster side
* @param {*} options
* @returns True if cluster has enabled commands otherwise false
*/
function user_cluster_has_enabled_manufacturer_command(name, side, options)
{
return queryEndpoint.selectEndPointTypeIds(this.global.db, this.global.sessionId)
.then((endpointTypes) => zclQuery.exportClustersAndEndpointDetailsFromEndpointTypes(this.global.db, endpointTypes))
.then((endpointsAndClusters) => zclQuery.exportCommandDetailsFromAllEndpointTypesAndClusters(
this.global.db, endpointsAndClusters))
.then((endpointCommands) => {
return !!endpointCommands.find(cmd => cmd.mfgCode && zclHelper.isStrEqual(name, cmd.clusterName)
&& zclHelper.isCommandAvailable(side, cmd.incoming, cmd.outgoing, cmd.commandSource, cmd.name));
})
}

function asValueIfNotPresent(type, isArray)
{
if (StringHelper.isString(type) || isArray) {
return 'NULL';
}

function fn(pkgId)
{
const options = { 'hash' : {} };
return zclHelper.asUnderlyingZclType.call(this, type, options).then(zclType => {
switch (zclType) {
case 'uint8_t':
return 'UINT8_MAX';
case 'uint16_t':
return 'UINT16_MAX';
case 'uint32_t':
return 'UINT32_MAX';
default:
error = 'Unhandled underlying type ' + zclType + ' for original type ' + type;
throw error;
}
})
}

const promise = templateUtil.ensureZclPackageId(this).then(fn.bind(this)).catch(err => console.log(err));
return templateUtil.templatePromise(this.global, promise)
}

// TODO Expose the readTypeLength as an additional member field of {{asUnderlyingZclType}} instead
// of having to call this method separately.
function asReadTypeLength(type)
Expand Down Expand Up @@ -324,16 +274,6 @@ function asPrintFormat(type)
return templateUtil.templatePromise(this.global, promise)
}

function isFirstElement(index)
{
return index == 0;
}

function isStrEndsWith(str, substr)
{
return str.endsWith(substr);
}

function asTypeLiteralSuffix(type)
{
switch (type) {
Expand All @@ -355,14 +295,9 @@ function asTypeLiteralSuffix(type)
//
// Module exports
//
exports.asPrintFormat = asPrintFormat;
exports.asReadType = asReadType;
exports.asReadTypeLength = asReadTypeLength;
exports.asValueIfNotPresent = asValueIfNotPresent;
exports.isFirstElement = isFirstElement;
exports.user_cluster_has_enabled_manufacturer_command = user_cluster_has_enabled_manufacturer_command;
exports.chip_endpoint_generated_functions = chip_endpoint_generated_functions
exports.chip_endpoint_cluster_list = chip_endpoint_cluster_list
exports.isSigned = ChipTypesHelper.isSigned;
exports.isStrEndsWith = isStrEndsWith;
exports.asTypeLiteralSuffix = asTypeLiteralSuffix;
exports.asPrintFormat = asPrintFormat;
exports.asReadType = asReadType;
exports.asReadTypeLength = asReadTypeLength;
exports.chip_endpoint_generated_functions = chip_endpoint_generated_functions
exports.chip_endpoint_cluster_list = chip_endpoint_cluster_list
exports.asTypeLiteralSuffix = asTypeLiteralSuffix;
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ void Dispatch{{asCamelCased side false}}Command(app::Command * apCommandObj, Com
uint32_t expectArgumentCount = 0;
uint32_t currentDecodeTagId = 0;
bool wasHandled = false;
{{#if (user_cluster_has_enabled_manufacturer_command name side)}}
{{else}}
{{/if}}
{
switch (aCommandId)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ private:

{{#chip_server_cluster_commands}}
{{#if (zcl_command_arguments_count this.id)}}
- (void){{asCamelCased name}}:{{#chip_server_cluster_command_arguments}}{{#if (isFirstElement index)}}{{else}}{{asCamelCased label}}:{{/if}}({{asObjectiveCBasicType type}}){{asCamelCased label}} {{/chip_server_cluster_command_arguments}}responseHandler:(ResponseHandler)responseHandler
- (void){{asCamelCased name}}:{{#chip_server_cluster_command_arguments}}{{#if index includeZero=false}}{{asCamelCased label}}:{{/if}}({{asObjectiveCBasicType type}}){{asCamelCased label}} {{/chip_server_cluster_command_arguments}}responseHandler:(ResponseHandler)responseHandler
{{else}}
- (void){{asCamelCased name}}:(ResponseHandler)responseHandler
{{/if}}
Expand Down
2 changes: 1 addition & 1 deletion src/darwin/Framework/CHIP/templates/CHIPClustersObjc.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ NS_ASSUME_NONNULL_BEGIN

{{#chip_server_cluster_commands}}
{{#if (zcl_command_arguments_count this.id)}}
- (void){{asCamelCased name}}:{{#chip_server_cluster_command_arguments}}{{#if (isFirstElement index)}}{{else}}{{asCamelCased label}}:{{/if}}({{asObjectiveCBasicType type}}){{asCamelCased label}} {{/chip_server_cluster_command_arguments}}responseHandler:(ResponseHandler)responseHandler;
- (void){{asCamelCased name}}:{{#chip_server_cluster_command_arguments}}{{#if index includeZero=false}}{{asCamelCased label}}:{{/if}}({{asObjectiveCBasicType type}}){{asCamelCased label}} {{/chip_server_cluster_command_arguments}}responseHandler:(ResponseHandler)responseHandler;
{{else}}
- (void){{asCamelCased name}}:(ResponseHandler)responseHandler;
{{/if}}
Expand Down

0 comments on commit 5505089

Please sign in to comment.