blob: 303a9895e449e24972e0ec6d20d35028ce194fb2 [file] [log] [blame]
Harpreet \"Eli\" Sanghacb350b82019-11-12 15:15:25 +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 CommandGetCapabilities : public Command {
27 std::string getDescription() const override { return "Retrieves vibrator capabilities."; }
28
29 std::string getUsageSummary() const override { return ""; }
30
31 UsageDetails getUsageDetails() const override {
32 UsageDetails details{};
33 return details;
34 }
35
36 Status doArgs(Args &args) override {
37 if (!args.empty()) {
38 std::cerr << "Unexpected Arguments!" << std::endl;
39 return USAGE;
40 }
41 return OK;
42 }
43
44 Status doMain(Args && /*args*/) override {
45 std::string statusStr;
46 int32_t cap;
47 Status ret;
48
49 if (auto hal = getHal<aidl::IVibrator>()) {
50 auto status = hal->call(&aidl::IVibrator::getCapabilities, &cap);
Harpreet \"Eli\" Sangha6ce6f732019-11-28 16:53:41 +090051 statusStr = status.getDescription();
Harpreet \"Eli\" Sanghacb350b82019-11-12 15:15:25 +090052 ret = status.isOk() ? OK : ERROR;
53 } else {
54 return UNAVAILABLE;
55 }
56
57 std::cout << "Status: " << statusStr << std::endl;
58 std::cout << "Capabilities: " << std::bitset<32>(cap) << std::endl;
59
60 return ret;
61 }
62};
63
64static const auto Command =
65 CommandRegistry<CommandVibrator>::Register<CommandGetCapabilities>("getCapabilities");
66
67} // namespace vibrator
68} // namespace idlcli
69} // namespace android