diff options
Diffstat (limited to 'cmds/idlcli/vibrator/CommandCompose.cpp')
-rw-r--r-- | cmds/idlcli/vibrator/CommandCompose.cpp | 55 |
1 files changed, 40 insertions, 15 deletions
diff --git a/cmds/idlcli/vibrator/CommandCompose.cpp b/cmds/idlcli/vibrator/CommandCompose.cpp index 4721a5f9ae..eb9008b68e 100644 --- a/cmds/idlcli/vibrator/CommandCompose.cpp +++ b/cmds/idlcli/vibrator/CommandCompose.cpp @@ -28,19 +28,33 @@ using aidl::CompositeEffect; class CommandCompose : public Command { std::string getDescription() const override { return "Compose vibration."; } - std::string getUsageSummary() const override { return "<delay> <primitive> <scale> ..."; } + std::string getUsageSummary() const override { + return "[options] <delay> <primitive> <scale> ..."; + } UsageDetails getUsageDetails() const override { UsageDetails details{ + {"-b", {"Block for duration of vibration."}}, {"<delay>", {"In milliseconds"}}, {"<primitive>", {"Primitive ID."}}, - {"<scale>", {"0.0 (exclusive) - 1.0 (inclusive)."}}, + {"<scale>", {"0.0 (inclusive) - 1.0 (inclusive)."}}, {"...", {"May repeat multiple times."}}, }; return details; } Status doArgs(Args &args) override { + while (args.get<std::string>().value_or("").find("-") == 0) { + auto opt = *args.pop<std::string>(); + if (opt == "--") { + break; + } else if (opt == "-b") { + mBlocking = true; + } else { + std::cerr << "Invalid Option '" << opt << "'!" << std::endl; + return USAGE; + } + } while (!args.empty()) { CompositeEffect effect; if (auto delay = args.pop<decltype(effect.delayMs)>()) { @@ -50,16 +64,15 @@ class CommandCompose : public Command { std::cerr << "Missing or Invalid Delay!" << std::endl; return USAGE; } - // TODO: Use range validation when supported by AIDL - if (auto primitive = args.pop<std::underlying_type_t<decltype(effect.primitive)>>()) { - effect.primitive = static_cast<decltype(effect.primitive)>(*primitive); + if (auto primitive = args.pop<decltype(effect.primitive)>()) { + effect.primitive = *primitive; std::cout << "Primitive: " << toString(effect.primitive) << std::endl; } else { std::cerr << "Missing or Invalid Primitive!" << std::endl; return USAGE; } if (auto scale = args.pop<decltype(effect.scale)>(); - scale && *scale > 0.0 && scale <= 1.0) { + scale && *scale >= 0.0 && scale <= 1.0) { effect.scale = *scale; std::cout << "Scale: " << effect.scale << std::endl; } else { @@ -76,21 +89,33 @@ class CommandCompose : public Command { } Status doMain(Args && /*args*/) override { - std::string statusStr; - Status ret; - if (auto hal = getHal<aidl::IVibrator>()) { - auto status = hal->call(&aidl::IVibrator::compose, mComposite, nullptr); - statusStr = status.getDescription(); - ret = status.isOk() ? OK : ERROR; - } else { + auto hal = getHal<aidl::IVibrator>(); + + if (!hal) { return UNAVAILABLE; } - std::cout << "Status: " << statusStr << std::endl; + ABinderProcess_setThreadPoolMaxThreadCount(1); + ABinderProcess_startThreadPool(); + + std::shared_ptr<VibratorCallback> callback; + + if (mBlocking) { + callback = ndk::SharedRefBase::make<VibratorCallback>(); + } + + auto status = hal->call(&aidl::IVibrator::compose, mComposite, callback); + + if (status.isOk() && callback) { + callback->waitForComplete(); + } + + std::cout << "Status: " << status.getDescription() << std::endl; - return ret; + return status.isOk() ? OK : ERROR; } + bool mBlocking; std::vector<CompositeEffect> mComposite; }; |