• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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         std::string statusStr;
61         int32_t duration;
62         Status ret;
63 
64         if (auto hal = getHal<aidl::IVibrator>()) {
65             auto status = hal->call(&aidl::IVibrator::getPrimitiveDuration, mPrimitive, &duration);
66             statusStr = status.getDescription();
67             ret = status.isOk() ? OK : ERROR;
68         } else {
69             return UNAVAILABLE;
70         }
71 
72         std::cout << "Status: " << statusStr << std::endl;
73         std::cout << "Duration: " << duration << std::endl;
74 
75         return ret;
76     }
77 
78     CompositePrimitive mPrimitive;
79 };
80 
81 static const auto Command = CommandRegistry<CommandVibrator>::Register<CommandGetPrimitiveDuration>(
82         "getPrimitiveDuration");
83 
84 } // namespace vibrator
85 } // namespace idlcli
86 } // namespace android
87