blob: 04f52726e3167e1bdb40647ce1f0488dff020191 [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
Steven Moreland0b8e3872019-06-25 08:54:34 -070017#pragma once
Yifan Hong443df792017-05-09 18:49:45 -070018
19#include <iomanip>
20#include <iostream>
21#include <string>
22#include <sstream>
23#include <utility>
24#include <vector>
25
26namespace android {
27namespace lshal {
28
29enum : unsigned int {
30 OK = 0,
Yifan Honga8bedc62017-09-08 18:00:31 -070031 // Return to Lshal::main to print help info.
Yifan Hong443df792017-05-09 18:49:45 -070032 USAGE = 1 << 0,
Yifan Honge3f88f12017-09-14 11:33:24 -070033 // no service managers
Yifan Hong443df792017-05-09 18:49:45 -070034 NO_BINDERIZED_MANAGER = 1 << 1,
35 NO_PASSTHROUGH_MANAGER = 1 << 2,
Yifan Honge3f88f12017-09-14 11:33:24 -070036 // general error in getting information from the three sources
Yifan Hong443df792017-05-09 18:49:45 -070037 DUMP_BINDERIZED_ERROR = 1 << 3,
38 DUMP_PASSTHROUGH_ERROR = 1 << 4,
39 DUMP_ALL_LIBS_ERROR = 1 << 5,
Yifan Honge3f88f12017-09-14 11:33:24 -070040 // I/O error in reading files
Yifan Hong443df792017-05-09 18:49:45 -070041 IO_ERROR = 1 << 6,
Yifan Honge3f88f12017-09-14 11:33:24 -070042 // Interface does not exist (IServiceManager::get fails)
Yifan Hong48dc9f82017-05-09 19:33:08 -070043 NO_INTERFACE = 1 << 7,
Yifan Honge3f88f12017-09-14 11:33:24 -070044 // Transaction error from hwbinder transactions
Yifan Hong48dc9f82017-05-09 19:33:08 -070045 TRANSACTION_ERROR = 1 << 8,
Yifan Hongfee209d2017-09-14 18:23:38 -070046 // No transaction error, but return value is unexpected.
47 BAD_IMPL = 1 << 9,
Yifan Hong13ba0a92018-06-25 16:15:56 -070048 // Cannot fetch VINTF data.
49 VINTF_ERROR = 1 << 10,
Yifan Hong443df792017-05-09 18:49:45 -070050};
51using Status = unsigned int;
52
53struct Arg {
54 int argc;
55 char **argv;
56};
57
58template <typename A>
59std::string join(const A &components, const std::string &separator) {
60 std::stringstream out;
61 bool first = true;
62 for (const auto &component : components) {
63 if (!first) {
64 out << separator;
65 }
66 out << component;
67
68 first = false;
69 }
70 return out.str();
71}
72
73std::string toHexString(uint64_t t);
74
75template<typename String>
76std::pair<String, String> splitFirst(const String &s, char c) {
77 const char *pos = strchr(s.c_str(), c);
78 if (pos == nullptr) {
79 return {s, {}};
80 }
81 return {String(s.c_str(), pos - s.c_str()), String(pos + 1)};
82}
83
84std::vector<std::string> split(const std::string &s, char c);
85
86void replaceAll(std::string *s, char from, char to);
87
88} // namespace lshal
89} // namespace android