Skip to content

Commit

Permalink
[darwin-framework-tool] Add a shortcut (CTL('_')) to stop the stack w…
Browse files Browse the repository at this point in the history
…hile in interactive mode (#22362)
  • Loading branch information
vivien-apple authored Sep 2, 2022
1 parent ff14b67 commit e89c90b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ class CHIPCommandBridge : public Command

static std::set<CHIPCommandBridge *> sDeferredCleanups;

void StopCommissioners();

void RestartCommissioners();

private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,16 @@

MTRDeviceController * CHIPCommandBridge::GetCommissioner(const char * identity) { return mControllers[identity]; }

void CHIPCommandBridge::RestartCommissioners()
void CHIPCommandBridge::StopCommissioners()
{
for (auto & pair : mControllers) {
[pair.second shutdown];
}
}

void CHIPCommandBridge::RestartCommissioners()
{
StopCommissioners();

auto factory = [MTRControllerFactory sharedInstance];
NSData * ipk = [gNocSigner getIPK];
Expand All @@ -159,9 +164,7 @@
void CHIPCommandBridge::ShutdownCommissioner()
{
ChipLogProgress(chipTool, "Shutting down controller");
for (auto & pair : mControllers) {
[pair.second shutdown];
}
StopCommissioners();
mControllers.clear();
mCurrentController = nil;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,22 @@ CHIP_ERROR RunCommand() override
chip::System::Clock::Timeout GetWaitDuration() const override { return chip::System::Clock::Seconds16(0); }
};

class StopCommand : public CHIPCommandBridge {
public:
StopCommand()
: CHIPCommandBridge("stop")
{
}

CHIP_ERROR RunCommand() override
{
StopCommissioners();
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 @@ -85,6 +101,13 @@ el_status_t RestartFunction()
return CSstay;
}

el_status_t StopFunction()
{
StopCommand cmd;
cmd.RunCommand();
return CSstay;
}

CHIP_ERROR InteractiveStartCommand::RunCommand()
{
read_history(kInteractiveModeHistoryFilePath);
Expand All @@ -94,6 +117,7 @@ el_status_t RestartFunction()
chip::Logging::SetLogRedirectCallback(LoggingCallback);

el_bind_key(CTL('^'), RestartFunction);
el_bind_key(CTL('_'), StopFunction);

char * command = nullptr;
while (YES) {
Expand Down

0 comments on commit e89c90b

Please sign in to comment.