Skip to content

Commit aff2e17

Browse files
authored
[darwin-framework-tool][interactive] Add Ctrl+Z as a shortcut key to suspend or resume the running controllers (project-chip#36302)
1 parent 91f4e07 commit aff2e17

File tree

3 files changed

+40
-3
lines changed

3 files changed

+40
-3
lines changed

examples/darwin-framework-tool/commands/common/CHIPCommandBridge.h

+2
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ class CHIPCommandBridge : public Command {
128128

129129
void RestartCommissioners();
130130

131+
void SuspendOrResumeCommissioners();
132+
131133
private:
132134
CHIP_ERROR InitializeCommissioner(
133135
std::string key, chip::FabricId fabricId, const chip::Credentials::AttestationTrustStore * trustStore);

examples/darwin-framework-tool/commands/common/CHIPCommandBridge.mm

+10
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,16 @@
358358
[[MTRDeviceControllerFactory sharedInstance] stopControllerFactory];
359359
}
360360

361+
void CHIPCommandBridge::SuspendOrResumeCommissioners()
362+
{
363+
for (auto & pair : mControllers) {
364+
__auto_type * commissioner = pair.second;
365+
if (commissioner.running) {
366+
commissioner.suspended ? [commissioner resume] : [commissioner suspend];
367+
}
368+
}
369+
}
370+
361371
CHIP_ERROR CHIPCommandBridge::StartWaiting(chip::System::Clock::Timeout duration)
362372
{
363373
auto waitingUntil = std::chrono::system_clock::now() + std::chrono::duration_cast<std::chrono::seconds>(duration);

examples/darwin-framework-tool/commands/interactive/InteractiveCommands.mm

+28-3
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@
3030
constexpr char kInteractiveModeInstruction[] = "╔══════════════════════════════════════════════════════════════════╗\n"
3131
"║ Interactive Mode ║\n"
3232
"╠══════════════════════════════════════════════════════════════════╣\n"
33-
"║ Stop and restart stack: [Ctrl+_] & [Ctrl+^ ] ║\n"
34-
"║ Trigger exit(0) : [Ctrl+@] ║\n"
35-
"║ Quit Interactive : 'quit()' or `quit` ║\n"
33+
"║ Stop and restart stack : [Ctrl+_] & [Ctrl+^ ] ║\n"
34+
"║ Suspend/Resume controllers: [Ctrl+Z] ║\n"
35+
"║ Trigger exit(0) : [Ctrl+@] ║\n"
36+
"║ Quit Interactive : 'quit()' or `quit` ║\n"
3637
"╚══════════════════════════════════════════════════════════════════╝\n";
3738
constexpr char kInteractiveModePrompt[] = ">>> ";
3839
constexpr char kInteractiveModeHistoryFilePath[] = "/tmp/darwin_framework_tool_history";
@@ -76,6 +77,22 @@ CHIP_ERROR RunCommand() override
7677
chip::System::Clock::Timeout GetWaitDuration() const override { return chip::System::Clock::Seconds16(0); }
7778
};
7879

80+
class SuspendOrResumeCommand : public CHIPCommandBridge {
81+
public:
82+
SuspendOrResumeCommand()
83+
: CHIPCommandBridge("suspend")
84+
{
85+
}
86+
87+
CHIP_ERROR RunCommand() override
88+
{
89+
SuspendOrResumeCommissioners();
90+
return CHIP_NO_ERROR;
91+
}
92+
93+
chip::System::Clock::Timeout GetWaitDuration() const override { return chip::System::Clock::Seconds16(0); }
94+
};
95+
7996
void ClearLine()
8097
{
8198
printf("\r\x1B[0J"); // Move cursor to the beginning of the line and clear from cursor to end of the screen
@@ -312,6 +329,13 @@ el_status_t StopFunction()
312329
return CSstay;
313330
}
314331

332+
el_status_t SuspendOrResumeFunction()
333+
{
334+
SuspendOrResumeCommand cmd;
335+
cmd.RunCommand();
336+
return CSstay;
337+
}
338+
315339
el_status_t ExitFunction()
316340
{
317341
exit(0);
@@ -333,6 +357,7 @@ el_status_t ExitFunction()
333357
el_bind_key(CTL('^'), RestartFunction);
334358
el_bind_key(CTL('_'), StopFunction);
335359
el_bind_key(CTL('@'), ExitFunction);
360+
el_bind_key(CTL('Z'), SuspendOrResumeFunction);
336361

337362
char * command = nullptr;
338363
int status;

0 commit comments

Comments
 (0)