Skip to content

Commit ba43ab7

Browse files
committed
Initial copy/merge of the codegendatamodel::write support
1 parent 28430f1 commit ba43ab7

10 files changed

+969
-69
lines changed

src/app/codegen-data-model/BUILD.gn

+4-1
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,11 @@ import("//build_overrides/chip.gni")
2020
#
2121
# Use `model.gni` to get access to:
2222
# CodegenDataModel.cpp
23-
# CodegenDataModel_Read.cpp
2423
# CodegenDataModel.h
24+
# CodegenDataModel_Read.cpp
25+
# CodegenDataModel_Write.cpp
26+
# EmberMetadata.cpp
27+
# EmberMetadata.h
2528
#
2629
# The above list of files exists to satisfy the "dependency linter"
2730
# since those files should technically be "visible to gn" even though we

src/app/codegen-data-model/CodegenDataModel.cpp

-7
Original file line numberDiff line numberDiff line change
@@ -231,13 +231,6 @@ bool CodegenDataModel::EmberCommandListIterator::Exists(const CommandId * list,
231231
return (*mCurrentHint == toCheck);
232232
}
233233

234-
CHIP_ERROR CodegenDataModel::WriteAttribute(const InteractionModel::WriteAttributeRequest & request,
235-
AttributeValueDecoder & decoder)
236-
{
237-
// TODO: this needs an implementation
238-
return CHIP_ERROR_NOT_IMPLEMENTED;
239-
}
240-
241234
CHIP_ERROR CodegenDataModel::Invoke(const InteractionModel::InvokeRequest & request, TLV::TLVReader & input_arguments,
242235
InteractionModel::InvokeReply & reply)
243236
{

src/app/codegen-data-model/CodegenDataModel_Read.cpp

+2-52
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17-
#include "lib/core/CHIPError.h"
1817
#include <app/codegen-data-model/CodegenDataModel.h>
1918

2019
#include <optional>
@@ -29,6 +28,7 @@
2928
#include <app/AttributeValueEncoder.h>
3029
#include <app/GlobalAttributes.h>
3130
#include <app/RequiredPrivilege.h>
31+
#include <app/codegen-data-model/EmberMetadata.h>
3232
#include <app/data-model/FabricScoped.h>
3333
#include <app/util/af-types.h>
3434
#include <app/util/attribute-metadata.h>
@@ -49,56 +49,6 @@ namespace app {
4949
namespace {
5050
using namespace chip::app::Compatibility::Internal;
5151

52-
// Fetch the source for the given attribute path: either a cluster (for global ones) or attribute
53-
// path.
54-
//
55-
// if returning a CHIP_ERROR, it will NEVER be CHIP_NO_ERROR.
56-
std::variant<const EmberAfCluster *, // global attribute, data from a cluster
57-
const EmberAfAttributeMetadata *, // a specific attribute stored by ember
58-
CHIP_ERROR // error, this will NEVER be CHIP_NO_ERROR
59-
>
60-
FindAttributeMetadata(const ConcreteAttributePath & aPath)
61-
{
62-
for (auto & attr : GlobalAttributesNotInMetadata)
63-
{
64-
65-
if (attr == aPath.mAttributeId)
66-
{
67-
const EmberAfCluster * cluster = emberAfFindServerCluster(aPath.mEndpointId, aPath.mClusterId);
68-
if (cluster == nullptr)
69-
{
70-
return (emberAfFindEndpointType(aPath.mEndpointId) == nullptr) ? CHIP_IM_GLOBAL_STATUS(UnsupportedEndpoint)
71-
: CHIP_IM_GLOBAL_STATUS(UnsupportedCluster);
72-
}
73-
74-
return cluster;
75-
}
76-
}
77-
const EmberAfAttributeMetadata * metadata =
78-
emberAfLocateAttributeMetadata(aPath.mEndpointId, aPath.mClusterId, aPath.mAttributeId);
79-
80-
if (metadata == nullptr)
81-
{
82-
const EmberAfEndpointType * type = emberAfFindEndpointType(aPath.mEndpointId);
83-
if (type == nullptr)
84-
{
85-
return CHIP_IM_GLOBAL_STATUS(UnsupportedEndpoint);
86-
}
87-
88-
const EmberAfCluster * cluster = emberAfFindClusterInType(type, aPath.mClusterId, CLUSTER_MASK_SERVER);
89-
if (cluster == nullptr)
90-
{
91-
return CHIP_IM_GLOBAL_STATUS(UnsupportedCluster);
92-
}
93-
94-
// Since we know the attribute is unsupported and the endpoint/cluster are
95-
// OK, this is the only option left.
96-
return CHIP_IM_GLOBAL_STATUS(UnsupportedAttribute);
97-
}
98-
99-
return metadata;
100-
}
101-
10252
/// Attempts to read via an attribute access interface (AAI)
10353
///
10454
/// If it returns a CHIP_ERROR, then this is a FINAL result (i.e. either failure or success).
@@ -320,7 +270,7 @@ CHIP_ERROR CodegenDataModel::ReadAttribute(const InteractionModel::ReadAttribute
320270
}
321271
}
322272

323-
auto metadata = FindAttributeMetadata(request.path);
273+
auto metadata = Ember::FindAttributeMetadata(request.path);
324274

325275
// Explicit failure in finding a suitable metadata
326276
if (const CHIP_ERROR * err = std::get_if<CHIP_ERROR>(&metadata))

0 commit comments

Comments
 (0)