Skip to content

Commit bca692b

Browse files
committed
Use CharSpan instead of "char *". Refine ifdef
1 parent db71e78 commit bca692b

File tree

4 files changed

+20
-15
lines changed

4 files changed

+20
-15
lines changed

examples/chef/common/clusters/door-lock/chef-doorlock-stubs.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616
* limitations under the License.
1717
*/
1818

19-
#ifdef MATTER_DM_PLUGIN_DOOR_LOCK_SERVER
20-
#include <app/clusters/door-lock-server/door-lock-server.h>
21-
#include <app/data-model/Nullable.h>
2219
#include <app/util/af.h>
20+
#include <app/data-model/Nullable.h>
2321
#include <lib/core/DataModelTypes.h>
2422

23+
#ifdef MATTER_DM_PLUGIN_DOOR_LOCK_SERVER
24+
#include <app/clusters/door-lock-server/door-lock-server.h>
2525
#include "chef-lock-manager.h"
2626

2727
using namespace chip;

examples/chef/common/clusters/door-lock/chef-lock-endpoint.cpp

+11-9
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,17 @@
1515
* See the License for the specific language governing permissions and
1616
* limitations under the License.
1717
*/
18-
#ifdef MATTER_DM_PLUGIN_DOOR_LOCK_SERVER
19-
#include "chef-lock-endpoint.h"
20-
#include <app-common/zap-generated/attributes/Accessors.h>
18+
19+
2120
#include <cstring>
21+
#include <app/util/af.h>
22+
#include <app-common/zap-generated/attributes/Accessors.h>
2223
#include <platform/CHIPDeviceLayer.h>
2324
#include <platform/internal/CHIPDeviceLayerInternal.h>
2425

26+
#ifdef MATTER_DM_PLUGIN_DOOR_LOCK_SERVER
27+
#include "chef-lock-endpoint.h"
28+
2529
using chip::to_underlying;
2630
using chip::app::DataModel::MakeNullable;
2731

@@ -83,7 +87,7 @@ bool LockEndpoint::GetUser(uint16_t userIndex, EmberAfPluginDoorLockUserInfo & u
8387
return true;
8488
}
8589

86-
user.userName = chip::CharSpan(userInDb.userName, strlen(userInDb.userName));
90+
user.userName = userInDb.userName;
8791
user.credentials = chip::Span<const CredentialStruct>(userInDb.credentials.data(), userInDb.credentials.size());
8892
user.userUniqueId = userInDb.userUniqueId;
8993
user.userType = userInDb.userType;
@@ -145,8 +149,8 @@ bool LockEndpoint::SetUser(uint16_t userIndex, chip::FabricIndex creator, chip::
145149
return false;
146150
}
147151

148-
chip::Platform::CopyString(userInStorage.userName, userName);
149-
userInStorage.userName[userName.size()] = 0;
152+
userInStorage.userName = chip::MutableCharSpan(userInStorage.userNameBuf, DOOR_LOCK_USER_NAME_BUFFER_SIZE);
153+
CopyCharSpanToMutableCharSpan(userName, userInStorage.userName);
150154
userInStorage.userUniqueId = uniqueId;
151155
userInStorage.userStatus = userStatus;
152156
userInStorage.userType = usertype;
@@ -606,9 +610,7 @@ bool LockEndpoint::weekDayScheduleForbidsAccess(uint16_t userIndex, bool * haveS
606610
[currentTime, calendarTime](const WeekDaysScheduleInfo & s) {
607611
auto startTime = s.schedule.startHour * chip::kSecondsPerHour + s.schedule.startMinute * chip::kSecondsPerMinute;
608612
auto endTime = s.schedule.endHour * chip::kSecondsPerHour + s.schedule.endMinute * chip::kSecondsPerMinute;
609-
bool ret =
610-
(s.status == DlScheduleStatus::kOccupied && (to_underlying(s.schedule.daysMask) & (1 << calendarTime.tm_wday)) &&
611-
startTime <= currentTime && currentTime <= endTime);
613+
612614
return s.status == DlScheduleStatus::kOccupied && (to_underlying(s.schedule.daysMask) & (1 << calendarTime.tm_wday)) &&
613615
startTime <= currentTime && currentTime <= endTime;
614616
});

examples/chef/common/clusters/door-lock/chef-lock-endpoint.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323

2424
struct LockUserInfo
2525
{
26-
char userName[DOOR_LOCK_USER_NAME_BUFFER_SIZE];
26+
char userNameBuf[DOOR_LOCK_USER_NAME_BUFFER_SIZE];
27+
chip::MutableCharSpan userName;
2728
uint32_t userUniqueId;
2829
UserStatusEnum userStatus;
2930
UserTypeEnum userType;

examples/chef/common/clusters/door-lock/chef-lock-manager.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@
1515
* See the License for the specific language governing permissions and
1616
* limitations under the License.
1717
*/
18-
#ifdef MATTER_DM_PLUGIN_DOOR_LOCK_SERVER
19-
#include "chef-lock-manager.h"
2018
#include <iostream>
19+
#include <app/util/af.h>
2120
#include <lib/support/logging/CHIPLogging.h>
2221

22+
#ifdef MATTER_DM_PLUGIN_DOOR_LOCK_SERVER
23+
#include "chef-lock-manager.h"
24+
2325
using chip::to_underlying;
2426

2527
LockManager LockManager::instance;

0 commit comments

Comments
 (0)