From ee601f852be5cf3898e40343c8f933d500908909 Mon Sep 17 00:00:00 2001 From: zhukangbin1 Date: Wed, 4 Jun 2025 10:36:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3uinput=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=EF=BC=8C=E5=BC=82=E5=B8=B8=E5=85=A5=E5=8F=82=E4=B8=8D=E6=8A=A5?= =?UTF-8?q?=E9=94=99=EF=BC=8C=E4=BE=9D=E7=84=B6=E6=89=A7=E8=A1=8C=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhukangbin1 --- .../include/input_replay_command.h | 4 ++-- .../inject_event/src/input_replay_command.cpp | 24 ++++++++++++------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/tools/inject_event/include/input_replay_command.h b/tools/inject_event/include/input_replay_command.h index 029e970bdd..a0107e1111 100644 --- a/tools/inject_event/include/input_replay_command.h +++ b/tools/inject_event/include/input_replay_command.h @@ -30,10 +30,10 @@ public: static int32_t HandleRecordReplayCommand(int32_t argc, char** argv); private: - bool ParseOptions(bool& useAllDevices); + bool ParseOptions(); bool ParseDeviceMapping(const std::string& mappingStr); void SetupSignalHandlers(); - bool ParseRecordCommand(bool useAllDevices); + bool ParseRecordCommand(); bool ParseReplayCommand(); bool ExecuteRecordCommand(); bool ExecuteReplayCommand(); diff --git a/tools/inject_event/src/input_replay_command.cpp b/tools/inject_event/src/input_replay_command.cpp index 2187e3d634..fbacbbe4fb 100644 --- a/tools/inject_event/src/input_replay_command.cpp +++ b/tools/inject_event/src/input_replay_command.cpp @@ -43,7 +43,7 @@ InputReplayCommand::InputReplayCommand(int32_t argc, char** argv) programName_ = (argc > 0) ? argv[0] : "uinput"; } -bool InputReplayCommand::ParseOptions(bool& useAllDevices) +bool InputReplayCommand::ParseOptions() { static struct option longOptions[] = { {"help", no_argument, 0, 'h'}, @@ -64,7 +64,7 @@ bool InputReplayCommand::ParseOptions(bool& useAllDevices) DeviceManager().PrintDeviceList(); exit(0); case 'a': - useAllDevices = true; + useAllDevices_ = true; break; case 'm': if (!ParseDeviceMapping(optarg)) { @@ -84,8 +84,7 @@ bool InputReplayCommand::Parse() PrintUsage(); return false; } - bool useAllDevices = false; - if (!ParseOptions(useAllDevices)) { + if (!ParseOptions()) { return false; } if (optind >= argc_) { @@ -99,7 +98,7 @@ bool InputReplayCommand::Parse() } filePath_ = argv_[optind++]; if (command_ == "record") { - return ParseRecordCommand(useAllDevices); + return ParseRecordCommand(); } else if (command_ == "replay") { return ParseReplayCommand(); } else { @@ -183,12 +182,11 @@ void InputReplayCommand::SetupSignalHandlers() sigaction(SIGTERM, &sa, nullptr); } -bool InputReplayCommand::ParseRecordCommand(bool useAllDevices) +bool InputReplayCommand::ParseRecordCommand() { - useAllDevices_ = useAllDevices; if (!useAllDevices_) { - for (int32_t i = optind; i < argc_; i++) { - devicePaths_.push_back(argv_[i]); + while (optind < argc_) { + devicePaths_.push_back(argv_[optind++]); } if (devicePaths_.empty()) { PrintError("No devices specified for recording"); @@ -196,11 +194,19 @@ bool InputReplayCommand::ParseRecordCommand(bool useAllDevices) return false; } } + if (optind < argc_) { + PrintError("Unexpected arguments for record command"); + return false; + } return true; } bool InputReplayCommand::ParseReplayCommand() { + if (useAllDevices_) { + PrintError("Not use -a option for replay command!"); + return false; + } if (optind < argc_) { PrintError("Unexpected arguments for replay command"); return false; -- Gitee