Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[darwin-framework-tool][interactive] Add Ctrl+G as a shortcut key to … #36325

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ class CHIPCommandBridge : public Command {

void SuspendOrResumeCommissioners();

MTRDevice * GetLastUsedDevice();

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 @@ -35,6 +35,7 @@
#include <string>

static CHIPToolPersistentStorageDelegate * storage = nil;
static MTRDevice * sLastUsedDevice = nil;
static DeviceDelegate * sDeviceDelegate = nil;
static dispatch_queue_t sDeviceDelegateDispatchQueue = nil;
std::set<CHIPCommandBridge *> CHIPCommandBridge::sDeferredCleanups;
Expand Down Expand Up @@ -312,6 +313,7 @@
}
[device addDelegate:sDeviceDelegate queue:sDeviceDelegateDispatchQueue];

sLastUsedDevice = device;
return device;
}

Expand Down Expand Up @@ -368,6 +370,11 @@
}
}

MTRDevice * CHIPCommandBridge::GetLastUsedDevice()
{
return sLastUsedDevice;
}

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 @@ -50,6 +50,9 @@ class SetUpDeviceCommand : public CHIPCommandBridge {
__auto_type queue = dispatch_queue_create("com.chip.devicedelegate", DISPATCH_QUEUE_SERIAL_WITH_AUTORELEASE_POOL);
[device addDelegate:delegate queue:queue];

// Make sure the device is registered as the latest MTRDevice.
DeviceWithNodeId(mNodeId);

mDelegate = delegate;
SetCommandExitStatus(CHIP_NO_ERROR);
return CHIP_NO_ERROR;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"╠══════════════════════════════════════════════════════════════════╣\n"
"║ Stop and restart stack : [Ctrl+_] & [Ctrl+^ ] ║\n"
"║ Suspend/Resume controllers: [Ctrl+Z] ║\n"
"║ Trigger Resubscription : [Ctrl+G] ║\n"
"║ Trigger exit(0) : [Ctrl+@] ║\n"
"║ Quit Interactive : 'quit()' or `quit` ║\n"
"╚══════════════════════════════════════════════════════════════════╝\n";
Expand All @@ -43,6 +44,10 @@
constexpr char kCategoryProgress[] = "Info";
constexpr char kCategoryDetail[] = "Debug";

@interface MTRDevice ()
- (void)_deviceMayBeReachable;
@end

namespace {

class RestartCommand : public CHIPCommandBridge {
Expand Down Expand Up @@ -93,6 +98,25 @@ CHIP_ERROR RunCommand() override
chip::System::Clock::Timeout GetWaitDuration() const override { return chip::System::Clock::Seconds16(0); }
};

class TriggerResubscriptionCommand : public CHIPCommandBridge {
public:
TriggerResubscriptionCommand()
: CHIPCommandBridge("trigger-resubscription")
{
}

CHIP_ERROR RunCommand() override
{
__auto_type * device = GetLastUsedDevice();
if (nil != device) {
[device _deviceMayBeReachable];
}
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 @@ -336,6 +360,13 @@ el_status_t SuspendOrResumeFunction()
return CSstay;
}

el_status_t TriggerResubscriptionFunction()
{
TriggerResubscriptionCommand cmd;
cmd.RunCommand();
return CSstay;
}

el_status_t ExitFunction()
{
exit(0);
Expand All @@ -358,6 +389,7 @@ el_status_t ExitFunction()
el_bind_key(CTL('_'), StopFunction);
el_bind_key(CTL('@'), ExitFunction);
el_bind_key(CTL('Z'), SuspendOrResumeFunction);
el_bind_key(CTL('G'), TriggerResubscriptionFunction);

char * command = nullptr;
int status;
Expand Down
Loading