Yifan Hong | 48dc9f8 | 2017-05-09 19:33:08 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2017 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "DebugCommand.h" |
| 18 | |
| 19 | #include "Lshal.h" |
| 20 | |
| 21 | namespace android { |
| 22 | namespace lshal { |
| 23 | |
| 24 | DebugCommand::DebugCommand(Lshal &lshal) : mLshal(lshal) { |
| 25 | } |
| 26 | |
| 27 | Status DebugCommand::parseArgs(const std::string &command, const Arg &arg) { |
| 28 | if (optind >= arg.argc) { |
| 29 | mLshal.usage(command); |
| 30 | return USAGE; |
| 31 | } |
| 32 | mInterfaceName = arg.argv[optind]; |
| 33 | ++optind; |
| 34 | for (; optind < arg.argc; ++optind) { |
| 35 | mOptions.push_back(arg.argv[optind]); |
| 36 | } |
| 37 | return OK; |
| 38 | } |
| 39 | |
| 40 | Status DebugCommand::main(const std::string &command, const Arg &arg) { |
| 41 | Status status = parseArgs(command, arg); |
| 42 | if (status != OK) { |
| 43 | return status; |
| 44 | } |
| 45 | auto pair = splitFirst(mInterfaceName, '/'); |
| 46 | return mLshal.emitDebugInfo( |
| 47 | pair.first, pair.second.empty() ? "default" : pair.second, mOptions, |
| 48 | mLshal.out().buf(), |
| 49 | mLshal.err()); |
| 50 | } |
| 51 | |
| 52 | } // namespace lshal |
| 53 | } // namespace android |
| 54 | |