Line data Source code
1 : /**
2 : *
3 : * Copyright (c) 2024 Project CHIP Authors
4 : *
5 : * Licensed under the Apache License, Version 2.0 (the "License");
6 : * you may not use this file except in compliance with the License.
7 : * You may obtain a copy of the License at
8 : *
9 : * http://www.apache.org/licenses/LICENSE-2.0
10 : *
11 : * Unless required by applicable law or agreed to in writing, software
12 : * distributed under the License is distributed on an "AS IS" BASIS,
13 : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 : * See the License for the specific language governing permissions and
15 : * limitations under the License.
16 : */
17 :
18 : #pragma once
19 :
20 : #include <app/ConcreteAttributePath.h>
21 : #include <app/util/MarkAttributeDirty.h>
22 : #include <app/util/attribute-metadata.h>
23 : #include <lib/core/DataModelTypes.h>
24 : #include <protocols/interaction_model/StatusCode.h>
25 :
26 : #include <cstdint>
27 :
28 : struct EmberAfWriteDataInput
29 : {
30 : // Where the input data originates from.
31 : //
32 : // NOTE: at this time there is no information regarding
33 : // input buffer size and it is assumed "correct" for the given data type.
34 : //
35 : // NOTE: technically this should be `const uint8_t*`, however ember internal logic uses a
36 : // `emAfReadOrWriteAttribute` method and because of the duality of read/write it needs
37 : // a non-const input. This is odd and should probably be fixed.
38 : uint8_t * dataPtr;
39 :
40 : // The data type that dataPtr points to
41 : EmberAfAttributeType dataType;
42 :
43 : // Controls when an attribute is marked dirty (via emberAfAttributeChanged)
44 : // kIfChanged - only if the dataPtr contains a different value than what currently exists
45 : // kNo - never called
46 : // kYes - always called
47 : chip::app::MarkAttributeDirty markDirty = chip::app::MarkAttributeDirty::kIfChanged;
48 :
49 118 : EmberAfWriteDataInput(uint8_t * data, EmberAfAttributeType type) : dataPtr(data), dataType(type) {}
50 :
51 : EmberAfWriteDataInput & SetMarkDirty(chip::app::MarkAttributeDirty value)
52 : {
53 : markDirty = value;
54 : return *this;
55 : }
56 : };
57 :
58 : /**
59 : * @brief write an attribute, performing all the checks.
60 : *
61 : * TODO: what are "all the checks"? There are limitations below
62 : * and generally input data pointer does not even have a size,
63 : * hence data validity check capabilities seem limited.
64 : *
65 : * This function will attempt to write the attribute value from
66 : * the provided pointer. This function will only check that the
67 : * attribute exists. If it does it will write the value into
68 : * the attribute table for the given attribute.
69 : *
70 : * This function will not check to see if the attribute is
71 : * writable since the read only / writable characteristic
72 : * of an attribute only pertains to external devices writing
73 : * over the air. Because this function is being called locally
74 : * it assumes that the device knows what it is doing and has permission
75 : * to perform the given operation.
76 : *
77 : * This function also does NOT check that the input dataType matches the expected
78 : * data type (as Accessors.h/cpp have this correct by default).
79 : * TODO: this not checking seems off - what if this is run without Accessors.h ?
80 : */
81 : chip::Protocols::InteractionModel::Status emberAfWriteAttribute(const chip::app::ConcreteAttributePath & path,
82 : const EmberAfWriteDataInput & input);
83 :
84 : /**
85 : * Override of emberAfWriteAttribute to reduce code size for calls that default
86 : * markDirty/changeListener and any other future customization calls.
87 : */
88 : chip::Protocols::InteractionModel::Status emberAfWriteAttribute(chip::EndpointId endpoint, chip::ClusterId cluster,
89 : chip::AttributeId attributeID, uint8_t * dataPtr,
90 : EmberAfAttributeType dataType);
91 :
92 : /**
93 : * @brief Read the attribute value, performing all the checks.
94 : *
95 : * This function will attempt to read the attribute and store it into the
96 : * pointer.
97 : *
98 : * dataPtr may be NULL, signifying that we don't need the value, just the status
99 : * (i.e. whether the attribute can be read).
100 : */
101 : chip::Protocols::InteractionModel::Status emberAfReadAttribute(chip::EndpointId endpoint, chip::ClusterId cluster,
102 : chip::AttributeId attributeID, uint8_t * dataPtr,
103 : uint16_t readLength);
|