Skip to content

Commit

Permalink
#26925 pass fabricIdx and nodeId instead of commandObj
Browse files Browse the repository at this point in the history
  • Loading branch information
mmarc committed Jul 19, 2023
1 parent c41c2de commit a1850d5
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 77 deletions.
17 changes: 9 additions & 8 deletions examples/lock-app/lock-common/include/LockEndpoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ class LockEndpoint

inline chip::EndpointId GetEndpointId() const { return mEndpointId; }

bool Lock(const chip::app::CommandHandler * commandObj, const Optional<chip::ByteSpan> & pin, OperationErrorEnum & err,
OperationSourceEnum opSource);
bool Unlock(const chip::app::CommandHandler * commandObj, const Optional<chip::ByteSpan> & pin, OperationErrorEnum & err,
OperationSourceEnum opSource);
bool Unbolt(const chip::app::CommandHandler * commandObj, const Optional<chip::ByteSpan> & pin, OperationErrorEnum & err,
OperationSourceEnum opSource);
bool Lock(const Nullable<chip::FabricIndex> & fabricIdx, const Nullable<chip::NodeId> & nodeId,
const Optional<chip::ByteSpan> & pin, OperationErrorEnum & err, OperationSourceEnum opSource);
bool Unlock(const Nullable<chip::FabricIndex> & fabricIdx, const Nullable<chip::NodeId> & nodeId,
const Optional<chip::ByteSpan> & pin, OperationErrorEnum & err, OperationSourceEnum opSource);
bool Unbolt(const Nullable<chip::FabricIndex> & fabricIdx, const Nullable<chip::NodeId> & nodeId,
const Optional<chip::ByteSpan> & pin, OperationErrorEnum & err, OperationSourceEnum opSource);

bool GetUser(uint16_t userIndex, EmberAfPluginDoorLockUserInfo & user) const;
bool SetUser(uint16_t userIndex, chip::FabricIndex creator, chip::FabricIndex modifier, const chip::CharSpan & userName,
Expand Down Expand Up @@ -101,8 +101,9 @@ class LockEndpoint
OperatingModeEnum operatingMode);

private:
bool setLockState(const chip::app::CommandHandler * commandObj, DlLockState lockState, const Optional<chip::ByteSpan> & pin,
OperationErrorEnum & err, OperationSourceEnum opSource = OperationSourceEnum::kUnspecified);
bool setLockState(const Nullable<chip::FabricIndex> & fabricIdx, const Nullable<chip::NodeId> & nodeId, DlLockState lockState,
const Optional<chip::ByteSpan> & pin, OperationErrorEnum & err,
OperationSourceEnum opSource = OperationSourceEnum::kUnspecified);
const char * lockStateToString(DlLockState lockState) const;

bool weekDayScheduleInAction(uint16_t userIndex) const;
Expand Down
12 changes: 6 additions & 6 deletions examples/lock-app/lock-common/include/LockManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ class LockManager

bool SendLockAlarm(chip::EndpointId endpointId, AlarmCodeEnum alarmCode);

bool Lock(const chip::app::CommandHandler * commandObj, chip::EndpointId endpointId, const Optional<chip::ByteSpan> & pin,
OperationErrorEnum & err, OperationSourceEnum opSource);
bool Unlock(const chip::app::CommandHandler * commandObj, chip::EndpointId endpointId, const Optional<chip::ByteSpan> & pin,
OperationErrorEnum & err, OperationSourceEnum opSource);
bool Unbolt(const chip::app::CommandHandler * commandObj, chip::EndpointId endpointId, const Optional<chip::ByteSpan> & pin,
OperationErrorEnum & err, OperationSourceEnum opSource);
bool Lock(chip::EndpointId endpointId, const Nullable<chip::FabricIndex> & fabricIdx, const Nullable<chip::NodeId> & nodeId,
const Optional<chip::ByteSpan> & pin, OperationErrorEnum & err, OperationSourceEnum opSource);
bool Unlock(chip::EndpointId endpointId, const Nullable<chip::FabricIndex> & fabricIdx, const Nullable<chip::NodeId> & nodeId,
const Optional<chip::ByteSpan> & pin, OperationErrorEnum & err, OperationSourceEnum opSource);
bool Unbolt(chip::EndpointId endpointId, const Nullable<chip::FabricIndex> & fabricIdx, const Nullable<chip::NodeId> & nodeId,
const Optional<chip::ByteSpan> & pin, OperationErrorEnum & err, OperationSourceEnum opSource);

