@@ -55,24 +55,26 @@ PyChipError pychip_CommandSender_SendGroupCommand(chip::GroupId groupId, chip::C
55
55
namespace chip {
56
56
namespace python {
57
57
58
- using OnCommandSenderResponseCallback = void (*)(PyObject appContext, chip::EndpointId endpointId, chip::ClusterId clusterId,
58
+ using OnCommandSenderResponseCallback = void (*)(PyObject appContext, chip::EndpointId endpointId, chip::ClusterId clusterId,
59
59
chip::CommandId commandId, size_t index,
60
60
std::underlying_type_t <Protocols::InteractionModel::Status> status,
61
61
chip::ClusterStatus clusterStatus, const uint8_t * payload, uint32_t length);
62
- using OnCommandSenderErrorCallback = void (*)(PyObject appContext,
62
+ using OnCommandSenderErrorCallback = void (*)(PyObject appContext,
63
63
std::underlying_type_t <Protocols::InteractionModel::Status> status,
64
64
chip::ClusterStatus clusterStatus, PyChipError chiperror);
65
- using OnCommandSenderDoneCallback = void (*)(PyObject appContext);
65
+ using OnCommandSenderDoneCallback = void (*)(PyObject appContext);
66
+ using TestOnlyOnCommandSenderDoneCallback = void (*)(PyObject appContext, python::TestOnlyPyOnDoneInfo testOnlyDoneInfo);
66
67
67
- OnCommandSenderResponseCallback gOnCommandSenderResponseCallback = nullptr ;
68
- OnCommandSenderErrorCallback gOnCommandSenderErrorCallback = nullptr ;
69
- OnCommandSenderDoneCallback gOnCommandSenderDoneCallback = nullptr ;
68
+ OnCommandSenderResponseCallback gOnCommandSenderResponseCallback = nullptr ;
69
+ OnCommandSenderErrorCallback gOnCommandSenderErrorCallback = nullptr ;
70
+ OnCommandSenderDoneCallback gOnCommandSenderDoneCallback = nullptr ;
71
+ TestOnlyOnCommandSenderDoneCallback gTestOnlyOnCommandSenderDoneCallback = nullptr ;
70
72
71
73
class CommandSenderCallback : public CommandSender ::ExtendableCallback
72
74
{
73
75
public:
74
- CommandSenderCallback (PyObject appContext, bool isBatchedCommands) :
75
- mAppContext (appContext), mIsBatchedCommands (isBatchedCommands)
76
+ CommandSenderCallback (PyObject appContext, bool isBatchedCommands, bool callTestOnlyOnDone ) :
77
+ mAppContext (appContext), mIsBatchedCommands (isBatchedCommands), mCallTestOnlyOnDone (callTestOnlyOnDone)
76
78
{}
77
79
78
80
void OnResponse (CommandSender * apCommandSender, const CommandSender::ResponseData & aResponseData) override
@@ -148,7 +150,17 @@ class CommandSenderCallback : public CommandSender::ExtendableCallback
148
150
149
151
void OnDone (CommandSender * apCommandSender) override
150
152
{
151
- gOnCommandSenderDoneCallback (mAppContext );
153
+ if (mCallTestOnlyOnDone )
154
+ {
155
+ python::TestOnlyPyOnDoneInfo testOnlyOnDoneInfo;
156
+ testOnlyOnDoneInfo.responseMessageCount = apCommandSender->GetInvokeResponseMessageCount ();
157
+ gTestOnlyOnCommandSenderDoneCallback (mAppContext , testOnlyOnDoneInfo);
158
+ }
159
+ else
160
+ {
161
+ gOnCommandSenderDoneCallback (mAppContext );
162
+ }
163
+
152
164
delete apCommandSender;
153
165
delete this ;
154
166
};
@@ -179,6 +191,7 @@ class CommandSenderCallback : public CommandSender::ExtendableCallback
179
191
PyObject mAppContext = nullptr ;
180
192
std::unordered_map<uint16_t , size_t > commandRefToIndex;
181
193
bool mIsBatchedCommands ;
194
+ bool mCallTestOnlyOnDone ;
182
195
};
183
196
184
197
PyChipError SendBatchCommandsInternal (void * appContext, DeviceProxy * device, uint16_t timedRequestTimeoutMs,
@@ -220,8 +233,10 @@ PyChipError SendBatchCommandsInternal(void * appContext, DeviceProxy * device, u
220
233
config.SetRemoteMaxPathsPerInvoke (remoteSessionParameters.GetMaxPathsPerInvoke ());
221
234
}
222
235
236
+ bool isBatchedCommands = true ;
237
+ bool callTestOnlyOnDone = testOnlyOverrides != nullptr ;
223
238
std::unique_ptr<CommandSenderCallback> callback =
224
- std::make_unique<CommandSenderCallback>(appContext, /* isBatchedCommands = */ true );
239
+ std::make_unique<CommandSenderCallback>(appContext, isBatchedCommands, callTestOnlyOnDone );
225
240
226
241
bool isTimedRequest = timedRequestTimeoutMs != 0 || testOnlySuppressTimedRequestMessage;
227
242
std::unique_ptr<CommandSender> sender =
@@ -315,11 +330,13 @@ using namespace chip::python;
315
330
extern " C" {
316
331
void pychip_CommandSender_InitCallbacks (OnCommandSenderResponseCallback onCommandSenderResponseCallback,
317
332
OnCommandSenderErrorCallback onCommandSenderErrorCallback,
318
- OnCommandSenderDoneCallback onCommandSenderDoneCallback)
333
+ OnCommandSenderDoneCallback onCommandSenderDoneCallback,
334
+ TestOnlyOnCommandSenderDoneCallback testOnlyOnCommandSenderDoneCallback)
319
335
{
320
- gOnCommandSenderResponseCallback = onCommandSenderResponseCallback;
321
- gOnCommandSenderErrorCallback = onCommandSenderErrorCallback;
322
- gOnCommandSenderDoneCallback = onCommandSenderDoneCallback;
336
+ gOnCommandSenderResponseCallback = onCommandSenderResponseCallback;
337
+ gOnCommandSenderErrorCallback = onCommandSenderErrorCallback;
338
+ gOnCommandSenderDoneCallback = onCommandSenderDoneCallback;
339
+ gTestOnlyOnCommandSenderDoneCallback = testOnlyOnCommandSenderDoneCallback;
323
340
}
324
341
325
342
PyChipError pychip_CommandSender_SendCommand (void * appContext, DeviceProxy * device, uint16_t timedRequestTimeoutMs,
@@ -331,8 +348,10 @@ PyChipError pychip_CommandSender_SendCommand(void * appContext, DeviceProxy * de
331
348
332
349
VerifyOrReturnError (device->GetSecureSession ().HasValue (), ToPyChipError (CHIP_ERROR_MISSING_SECURE_SESSION));
333
350
351
+ bool isBatchedCommands = false ;
352
+ bool callTestOnlyOnDone = false ;
334
353
std::unique_ptr<CommandSenderCallback> callback =
335
- std::make_unique<CommandSenderCallback>(appContext, /* isBatchedCommands = */ false );
354
+ std::make_unique<CommandSenderCallback>(appContext, isBatchedCommands, callTestOnlyOnDone );
336
355
std::unique_ptr<CommandSender> sender =
337
356
std::make_unique<CommandSender>(callback.get (), device->GetExchangeManager (),
338
357
/* is timed request */ timedRequestTimeoutMs != 0 , suppressResponse);
@@ -406,8 +425,10 @@ PyChipError pychip_CommandSender_TestOnlySendCommandTimedRequestNoTimedInvoke(
406
425
407
426
VerifyOrReturnError (device->GetSecureSession ().HasValue (), ToPyChipError (CHIP_ERROR_MISSING_SECURE_SESSION));
408
427
428
+ bool isBatchedCommands = false ;
429
+ bool callTestOnlyOnDone = false ;
409
430
std::unique_ptr<CommandSenderCallback> callback =
410
- std::make_unique<CommandSenderCallback>(appContext, /* isBatchedCommands = */ false );
431
+ std::make_unique<CommandSenderCallback>(appContext, isBatchedCommands, callTestOnlyOnDone );
411
432
std::unique_ptr<CommandSender> sender = std::make_unique<CommandSender>(callback.get (), device->GetExchangeManager (),
412
433
/* is timed request */ true , suppressResponse);
413
434
0 commit comments