Skip to content

Commit

Permalink
Darwin: cluster & attribute introspection (project-chip#31026)
Browse files Browse the repository at this point in the history
* darwin: ability to map from ID to name

* Restyled by whitespace

* change to standalone functions

* generated files

* Apply suggestions from code review

breaks in default cases.

Co-authored-by: Boris Zbarsky <[email protected]>

* Make the header not auto-generated

add code comments

* add files to Xcode project

* Updated generated file after rebase

* Fix compilation fails

* Add new API to Matter.h

* Remove not generated header file.

* Apply suggestions from code review

Co-authored-by: Boris Zbarsky <[email protected]>

* updated generated file after rebase

* Restyled by whitespace

* Restyled by clang-format

* regen after rebase

* add missing includes

* Restyled by clang-format

* make the clusterNames header public

* Apply suggestions from code review

Co-authored-by: Boris Zbarsky <[email protected]>

* regen

---------

Co-authored-by: Restyled.io <[email protected]>
Co-authored-by: Boris Zbarsky <[email protected]>
  • Loading branch information
3 people authored Feb 2, 2024
1 parent 8834be1 commit e59f2ad
Show file tree
Hide file tree
Showing 6 changed files with 8,801 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/darwin/Framework/CHIP/MTRClusterNames.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
*
* Copyright (c) 2023 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#pragma once

#import <Matter/MTRClusterConstants.h>
#import <Matter/MTRDefines.h>

/**
* This file defines functions to resolve Matter cluster and attribute IDs into
* strings.
*/

/**
* Resolve Matter cluster IDs into a descriptive string.
*
* For unknown IDs, a string '<Unknown clusterID %d>' will be returned.
*/
MTR_EXTERN MTR_NEWLY_AVAILABLE NSString * MTRClusterNameForID(MTRClusterIDType clusterID);

/**
* Resolve Matter attribute IDs into a descriptive string.
*
* For unknown IDs, a string '<Unknown clusterID %d>' (if the cluster ID is not known)
* or '<Unknown attributeID %d>' (if the cluster ID is known but the attribute ID is not known)
* will be returned.
*/
MTR_EXTERN MTR_NEWLY_AVAILABLE NSString * MTRAttributeNameForID(MTRClusterIDType clusterID, MTRAttributeIDType attributeID);
1 change: 1 addition & 0 deletions src/darwin/Framework/CHIP/Matter.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#import <Matter/MTRCertificates.h>
#import <Matter/MTRCluster.h>
#import <Matter/MTRClusterConstants.h>
#import <Matter/MTRClusterNames.h>
#import <Matter/MTRClusterStateCacheContainer.h>
#import <Matter/MTRClusters.h>
#import <Matter/MTRCommandPayloadsObjc.h>
Expand Down
89 changes: 89 additions & 0 deletions src/darwin/Framework/CHIP/templates/MTRClusterNames-src.zapt
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
{{> header excludeZapComment=true}}


#import <Matter/MTRClusterNames.h>

// @implementation MTRClusterAttributeIDType

#pragma mark - Clusters IDs

NSString * MTRClusterNameForID(MTRClusterIDType clusterID)
{
NSString * result = nil;

switch (clusterID) {

{{#zcl_clusters}}
{{#if (isSupported (asUpperCamelCase label preserveAcronyms=true) isForIds=true)}}
{{~#*inline "cluster"}}{{asUpperCamelCase label preserveAcronyms=true}}{{/inline~}}
case MTRClusterIDType{{>cluster}}ID:
result = @"{{>cluster}}";
break;
{{/if}}
{{/zcl_clusters}}

default:
result = [NSString stringWithFormat:@"<Unknown clusterID %d>", clusterID];
break;
}

return result;
}


#pragma mark - Attributes IDs

NSString * MTRAttributeNameForID(MTRClusterIDType clusterID, MTRAttributeIDType attributeID)
{
NSString * result = nil;

switch (clusterID) {

{{#zcl_clusters}}
{{#if (isSupported (asUpperCamelCase label preserveAcronyms=true) isForIds=true)}}
{{~#*inline "cluster"}}{{asUpperCamelCase label preserveAcronyms=true}}{{/inline~}}
case MTRClusterIDType{{>cluster}}ID:

switch (attributeID) {

{{/if}}

{{#*inline "attributeIDs"}}
{{#zcl_attributes_server}}
{{~#*inline "cluster"}}{{asUpperCamelCase ../clusterName preserveAcronyms=true}}{{/inline~}}
{{~#*inline "attribute"}}{{asUpperCamelCase label preserveAcronyms=true}}{{/inline~}}
{{#first}}
{{#if (isSupported (asUpperCamelCase ../clusterName preserveAcronyms=true) isForIds=true)}}
// Cluster {{> cluster}} attributes
{{/if}}
{{/first}}
{{#if (and (isSupported (asUpperCamelCase ../clusterName preserveAcronyms=true) attribute=(asUpperCamelCase label preserveAcronyms=true) isForIds=true)
(or clusterRef
(isSupported "" globalAttribute=(asUpperCamelCase label preserveAcronyms=true) isForIds=true)))}}
case MTRAttributeIDTypeCluster{{>cluster}}Attribute{{>attribute}}ID:
result = @"{{>attribute}}";
break;

{{/if}}
{{/zcl_attributes_server}}
{{/inline}}

{{> attributeIDs clusterName=label}}

{{#if (isSupported (asUpperCamelCase label preserveAcronyms=true) isForIds=true)}}
default:
result = [NSString stringWithFormat:@"<Unknown attributeID %d>", attributeID];
break;
}
{{/if}}

{{/zcl_clusters}}
default:
result = [NSString stringWithFormat:@"<Unknown clusterID %d>", clusterID];
break;
}

return result;
}

// @end
5 changes: 5 additions & 0 deletions src/darwin/Framework/CHIP/templates/templates.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@
"name": "Constants for cluster IDs",
"output": "src/darwin/Framework/CHIP/zap-generated/MTRClusterConstants.h"
},
{
"path": "MTRClusterNames-src.zapt",
"name": "Objc Cluster Names API",
"output": "src/darwin/Framework/CHIP/zap-generated/MTRClusterNames.mm"
},
{
"path": "MTRAttributeSpecifiedCheck-src.zapt",
"name": "Function to check if attribute is specified",
Expand Down
Loading

0 comments on commit e59f2ad

Please sign in to comment.