diff options
| -rw-r--r-- | cmds/idlcli/CommandVibrator.cpp | 2 | ||||
| -rw-r--r-- | cmds/idlcli/IdlCli.h | 35 | ||||
| -rw-r--r-- | cmds/idlcli/main.cpp | 2 | ||||
| -rw-r--r-- | cmds/idlcli/utils.h | 2 | ||||
| -rw-r--r-- | cmds/idlcli/vibrator.h | 43 |
5 files changed, 65 insertions, 19 deletions
diff --git a/cmds/idlcli/CommandVibrator.cpp b/cmds/idlcli/CommandVibrator.cpp index a7a70c38af..81bdbe25d7 100644 --- a/cmds/idlcli/CommandVibrator.cpp +++ b/cmds/idlcli/CommandVibrator.cpp @@ -22,7 +22,7 @@ namespace idlcli { class IdlCli; class CommandVibrator : public CommandWithSubcommands<CommandVibrator> { - std::string getDescription() const override { return "Invoke Vibrator HIDL APIs."; } + std::string getDescription() const override { return "Invoke Vibrator IDL APIs."; } std::string getUsageSummary() const override { return "<api> [arguments]"; } diff --git a/cmds/idlcli/IdlCli.h b/cmds/idlcli/IdlCli.h index dd8430415e..24a40d99e6 100644 --- a/cmds/idlcli/IdlCli.h +++ b/cmds/idlcli/IdlCli.h @@ -25,14 +25,47 @@ namespace idlcli { class IdlCli : public CommandWithSubcommands<IdlCli> { std::string getDescription() const override { return "Invoke IDL APIs."; } - std::string getUsageSummary() const override { return "<idl> [arguments]"; } + std::string getUsageSummary() const override { return "<idl> [options] [arguments]"; } UsageDetails getUsageDetails() const override { UsageDetails details{ + {"-n <name>", {"Get named service, rather than default."}}, {"<idl>", CommandRegistry<IdlCli>::List()}, }; 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 == "-n") { + if (auto name = args.pop<decltype(mName)>()) { + mName = *name; + } else { + std::cerr << "Missing Value for Name!" << std::endl; + return USAGE; + } + } else { + std::cerr << "Invalid Option '" << opt << "'!" << std::endl; + return USAGE; + } + } + return CommandWithSubcommands::doArgs(args); + } + + IdlCli() {} + + std::string mName; + +public: + static IdlCli &Get() { + static IdlCli instance; + return instance; + } + + auto getName() { return mName; } }; } // namespace idlcli diff --git a/cmds/idlcli/main.cpp b/cmds/idlcli/main.cpp index 9ed9d8216a..308f294b8d 100644 --- a/cmds/idlcli/main.cpp +++ b/cmds/idlcli/main.cpp @@ -19,5 +19,5 @@ int main(const int argc, const char* const argv[]) { using namespace ::android::idlcli; - return IdlCli{}.main(Args{argc, argv}); + return IdlCli::Get().main(Args{argc, argv}); } diff --git a/cmds/idlcli/utils.h b/cmds/idlcli/utils.h index b8744555e2..262f2e50b6 100644 --- a/cmds/idlcli/utils.h +++ b/cmds/idlcli/utils.h @@ -249,7 +249,7 @@ private: template <typename T> class CommandWithSubcommands : public Command { -private: +protected: Status doArgs(Args &args) override { mCommand = CommandRegistry<T>::Create(*args.get()); if (!mCommand) { diff --git a/cmds/idlcli/vibrator.h b/cmds/idlcli/vibrator.h index 6c30a9e2ca..dfbb8863bd 100644 --- a/cmds/idlcli/vibrator.h +++ b/cmds/idlcli/vibrator.h @@ -13,24 +13,24 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef FRAMEWORK_NATIVE_CMDS_IDLCLI_VIBRATOR_H_ -#define FRAMEWORK_NATIVE_CMDS_IDLCLI_VIBRATOR_H_ +#pragma once #include <future> #include <aidl/android/hardware/vibrator/BnVibratorCallback.h> #include <aidl/android/hardware/vibrator/IVibrator.h> +#include <aidl/android/hardware/vibrator/IVibratorManager.h> #include <android/binder_manager.h> #include <android/binder_process.h> #include <android/hardware/vibrator/1.3/IVibrator.h> +#include "IdlCli.h" #include "utils.h" -#include "log/log.h" - namespace android { using hardware::Return; +using idlcli::IdlCli; static constexpr int NUM_TRIES = 2; @@ -47,20 +47,34 @@ inline ndk::ScopedAStatus NullptrStatus() { } template <typename I> -inline auto getService() { - return I::getService(); +inline auto getService(std::string name) { + const auto instance = std::string() + I::descriptor + "/" + name; + auto vibBinder = ndk::SpAIBinder(AServiceManager_getService(instance.c_str())); + return I::fromBinder(vibBinder); } template <> -inline auto getService<aidl::android::hardware::vibrator::IVibrator>() { - const auto instance = - std::string() + aidl::android::hardware::vibrator::IVibrator::descriptor + "/default"; - auto vibBinder = ndk::SpAIBinder(AServiceManager_getService(instance.c_str())); - return aidl::android::hardware::vibrator::IVibrator::fromBinder(vibBinder); +inline auto getService<android::hardware::vibrator::V1_0::IVibrator>(std::string name) { + return android::hardware::vibrator::V1_0::IVibrator::getService(name); +} + +template <> +inline auto getService<android::hardware::vibrator::V1_1::IVibrator>(std::string name) { + return android::hardware::vibrator::V1_1::IVibrator::getService(name); +} + +template <> +inline auto getService<android::hardware::vibrator::V1_2::IVibrator>(std::string name) { + return android::hardware::vibrator::V1_2::IVibrator::getService(name); +} + +template <> +inline auto getService<android::hardware::vibrator::V1_3::IVibrator>(std::string name) { + return android::hardware::vibrator::V1_3::IVibrator::getService(name); } template <typename I> -using shared_ptr = std::result_of_t<decltype(getService<I>)&()>; +using shared_ptr = std::result_of_t<decltype(getService<I>)&(std::string)>; template <typename I> class HalWrapper { @@ -68,7 +82,8 @@ public: static std::unique_ptr<HalWrapper> Create() { // Assume that if getService returns a nullptr, HAL is not available on the // device. - auto hal = getService<I>(); + const auto name = IdlCli::Get().getName(); + auto hal = getService<I>(name.empty() ? "default" : name); return hal ? std::unique_ptr<HalWrapper>(new HalWrapper(std::move(hal))) : nullptr; } @@ -121,5 +136,3 @@ private: } // namespace idlcli } // namespace android - -#endif // FRAMEWORK_NATIVE_CMDS_IDLCLI_VIBRATOR_H_ |