-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Basic data model structure #1468
Closed
Closed
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
10e1df4
Prefix simulated datamodel with 'App' to avoid conflicts
kedars 4cca13d
Create baseline classes for 'Value' and 'Attribute'
kedars 3d409c8
Use enum instead of template
kedars eb9c412
Get a basic Cluster Server structure
kedars a43a2c9
Let LEDWidget class in wifi-echo implement the OnOff Cluster
kedars ed27179
Restyled by clang-format
restyled-commits dc2f1d9
Fix incorrect data type
kedars 1e4612c
Endpoint 0 is reserved
kedars 2a33054
Eliminate CHIP prefix from the datatype/function names
kedars 71f575f
Move to lib/datamodel from lib/core
kedars 825133e
Use a static allocation of the Basic Cluster instead of on the heap
kedars 8ef76bf
add skeleton tests directory, tweaks to make system
3424e9e
fixup
d4e4f54
remove CHIP for files that live in datamodel/ subdir
5fd8f44
more little renames
16d7861
Add tests for ClusterServer
kedars 19133b5
Use CHIPError.h for errors
kedars 9b5a74d
Move standard clusters in their own files
kedars 679cc6b
Documentation updates
kedars 5eee74d
Missed the change in the test file
kedars 725ddca
* add Deque.h
300cf24
fixups
8e8e293
add documentation
adfc032
Minor fixes
kedars 38ef849
Include Dequeue.h to the build system
kedars bc6f68e
Fix tests
kedars b520ca1
Restyled fixes
restyled-commits d2178f4
Add 'gn' support
kedars f878cec
Fixes from review feedback
kedars 94c7525
include lib/datamodel/.. -> include datamodel/...
087e036
Move the ZCLVersion/StackVersion within the SDK
kedars 8a84cfb
restyle
kedars 3e390b8
functor instead of std::function
4901e06
Use 'g' prefix for globals
kedars 41fe827
Introduce ClusterId_t and AttributeId_t
kedars f42189d
Don't embed 'enum' or min/max in the Attribute class
kedars File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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,117 @@ | ||
/* | ||
* | ||
* Copyright (c) 2020 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. | ||
*/ | ||
|
||
/** | ||
* @file | ||
* This file contains definitions for working with CHIP Attributes | ||
* | ||
*/ | ||
|
||
#ifndef CHIP_ATTRIBUTE_H_ | ||
#define CHIP_ATTRIBUTE_H_ | ||
|
||
#include <datamodel/Deque.h> | ||
#include <datamodel/Value.h> | ||
|
||
#include <core/CHIPError.h> | ||
|
||
namespace chip { | ||
namespace DataModel { | ||
|
||
typedef uint16_t AttributeId_t; | ||
/** | ||
* @brief | ||
* This class implements a single attribute. | ||
*/ | ||
class Attribute | ||
{ | ||
private: | ||
Deque<Attribute> mDeque; | ||
friend class Cluster; | ||
|
||
public: | ||
AttributeId_t mAttrId; | ||
|
||
Attribute(AttributeId_t attrId) : mDeque(this), mAttrId(attrId) {} | ||
|
||
/** | ||
* @brief | ||
* Set this attribute to a value | ||
* | ||
* @param value the new value that this attribute should be updated with | ||
*/ | ||
virtual CHIP_ERROR Set(const Value & newValue) = 0; | ||
|
||
/* Need to define the behaviour when Value contains pointers | ||
* to allocated data | ||
*/ | ||
/** | ||
* @brief | ||
* Get the value of this attribute | ||
* | ||
*/ | ||
virtual Value Get(void) = 0; | ||
}; | ||
|
||
template <typename ValueType> | ||
class AttributeSimple : public Attribute | ||
{ | ||
private: | ||
ValueType mValue; | ||
|
||
public: | ||
AttributeSimple(AttributeId_t attrId) : Attribute(attrId) {} | ||
AttributeSimple(AttributeId_t attrId, ValueType value) : Attribute(attrId), mValue(value) {} | ||
|
||
CHIP_ERROR Set(const Value & newValue) { return ValueToType(newValue, mValue); } | ||
|
||
Value Get(void) { return TypeToValue(mValue); } | ||
}; | ||
|
||
template <typename ValueType, ValueType min, ValueType max> | ||
class AttributeWithRange : public Attribute | ||
{ | ||
private: | ||
ValueType mValue; | ||
const ValueType mMin = min; | ||
const ValueType mMax = max; | ||
|
||
public: | ||
AttributeWithRange(AttributeId_t attrId) : Attribute(attrId) {} | ||
AttributeWithRange(AttributeId_t attrId, ValueType value) : Attribute(attrId), mValue(value) {} | ||
|
||
CHIP_ERROR Set(const Value & newValue) | ||
{ | ||
ValueType tmp; | ||
if (ValueToType(newValue, tmp) == CHIP_NO_ERROR) | ||
{ | ||
if ((tmp >= mMin) && (tmp <= mMax)) | ||
{ | ||
mValue = tmp; | ||
return CHIP_NO_ERROR; | ||
} | ||
} | ||
return CHIP_ERROR_INTERNAL; | ||
} | ||
|
||
Value Get(void) { return TypeToValue(mValue); } | ||
}; | ||
|
||
} // namespace DataModel | ||
} // namespace chip | ||
|
||
#endif /* CHIP_ATTRIBUTE_H_ */ |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This means a vtable pointer for every attribute, as well as extra vtables for each subclass (2 so far).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is also type-erased, with
Value
hiding the actual type of the underlying value element.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With Value being still a union, it means that the caller is still going to pay the penalty of maximal storage when utilizing this API.
This API is no better than just having
Set(void *value)
- the union insideValue
is effectively an opaque data store. In fact, the latter is better since the caller-side allocated storage for the value is exactly as big as the type of the value they're trying to set.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
The other thing to note is that for primitive values that fit in a single register passing them by value produces slightly smaller code than the const reference.