-
Notifications
You must be signed in to change notification settings - Fork 2.4k
ZoneMgmtCluster Migration PR#3 move structs #43590
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
Open
marybadalyan
wants to merge
10
commits into
project-chip:master
Choose a base branch
from
marybadalyan:move/zone-management
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.
+481
−359
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
428ba51
Code movements;name changes
marybadalyan 75e04da
Restyled by whitespace
restyled-commits 8671a3d
Restyled by clang-format
restyled-commits 8b72be3
Resolve comments
marybadalyan 51f8607
Restyled by clang-format
restyled-commits 0f5a231
Remove redundant usings;Fix include
marybadalyan 1526b56
Revert name change
marybadalyan cd558eb
Restyled by clang-format
restyled-commits 5703838
Fix naming
marybadalyan 9baa205
Merge branch 'master' into move/zone-management
marybadalyan 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
172 changes: 172 additions & 0 deletions
172
src/app/clusters/zone-management-server/CodegenIntegration.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,172 @@ | ||
| /* | ||
| * | ||
| * 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 <app/AttributeAccessInterface.h> | ||
| #include <app/CommandHandlerInterface.h> | ||
| #include <app/SafeAttributePersistenceProvider.h> | ||
| #include <app/StatusResponse.h> | ||
| #include <app/clusters/zone-management-server/Delegate.h> | ||
| #include <app/clusters/zone-management-server/TwoDCartesianZoneStorage.h> | ||
| #include <app/clusters/zone-management-server/ZoneInformationStorage.h> | ||
| #include <lib/core/CHIPPersistentStorageDelegate.h> | ||
| #include <optional> | ||
| #include <protocols/interaction_model/StatusCode.h> | ||
| #include <vector> | ||
|
|
||
| namespace chip { | ||
| namespace app { | ||
| namespace Clusters { | ||
| namespace ZoneManagement { | ||
|
|
||
| class ZoneMgmtServer : public CommandHandlerInterface, public AttributeAccessInterface | ||
| { | ||
| public: | ||
| /** | ||
| * @brief Creates a Zone Management cluster instance. The Init() function needs to be called for this instance | ||
| * to be registered and called by the interaction model at the appropriate times. | ||
| * | ||
| * @param aDelegate A reference to the delegate to be used by this server. | ||
| * Note: the caller must ensure that the delegate lives throughout the instance's | ||
| * lifetime. | ||
| * | ||
| * @param aEndpointId The endpoint on which this cluster exists. This must match the zap configuration. | ||
| * @param aFeatures The bitflags value that identifies which features are supported by this instance. | ||
| * @param aMaxUserDefinedZones The maximum number of user-defined zones supported by the device. | ||
| * This value is specified by the device manufacturer. | ||
| * @param aMaxZones The maximum number of zones that are allowed to exist on the device. This is the | ||
| * sum of the predefined built-in zones and the user-defined zones. | ||
| * @param aSensitivityMax The hardware-specific value for the number of supported sensitivity levels. | ||
| * This value is specified by the device manufacturer. | ||
| * @param aTwoDCartesianMax The maximum X and Y points that are allowed for TwoD Cartesian Zones. | ||
| * | ||
| */ | ||
| ZoneMgmtServer(Delegate & aDelegate, EndpointId aEndpointId, const BitFlags<Feature> aFeatures, uint8_t aMaxUserDefinedZones, | ||
| uint8_t aMaxZones, uint8_t aSensitivityMax, const TwoDCartesianVertexStruct & aTwoDCartesianMax); | ||
|
|
||
| ~ZoneMgmtServer() override; | ||
|
|
||
| /** | ||
| * @brief Initialise the Zone Management server instance. | ||
| * This function must be called after defining a ZoneMgmtServer class object. | ||
| * @return Returns an error if some of the constraint/feature validation checks fail or | ||
| * the CommandHandler or AttributeHandler registration fails, else returns CHIP_NO_ERROR. | ||
| */ | ||
| CHIP_ERROR Init(); | ||
|
|
||
| bool HasFeature(Feature feature) const; | ||
|
|
||
| // Attribute Setters | ||
| CHIP_ERROR SetSensitivity(uint8_t aSensitivity); | ||
|
|
||
| // Attribute Getters | ||
| const std::vector<ZoneInformationStorage> & GetZones() const { return mZones; } | ||
|
|
||
| const std::vector<ZoneTriggerControlStruct> & GetTriggers() const { return mTriggers; } | ||
|
|
||
| const Optional<ZoneTriggerControlStruct> GetTriggerForZone(uint16_t zoneID); | ||
|
|
||
| uint8_t GetMaxUserDefinedZones() const { return mMaxUserDefinedZones; } | ||
| uint8_t GetMaxZones() const { return mMaxZones; } | ||
| uint8_t GetSensitivityMax() const { return mSensitivityMax; } | ||
| uint8_t GetSensitivity() const { return mSensitivity; } | ||
| const TwoDCartesianVertexStruct & GetTwoDCartesianMax() const { return mTwoDCartesianMax; } | ||
|
|
||
| CHIP_ERROR AddZone(const ZoneInformationStorage & zone); | ||
| CHIP_ERROR UpdateZone(uint16_t zoneId, const ZoneInformationStorage & zone); | ||
| CHIP_ERROR RemoveZone(uint16_t zoneId); | ||
|
|
||
| Protocols::InteractionModel::Status AddOrUpdateTrigger(const ZoneTriggerControlStruct & trigger); | ||
| Protocols::InteractionModel::Status RemoveTrigger(uint16_t zoneId); | ||
|
|
||
| // Generate Zone events | ||
| Protocols::InteractionModel::Status GenerateZoneTriggeredEvent(uint16_t zoneID, ZoneEventTriggeredReasonEnum triggerReason); | ||
| Protocols::InteractionModel::Status GenerateZoneStoppedEvent(uint16_t zoneID, ZoneEventStoppedReasonEnum stopReason); | ||
|
|
||
| private: | ||
| Delegate & mDelegate; | ||
marybadalyan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| EndpointId mEndpointId; | ||
| const BitFlags<Feature> mFeatures; | ||
|
|
||
| // Attributes | ||
| const uint8_t mMaxUserDefinedZones; | ||
| const uint8_t mMaxZones; | ||
| const uint8_t mSensitivityMax; | ||
| const TwoDCartesianVertexStruct mTwoDCartesianMax; | ||
| uint8_t mUserDefinedZonesCount = 0; | ||
|
|
||
| std::vector<ZoneInformationStorage> mZones; | ||
| std::vector<ZoneTriggerControlStruct> mTriggers; | ||
| uint8_t mSensitivity = 0; | ||
|
|
||
| /** | ||
| * IM-level implementation of read | ||
| * @return appropriately mapped CHIP_ERROR if applicable | ||
| */ | ||
| CHIP_ERROR Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) override; | ||
|
|
||
| /** | ||
| * IM-level implementation of write | ||
| * @return appropriately mapped CHIP_ERROR if applicable | ||
| */ | ||
| CHIP_ERROR Write(const ConcreteDataAttributePath & aPath, AttributeValueDecoder & aDecoder) override; | ||
|
|
||
| /** | ||
| * Helper function that loads all the persistent attributes from the KVS. | ||
| */ | ||
| void LoadPersistentAttributes(); | ||
|
|
||
| CHIP_ERROR ReadAndEncodeZones(const AttributeValueEncoder::ListEncodeHelper & encoder); | ||
|
|
||
| CHIP_ERROR ReadAndEncodeTriggers(const AttributeValueEncoder::ListEncodeHelper & encoder); | ||
|
|
||
| Protocols::InteractionModel::Status ValidateTwoDCartesianZone(const TwoDCartesianZoneDecodableStruct & zone); | ||
|
|
||
| Protocols::InteractionModel::Status ValidateTrigger(const ZoneTriggerControlStruct & trigger); | ||
|
|
||
| // Utility that matches a given zone's ZoneUse and verices with the given | ||
| // parameters to check if they match. Used by ZoneAlreadyExists(). | ||
| bool DoZoneUseAndVerticesMatch(ZoneUseEnum use, const std::vector<TwoDCartesianVertexStruct> & vertices, | ||
| const TwoDCartesianZoneStorage & zone); | ||
|
|
||
| // Utility function to check if a given ZoneUse and a TwoDVertex already | ||
| // exists in mZones. | ||
| bool ZoneAlreadyExists(ZoneUseEnum zoneUse, const std::vector<TwoDCartesianVertexStruct> & vertices, | ||
| const DataModel::Nullable<uint16_t> & excludeZoneId); | ||
|
|
||
| /** | ||
| * @brief Inherited from CommandHandlerInterface | ||
| */ | ||
| void InvokeCommand(HandlerContext & ctx) override; | ||
|
|
||
| void HandleCreateTwoDCartesianZone(HandlerContext & ctx, const Commands::CreateTwoDCartesianZone::DecodableType & req); | ||
|
|
||
| void HandleUpdateTwoDCartesianZone(HandlerContext & ctx, const Commands::UpdateTwoDCartesianZone::DecodableType & req); | ||
|
|
||
| void HandleRemoveZone(HandlerContext & ctx, const Commands::RemoveZone::DecodableType & req); | ||
|
|
||
| void HandleCreateOrUpdateTrigger(HandlerContext & ctx, const Commands::CreateOrUpdateTrigger::DecodableType & req); | ||
|
|
||
| void HandleRemoveTrigger(HandlerContext & ctx, const Commands::RemoveTrigger::DecodableType & req); | ||
| }; | ||
|
|
||
| } // namespace ZoneManagement | ||
| } // 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,154 @@ | ||
| /* | ||
| * | ||
| * Copyright (c) 2025 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 <app/clusters/zone-management-server/TwoDCartesianZoneStorage.h> | ||
| #include <app/clusters/zone-management-server/ZoneInformationStorage.h> | ||
| #include <protocols/interaction_model/StatusCode.h> | ||
| #include <vector> | ||
|
|
||
| namespace chip { | ||
| namespace app { | ||
| namespace Clusters { | ||
| namespace ZoneManagement { | ||
|
|
||
| class ZoneMgmtServer; | ||
|
|
||
| /** @brief | ||
| * Defines interfaces for implementing application-specific logic for various aspects of the ZoneManagement Cluster. | ||
| * Specifically, it defines interfaces for the command handling and loading of the allocated streams. | ||
| */ | ||
| class Delegate | ||
marybadalyan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| public: | ||
| Delegate() = default; | ||
|
|
||
| virtual ~Delegate() = default; | ||
|
|
||
| /** | ||
| * @brief Command Delegate for creation of TwoDCartesianZone with the provided parameters. | ||
| * | ||
| * @param[in] zone Structure with parameters for defining a TwoDCartesian zone. | ||
| * | ||
| * @param[out] outZoneID Indicates the ID of the created zone. | ||
| * | ||
| * @return Success if the creation is successful and a zoneID was | ||
| * produced; otherwise, the command SHALL be rejected with an appropriate | ||
| * error. | ||
| */ | ||
| virtual Protocols::InteractionModel::Status CreateTwoDCartesianZone(const TwoDCartesianZoneStorage & zone, | ||
| uint16_t & outZoneID) = 0; | ||
|
|
||
| /** | ||
| * @brief Command Delegate for updating of a TwoDCartesianZone with the provided parameters. | ||
| * | ||
| * @param[in] zoneID Indicates the ID of the zone to update. | ||
| * @param[in] zone Structure with parameters for a TwoDCartesian zone. | ||
| * | ||
| * | ||
| * @return Success if the update is successful; otherwise, the command SHALL be | ||
| * rejected with an appropriate error. | ||
| */ | ||
| virtual Protocols::InteractionModel::Status UpdateTwoDCartesianZone(uint16_t zoneID, const TwoDCartesianZoneStorage & zone) = 0; | ||
|
|
||
| /** | ||
| * @brief Command Delegate for the removal of a TwoDCartesianZone for a given zoneID. | ||
| * | ||
| * @param[in] zoneID Indicates the ID of the zone to remove. | ||
| * | ||
| * @return Success if the removal is successful; otherwise, the command SHALL be | ||
| * rejected with an appropriate error. | ||
| */ | ||
| virtual Protocols::InteractionModel::Status RemoveZone(uint16_t zoneID) = 0; | ||
|
|
||
| /** | ||
| * @brief Command Delegate for creation of a ZoneTrigger. | ||
| * | ||
| * @param[in] zoneTrigger Structure with parameters for defining a ZoneTriggerControl. | ||
| * | ||
| * @return Success if the creation is successful; otherwise, the command SHALL be | ||
| * rejected with an appropriate error. | ||
| */ | ||
| virtual Protocols::InteractionModel::Status CreateTrigger(const ZoneTriggerControlStruct & zoneTrigger) = 0; | ||
|
|
||
| /** | ||
| * @brief Command Delegate for update of a ZoneTrigger. | ||
| * | ||
| * @param[in] zoneTrigger Structure with parameters for defining a ZoneTriggerControl. | ||
| * | ||
| * @return Success if the update is successful; otherwise, the command SHALL be | ||
| * rejected with an appropriate error. | ||
| */ | ||
| virtual Protocols::InteractionModel::Status UpdateTrigger(const ZoneTriggerControlStruct & zoneTrigger) = 0; | ||
|
|
||
| /** | ||
| * @brief Command Delegate for the removal of a ZoneTrigger for a given zoneID. | ||
| * | ||
| * @param[in] zoneID Indicates the ID of the zone to remove the ZoneTrigger for. | ||
| * | ||
| * @return Success if the removal is successful; otherwise, the command SHALL be | ||
| * rejected with an appropriate error. | ||
| */ | ||
| virtual Protocols::InteractionModel::Status RemoveTrigger(uint16_t zoneID) = 0; | ||
|
|
||
| /** | ||
| * @brief Delegate callback for notifying change in an attribute. | ||
| * | ||
| */ | ||
| virtual void OnAttributeChanged(AttributeId attributeId) = 0; | ||
|
|
||
| /** | ||
| * @brief Callback into the delegate once persistent attributes managed by | ||
| * the Cluster have been loaded from Storage. | ||
| */ | ||
| virtual CHIP_ERROR PersistentAttributesLoadedCallback() = 0; | ||
|
|
||
| /** | ||
| * Delegate function to load the created zones and triggers. | ||
| * The application is responsible for persisting them. The Load APIs | ||
| * would be used to load the persisted zones and triggers into the cluster | ||
| * server list members at initialization. | ||
| * Once loaded, the cluster server can serve Reads on these | ||
| * attributes. | ||
| */ | ||
| virtual CHIP_ERROR LoadZones(std::vector<ZoneInformationStorage> & aZones) = 0; | ||
|
|
||
| virtual CHIP_ERROR LoadTriggers(std::vector<ZoneTriggerControlStruct> & aTriggers) = 0; | ||
|
|
||
| ZoneMgmtServer * GetZoneMgmtServer() const { return mZoneMgmtServer; } | ||
|
|
||
| private: | ||
| friend class ZoneMgmtServer; | ||
|
|
||
| ZoneMgmtServer * mZoneMgmtServer = nullptr; | ||
|
|
||
| /** | ||
| * This method is used by the SDK to ensure the delegate points to the server instance it's associated with. | ||
| * When a server instance is created or destroyed, this method will be called to set and clear, respectively, | ||
| * the pointer to the server instance. | ||
| * | ||
| * @param aZoneMgmtServer A pointer to the ZoneMgmtServer object related to this delegate object. | ||
| */ | ||
| void SetZoneMgmtServer(ZoneMgmtServer * aZoneMgmtServer) { mZoneMgmtServer = aZoneMgmtServer; } | ||
| }; | ||
|
|
||
| } // namespace ZoneManagement | ||
| } // 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.