blob: 5fb1faca164bbbd802524a515b88addc2637f86d [file] [log] [blame]
Harpreet "Eli" Sanghae47ae682019-06-05 16:52:47 +09001/*
2 * Copyright (C) 2019 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 "utils.h"
17#include "vibrator.h"
18
19namespace android {
20namespace idlcli {
21
22class CommandVibrator;
23
24namespace vibrator {
25
26class CommandSetExternalControl : public Command {
27 std::string getDescription() const override {
28 return "Enable/disable vibration external control.";
29 }
30
31 std::string getUsageSummary() const override { return "<enable>"; }
32
33 UsageDetails getUsageDetails() const override {
34 UsageDetails details{
35 {"<enable>", {"0/1."}},
36 };
37 return details;
38 }
39
40 Status doArgs(Args &args) override {
41 if (auto enable = args.pop<decltype(mEnable)>()) {
42 mEnable = *enable;
43 } else {
44 std::cerr << "Missing Enable!" << std::endl;
45 return USAGE;
46 }
47 return OK;
48 }
49
50 Status doMain(Args && /*args*/) override {
51 auto ret = halCall(&V1_3::IVibrator::setExternalControl, mEnable);
52
53 if (!ret.isOk()) {
54 return UNAVAILABLE;
55 }
56
57 std::cout << "Status: " << toString(ret) << std::endl;
58
59 return ret == V1_0::Status::OK ? OK : ERROR;
60 }
61
62 bool mEnable;
63};
64
65static const auto Command =
66 CommandRegistry<CommandVibrator>::Register<CommandSetExternalControl>("setExternalControl");
67
68} // namespace vibrator
69} // namespace idlcli
70} // namespace android