bool GetUser(chip::EndpointId endpointId, uint16_t userIndex, EmberAfPluginDoorLockUserInfo & user);
bool SetUser(chip::EndpointId endpointId, uint16_t userIndex, chip::FabricIndex creator, chip::FabricIndex modifier,
Expand Down
27 changes: 14 additions & 13 deletions examples/lock-app/lock-common/src/LockEndpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,28 @@
using chip::to_underlying;
using chip::app::DataModel::MakeNullable;

bool LockEndpoint::Lock(const chip::app::CommandHandler * commandObj, const Optional<chip::ByteSpan> & pin,
OperationErrorEnum & err, OperationSourceEnum opSource)
bool LockEndpoint::Lock(const Nullable<chip::FabricIndex> & fabricIdx, const Nullable<chip::NodeId> & nodeId,
const Optional<chip::ByteSpan> & pin, OperationErrorEnum & err, OperationSourceEnum opSource)
{
return setLockState(commandObj, DlLockState::kLocked, pin, err, opSource);
return setLockState(fabricIdx, nodeId, DlLockState::kLocked, pin, err, opSource);
}

bool LockEndpoint::Unlock(const chip::app::CommandHandler * commandObj, const Optional<chip::ByteSpan> & pin,
OperationErrorEnum & err, OperationSourceEnum opSource)
bool LockEndpoint::Unlock(const Nullable<chip::FabricIndex> & fabricIdx, const Nullable<chip::NodeId> & nodeId,
const Optional<chip::ByteSpan> & pin, OperationErrorEnum & err, OperationSourceEnum opSource)
{
if (DoorLockServer::Instance().SupportsUnbolt(mEndpointId))
{
// If Unbolt is supported Unlock is supposed to pull the latch
setLockState(commandObj, DlLockState::kUnlatched, pin, err, opSource);
setLockState(fabricIdx, nodeId, DlLockState::kUnlatched, pin, err, opSource);
}

return setLockState(commandObj, DlLockState::kUnlocked, pin, err, opSource);
return setLockState(fabricIdx, nodeId, DlLockState::kUnlocked, pin, err, opSource);
}

bool LockEndpoint::Unbolt(const chip::app::CommandHandler * commandObj, const Optional<chip::ByteSpan> & pin,
OperationErrorEnum & err, OperationSourceEnum opSource)
bool LockEndpoint::Unbolt(const Nullable<chip::FabricIndex> & fabricIdx, const Nullable<chip::NodeId> & nodeId,
const Optional<chip::ByteSpan> & pin, OperationErrorEnum & err, OperationSourceEnum opSource)
{
return setLockState(commandObj, DlLockState::kUnlocked, pin, err, opSource);
return setLockState(fabricIdx, nodeId, DlLockState::kUnlocked, pin, err, opSource);
}

bool LockEndpoint::GetUser(uint16_t userIndex, EmberAfPluginDoorLockUserInfo & user) const
Expand Down Expand Up @@ -391,8 +391,9 @@ DlStatus LockEndpoint::SetSchedule(uint8_t holidayIndex, DlScheduleStatus status
return DlStatus::kSuccess;
}

bool LockEndpoint::setLockState(const chip::app::CommandHandler * commandObj, DlLockState lockState,
const Optional<chip::ByteSpan> & pin, OperationErrorEnum & err, OperationSourceEnum opSource)
bool LockEndpoint::setLockState(const Nullable<chip::FabricIndex> & fabricIdx, const Nullable<chip::NodeId> & nodeId,
DlLockState lockState, const Optional<chip::ByteSpan> & pin, OperationErrorEnum & err,
OperationSourceEnum opSource)
{
// Assume pin is required until told otherwise
bool requirePin = true;
Expand Down Expand Up @@ -478,7 +479,7 @@ bool LockEndpoint::setLockState(const chip::app::CommandHandler * commandObj, Dl
LockOpCredentials userCredential[] = { { CredentialTypeEnum::kPin, uint16_t(credentialIndex) } };
auto userCredentials = MakeNullable<List<const LockOpCredentials>>(userCredential);
DoorLockServer::Instance().SetLockState(mEndpointId, mLockState, opSource, MakeNullable(static_cast<uint16_t>(userIndex + 1)),
userCredentials, commandObj);
userCredentials, fabricIdx, nodeId);

return true;
}
Expand Down
21 changes: 12 additions & 9 deletions examples/lock-app/lock-common/src/LockManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,40 +134,43 @@ bool LockManager::SendLockAlarm(chip::EndpointId endpointId, AlarmCodeEnum alarm
return lockEndpoint->SendLockAlarm(alarmCode);
}

bool LockManager::Lock(const chip::app::CommandHandler * commandObj, chip::EndpointId endpointId,
const Optional<chip::ByteSpan> & pin, OperationErrorEnum & err, OperationSourceEnum opSource)
bool LockManager::Lock(chip::EndpointId endpointId, const Nullable<chip::FabricIndex> & fabricIdx,
const Nullable<chip::NodeId> & nodeId, const Optional<chip::ByteSpan> & pin, OperationErrorEnum & err,
OperationSourceEnum opSource)
{
auto lockEndpoint = getEndpoint(endpointId);
if (nullptr == lockEndpoint)
{
ChipLogError(Zcl, "Unable to lock the door - endpoint does not exist or not initialized [endpointId=%d]", endpointId);
return false;
}
return lockEndpoint->Lock(commandObj, pin, err, opSource);
return lockEndpoint->Lock(fabricIdx, nodeId, pin, err, opSource);
}

bool LockManager::Unlock(const chip::app::CommandHandler * commandObj, chip::EndpointId endpointId,
const Optional<chip::ByteSpan> & pin, OperationErrorEnum & err, OperationSourceEnum opSource)
bool LockManager::Unlock(chip::EndpointId endpointId, const Nullable<chip::FabricIndex> & fabricIdx,
const Nullable<chip::NodeId> & nodeId, const Optional<chip::ByteSpan> & pin, OperationErrorEnum & err,
OperationSourceEnum opSource)
{
auto lockEndpoint = getEndpoint(endpointId);
if (nullptr == lockEndpoint)
{
ChipLogError(Zcl, "Unable to unlock the door - endpoint does not exist or not initialized [endpointId=%d]", endpointId);
return false;
}
return lockEndpoint->Unlock(commandObj, pin, err, opSource);
return lockEndpoint->Unlock(fabricIdx, nodeId, pin, err, opSource);
}

bool LockManager::Unbolt(const chip::app::CommandHandler * commandObj, chip::EndpointId endpointId,
const Optional<chip::ByteSpan> & pin, OperationErrorEnum & err, OperationSourceEnum opSource)
bool LockManager::Unbolt(chip::EndpointId endpointId, const Nullable<chip::FabricIndex> & fabricIdx,
const Nullable<chip::NodeId> & nodeId, const Optional<chip::ByteSpan> & pin, OperationErrorEnum & err,
OperationSourceEnum opSource)
{
auto lockEndpoint = getEndpoint(endpointId);
if (nullptr == lockEndpoint)
{
ChipLogError(Zcl, "Unable to unbolt the door - endpoint does not exist or not initialized [endpointId=%d]", endpointId);
return false;
}
return lockEndpoint->Unbolt(commandObj, pin, err, opSource);
return lockEndpoint->Unbolt(fabricIdx, nodeId, pin, err, opSource);
}

bool LockManager::GetUser(chip::EndpointId endpointId, uint16_t userIndex, EmberAfPluginDoorLockUserInfo & user)
Expand Down
21 changes: 12 additions & 9 deletions examples/lock-app/lock-common/src/ZCLDoorLockCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,25 @@ using namespace chip::app::Clusters::DoorLock;
// should wait for door to be locked on lock command and return success) but
// door lock server should check pin before even calling the lock-door
// callback.
bool emberAfPluginDoorLockOnDoorLockCommand(const chip::app::CommandHandler * commandObj, chip::EndpointId endpointId,
const Optional<ByteSpan> & pinCode, OperationErrorEnum & err)
bool emberAfPluginDoorLockOnDoorLockCommand(chip::EndpointId endpointId, const Nullable<chip::FabricIndex> & fabricIdx,
const Nullable<chip::NodeId> & nodeId, const Optional<ByteSpan> & pinCode,
OperationErrorEnum & err)
{
return LockManager::Instance().Lock(commandObj, endpointId, pinCode, err, OperationSourceEnum::kRemote);
return LockManager::Instance().Lock(endpointId, fabricIdx, nodeId, pinCode, err, OperationSourceEnum::kRemote);
}

bool emberAfPluginDoorLockOnDoorUnlockCommand(const chip::app::CommandHandler * commandObj, chip::EndpointId endpointId,
const Optional<ByteSpan> & pinCode, OperationErrorEnum & err)
bool emberAfPluginDoorLockOnDoorUnlockCommand(chip::EndpointId endpointId, const Nullable<chip::FabricIndex> & fabricIdx,
const Nullable<chip::NodeId> & nodeId, const Optional<ByteSpan> & pinCode,
OperationErrorEnum & err)
{
return LockManager::Instance().Unlock(commandObj, endpointId, pinCode, err, OperationSourceEnum::kRemote);
return LockManager::Instance().Unlock(endpointId, fabricIdx, nodeId, pinCode, err, OperationSourceEnum::kRemote);
}

bool emberAfPluginDoorLockOnDoorUnboltCommand(const chip::app::CommandHandler * commandObj, chip::EndpointId endpointId,
const Optional<ByteSpan> & pinCode, OperationErrorEnum & err)
bool emberAfPluginDoorLockOnDoorUnboltCommand(chip::EndpointId endpointId, const Nullable<chip::FabricIndex> & fabricIdx,
const Nullable<chip::NodeId> & nodeId, const Optional<ByteSpan> & pinCode,
OperationErrorEnum & err)
{
return LockManager::Instance().Unbolt(commandObj, endpointId, pinCode, err, OperationSourceEnum::kRemote);
return LockManager::Instance().Unbolt(endpointId, fabricIdx, nodeId, pinCode, err, OperationSourceEnum::kRemote);
}

bool emberAfPluginDoorLockGetUser(chip::EndpointId endpointId, uint16_t userIndex, EmberAfPluginDoorLockUserInfo & user)
Expand Down
15 changes: 9 additions & 6 deletions src/app/clusters/door-lock-server/door-lock-server-callback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,24 +45,27 @@ using namespace chip::app::Clusters::DoorLock;
// =============================================================================

bool __attribute__((weak))
emberAfPluginDoorLockOnDoorLockCommand(const chip::app::CommandHandler * commandObj, chip::EndpointId endpointId,
const Optional<ByteSpan> & pinCode, OperationErrorEnum & err)
emberAfPluginDoorLockOnDoorLockCommand(chip::EndpointId endpointId, const Nullable<chip::FabricIndex> & fabricIdx,
const Nullable<chip::NodeId> & nodeId, const Optional<ByteSpan> & pinCode,
OperationErrorEnum & err)
{
err = OperationErrorEnum::kUnspecified;
return false;
}

bool __attribute__((weak))
emberAfPluginDoorLockOnDoorUnlockCommand(const chip::app::CommandHandler * commandObj, chip::EndpointId endpointId,
const Optional<ByteSpan> & pinCode, OperationErrorEnum & err)
emberAfPluginDoorLockOnDoorUnlockCommand(chip::EndpointId endpointId, const Nullable<chip::FabricIndex> & fabricIdx,
const Nullable<chip::NodeId> & nodeId, const Optional<ByteSpan> & pinCode,
OperationErrorEnum & err)
{
err = OperationErrorEnum::kUnspecified;
return false;
}

bool __attribute__((weak))
emberAfPluginDoorLockOnDoorUnboltCommand(const chip::app::CommandHandler * commandObj, chip::EndpointId endpointId,
const Optional<ByteSpan> & pinCode, OperationErrorEnum & err)
emberAfPluginDoorLockOnDoorUnboltCommand(chip::EndpointId endpointId, const Nullable<chip::FabricIndex> & fabricIdx,
const Nullable<chip::NodeId> & nodeId, const Optional<ByteSpan> & pinCode,
OperationErrorEnum & err)
{
err = OperationErrorEnum::kUnspecified;
return false;
Expand Down
18 changes: 5 additions & 13 deletions src/app/clusters/door-lock-server/door-lock-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ bool DoorLockServer::SetLockState(chip::EndpointId endpointId, DlLockState newLo

bool DoorLockServer::SetLockState(chip::EndpointId endpointId, DlLockState newLockState, OperationSourceEnum opSource,
const Nullable<uint16_t> & userIndex, const Nullable<List<const LockOpCredentials>> & credentials,
const chip::app::CommandHandler * commandObj)
const Nullable<chip::FabricIndex> & fabricIdx, const Nullable<chip::NodeId> & nodeId)
{
bool success = SetLockState(endpointId, newLockState);

Expand All @@ -128,17 +128,8 @@ bool DoorLockServer::SetLockState(chip::EndpointId endpointId, DlLockState newLo
opType = LockOperationTypeEnum::kUnlatch;
}

if (commandObj == nullptr)
{
SendLockOperationEvent(endpointId, opType, opSource, OperationErrorEnum::kUnspecified, userIndex,
Nullable<chip::FabricIndex>(), Nullable<chip::NodeId>(), credentials, success);
}
else
{
SendLockOperationEvent(endpointId, opType, opSource, OperationErrorEnum::kUnspecified, userIndex,
Nullable<chip::FabricIndex>(getFabricIndex(commandObj)),
Nullable<chip::NodeId>(getNodeId(commandObj)), credentials, success);
}
SendLockOperationEvent(endpointId, opType, opSource, OperationErrorEnum::kUnspecified, userIndex, fabricIdx, nodeId,
credentials, success);

// Reset wrong entry attempts (in case there were any incorrect credentials presented before) if lock/unlock was a success
// and a valid credential was presented.
Expand Down Expand Up @@ -3435,7 +3426,8 @@ bool DoorLockServer::HandleRemoteLockOperation(chip::app::CommandHandler * comma
}

// credentials check succeeded, try to lock/unlock door
success = opHandler(commandObj, endpoint, pinCode, reason);
success = opHandler(endpoint, Nullable<chip::FabricIndex>(getFabricIndex(commandObj)),
Nullable<chip::NodeId>(getNodeId(commandObj)), pinCode, reason);
// The app should trigger the lock state change as it may take a while before the lock actually locks/unlocks
exit:
if (!success && reason == OperationErrorEnum::kInvalidCredential)
Expand Down
Loading

0 comments on commit a1850d5

Please sign in to comment.