Skip to content

Commit

Permalink
[darwin-framework-tool][interactive] Add Ctrl+Z as a shortcut key to …
Browse files Browse the repository at this point in the history
…suspend or resume the running controllers (#36302)
  • Loading branch information
vivien-apple authored Oct 31, 2024
1 parent 91f4e07 commit aff2e17
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ class CHIPCommandBridge : public Command {

void RestartCommissioners();

void SuspendOrResumeCommissioners();

private:
CHIP_ERROR InitializeCommissioner(
std::string key, chip::FabricId fabricId, const chip::Credentials::AttestationTrustStore * trustStore);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,16 @@
[[MTRDeviceControllerFactory sharedInstance] stopControllerFactory];
}

void CHIPCommandBridge::SuspendOrResumeCommissioners()
{
for (auto & pair : mControllers) {
__auto_type * commissioner = pair.second;
if (commissioner.running) {
commissioner.suspended ? [commissioner resume] : [commissioner suspend];
}
}
}

CHIP_ERROR CHIPCommandBridge::StartWaiting(chip::System::Clock::Timeout duration)
{
auto waitingUntil = std::chrono::system_clock::now() + std::chrono::duration_cast<std::chrono::seconds>(duration);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@
constexpr char kInteractiveModeInstruction[] = "╔══════════════════════════════════════════════════════════════════╗\n"
"║ Interactive Mode ║\n"
"╠══════════════════════════════════════════════════════════════════╣\n"
"║ Stop and restart stack: [Ctrl+_] & [Ctrl+^ ] ║\n"
"║ Trigger exit(0) : [Ctrl+@] ║\n"
"║ Quit Interactive : 'quit()' or `quit` ║\n"
"║ Stop and restart stack : [Ctrl+_] & [Ctrl+^ ] ║\n"
"║ Suspend/Resume controllers: [Ctrl+Z] ║\n"
"║ Trigger exit(0) : [Ctrl+@] ║\n"
"║ Quit Interactive : 'quit()' or `quit` ║\n"
"╚══════════════════════════════════════════════════════════════════╝\n";
constexpr char kInteractiveModePrompt[] = ">>> ";
constexpr char kInteractiveModeHistoryFilePath[] = "/tmp/darwin_framework_tool_history";
Expand Down Expand Up @@ -76,6 +77,22 @@ CHIP_ERROR RunCommand() override
chip::System::Clock::Timeout GetWaitDuration() const override { return chip::System::Clock::Seconds16(0); }
};

class SuspendOrResumeCommand : public CHIPCommandBridge {
public:
SuspendOrResumeCommand()
: CHIPCommandBridge("suspend")
{
}

CHIP_ERROR RunCommand() override
{
SuspendOrResumeCommissioners();
return CHIP_NO_ERROR;
}

chip::System::Clock::Timeout GetWaitDuration() const override { return chip::System::Clock::Seconds16(0); }
};

void ClearLine()
{
printf("\r\x1B[0J"); // Move cursor to the beginning of the line and clear from cursor to end of the screen
Expand Down Expand Up @@ -312,6 +329,13 @@ el_status_t StopFunction()
return CSstay;
}

el_status_t SuspendOrResumeFunction()
{
SuspendOrResumeCommand cmd;
cmd.RunCommand();
return CSstay;
}

el_status_t ExitFunction()
{
exit(0);
Expand All @@ -333,6 +357,7 @@ el_status_t ExitFunction()
el_bind_key(CTL('^'), RestartFunction);
el_bind_key(CTL('_'), StopFunction);
el_bind_key(CTL('@'), ExitFunction);
el_bind_key(CTL('Z'), SuspendOrResumeFunction);

char * command = nullptr;
int status;
Expand Down

0 comments on commit aff2e17

Please sign in to comment.