blob: d21764ce3e4fc9b93005d8a693d35923fdd79c8a [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 Honga8bedc62017-09-08 18:00:31 -070024Status DebugCommand::parseArgs(const Arg &arg) {
Yifan Hong48dc9f82017-05-09 19:33:08 -070025 if (optind >= arg.argc) {
Yifan Hong48dc9f82017-05-09 19:33:08 -070026 return USAGE;
27 }
28 mInterfaceName = arg.argv[optind];
29 ++optind;
30 for (; optind < arg.argc; ++optind) {
31 mOptions.push_back(arg.argv[optind]);
32 }
33 return OK;
34}
35
Yifan Honga8bedc62017-09-08 18:00:31 -070036Status DebugCommand::main(const Arg &arg) {
37 Status status = parseArgs(arg);
Yifan Hong48dc9f82017-05-09 19:33:08 -070038 if (status != OK) {
39 return status;
40 }
41 auto pair = splitFirst(mInterfaceName, '/');
42 return mLshal.emitDebugInfo(
43 pair.first, pair.second.empty() ? "default" : pair.second, mOptions,
44 mLshal.out().buf(),
45 mLshal.err());
46}
47
Yifan Honga8bedc62017-09-08 18:00:31 -070048void DebugCommand::usage() const {
49
50 static const std::string debug =
51 "debug:\n"
52 " lshal debug <interface> [options [options [...]]] \n"
53 " Print debug information of a specified interface.\n"
54 " <inteface>: Format is `android.hardware.foo@1.0::IFoo/default`.\n"
55 " If instance name is missing `default` is used.\n"
56 " options: space separated options to IBase::debug.\n";
57
58 mLshal.err() << debug;
59}
60
Yifan Hong48dc9f82017-05-09 19:33:08 -070061} // namespace lshal
62} // namespace android
63