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 and pull[bot] committed Oct 24, 2022
1 parent f1e43a1 commit 2892027
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 2892027

Please sign in to comment.