diff --git a/examples/darwin-framework-tool/commands/common/CHIPCommandBridge.h b/examples/darwin-framework-tool/commands/common/CHIPCommandBridge.h index 23eb9bb52a7df7..c9406d04c95b2c 100644 --- a/examples/darwin-framework-tool/commands/common/CHIPCommandBridge.h +++ b/examples/darwin-framework-tool/commands/common/CHIPCommandBridge.h @@ -95,6 +95,8 @@ class CHIPCommandBridge : public Command static std::set sDeferredCleanups; + void StopCommissioners(); + void RestartCommissioners(); private: diff --git a/examples/darwin-framework-tool/commands/common/CHIPCommandBridge.mm b/examples/darwin-framework-tool/commands/common/CHIPCommandBridge.mm index 06791fe0653eb1..5c527cd6423ed2 100644 --- a/examples/darwin-framework-tool/commands/common/CHIPCommandBridge.mm +++ b/examples/darwin-framework-tool/commands/common/CHIPCommandBridge.mm @@ -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]; @@ -159,9 +164,7 @@ void CHIPCommandBridge::ShutdownCommissioner() { ChipLogProgress(chipTool, "Shutting down controller"); - for (auto & pair : mControllers) { - [pair.second shutdown]; - } + StopCommissioners(); mControllers.clear(); mCurrentController = nil; diff --git a/examples/darwin-framework-tool/commands/interactive/InteractiveCommands.mm b/examples/darwin-framework-tool/commands/interactive/InteractiveCommands.mm index 7252f26c6887a8..5ece0a85a227f6 100644 --- a/examples/darwin-framework-tool/commands/interactive/InteractiveCommands.mm +++ b/examples/darwin-framework-tool/commands/interactive/InteractiveCommands.mm @@ -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 @@ -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); @@ -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) {