blob: 7eca14e0f7a2d7538a01d0bff64e59f362db2c0b [file] [log] [blame]
Yifan Hong443df792017-05-09 18:49:45 -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#ifndef FRAMEWORK_NATIVE_CMDS_LSHAL_UTILS_H_
18#define FRAMEWORK_NATIVE_CMDS_LSHAL_UTILS_H_
19
20#include <iomanip>
21#include <iostream>
22#include <string>
23#include <sstream>
24#include <utility>
25#include <vector>
26
27namespace android {
28namespace lshal {
29
30enum : unsigned int {
31 OK = 0,
Yifan Honga8bedc62017-09-08 18:00:31 -070032 // Return to Lshal::main to print help info.
Yifan Hong443df792017-05-09 18:49:45 -070033 USAGE = 1 << 0,
Yifan Honge3f88f12017-09-14 11:33:24 -070034 // no service managers
Yifan Hong443df792017-05-09 18:49:45 -070035 NO_BINDERIZED_MANAGER = 1 << 1,
36 NO_PASSTHROUGH_MANAGER = 1 << 2,
Yifan Honge3f88f12017-09-14 11:33:24 -070037 // general error in getting information from the three sources
Yifan Hong443df792017-05-09 18:49:45 -070038 DUMP_BINDERIZED_ERROR = 1 << 3,
39 DUMP_PASSTHROUGH_ERROR = 1 << 4,
40 DUMP_ALL_LIBS_ERROR = 1 << 5,
Yifan Honge3f88f12017-09-14 11:33:24 -070041 // I/O error in reading files
Yifan Hong443df792017-05-09 18:49:45 -070042 IO_ERROR = 1 << 6,
Yifan Honge3f88f12017-09-14 11:33:24 -070043 // Interface does not exist (IServiceManager::get fails)
Yifan Hong48dc9f82017-05-09 19:33:08 -070044 NO_INTERFACE = 1 << 7,
Yifan Honge3f88f12017-09-14 11:33:24 -070045 // Transaction error from hwbinder transactions
Yifan Hong48dc9f82017-05-09 19:33:08 -070046 TRANSACTION_ERROR = 1 << 8,
Yifan Hong443df792017-05-09 18:49:45 -070047};
48using Status = unsigned int;
49
50struct Arg {
51 int argc;
52 char **argv;
53};
54
55template <typename A>
56std::string join(const A &components, const std::string &separator) {
57 std::stringstream out;
58 bool first = true;
59 for (const auto &component : components) {
60 if (!first) {
61 out << separator;
62 }
63 out << component;
64
65 first = false;
66 }
67 return out.str();
68}
69
70std::string toHexString(uint64_t t);
71
72template<typename String>
73std::pair<String, String> splitFirst(const String &s, char c) {
74 const char *pos = strchr(s.c_str(), c);
75 if (pos == nullptr) {
76 return {s, {}};
77 }
78 return {String(s.c_str(), pos - s.c_str()), String(pos + 1)};
79}
80
81std::vector<std::string> split(const std::string &s, char c);
82
83void replaceAll(std::string *s, char from, char to);
84
85} // namespace lshal
86} // namespace android
87
88#endif // FRAMEWORK_NATIVE_CMDS_LSHAL_UTILS_H_