Skip to content

Commit 38a7e7a

Browse files
committed
- Replaced the use of char * with MutableCharSpan.
- Removed the use of the VerifyOrExit macro. - Removed `IsSupportedMapChangeAllowed` check in the `AddSupportedMap` method as adding maps does not compromise any of the other attributes.
1 parent 2921b8a commit 38a7e7a

File tree

4 files changed

+283
-313
lines changed

4 files changed

+283
-313
lines changed

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

+3-4
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,12 @@ class RvcServiceAreaDelegate : public Delegate
4444
CHIP_ERROR Init() override;
4545

4646
// command support
47-
bool IsSetSelectedLocationsAllowed(char * statusText) override;
47+
bool IsSetSelectedLocationsAllowed(MutableCharSpan statusText) override;
4848

4949
bool IsValidSelectLocationsSet(const ServiceArea::Commands::SelectLocations::DecodableType & req,
50-
ServiceArea::SelectLocationsStatus & locationStatus, char * statusText,
51-
bool & useStatusText) override;
50+
ServiceArea::SelectLocationsStatus & locationStatus, MutableCharSpan statusText) override;
5251

53-
bool HandleSkipCurrentLocation(char * skipStatusText) override;
52+
bool HandleSkipCurrentLocation(MutableCharSpan skipStatusText) override;
5453

5554
//*************************************************************************
5655
// Supported Locations accessors

examples/rvc-app/rvc-common/src/rvc-service-area-delegate.cpp

+17-23
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <app-common/zap-generated/attributes/Accessors.h>
1919
#include <rvc-service-area-delegate.h>
2020

21+
using namespace chip;
2122
using namespace chip::app::Clusters;
2223
using namespace chip::app::Clusters::ServiceArea;
2324

@@ -74,14 +75,13 @@ CHIP_ERROR RvcServiceAreaDelegate::Init()
7475
//*************************************************************************
7576
// command support
7677

77-
bool RvcServiceAreaDelegate::IsSetSelectedLocationsAllowed(char * statusText)
78+
bool RvcServiceAreaDelegate::IsSetSelectedLocationsAllowed(MutableCharSpan statusText)
7879
{
7980
return true; // TODO IMPLEMENT
8081
};
8182

