-
Notifications
You must be signed in to change notification settings - Fork 2.4k
[BasicInformation] fetch data via a delegate #43569
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
Draft
andy31415
wants to merge
14
commits into
project-chip:master
Choose a base branch
from
andy31415:basic_info_delegate
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 3 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
4fcc37f
Starting a delegate-based basic info implementation
andy31415 1afbe12
Attempt to reduce flash size overhead
andy31415 744fbde
Restyle
andy31415 d8fb3aa
Do not syntesize const char span
andy31415 56ca528
Add back IngoreUnimplemented
andy31415 52b3d2b
Restyle
andy31415 ab56f8b
Move ignoreunimplemented a bit ... want smaller code
andy31415 9ac4fdb
move more logic to string bits, so we maybe save more flash
andy31415 43c85d5
Restyle
andy31415 bbc6606
More changes to reduce vtable size
andy31415 bcc09a4
More consolidation
andy31415 518e7f2
Another attempt to reduce flash... I am afraid this becomes less and …
andy31415 b1d462d
Restyle
andy31415 4f50ce2
Slight update
andy31415 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 hidden or 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 hidden or 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
196 changes: 62 additions & 134 deletions
196
src/app/clusters/basic-information/BasicInformationCluster.cpp
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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
66 changes: 66 additions & 0 deletions
66
src/app/clusters/basic-information/BasicInformationDelegate.h
This file contains hidden or 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,66 @@ | ||
| /* | ||
| * Copyright (c) 2026 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 | ||
|
|
||
| #include <cstddef> | ||
| #include <cstdint> | ||
|
|
||
| #include <clusters/BasicInformation/Enums.h> | ||
| #include <lib/core/CHIPError.h> | ||
| #include <lib/core/DataModelTypes.h> | ||
| #include <lib/support/Span.h> | ||
| #include <platform/DeviceInstanceInfoProvider.h> | ||
|
|
||
| namespace chip { | ||
| namespace app { | ||
| namespace Clusters { | ||
| namespace BasicInformation { | ||
|
|
||
| class BasicInformationDelegate | ||
| { | ||
| public: | ||
| virtual ~BasicInformationDelegate() = default; | ||
|
|
||
| // String Getters | ||
| virtual CHIP_ERROR GetStringAttribute(chip::AttributeId attributeId, MutableCharSpan & buffer) = 0; | ||
| virtual CHIP_ERROR GetManufacturingDate(uint16_t & year, uint8_t & month, uint8_t & day) = 0; | ||
| virtual CHIP_ERROR GetManufacturingDateSuffix(MutableCharSpan & suffixBuffer) = 0; | ||
|
|
||
| // Value Getters | ||
| virtual CHIP_ERROR GetVendorId(uint16_t & vendorId) = 0; | ||
| virtual CHIP_ERROR GetProductId(uint16_t & productId) = 0; | ||
| virtual CHIP_ERROR GetHardwareVersion(uint16_t & hardwareVersion) = 0; | ||
| virtual CHIP_ERROR GetSoftwareVersion(uint32_t & softwareVersion) = 0; | ||
| virtual CHIP_ERROR GetProductFinish(ProductFinishEnum * finish) = 0; | ||
| virtual CHIP_ERROR GetProductPrimaryColor(ColorEnum * primaryColor) = 0; | ||
| virtual CHIP_ERROR GetLocalConfigDisabled(bool & localConfigDisabled) = 0; | ||
| virtual CHIP_ERROR GetConfigurationVersion(uint32_t & configurationVersion) = 0; | ||
| virtual DeviceLayer::DeviceInstanceInfoProvider::DeviceInfoCapabilityMinimas GetSupportedCapabilityMinimaValues() = 0; | ||
|
|
||
| // Setters | ||
| virtual CHIP_ERROR SetLocalConfigDisabled(bool localConfigDisabled) = 0; | ||
| virtual CHIP_ERROR StoreConfigurationVersion(uint32_t configurationVersion) = 0; | ||
| virtual CHIP_ERROR StoreLocation(const CharSpan & code) = 0; | ||
|
|
||
| // Misc | ||
| virtual uint16_t GetSubscriptionsPerFabric() const = 0; | ||
| }; | ||
|
|
||
| } // namespace BasicInformation | ||
| } // namespace Clusters | ||
| } // namespace app | ||
| } // namespace chip |
This file contains hidden or 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
189 changes: 189 additions & 0 deletions
189
src/app/clusters/basic-information/DeviceLayerBasicInformationDelegate.cpp
This file contains hidden or 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,189 @@ | ||
| /* | ||
| * Copyright (c) 2026 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. | ||
| */ | ||
|
|
||
| #include "lib/core/CHIPError.h" | ||
| #include "lib/support/Span.h" | ||
| #include <app/clusters/basic-information/DeviceLayerBasicInformationDelegate.h> | ||
| #include <clusters/BasicInformation/Attributes.h> | ||
| #include <clusters/BasicInformation/Enums.h> | ||
| #include <platform/CHIPDeviceError.h> | ||
|
|
||
| namespace chip { | ||
| namespace app { | ||
| namespace Clusters { | ||
| namespace BasicInformation { | ||
|
|
||
| using namespace DeviceLayer; | ||
|
|
||
| CHIP_ERROR DeviceLayerBasicInformationDelegate::GetStringAttribute(chip::AttributeId attributeId, MutableCharSpan & buffer) | ||
| { | ||
| using namespace Attributes; | ||
|
|
||
| CHIP_ERROR err = CHIP_NO_ERROR; | ||
| size_t dataLen = 0; | ||
|
|
||
| switch (attributeId) | ||
| { | ||
| case VendorName::Id: | ||
| err = mContext.deviceInstanceInfoProvider.GetVendorName(buffer.data(), buffer.size()); | ||
| break; | ||
| case ProductName::Id: | ||
| err = mContext.deviceInstanceInfoProvider.GetProductName(buffer.data(), buffer.size()); | ||
| break; | ||
| case PartNumber::Id: | ||
| err = mContext.deviceInstanceInfoProvider.GetPartNumber(buffer.data(), buffer.size()); | ||
| break; | ||
| case ProductURL::Id: | ||
| err = mContext.deviceInstanceInfoProvider.GetProductURL(buffer.data(), buffer.size()); | ||
| break; | ||
| case ProductLabel::Id: | ||
| err = mContext.deviceInstanceInfoProvider.GetProductLabel(buffer.data(), buffer.size()); | ||
| break; | ||
| case SerialNumber::Id: | ||
| err = mContext.deviceInstanceInfoProvider.GetSerialNumber(buffer.data(), buffer.size()); | ||
| break; | ||
| case HardwareVersionString::Id: | ||
| err = mContext.deviceInstanceInfoProvider.GetHardwareVersionString(buffer.data(), buffer.size()); | ||
| break; | ||
| case SoftwareVersionString::Id: | ||
| err = mContext.configurationManager.GetSoftwareVersionString(buffer.data(), buffer.size()); | ||
| break; | ||
| case UniqueID::Id: | ||
| err = mContext.configurationManager.GetUniqueId(buffer.data(), buffer.size()); | ||
| break; | ||
| case Location::Id: { | ||
| constexpr size_t kExpectedFixedLocationLength = 2; | ||
| err = mContext.configurationManager.GetCountryCode(buffer.data(), buffer.size(), dataLen); | ||
| if ((err != CHIP_NO_ERROR) || (dataLen != kExpectedFixedLocationLength)) | ||
| { | ||
| // Fallback that was here historically | ||
| return CopyCharSpanToMutableCharSpan("XX"_span, buffer); | ||
| } | ||
|
|
||
| buffer.reduce_size(dataLen); | ||
| return err; | ||
| } | ||
| default: | ||
| return CHIP_ERROR_INVALID_ARGUMENT; | ||
| } | ||
|
|
||
| if (err == CHIP_NO_ERROR) | ||
| { | ||
| buffer.reduce_size(strlen(buffer.data())); | ||
| } | ||
| else if (err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND || err == CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE) | ||
| { | ||
| // If the config is not found or the feature is unsupported, return an empty string. | ||
| buffer.reduce_size(0); | ||
| err = CHIP_NO_ERROR; | ||
| } | ||
|
|
||
| return err; | ||
| } | ||
|
|
||
| CHIP_ERROR DeviceLayerBasicInformationDelegate::GetManufacturingDate(uint16_t & year, uint8_t & month, uint8_t & day) | ||
| { | ||
| return mContext.deviceInstanceInfoProvider.GetManufacturingDate(year, month, day); | ||
| } | ||
|
|
||
| CHIP_ERROR DeviceLayerBasicInformationDelegate::GetManufacturingDateSuffix(MutableCharSpan & suffixBuffer) | ||
| { | ||
| return mContext.deviceInstanceInfoProvider.GetManufacturingDateSuffix(suffixBuffer); | ||
| } | ||
|
|
||
| CHIP_ERROR DeviceLayerBasicInformationDelegate::GetVendorId(uint16_t & vendorId) | ||
| { | ||
| return mContext.deviceInstanceInfoProvider.GetVendorId(vendorId); | ||
| } | ||
|
|
||
| CHIP_ERROR DeviceLayerBasicInformationDelegate::GetProductId(uint16_t & productId) | ||
| { | ||
| return mContext.deviceInstanceInfoProvider.GetProductId(productId); | ||
| } | ||
|
|
||
| CHIP_ERROR DeviceLayerBasicInformationDelegate::GetHardwareVersion(uint16_t & hardwareVersion) | ||
| { | ||
| return mContext.deviceInstanceInfoProvider.GetHardwareVersion(hardwareVersion); | ||
| } | ||
|
|
||
| CHIP_ERROR DeviceLayerBasicInformationDelegate::GetSoftwareVersion(uint32_t & softwareVersion) | ||
| { | ||
| return mContext.configurationManager.GetSoftwareVersion(softwareVersion); | ||
| } | ||
|
|
||
| CHIP_ERROR DeviceLayerBasicInformationDelegate::GetProductFinish(ProductFinishEnum * finish) | ||
| { | ||
| return mContext.deviceInstanceInfoProvider.GetProductFinish(finish); | ||
| } | ||
|
|
||
| CHIP_ERROR DeviceLayerBasicInformationDelegate::GetProductPrimaryColor(ColorEnum * primaryColor) | ||
| { | ||
| return mContext.deviceInstanceInfoProvider.GetProductPrimaryColor(primaryColor); | ||
| } | ||
|
|
||
| CHIP_ERROR DeviceLayerBasicInformationDelegate::GetLocalConfigDisabled(bool & localConfigDisabled) | ||
| { | ||
| return mContext.deviceInstanceInfoProvider.GetLocalConfigDisabled(localConfigDisabled); | ||
| } | ||
|
|
||
| CHIP_ERROR DeviceLayerBasicInformationDelegate::GetConfigurationVersion(uint32_t & configurationVersion) | ||
| { | ||
| return mContext.configurationManager.GetConfigurationVersion(configurationVersion); | ||
| } | ||
|
|
||
| DeviceInstanceInfoProvider::DeviceInfoCapabilityMinimas DeviceLayerBasicInformationDelegate::GetSupportedCapabilityMinimaValues() | ||
| { | ||
| return mContext.deviceInstanceInfoProvider.GetSupportedCapabilityMinimaValues(); | ||
| } | ||
|
|
||
| CHIP_ERROR DeviceLayerBasicInformationDelegate::SetLocalConfigDisabled(bool localConfigDisabled) | ||
| { | ||
| return mContext.deviceInstanceInfoProvider.SetLocalConfigDisabled(localConfigDisabled); | ||
| } | ||
|
|
||
| CHIP_ERROR DeviceLayerBasicInformationDelegate::StoreConfigurationVersion(uint32_t configurationVersion) | ||
| { | ||
| return mContext.configurationManager.StoreConfigurationVersion(configurationVersion); | ||
| } | ||
|
|
||
| CHIP_ERROR DeviceLayerBasicInformationDelegate::StoreLocation(const CharSpan & code) | ||
| { | ||
| return mContext.configurationManager.StoreCountryCode(code.data(), code.size()); | ||
| } | ||
|
|
||
| uint16_t DeviceLayerBasicInformationDelegate::GetSubscriptionsPerFabric() const | ||
| { | ||
| return mContext.subscriptionsPerFabric; | ||
| } | ||
|
|
||
| CHIP_ERROR DeviceLayerBasicInformationDelegate::IgnoreUnimplemented(CHIP_ERROR status, char * buf, size_t bufSize) | ||
| { | ||
| if (status == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND || status == CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE) | ||
| { | ||
| if (bufSize > 0) | ||
| { | ||
| buf[0] = 0; | ||
| } | ||
| return CHIP_NO_ERROR; | ||
| } | ||
| return status; | ||
| } | ||
|
|
||
| } // namespace BasicInformation | ||
| } // namespace Clusters | ||
| } // namespace app | ||
| } // namespace chip | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.