| Yifan Hong | 443df79 | 2017-05-09 18:49:45 -0700 | [diff] [blame] | 1 | /* | 
|  | 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 |  | 
|  | 27 | namespace android { | 
|  | 28 | namespace lshal { | 
|  | 29 |  | 
|  | 30 | enum : unsigned int { | 
|  | 31 | OK                                      = 0, | 
| Yifan Hong | a8bedc6 | 2017-09-08 18:00:31 -0700 | [diff] [blame] | 32 | // Return to Lshal::main to print help info. | 
| Yifan Hong | 443df79 | 2017-05-09 18:49:45 -0700 | [diff] [blame] | 33 | USAGE                                   = 1 << 0, | 
| Yifan Hong | e3f88f1 | 2017-09-14 11:33:24 -0700 | [diff] [blame] | 34 | // no service managers | 
| Yifan Hong | 443df79 | 2017-05-09 18:49:45 -0700 | [diff] [blame] | 35 | NO_BINDERIZED_MANAGER                   = 1 << 1, | 
|  | 36 | NO_PASSTHROUGH_MANAGER                  = 1 << 2, | 
| Yifan Hong | e3f88f1 | 2017-09-14 11:33:24 -0700 | [diff] [blame] | 37 | // general error in getting information from the three sources | 
| Yifan Hong | 443df79 | 2017-05-09 18:49:45 -0700 | [diff] [blame] | 38 | DUMP_BINDERIZED_ERROR                   = 1 << 3, | 
|  | 39 | DUMP_PASSTHROUGH_ERROR                  = 1 << 4, | 
|  | 40 | DUMP_ALL_LIBS_ERROR                     = 1 << 5, | 
| Yifan Hong | e3f88f1 | 2017-09-14 11:33:24 -0700 | [diff] [blame] | 41 | // I/O error in reading files | 
| Yifan Hong | 443df79 | 2017-05-09 18:49:45 -0700 | [diff] [blame] | 42 | IO_ERROR                                = 1 << 6, | 
| Yifan Hong | e3f88f1 | 2017-09-14 11:33:24 -0700 | [diff] [blame] | 43 | // Interface does not exist (IServiceManager::get fails) | 
| Yifan Hong | 48dc9f8 | 2017-05-09 19:33:08 -0700 | [diff] [blame] | 44 | NO_INTERFACE                            = 1 << 7, | 
| Yifan Hong | e3f88f1 | 2017-09-14 11:33:24 -0700 | [diff] [blame] | 45 | // Transaction error from hwbinder transactions | 
| Yifan Hong | 48dc9f8 | 2017-05-09 19:33:08 -0700 | [diff] [blame] | 46 | TRANSACTION_ERROR                       = 1 << 8, | 
| Yifan Hong | fee209d | 2017-09-14 18:23:38 -0700 | [diff] [blame] | 47 | // No transaction error, but return value is unexpected. | 
|  | 48 | BAD_IMPL                                = 1 << 9, | 
| Yifan Hong | 13ba0a9 | 2018-06-25 16:15:56 -0700 | [diff] [blame] | 49 | // Cannot fetch VINTF data. | 
|  | 50 | VINTF_ERROR                             = 1 << 10, | 
| Yifan Hong | 443df79 | 2017-05-09 18:49:45 -0700 | [diff] [blame] | 51 | }; | 
|  | 52 | using Status = unsigned int; | 
|  | 53 |  | 
|  | 54 | struct Arg { | 
|  | 55 | int argc; | 
|  | 56 | char **argv; | 
|  | 57 | }; | 
|  | 58 |  | 
|  | 59 | template <typename A> | 
|  | 60 | std::string join(const A &components, const std::string &separator) { | 
|  | 61 | std::stringstream out; | 
|  | 62 | bool first = true; | 
|  | 63 | for (const auto &component : components) { | 
|  | 64 | if (!first) { | 
|  | 65 | out << separator; | 
|  | 66 | } | 
|  | 67 | out << component; | 
|  | 68 |  | 
|  | 69 | first = false; | 
|  | 70 | } | 
|  | 71 | return out.str(); | 
|  | 72 | } | 
|  | 73 |  | 
|  | 74 | std::string toHexString(uint64_t t); | 
|  | 75 |  | 
|  | 76 | template<typename String> | 
|  | 77 | std::pair<String, String> splitFirst(const String &s, char c) { | 
|  | 78 | const char *pos = strchr(s.c_str(), c); | 
|  | 79 | if (pos == nullptr) { | 
|  | 80 | return {s, {}}; | 
|  | 81 | } | 
|  | 82 | return {String(s.c_str(), pos - s.c_str()), String(pos + 1)}; | 
|  | 83 | } | 
|  | 84 |  | 
|  | 85 | std::vector<std::string> split(const std::string &s, char c); | 
|  | 86 |  | 
|  | 87 | void replaceAll(std::string *s, char from, char to); | 
|  | 88 |  | 
|  | 89 | }  // namespace lshal | 
|  | 90 | }  // namespace android | 
|  | 91 |  | 
|  | 92 | #endif  // FRAMEWORK_NATIVE_CMDS_LSHAL_UTILS_H_ |