@@ -65,6 +65,7 @@ struct InteractiveServerResult
65
65
{
66
66
bool mEnabled = false ;
67
67
bool mIsAsyncReport = false ;
68
+ uint16_t mTimeout = 0 ;
68
69
int mStatus = EXIT_SUCCESS;
69
70
std::vector<std::string> mResults ;
70
71
std::vector<InteractiveServerResultLog> mLogs ;
@@ -92,18 +93,31 @@ struct InteractiveServerResult
92
93
// protected by a mutex.
93
94
std::mutex mMutex ;
94
95
95
- void Setup (bool isAsyncReport)
96
+ void Setup (bool isAsyncReport, uint16_t timeout )
96
97
{
97
98
auto lock = ScopedLock (mMutex );
98
99
mEnabled = true ;
99
100
mIsAsyncReport = isAsyncReport;
101
+ mTimeout = timeout;
102
+
103
+ if (mIsAsyncReport && mTimeout )
104
+ {
105
+ chip::DeviceLayer::PlatformMgr ().ScheduleWork (StartAsyncTimeout, reinterpret_cast <intptr_t >(this ));
106
+ }
100
107
}
101
108
102
109
void Reset ()
103
110
{
104
- auto lock = ScopedLock (mMutex );
111
+ auto lock = ScopedLock (mMutex );
112
+
113
+ if (mIsAsyncReport && mTimeout )
114
+ {
115
+ chip::DeviceLayer::PlatformMgr ().ScheduleWork (StopAsyncTimeout, reinterpret_cast <intptr_t >(this ));
116
+ }
117
+
105
118
mEnabled = false ;
106
119
mIsAsyncReport = false ;
120
+ mTimeout = 0 ;
107
121
mStatus = EXIT_SUCCESS;
108
122
mResults .clear ();
109
123
mLogs .clear ();
@@ -204,6 +218,24 @@ struct InteractiveServerResult
204
218
content << " }" ;
205
219
return content.str ();
206
220
}
221
+
222
+ static void StartAsyncTimeout (intptr_t arg)
223
+ {
224
+ auto self = reinterpret_cast <InteractiveServerResult *>(arg);
225
+ auto timeout = chip::System::Clock::Seconds16 (self->mTimeout );
226
+ chip::DeviceLayer::SystemLayer ().StartTimer (timeout, OnAsyncTimeout, self);
227
+ }
228
+
229
+ static void StopAsyncTimeout (intptr_t arg)
230
+ {
231
+ auto self = reinterpret_cast <InteractiveServerResult *>(arg);
232
+ chip::DeviceLayer::SystemLayer ().CancelTimer (OnAsyncTimeout, self);
233
+ }
234
+
235
+ static void OnAsyncTimeout (chip::System::Layer *, void * appState)
236
+ {
237
+ RemoteDataModelLogger::LogErrorAsJSON (CHIP_ERROR_TIMEOUT);
238
+ }
207
239
};
208
240
209
241
InteractiveServerResult gInteractiveServerResult ;
@@ -263,7 +295,19 @@ CHIP_ERROR InteractiveServerCommand::RunCommand()
263
295
bool InteractiveServerCommand::OnWebSocketMessageReceived (char * msg)
264
296
{
265
297
bool isAsyncReport = strlen (msg) == 0 ;
266
- gInteractiveServerResult .Setup (isAsyncReport);
298
+ uint16_t timeout = 0 ;
299
+ if (!isAsyncReport && strlen (msg) <= 5 /* Only look for numeric values <= 65535 */ )
300
+ {
301
+ std::stringstream ss;
302
+ ss << msg;
303
+ ss >> timeout;
304
+ if (!ss.fail ())
305
+ {
306
+ isAsyncReport = true ;
307
+ }
308
+ }
309
+
310
+ gInteractiveServerResult .Setup (isAsyncReport, timeout);
267
311
VerifyOrReturnValue (!isAsyncReport, true );
268
312
269
313
auto shouldStop = ParseCommand (msg, &gInteractiveServerResult .mStatus );
0 commit comments