diff options
author | 2017-01-26 18:32:28 +0000 | |
---|---|---|
committer | 2017-01-26 18:32:28 +0000 | |
commit | d773d824b828af8147569f715dffcba3cc7a9f52 (patch) | |
tree | 18e499fa03a8974234805bb6e4b3abc09925321c | |
parent | 1b705dc20b346ccda5f5ce02287c28aaa50491e2 (diff) | |
parent | 684fae26ec8a7fa5b4ee115e9f14cd55bd23d95f (diff) |
Add an lshal command. am: 85dd3ad89f am: a763ae7121 am: 5a0eaa454f
am: 684fae26ec
Change-Id: I3ecd794a8d51e3c316cf2974af0c7c95a4bfcef5
-rw-r--r-- | cmds/lshal/Android.bp | 26 | ||||
-rw-r--r-- | cmds/lshal/lshal.cpp | 117 |
2 files changed, 143 insertions, 0 deletions
diff --git a/cmds/lshal/Android.bp b/cmds/lshal/Android.bp new file mode 100644 index 0000000000..dd8104d180 --- /dev/null +++ b/cmds/lshal/Android.bp @@ -0,0 +1,26 @@ +// Copyright (C) 2016 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +cc_binary { + name: "lshal", + shared_libs: [ + "libutils", + "libhidlbase", + "android.hidl.manager@1.0", + "libhidltransport", + ], + srcs: [ + "lshal.cpp" + ], +} diff --git a/cmds/lshal/lshal.cpp b/cmds/lshal/lshal.cpp new file mode 100644 index 0000000000..bc8bf39d0e --- /dev/null +++ b/cmds/lshal/lshal.cpp @@ -0,0 +1,117 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include <getopt.h> + +#include <map> +#include <iomanip> +#include <iostream> +#include <sstream> + +#include <android/hidl/manager/1.0/IServiceManager.h> +#include <hidl/ServiceManagement.h> + +template <typename A, typename B, typename C, typename D> +void printColumn(std::stringstream &stream, + const A &a, const B &b, const C &c, const D &d) { + using namespace ::std; + stream << left + << setw(70) << a << "\t" + << setw(20) << b << "\t" + << setw(10) << c << "\t" + << setw(5) << d << "\t" + << endl; +} + +int dump() { + using namespace ::std; + using namespace ::android::hardware; + using namespace ::android::hidl::manager::V1_0; + + std::map<std::string, ::android::sp<IServiceManager>> mapping = { + {"hwbinder", defaultServiceManager()}, + {"passthrough", getPassthroughServiceManager()} + }; + + std::stringstream stream; + + stream << "All services:" << endl; + stream << left; + printColumn(stream, "Interface", "Instance", "Transport", "Ref"); + + for (const auto &pair : mapping) { + const std::string &mode = pair.first; + const ::android::sp<IServiceManager> &manager = pair.second; + + if (manager == nullptr) { + cerr << "Failed to get IServiceManager for " << mode << "!" << endl; + continue; + } + + auto ret = manager->debugDump([&](const auto ®istered) { + for (const auto &info : registered) { + printColumn(stream, + info.interfaceName, + info.instanceName.empty() ? "N/A" : info.instanceName, + mode, + info.refCount == 0 ? "N/A" : std::to_string(info.refCount - 1)); + } + }); + if (!ret.isOk()) { + cerr << "Failed to list services for " << mode << ": " + << ret.description() << endl; + } + } + cout << stream.rdbuf(); + return 0; +} + +int usage() { + using namespace ::std; + cerr + << "usage: lshal" << endl + << " To dump all hals." << endl + << "or:" << endl + << " lshal [-h|--help]" << endl + << " -h, --help: show this help information." << endl; + return -1; +} + +int main(int argc, char **argv) { + static struct option longOptions[] = { + {"help", no_argument, 0, 'h' }, + { 0, 0, 0, 0 } + }; + + int optionIndex; + int c; + optind = 1; + for (;;) { + // using getopt_long in case we want to add other options in the future + c = getopt_long(argc, argv, "h", longOptions, &optionIndex); + if (c == -1) { + break; + } + switch (c) { + case 'h': // falls through + default: // see unrecognized options + return usage(); + } + } + return dump(); + +} |