8283
bool RvcServiceAreaDelegate::IsValidSelectLocationsSet(const Commands::SelectLocations::DecodableType & req,
83-
SelectLocationsStatus & locationStatus, char * statusText,
84-
bool & useStatusText)
84+
SelectLocationsStatus & locationStatus, MutableCharSpan statusText)
8585
{
8686
bool ret_value = false;
8787

@@ -90,7 +90,7 @@ bool RvcServiceAreaDelegate::IsValidSelectLocationsSet(const Commands::SelectLoc
9090
return ret_value;
9191
};
9292

93-
bool RvcServiceAreaDelegate::HandleSkipCurrentLocation(char * skipStatusText)
93+
bool RvcServiceAreaDelegate::HandleSkipCurrentLocation(MutableCharSpan skipStatusText)
9494
{
9595
bool ret_value = false;
9696

@@ -177,23 +177,20 @@ bool RvcServiceAreaDelegate::AddSupportedLocation(const LocationStructureWrapper
177177

178178
bool RvcServiceAreaDelegate::ModifySupportedLocation(uint32_t listIndex, const LocationStructureWrapper & modifiedLocation)
179179
{
180-
bool ret_value = false;
181-
182180
// The server instance (caller) is responsible for ensuring that there are no duplicate location IDs, list size not exceeded,
183181
// etc.
184182

185183
// Double-check that locationID's match.
186-
VerifyOrExit((modifiedLocation.locationID == mSupportedLocations[listIndex].locationID),
187-
ChipLogError(Zcl, "ModifySupportedLocation - new locationID %u does not match existing locationID %u",
188-
modifiedLocation.locationID, mSupportedLocations[listIndex].locationID));
184+
if (modifiedLocation.locationID != mSupportedLocations[listIndex].locationID)
185+
{
186+
ChipLogError(Zcl, "ModifySupportedLocation - locationID's do not match, new locationID %u, existing locationID %u",
187+
modifiedLocation.locationID, mSupportedLocations[listIndex].locationID);
188+
return false;
189+
}
189190

190191
// checks passed, update the attribute
191192
mSupportedLocations[listIndex] = modifiedLocation;
192-
ret_value = true;
193-
194-
exit:
195-
196-
return ret_value;
193+
return true;
197194
}
198195

199196
bool RvcServiceAreaDelegate::ClearSupportedLocations()
@@ -285,22 +282,19 @@ bool RvcServiceAreaDelegate::AddSupportedMap(const MapStructureWrapper & newMap,
285282

286283
bool RvcServiceAreaDelegate::ModifySupportedMap(uint32_t listIndex, const MapStructureWrapper & modifiedMap)
287284
{
288-
bool ret_value = false;
289-
290285
// The server instance (caller) is responsible for ensuring that there are no duplicate location IDs, list size not exceeded,
291286
// etc.
292287

293288
// Double-check that mapID's match.
294-
VerifyOrExit((modifiedMap.mapID == mSupportedMaps[listIndex].mapID),
295-
ChipLogError(Zcl, "ModifySupportedMap - mapID's do not match, new mapID %u, existing mapID %u", modifiedMap.mapID,
296-
mSupportedMaps[listIndex].mapID));
289+
if (modifiedMap.mapID != mSupportedMaps[listIndex].mapID) {
290+
ChipLogError(Zcl, "ModifySupportedMap - mapID's do not match, new mapID %u, existing mapID %u", modifiedMap.mapID,
291+
mSupportedMaps[listIndex].mapID);
292+
return false;
293+
}
297294

298295
// save modified map
299296
mSupportedMaps[listIndex] = modifiedMap;
300-
ret_value = true;
301-
302-
exit:
303-
return ret_value;
297+
return true;
304298
}
305299

306300
bool RvcServiceAreaDelegate::ClearSupportedMaps()

src/app/clusters/service-area-server/service-area-delegate.h

+7-8
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,19 @@ class Delegate
6767
// Command handling support
6868

6969
/**
70-
* @brief can the selected locations be set by the client in the current operating mode?
70+
* @brief Can the selected locations be set by the client in the current operating mode?
7171
* @param[out] statusText text describing why selected locations cannot be set (if return is false).
7272
* @return true if the current device state allows selected locations to be set by user.
7373
*
7474
* @note The statusText field SHOULD indicate why the request is not allowed, given the current mode
7575
* of the device, which may involve other clusters.
7676
*/
77-
virtual bool IsSetSelectedLocationsAllowed(char * statusText) = 0;
77+
virtual bool IsSetSelectedLocationsAllowed(MutableCharSpan statusText) = 0;
7878

7979
/**
8080
* Given a set of locations to be set to the SelectedLocations attribute, this method should check that:
81-
* - There are no duplicates in the list. If there are duplicates, the locationStatus should be set to
82-
* DuplicatedLocations and the statusText should be an empty string.
81+
* - There are no duplicates in the list. If there are duplicates, the locationStatus SHALL be set to
82+
* DuplicatedLocations and the statusText SHALL be an empty string.
8383
* - The set of locations as a whole is valid and reachable by the device. If the set of locations is invalid,
8484
* the locationStatus should be set to InvalidSet and the statusText SHALL include a vendor-defined error description.
8585
*
@@ -89,14 +89,13 @@ class Delegate
8989
* @param[out] locationStatus Success if all checks pass, error code if failure.
9090
* @param[out] statusText text describing failure (see description above), size kMaxSizeStatusText + 1 byte for terminating
9191
* character.
92-
* @param[out] useStatusText if true, the statusText value should be returned in the command response.
9392
* @return true if success.
9493
*
9594
* @note If the SelectLocations command is allowed when the device is operating and the selected locations change to none, the
9695
* device must stop.
9796
*/
9897
virtual bool IsValidSelectLocationsSet(const Commands::SelectLocations::DecodableType & req,
99-
SelectLocationsStatus & locationStatus, char * statusText, bool & useStatusText) = 0;
98+
SelectLocationsStatus & locationStatus, MutableCharSpan statusText) = 0;
10099

101100
/**
102101
* @brief The server instance ensures that the SelectedLocations and CurrentLocation attributes are not null before
@@ -124,10 +123,10 @@ class Delegate
124123
* InvalidInMode, the StatusText field SHOULD indicate why the request is not allowed, given the current mode of the device,
125124
* which may involve other clusters.
126125
*/
127-
virtual bool HandleSkipCurrentLocation(char * skipStatusText)
126+
virtual bool HandleSkipCurrentLocation(MutableCharSpan skipStatusText)
128127
{
129128
// device support of this command is optional
130-
strncat(skipStatusText, "Skip Current Location command not supported by device", kMaxSizeStatusText);
129+
chip::CopyCharSpanToMutableCharSpan("Skip Current Location command not supported by device"_span, skipStatusText);
131130
return false;
132131
}
133132

0 commit comments

Comments
 (0)