| Harpreet "Eli" Sangha | e47ae68 | 2019-06-05 16:52:47 +0900 | [diff] [blame] | 1 | /* | 
|  | 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 |  | 
|  | 19 | namespace android { | 
|  | 20 | namespace idlcli { | 
|  | 21 |  | 
|  | 22 | class CommandVibrator; | 
|  | 23 |  | 
|  | 24 | namespace vibrator { | 
|  | 25 |  | 
|  | 26 | class 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 { | 
| Harpreet \"Eli\" Sangha | cb350b8 | 2019-11-12 15:15:25 +0900 | [diff] [blame] | 51 | std::string statusStr; | 
|  | 52 | Status ret; | 
| Harpreet "Eli" Sangha | e47ae68 | 2019-06-05 16:52:47 +0900 | [diff] [blame] | 53 |  | 
| Harpreet \"Eli\" Sangha | cb350b8 | 2019-11-12 15:15:25 +0900 | [diff] [blame] | 54 | if (auto hal = getHal<aidl::IVibrator>()) { | 
|  | 55 | auto status = hal->call(&aidl::IVibrator::setExternalControl, mEnable); | 
| Harpreet \"Eli\" Sangha | 6ce6f73 | 2019-11-28 16:53:41 +0900 | [diff] [blame] | 56 | statusStr = status.getDescription(); | 
| Harpreet \"Eli\" Sangha | cb350b8 | 2019-11-12 15:15:25 +0900 | [diff] [blame] | 57 | ret = status.isOk() ? OK : ERROR; | 
|  | 58 | } else if (auto hal = getHal<V1_3::IVibrator>()) { | 
|  | 59 | auto status = hal->call(&V1_3::IVibrator::setExternalControl, mEnable); | 
|  | 60 | statusStr = toString(status); | 
|  | 61 | ret = status.isOk() && status == V1_0::Status::OK ? OK : ERROR; | 
|  | 62 | } else { | 
| Harpreet "Eli" Sangha | e47ae68 | 2019-06-05 16:52:47 +0900 | [diff] [blame] | 63 | return UNAVAILABLE; | 
|  | 64 | } | 
|  | 65 |  | 
| Harpreet \"Eli\" Sangha | cb350b8 | 2019-11-12 15:15:25 +0900 | [diff] [blame] | 66 | std::cout << "Status: " << statusStr << std::endl; | 
| Harpreet "Eli" Sangha | e47ae68 | 2019-06-05 16:52:47 +0900 | [diff] [blame] | 67 |  | 
| Harpreet \"Eli\" Sangha | cb350b8 | 2019-11-12 15:15:25 +0900 | [diff] [blame] | 68 | return ret; | 
| Harpreet "Eli" Sangha | e47ae68 | 2019-06-05 16:52:47 +0900 | [diff] [blame] | 69 | } | 
|  | 70 |  | 
|  | 71 | bool mEnable; | 
|  | 72 | }; | 
|  | 73 |  | 
|  | 74 | static const auto Command = | 
|  | 75 | CommandRegistry<CommandVibrator>::Register<CommandSetExternalControl>("setExternalControl"); | 
|  | 76 |  | 
|  | 77 | } // namespace vibrator | 
|  | 78 | } // namespace idlcli | 
|  | 79 | } // namespace android |