@@ -28,17 +28,16 @@ CHIP_ERROR CloseSessionCommand::RunCommand()
28
28
CommissioneeDeviceProxy * commissioneeDeviceProxy = nullptr ;
29
29
if (CHIP_NO_ERROR == CurrentCommissioner ().GetDeviceBeingCommissioned (mDestinationId , &commissioneeDeviceProxy))
30
30
{
31
- return CloseSession (commissioneeDeviceProxy);
31
+ VerifyOrReturnError (commissioneeDeviceProxy->GetSecureSession ().HasValue (), CHIP_ERROR_INCORRECT_STATE);
32
+ return CloseSession (*commissioneeDeviceProxy->GetExchangeManager (), commissioneeDeviceProxy->GetSecureSession ().Value ());
32
33
}
33
34
34
35
return CurrentCommissioner ().GetConnectedDevice (mDestinationId , &mOnDeviceConnectedCallback ,
35
36
&mOnDeviceConnectionFailureCallback );
36
37
}
37
38
38
- CHIP_ERROR CloseSessionCommand::CloseSession (DeviceProxy * device )
39
+ CHIP_ERROR CloseSessionCommand::CloseSession (Messaging::ExchangeManager & exchangeMgr, const SessionHandle & sessionHandle )
39
40
{
40
- VerifyOrReturnError (device->GetSecureSession ().HasValue (), CHIP_ERROR_INCORRECT_STATE);
41
-
42
41
// TODO perhaps factor out this code into something on StatusReport that
43
42
// takes an exchange and maybe a SendMessageFlags?
44
43
SecureChannel::StatusReport statusReport (SecureChannel::GeneralStatusCode::kSuccess , SecureChannel::Id,
@@ -51,7 +50,7 @@ CHIP_ERROR CloseSessionCommand::CloseSession(DeviceProxy * device)
51
50
System::PacketBufferHandle msg = bbuf.Finalize ();
52
51
VerifyOrReturnError (!msg.IsNull (), CHIP_ERROR_NO_MEMORY);
53
52
54
- auto * exchange = device-> GetExchangeManager ()-> NewContext (device-> GetSecureSession (). Value () , nullptr );
53
+ auto * exchange = exchangeMgr. NewContext (sessionHandle , nullptr );
55
54
VerifyOrReturnError (exchange != nullptr , CHIP_ERROR_NO_MEMORY);
56
55
57
56
// Per spec, CloseSession reports are always sent with MRP disabled.
@@ -69,12 +68,13 @@ CHIP_ERROR CloseSessionCommand::CloseSession(DeviceProxy * device)
69
68
return err;
70
69
}
71
70
72
- void CloseSessionCommand::OnDeviceConnectedFn (void * context, OperationalDeviceProxy * device)
71
+ void CloseSessionCommand::OnDeviceConnectedFn (void * context, Messaging::ExchangeManager & exchangeMgr,
72
+ SessionHandle & sessionHandle)
73
73
{
74
74
auto * command = reinterpret_cast <CloseSessionCommand *>(context);
75
75
VerifyOrReturn (command != nullptr , ChipLogError (chipTool, " OnDeviceConnectedFn: context is null" ));
76
76
77
- CHIP_ERROR err = command->CloseSession (device );
77
+ CHIP_ERROR err = command->CloseSession (exchangeMgr, sessionHandle );
78
78
VerifyOrReturn (CHIP_NO_ERROR == err, command->SetCommandExitStatus (err));
79
79
}
80
80
0 commit comments