-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Zap add accessors helpers for attributes (#7183)
* Add Attributes Accessors into src/app/common/gen * Update some ZCL definition types to use the types from the spec * Update gen/ folders
- Loading branch information
1 parent
c2b9b9c
commit 311035a
Showing
15 changed files
with
10,748 additions
and
144 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* | ||
* Copyright (c) 2021 Project CHIP Authors | ||
* | ||
* 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. | ||
*/ | ||
|
||
const kType = 'STRUCT'; | ||
|
||
function isStruct(type) | ||
{ | ||
return type.toUpperCase() == kType; | ||
} | ||
|
||
// | ||
// Module exports | ||
// | ||
exports.isStruct = isStruct; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* | ||
* Copyright (c) 2021 Project CHIP Authors | ||
* | ||
* 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. | ||
*/ | ||
|
||
const ListHelper = require('../../common/ListHelper.js'); | ||
const StringHelper = require('../../common/StringHelper.js'); | ||
const StructHelper = require('../../common/StructHelper.js'); | ||
|
||
// Issue #8202 | ||
// The specification allow non-standard signed and unsigned integer with a width of 24, 40, 48 or 56, but those types does not have | ||
// proper support yet into the codebase and the resulting generated code can not be built with them. | ||
// Once they are supported, the following method could be removed. | ||
const unsupportedTypes = [ 'INT24S', 'INT40S', 'INT48S', 'INT56S', 'INT24U', 'INT40U', 'INT48U', 'INT56U' ]; | ||
function isUnsupportedType(type) | ||
{ | ||
return unsupportedTypes.includes(type.toUpperCase()); | ||
} | ||
|
||
function canHaveSimpleAccessors(type) | ||
{ | ||
if (StringHelper.isString(type)) { | ||
return false; | ||
} | ||
|
||
if (ListHelper.isList(type)) { | ||
return false; | ||
} | ||
|
||
if (StructHelper.isStruct(type)) { | ||
return false; | ||
} | ||
|
||
if (isUnsupportedType(type)) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
// | ||
// Module exports | ||
// | ||
exports.canHaveSimpleAccessors = canHaveSimpleAccessors; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/app/zap-templates/templates/app/attributes/Accessors-src.zapt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
{{>header}} | ||
|
||
/** | ||
* @file | ||
* This file contains definitions for accessors around clusters attributes. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <app/common/gen/attributes/Accessors.h> | ||
|
||
#include <app/common/gen/ids/Attributes.h> | ||
#include <app/common/gen/ids/Clusters.h> | ||
|
||
namespace chip { | ||
namespace app { | ||
namespace Clusters { | ||
|
||
{{#zcl_clusters}} | ||
{{#zcl_attributes_server}} | ||
{{#if (hasSpecificAttributes)}} | ||
{{#first}} | ||
namespace {{asUpperCamelCase parent.label}} { | ||
namespace Attributes { | ||
{{/first}} | ||
{{#if clusterRef}} | ||
{{#if (canHaveSimpleAccessors type)}} | ||
EmberAfStatus Get{{asUpperCamelCase label}}(chip::EndpointId endpoint, {{asUnderlyingZclType type}} * {{asLowerCamelCase label}}) | ||
{ | ||
return emberAfReadServerAttribute(endpoint, {{asUpperCamelCase parent.label}}::Id, Ids::{{asUpperCamelCase label}}, (uint8_t *) {{asLowerCamelCase label}}, sizeof(*{{asLowerCamelCase label}})); | ||
|
||
} | ||
EmberAfStatus Set{{asUpperCamelCase label}}(chip::EndpointId endpoint, {{asUnderlyingZclType type}} {{asLowerCamelCase label}}) | ||
{ | ||
return emberAfWriteServerAttribute(endpoint, {{asUpperCamelCase parent.label}}::Id, Ids::{{asUpperCamelCase label}}, (uint8_t *) &{{asLowerCamelCase label}}, ZCL_{{asDelimitedMacro type}}_ATTRIBUTE_TYPE); | ||
} | ||
{{/if}} | ||
{{/if}} | ||
{{#last}} | ||
} // namespace Attributes | ||
} // {{asUpperCamelCase parent.label}} | ||
|
||
{{/last}} | ||
{{/if}} | ||
{{/zcl_attributes_server}} | ||
{{/zcl_clusters}} | ||
|
||
} // Clusters | ||
} // app | ||
} // chip |
41 changes: 41 additions & 0 deletions
41
src/app/zap-templates/templates/app/attributes/Accessors.zapt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{{>header}} | ||
|
||
/** | ||
* @file | ||
* This file contains declarations for accessors around clusters attributes. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <app/util/af-types.h> | ||
#include <lib/support/Span.h> | ||
|
||
namespace chip { | ||
namespace app { | ||
namespace Clusters { | ||
|
||
{{#zcl_clusters}} | ||
{{#zcl_attributes_server}} | ||
{{#if (hasSpecificAttributes)}} | ||
{{#first}} | ||
namespace {{asUpperCamelCase parent.label}} { | ||
namespace Attributes { | ||
{{/first}} | ||
{{#if clusterRef}} | ||
{{#if (canHaveSimpleAccessors type)}} | ||
EmberAfStatus Get{{asUpperCamelCase label}}(chip::EndpointId endpoint, {{asUnderlyingZclType type}} * {{asLowerCamelCase label}}); // {{type}} {{isArray}} | ||
EmberAfStatus Set{{asUpperCamelCase label}}(chip::EndpointId endpoint, {{asUnderlyingZclType type}} {{asLowerCamelCase label}}); | ||
{{/if}} | ||
{{/if}} | ||
{{#last}} | ||
} // namespace Attributes | ||
} // {{asUpperCamelCase parent.label}} | ||
|
||
{{/last}} | ||
{{/if}} | ||
{{/zcl_attributes_server}} | ||
{{/zcl_clusters}} | ||
|
||
} // Clusters | ||
} // app | ||
} // chip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.