Skip to content

Commit e89c90b

Browse files
authored
[darwin-framework-tool] Add a shortcut (CTL('_')) to stop the stack while in interactive mode (#22362)
1 parent ff14b67 commit e89c90b

File tree

3 files changed

+33
-4
lines changed

3 files changed

+33
-4
lines changed

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

+2
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ class CHIPCommandBridge : public Command
9595

9696
static std::set<CHIPCommandBridge *> sDeferredCleanups;
9797

98+
void StopCommissioners();
99+
98100
void RestartCommissioners();
99101

100102
private:

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

+7-4
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,16 @@
136136

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

139-
void CHIPCommandBridge::RestartCommissioners()
139+
void CHIPCommandBridge::StopCommissioners()
140140
{
141141
for (auto & pair : mControllers) {
142142
[pair.second shutdown];
143143
}
144+
}
145+
146+
void CHIPCommandBridge::RestartCommissioners()
147+
{
148+
StopCommissioners();
144149

145150
auto factory = [MTRControllerFactory sharedInstance];
146151
NSData * ipk = [gNocSigner getIPK];
@@ -159,9 +164,7 @@
159164
void CHIPCommandBridge::ShutdownCommissioner()
160165
{
161166
ChipLogProgress(chipTool, "Shutting down controller");
162-
for (auto & pair : mControllers) {
163-
[pair.second shutdown];
164-
}
167+
StopCommissioners();
165168
mControllers.clear();
166169
mCurrentController = nil;
167170

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

+24
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,22 @@ CHIP_ERROR RunCommand() override
4747
chip::System::Clock::Timeout GetWaitDuration() const override { return chip::System::Clock::Seconds16(0); }
4848
};
4949

50+
class StopCommand : public CHIPCommandBridge {
51+
public:
52+
StopCommand()
53+
: CHIPCommandBridge("stop")
54+
{
55+
}
56+
57+
CHIP_ERROR RunCommand() override
58+
{
59+
StopCommissioners();
60+
return CHIP_NO_ERROR;
61+
}
62+
63+
chip::System::Clock::Timeout GetWaitDuration() const override { return chip::System::Clock::Seconds16(0); }
64+
};
65+
5066
void ClearLine()
5167
{
5268
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()
85101
return CSstay;
86102
}
87103

104+
el_status_t StopFunction()
105+
{
106+
StopCommand cmd;
107+
cmd.RunCommand();
108+
return CSstay;
109+
}
110+
88111
CHIP_ERROR InteractiveStartCommand::RunCommand()
89112
{
90113
read_history(kInteractiveModeHistoryFilePath);
@@ -94,6 +117,7 @@ el_status_t RestartFunction()
94117
chip::Logging::SetLogRedirectCallback(LoggingCallback);
95118

96119
el_bind_key(CTL('^'), RestartFunction);
120+
el_bind_key(CTL('_'), StopFunction);
97121

98122
char * command = nullptr;
99123
while (YES) {

0 commit comments

Comments
 (0)