Skip to content

Commit 5ffb598

Browse files
hicklinrestyled-commitsbzbarsky-apple
authored
Create memory delegate (project-chip#35176)
* Created a memory delegate in service area cluster server. * Added supported areas and supported maps Remove methods to the MemoryDelegate and the Instance. * Added selected areas and progress Remove methods to the MemoryDelegate and the Instance. * Moved the `HandleSupportedAreasUpdated` into the server. * Updated the RVC example app according to the latest changes. * Added the suffix Raw to unsanitary methods in the MemoryDelegate. * Restyled by whitespace * Restyled by clang-format * Restyled by gn * Removed unused variables * Restyled by clang-format * Added a readme for the service area cluster. * Restyled by prettier-markdown * Renamed MemoryDelegate to StorageDelegate. * Added documentation noting how to handle MutableCharSpan out params to avoid memory leaks * Restyled by clang-format * Restyled by prettier-markdown * restarting restyler. * Added missed untraced files. * Restyled by clang-format * Apply suggestions from code review Co-authored-by: Boris Zbarsky <bzbarsky@apple.com> * Restyled by clang-format --------- Co-authored-by: Restyled.io <commits@restyled.io> Co-authored-by: Boris Zbarsky <bzbarsky@apple.com>
1 parent e79c277 commit 5ffb598

15 files changed

+1291
-866
lines changed

examples/rvc-app/linux/BUILD.gn

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ executable("chip-rvc-app") {
2828
"${chip_root}/examples/rvc-app/rvc-common/src/rvc-mode-delegates.cpp",
2929
"${chip_root}/examples/rvc-app/rvc-common/src/rvc-operational-state-delegate.cpp",
3030
"${chip_root}/examples/rvc-app/rvc-common/src/rvc-service-area-delegate.cpp",
31+
"${chip_root}/examples/rvc-app/rvc-common/src/rvc-service-area-storage-delegate.cpp",
3132
"RvcAppCommandDelegate.cpp",
3233
"include/CHIPProjectAppConfig.h",
3334
"main.cpp",

examples/rvc-app/rvc-common/include/rvc-device.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "rvc-mode-delegates.h"
44
#include "rvc-operational-state-delegate.h"
55
#include "rvc-service-area-delegate.h"
6+
#include "rvc-service-area-storage-delegate.h"
67
#include <app/clusters/mode-base-server/mode-base-server.h>
78
#include <app/clusters/operational-state-server/operational-state-server.h>
89
#include <app/clusters/service-area-server/service-area-delegate.h>
@@ -27,6 +28,7 @@ class RvcDevice
2728
RvcOperationalState::Instance mOperationalStateInstance;
2829

2930
ServiceArea::RvcServiceAreaDelegate mServiceAreaDelegate;
31+
ServiceArea::RvcServiceAreaStorageDelegate mStorageDelegate;
3032
ServiceArea::Instance mServiceAreaInstance;
3133

3234
bool mDocked = false;
@@ -44,7 +46,7 @@ class RvcDevice
4446
mRunModeDelegate(), mRunModeInstance(&mRunModeDelegate, aRvcClustersEndpoint, RvcRunMode::Id, 0), mCleanModeDelegate(),
4547
mCleanModeInstance(&mCleanModeDelegate, aRvcClustersEndpoint, RvcCleanMode::Id, 0), mOperationalStateDelegate(),
4648
mOperationalStateInstance(&mOperationalStateDelegate, aRvcClustersEndpoint), mServiceAreaDelegate(),
47-
mServiceAreaInstance(&mServiceAreaDelegate, aRvcClustersEndpoint,
49+
mServiceAreaInstance(&mStorageDelegate, &mServiceAreaDelegate, aRvcClustersEndpoint,
4850
BitMask<ServiceArea::Feature>(ServiceArea::Feature::kMaps, ServiceArea::Feature::kProgressReporting))
4951
{
5052
// set the current-mode at start-up

examples/rvc-app/rvc-common/include/rvc-service-area-delegate.h

-78
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,6 @@ namespace ServiceArea {
3838
class RvcServiceAreaDelegate : public Delegate
3939
{
4040
private:
41-
// containers for array attributes.
42-
std::vector<ServiceArea::AreaStructureWrapper> mSupportedAreas;
43-
std::vector<ServiceArea::MapStructureWrapper> mSupportedMaps;
44-
std::vector<uint32_t> mSelectedAreas;
45-
std::vector<ServiceArea::Structs::ProgressStruct::Type> mProgressList;
46-
4741
RvcDevice * mIsSetSelectedAreasAllowedDeviceInstance;
4842
IsSetSelectedAreasAllowedCallback mIsSetSelectedAreasAllowedCallback;
4943
RvcDevice * mHandleSkipAreaDeviceInstance;
@@ -84,82 +78,10 @@ class RvcServiceAreaDelegate : public Delegate
8478

8579
bool HandleSkipArea(uint32_t skippedArea, MutableCharSpan & skipStatusText) override;
8680

87-
//*************************************************************************
88-
// Supported Areas accessors
89-
9081
bool IsSupportedAreasChangeAllowed() override;
9182

92-
uint32_t GetNumberOfSupportedAreas() override;
93-
94-
bool GetSupportedAreaByIndex(uint32_t listIndex, AreaStructureWrapper & supportedArea) override;
95-
96-
bool GetSupportedAreaById(uint32_t aAreaId, uint32_t & listIndex, AreaStructureWrapper & supportedArea) override;
97-
98-
bool AddSupportedArea(const AreaStructureWrapper & newArea, uint32_t & listIndex) override;
99-
100-
bool ModifySupportedArea(uint32_t listIndex, const AreaStructureWrapper & modifiedArea) override;
101-
102-
bool ClearSupportedAreas() override;
103-
104-
/**
105-
* This is a more sophisticated way of ensuring that we all attributes are still valid when a supported area is removed.
106-
* Rather than clearing all the attributes that depend on the supported aeras, we only remove the elements that point to
107-
* the removed supported areas.
108-
*/
109-
void HandleSupportedAreasUpdated() override;
110-
111-
/**
112-
* Note: Call the HandleSupportedAreasUpdated() method when finished removing supported areas.
113-
*/
114-
bool RemoveSupportedArea(uint32_t areaId);
115-
116-
//*************************************************************************
117-
// Supported Maps accessors
118-
11983
bool IsSupportedMapChangeAllowed() override;
12084

121-
uint32_t GetNumberOfSupportedMaps() override;
122-
123-
bool GetSupportedMapByIndex(uint32_t listIndex, ServiceArea::MapStructureWrapper & supportedMap) override;
124-
125-
bool GetSupportedMapById(uint32_t aMapId, uint32_t & listIndex, ServiceArea::MapStructureWrapper & supportedMap) override;
126-
127-
bool AddSupportedMap(const ServiceArea::MapStructureWrapper & newMap, uint32_t & listIndex) override;
128-
129-
bool ModifySupportedMap(uint32_t listIndex, const ServiceArea::MapStructureWrapper & newMap) override;
130-
131-
bool ClearSupportedMaps() override;
132-
133-
bool RemoveSupportedMap(uint32_t mapId);
134-
135-
//*************************************************************************
136-
// Selected Areas accessors
137-
138-
uint32_t GetNumberOfSelectedAreas() override;
139-
140-
bool GetSelectedAreaByIndex(uint32_t listIndex, uint32_t & selectedArea) override;
141-
142-
bool AddSelectedArea(uint32_t aAreaId, uint32_t & listIndex) override;
143-
144-
bool ClearSelectedAreas() override;
145-
146-
//*************************************************************************
147-
// Progress accessors
148-
149-
uint32_t GetNumberOfProgressElements() override;
150-
151-
bool GetProgressElementByIndex(uint32_t listIndex, ServiceArea::Structs::ProgressStruct::Type & aProgressElement) override;
152-
153-
bool GetProgressElementById(uint32_t aAreaId, uint32_t & listIndex,
154-
ServiceArea::Structs::ProgressStruct::Type & aProgressElement) override;
155-
156-
bool AddProgressElement(const ServiceArea::Structs::ProgressStruct::Type & newProgressElement, uint32_t & listIndex) override;
157-
158-
bool ModifyProgressElement(uint32_t listIndex,
159-
const ServiceArea::Structs::ProgressStruct::Type & modifiedProgressElement) override;
160-
161-
bool ClearProgress() override;
162-
16385
//*************************************************************************
16486
// RVC device callback setters
16587

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/*
2+
*
3+
* Copyright (c) 2024 Project CHIP Authors
4+
* All rights reserved.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
#pragma once
20+
21+
#include <app/clusters/service-area-server/service-area-storage-delegate.h>
22+
#include <app/util/config.h>
23+
#include <cstring>
24+
#include <vector>
25+
26+
namespace chip {
27+
namespace app {
28+
namespace Clusters {
29+
30+
class RvcDevice;
31+
32+
namespace ServiceArea {
33+
34+
class RvcServiceAreaStorageDelegate : public StorageDelegate
35+
{
36+
private:
37+
// containers for array attributes.
38+
std::vector<ServiceArea::AreaStructureWrapper> mSupportedAreas;
39+
std::vector<ServiceArea::MapStructureWrapper> mSupportedMaps;
40+
std::vector<uint32_t> mSelectedAreas;
41+
std::vector<ServiceArea::Structs::ProgressStruct::Type> mProgressList;
42+
43+
public:
44+
//*************************************************************************
45+
// Supported Areas accessors
46+
47+
uint32_t GetNumberOfSupportedAreas() override;
48+
49+
bool GetSupportedAreaByIndex(uint32_t listIndex, AreaStructureWrapper & supportedArea) override;
50+
51+
bool GetSupportedAreaById(uint32_t aAreaId, uint32_t & listIndex, AreaStructureWrapper & supportedArea) override;
52+
53+
bool AddSupportedAreaRaw(const AreaStructureWrapper & newArea, uint32_t & listIndex) override;
54+
55+
bool ModifySupportedAreaRaw(uint32_t listIndex, const AreaStructureWrapper & modifiedArea) override;
56+
57+
bool ClearSupportedAreasRaw() override;
58+
59+
bool RemoveSupportedAreaRaw(uint32_t areaId) override;
60+
61+
//*************************************************************************
62+
// Supported Maps accessors
63+
64+
uint32_t GetNumberOfSupportedMaps() override;
65+
66+
bool GetSupportedMapByIndex(uint32_t listIndex, ServiceArea::MapStructureWrapper & supportedMap) override;
67+
68+
bool GetSupportedMapById(uint32_t aMapId, uint32_t & listIndex, ServiceArea::MapStructureWrapper & supportedMap) override;
69+
70+
bool AddSupportedMapRaw(const MapStructureWrapper & newMap, uint32_t & listIndex) override;
71+
72+
bool ModifySupportedMapRaw(uint32_t listIndex, const MapStructureWrapper & newMap) override;
73+
74+
bool ClearSupportedMapsRaw() override;
75+
76+
bool RemoveSupportedMapRaw(uint32_t mapId) override;
77+
78+
//*************************************************************************
79+
// Selected Areas accessors
80+
81+
uint32_t GetNumberOfSelectedAreas() override;
82+
83+
bool GetSelectedAreaByIndex(uint32_t listIndex, uint32_t & selectedArea) override;
84+
85+
bool AddSelectedAreaRaw(uint32_t aAreaId, uint32_t & listIndex) override;
86+
87+
bool ClearSelectedAreasRaw() override;
88+
89+
bool RemoveSelectedAreasRaw(uint32_t areaId) override;
90+
91+
//*************************************************************************
92+
// Progress accessors
93+
94+
uint32_t GetNumberOfProgressElements() override;
95+
96+
bool GetProgressElementByIndex(uint32_t listIndex, ServiceArea::Structs::ProgressStruct::Type & aProgressElement) override;
97+
98+
bool GetProgressElementById(uint32_t aAreaId, uint32_t & listIndex,
99+
ServiceArea::Structs::ProgressStruct::Type & aProgressElement) override;
100+
101+
bool AddProgressElementRaw(const Structs::ProgressStruct::Type & newProgressElement, uint32_t & listIndex) override;
102+
103+
bool ModifyProgressElementRaw(uint32_t listIndex, const Structs::ProgressStruct::Type & modifiedProgressElement) override;
104+
105+
bool ClearProgressRaw() override;
106+
107+
bool RemoveProgressElementRaw(uint32_t areaId) override;
108+
};
109+
110+
} // namespace ServiceArea
111+
} // namespace Clusters
112+
} // namespace app
113+
} // namespace chip

examples/rvc-app/rvc-common/src/rvc-device.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -339,12 +339,12 @@ void RvcDevice::HandleAddServiceAreaArea(ServiceArea::AreaStructureWrapper & are
339339

340340
void RvcDevice::HandleRemoveServiceAreaMap(uint32_t mapId)
341341
{
342-
mServiceAreaDelegate.RemoveSupportedMap(mapId);
342+
mServiceAreaInstance.RemoveSupportedMap(mapId);
343343
}
344344

345345
void RvcDevice::HandleRemoveServiceAreaArea(uint32_t areaId)
346346
{
347-
mServiceAreaDelegate.RemoveSupportedArea(areaId);
347+
mServiceAreaInstance.RemoveSupportedArea(areaId);
348348
}
349349

350350
void RvcDevice::HandleErrorEvent(const std::string & error)
@@ -439,7 +439,7 @@ void RvcDevice::UpdateServiceAreaProgressOnExit()
439439

440440
uint32_t i = 0;
441441
ServiceArea::Structs::ProgressStruct::Type progressElement;
442-
while (mServiceAreaDelegate.GetProgressElementByIndex(i, progressElement))
442+
while (mServiceAreaInstance.GetProgressElementByIndex(i, progressElement))
443443
{
444444
if (progressElement.status == ServiceArea::OperationalStatusEnum::kOperating ||
445445
progressElement.status == ServiceArea::OperationalStatusEnum::kPending)

0 commit comments

Comments
 (0)