@@ -51,39 +51,6 @@ static constexpr uint8_t DOOR_LOCK_ALIRO_CREDENTIAL_SIZE = 65;
51
51
52
52
static constexpr uint32_t DOOR_LOCK_MAX_LOCK_TIMEOUT_SEC = MAX_INT32U_VALUE / MILLISECOND_TICKS_PER_SECOND;
53
53
54
- static constexpr size_t kDoorLockDelegateTableSize =
55
- MATTER_DM_DOOR_LOCK_CLUSTER_SERVER_ENDPOINT_COUNT + CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT;
56
-
57
- static_assert (kDoorLockDelegateTableSize <= kEmberInvalidEndpointIndex , " Door Lock Delegate table size error" );
58
-
59
- namespace chip {
60
- namespace app {
61
- namespace Clusters {
62
- namespace DoorLock {
63
-
64
- Delegate * gDelegateTable [kDoorLockDelegateTableSize ] = { nullptr };
65
-
66
- Delegate * GetDelegate (EndpointId endpoint)
67
- {
68
- uint16_t ep = emberAfGetClusterServerEndpointIndex (endpoint, DoorLock::Id, MATTER_DM_DOOR_LOCK_CLUSTER_SERVER_ENDPOINT_COUNT);
69
- return (ep >= kDoorLockDelegateTableSize ? nullptr : gDelegateTable [ep]);
70
- }
71
-
72
- void SetDefaultDelegate (EndpointId endpoint, Delegate * delegate)
73
- {
74
- uint16_t ep = emberAfGetClusterServerEndpointIndex (endpoint, DoorLock::Id, MATTER_DM_DOOR_LOCK_CLUSTER_SERVER_ENDPOINT_COUNT);
75
- // if endpoint is found
76
- if (ep < ArraySize (gDelegateTable ))
77
- {
78
- gDelegateTable [ep] = delegate;
79
- }
80
- }
81
-
82
- } // namespace DoorLock
83
- } // namespace Clusters
84
- } // namespace app
85
- } // namespace chip
86
-
87
54
DoorLockServer DoorLockServer::instance;
88
55
89
56
class DoorLockClusterFabricDelegate : public chip ::FabricTable::Delegate
@@ -117,7 +84,18 @@ DoorLockServer & DoorLockServer::Instance()
117
84
*
118
85
* @param endpointId
119
86
*/
120
- void DoorLockServer::InitServer (chip::EndpointId endpointId)
87
+ void DoorLockServer::InitServer (EndpointId endpointId)
88
+ {
89
+ CHIP_ERROR err = InitEndpoint (endpointId);
90
+
91
+ // We have no way to communicate this error, so just log it.
92
+ if (err != CHIP_NO_ERROR)
93
+ {
94
+ ChipLogError (Zcl, " Door Lock cluster initialization on endpoint %d failed: %" CHIP_ERROR_FORMAT, endpointId, err.Format ());
95
+ }
96
+ }
97
+
98
+ CHIP_ERROR DoorLockServer::InitEndpoint (EndpointId endpointId, Delegate * delegate)
121
99
{
122
100
ChipLogProgress (Zcl, " Door Lock cluster initialized at endpoint #%u" , endpointId);
123
101
@@ -128,11 +106,48 @@ void DoorLockServer::InitServer(chip::EndpointId endpointId)
128
106
}
129
107
SetActuatorEnabled (endpointId, true );
130
108
131
- for (auto & ep : mEndpointCtx )
109
+ auto * endpointContext = getContext (endpointId);
110
+ if (!endpointContext)
111
+ {
112
+ ChipLogError (Zcl, " Invalid endpoint %d for initializing lock server: no endpoint context available" , endpointId);
113
+ return CHIP_ERROR_INVALID_ARGUMENT;
114
+ }
115
+
116
+ endpointContext->lockoutEndTimestamp = endpointContext->lockoutEndTimestamp .zero ();
117
+ endpointContext->wrongCodeEntryAttempts = 0 ;
118
+ endpointContext->delegate = delegate;
119
+ return CHIP_NO_ERROR;
120
+ }
121
+
122
+ void DoorLockServer::ShutdownEndpoint (EndpointId endpointId)
123
+ {
124
+ auto * endpointContext = getContext (endpointId);
125
+ if (!endpointContext)
132
126
{
133
- ep. lockoutEndTimestamp = ep. lockoutEndTimestamp . zero ( );
134
- ep. wrongCodeEntryAttempts = 0 ;
127
+ ChipLogError (Zcl, " Invalid endpoint %d for shutting down lock server: no endpoint context available " , endpointId );
128
+ return ;
135
129
}
130
+
131
+ endpointContext->delegate = nullptr ;
132
+ }
133
+
134
+ CHIP_ERROR DoorLockServer::SetDelegate (chip::EndpointId endpointId, chip::app::Clusters::DoorLock::Delegate * delegate)
135
+ {
136
+ if (!delegate)
137
+ {
138
+ ChipLogError (Zcl, " Trying to set a null DoorLock::Delegate on endpoint %d" , endpointId);
139
+ return CHIP_ERROR_INVALID_ARGUMENT;
140
+ }
141
+
142
+ auto * endpointContext = getContext (endpointId);
143
+ if (!endpointContext)
144
+ {
145
+ ChipLogError (Zcl, " Invalid endpoint %d for setting a delegate: no endpoint context available" , endpointId);
146
+ return CHIP_ERROR_INVALID_ARGUMENT;
147
+ }
148
+
149
+ endpointContext->delegate = delegate;
150
+ return CHIP_NO_ERROR;
136
151
}
137
152
138
153
bool DoorLockServer::SetLockState (chip::EndpointId endpointId, DlLockState newLockState)
@@ -3445,6 +3460,17 @@ EmberAfDoorLockEndpointContext * DoorLockServer::getContext(chip::EndpointId end
3445
3460
return nullptr ;
3446
3461
}
3447
3462
3463
+ Delegate * DoorLockServer::GetDelegate (EndpointId endpointId)
3464
+ {
3465
+ auto * endpointContext = getContext (endpointId);
3466
+ if (!endpointContext)
3467
+ {
3468
+ return nullptr ;
3469
+ }
3470
+
3471
+ return endpointContext->delegate ;
3472
+ }
3473
+
3448
3474
bool DoorLockServer::HandleRemoteLockOperation (chip::app::CommandHandler * commandObj,
3449
3475
const chip::app::ConcreteCommandPath & commandPath, LockOperationTypeEnum opType,
3450
3476
RemoteLockOpHandler opHandler, const Optional<ByteSpan> & pinCode)
0 commit comments