| Yifan Hong | 8388ba3 | 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, | 
|  | 32 | USAGE                                   = 1 << 0, | 
|  | 33 | NO_BINDERIZED_MANAGER                   = 1 << 1, | 
|  | 34 | NO_PASSTHROUGH_MANAGER                  = 1 << 2, | 
|  | 35 | DUMP_BINDERIZED_ERROR                   = 1 << 3, | 
|  | 36 | DUMP_PASSTHROUGH_ERROR                  = 1 << 4, | 
|  | 37 | DUMP_ALL_LIBS_ERROR                     = 1 << 5, | 
|  | 38 | IO_ERROR                                = 1 << 6, | 
| Yifan Hong | 4d71d29 | 2017-05-09 19:33:08 -0700 | [diff] [blame] | 39 | NO_INTERFACE                            = 1 << 7, | 
|  | 40 | TRANSACTION_ERROR                       = 1 << 8, | 
| Yifan Hong | 8388ba3 | 2017-05-09 18:49:45 -0700 | [diff] [blame] | 41 | }; | 
|  | 42 | using Status = unsigned int; | 
|  | 43 |  | 
|  | 44 | struct Arg { | 
|  | 45 | int argc; | 
|  | 46 | char **argv; | 
|  | 47 | }; | 
|  | 48 |  | 
|  | 49 | template <typename A> | 
|  | 50 | std::string join(const A &components, const std::string &separator) { | 
|  | 51 | std::stringstream out; | 
|  | 52 | bool first = true; | 
|  | 53 | for (const auto &component : components) { | 
|  | 54 | if (!first) { | 
|  | 55 | out << separator; | 
|  | 56 | } | 
|  | 57 | out << component; | 
|  | 58 |  | 
|  | 59 | first = false; | 
|  | 60 | } | 
|  | 61 | return out.str(); | 
|  | 62 | } | 
|  | 63 |  | 
|  | 64 | std::string toHexString(uint64_t t); | 
|  | 65 |  | 
|  | 66 | template<typename String> | 
|  | 67 | std::pair<String, String> splitFirst(const String &s, char c) { | 
|  | 68 | const char *pos = strchr(s.c_str(), c); | 
|  | 69 | if (pos == nullptr) { | 
|  | 70 | return {s, {}}; | 
|  | 71 | } | 
|  | 72 | return {String(s.c_str(), pos - s.c_str()), String(pos + 1)}; | 
|  | 73 | } | 
|  | 74 |  | 
|  | 75 | std::vector<std::string> split(const std::string &s, char c); | 
|  | 76 |  | 
|  | 77 | void replaceAll(std::string *s, char from, char to); | 
|  | 78 |  | 
|  | 79 | }  // namespace lshal | 
|  | 80 | }  // namespace android | 
|  | 81 |  | 
|  | 82 | #endif  // FRAMEWORK_NATIVE_CMDS_LSHAL_UTILS_H_ |