1 /* 2 * Copyright (C) 2020 The Android Open Source Project * 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include <future> 17 18 #include "utils.h" 19 #include "vibrator.h" 20 21 namespace android { 22 namespace idlcli { 23 24 class CommandVibrator; 25 26 namespace vibrator { 27 28 using aidl::CompositePrimitive; 29 30 class CommandGetPrimitiveDuration : public Command { getDescription() const31 std::string getDescription() const override { 32 return "Retrieve effect primitive's duration in milliseconds."; 33 } 34 getUsageSummary() const35 std::string getUsageSummary() const override { return "<primitive>"; } 36 getUsageDetails() const37 UsageDetails getUsageDetails() const override { 38 UsageDetails details{ 39 {"<primitive>", {"Primitive ID."}}, 40 }; 41 return details; 42 } 43 doArgs(Args & args)44 Status doArgs(Args &args) override { 45 if (auto primitive = args.pop<decltype(mPrimitive)>()) { 46 mPrimitive = *primitive; 47 std::cout << "Primitive: " << toString(mPrimitive) << std::endl; 48 } else { 49 std::cerr << "Missing or Invalid Primitive!" << std::endl; 50 return USAGE; 51 } 52 if (!args.empty()) { 53 std::cerr << "Unexpected Arguments!" << std::endl; 54 return USAGE; 55 } 56 return OK; 57 } 58 doMain(Args &&)59 Status doMain(Args && /*args*/) override { 60 auto hal = getHal(); 61 62 if (!hal) { 63 return UNAVAILABLE; 64 } 65 66 int32_t duration; 67 auto status = hal->getPrimitiveDuration(mPrimitive, &duration); 68 69 std::cout << "Status: " << status.getDescription() << std::endl; 70 std::cout << "Duration: " << duration << std::endl; 71 72 return status.isOk() ? OK : ERROR; 73 } 74 75 CompositePrimitive mPrimitive; 76 }; 77 78 static const auto Command = CommandRegistry<CommandVibrator>::Register<CommandGetPrimitiveDuration>( 79 "getPrimitiveDuration"); 80 81 } // namespace vibrator 82 } // namespace idlcli 83 } // namespace android 84