blob: e657bcf4e663bfaa38d21a2a30d139f04243ead5 [file] [log] [blame]
Yifan Hong48dc9f82017-05-09 19:33:08 -07001/*
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
21namespace android {
22namespace lshal {
23
Yifan Hong48dc9f82017-05-09 19:33:08 -070024Status DebugCommand::parseArgs(const std::string &command, const Arg &arg) {
25 if (optind >= arg.argc) {
26 mLshal.usage(command);
27 return USAGE;
28 }
29 mInterfaceName = arg.argv[optind];
30 ++optind;
31 for (; optind < arg.argc; ++optind) {
32 mOptions.push_back(arg.argv[optind]);
33 }
34 return OK;
35}
36
37Status DebugCommand::main(const std::string &command, const Arg &arg) {
38 Status status = parseArgs(command, arg);
39 if (status != OK) {
40 return status;
41 }
42 auto pair = splitFirst(mInterfaceName, '/');
43 return mLshal.emitDebugInfo(
44 pair.first, pair.second.empty() ? "default" : pair.second, mOptions,
45 mLshal.out().buf(),
46 mLshal.err());
47}
48
49} // namespace lshal
50} // namespace android
51