Skip to content

Commit

Permalink
Fix zapTypeToClusterObjectType to handle global structs/enums/bitmaps.
Browse files Browse the repository at this point in the history
Some queries were fixed to output the cluster count for objects (so that global
ones can be detected), and zapTypeToClusterObjectType was modified to put global
things in the right namespaces.
  • Loading branch information
bzbarsky-apple committed Jul 25, 2024
1 parent 47c9974 commit 3210ceb
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 5 deletions.
1 change: 1 addition & 0 deletions src-electron/db/query-bitmap.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ async function selectBitmapByName(db, packageIds, name) {
SELECT
BITMAP.BITMAP_ID,
DATA_TYPE.NAME AS NAME,
(SELECT COUNT(1) FROM DATA_TYPE_CLUSTER WHERE DATA_TYPE_CLUSTER.DATA_TYPE_REF = BITMAP.BITMAP_ID) AS BITMAP_CLUSTER_COUNT,
BITMAP.SIZE AS SIZE
FROM BITMAP
INNER JOIN DATA_TYPE ON BITMAP.BITMAP_ID = DATA_TYPE.DATA_TYPE_ID
Expand Down
1 change: 1 addition & 0 deletions src-electron/db/query-enum.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ async function selectEnumByName(db, name, packageIds) {
SELECT
ENUM.ENUM_ID,
DATA_TYPE.NAME AS NAME,
(SELECT COUNT(1) FROM DATA_TYPE_CLUSTER WHERE DATA_TYPE_CLUSTER.DATA_TYPE_REF = ENUM.ENUM_ID) AS ENUM_CLUSTER_COUNT,
ENUM.SIZE AS SIZE
FROM
ENUM
Expand Down
1 change: 1 addition & 0 deletions src-electron/db/query-struct.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ SELECT
STRUCT.IS_FABRIC_SCOPED,
STRUCT.API_MATURITY,
DATA_TYPE.NAME,
(SELECT COUNT(1) FROM DATA_TYPE_CLUSTER WHERE DATA_TYPE_CLUSTER.DATA_TYPE_REF = STRUCT.STRUCT_ID) AS STRUCT_CLUSTER_COUNT,
DATA_TYPE.DISCRIMINATOR_REF
FROM
STRUCT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -613,12 +613,31 @@ function asMEI(prefix, suffix) {
}

// Not to be exported.
function nsValueToNamespace(ns) {
function nsValueToNamespace(ns, clusterCount) {
if (ns === undefined) {
// This use is happening within a specific cluster namespace already, so
// usually there is no need for more prefixing. But for globals, we need to
// prefix them with "Globals::", because they are not in fact in the cluster
// namespace.
if (clusterCount == 0) {
return 'Globals::';
}

return '';
}

if (ns == 'detail') {
return ns;
}

return asUpperCamelCase(ns);
const prefix = 'chip::app::Clusters::';
const postfix = '::';

if (clusterCount == 0) {
return `${prefix}Globals${postfix}`;
}

return `${prefix}${asUpperCamelCase(ns)}${postfix}`;
}

/*
Expand All @@ -644,9 +663,6 @@ async function zapTypeToClusterObjectType(type, isDecodable, options) {

let passByReference = false;
async function fn(pkgId) {
const ns = options.hash.ns
? 'chip::app::Clusters::' + nsValueToNamespace(options.hash.ns) + '::'
: '';
const typeChecker = async (method) =>
zclHelper[method](this.global.db, type, pkgId).then(
(zclType) => zclType != 'unknown'
Expand Down Expand Up @@ -676,6 +692,13 @@ async function zapTypeToClusterObjectType(type, isDecodable, options) {
if (s) {
return 'uint' + s[1] + '_t';
}

const enumObj = await zclQuery.selectEnumByName(
this.global.db,
type,
pkgId
);
const ns = nsValueToNamespace(options.hash.ns, enumObj.enumClusterCount);
return ns + asUpperCamelCase.call(this, type, options);
}

Expand All @@ -685,13 +708,32 @@ async function zapTypeToClusterObjectType(type, isDecodable, options) {
if (s) {
return 'uint' + s[1] + '_t';
}

const bitmapObj = await zclQuery.selectBitmapByName(
this.global.db,
pkgId,
type
);
const ns = nsValueToNamespace(
options.hash.ns,
bitmapObj.bitmapClusterCount
);
return (
'chip::BitMask<' + ns + asUpperCamelCase.call(this, type, options) + '>'
);
}

if (types.isStruct) {
passByReference = true;
const structObj = await zclQuery.selectStructByName(
this.global.db,
type,
pkgId
);
const ns = nsValueToNamespace(
options.hash.ns,
structObj.structClusterCount
);
return (
ns +
'Structs::' +
Expand All @@ -703,6 +745,8 @@ async function zapTypeToClusterObjectType(type, isDecodable, options) {

if (types.isEvent) {
passByReference = true;
// There are no global events, so just pass 1 for cluster count.
const ns = nsValueToNamespace(options.hash.ns, 1);
return (
ns +
'Events::' +
Expand Down

0 comments on commit 3210ceb

Please sign in to comment.