Yifan Hong | b0dde93 | 2017-02-10 17:49:58 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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_TABLE_ENTRY_H_ |
| 18 | #define FRAMEWORK_NATIVE_CMDS_LSHAL_TABLE_ENTRY_H_ |
| 19 | |
| 20 | #include <stdint.h> |
| 21 | |
| 22 | #include <string> |
| 23 | #include <vector> |
Yifan Hong | 38d53e0 | 2017-02-13 17:51:59 -0800 | [diff] [blame] | 24 | #include <iostream> |
Yifan Hong | b0dde93 | 2017-02-10 17:49:58 -0800 | [diff] [blame] | 25 | |
Yifan Hong | f31aa05 | 2018-02-02 15:17:51 -0800 | [diff] [blame] | 26 | #include <procpartition/procpartition.h> |
Yifan Hong | 0ad64f5 | 2018-05-25 15:29:17 -0700 | [diff] [blame] | 27 | #include <vintf/Arch.h> |
Yifan Hong | 8304e41 | 2018-05-25 15:05:36 -0700 | [diff] [blame] | 28 | #include <vintf/Transport.h> |
Yifan Hong | f31aa05 | 2018-02-02 15:17:51 -0800 | [diff] [blame] | 29 | |
Yifan Hong | d4a77e8 | 2017-09-06 19:40:24 -0700 | [diff] [blame] | 30 | #include "TextTable.h" |
| 31 | |
Yifan Hong | b0dde93 | 2017-02-10 17:49:58 -0800 | [diff] [blame] | 32 | namespace android { |
| 33 | namespace lshal { |
| 34 | |
Yifan Hong | f31aa05 | 2018-02-02 15:17:51 -0800 | [diff] [blame] | 35 | using android::procpartition::Partition; |
Yifan Hong | b0dde93 | 2017-02-10 17:49:58 -0800 | [diff] [blame] | 36 | using Pids = std::vector<int32_t>; |
| 37 | |
Yifan Hong | d4a77e8 | 2017-09-06 19:40:24 -0700 | [diff] [blame] | 38 | enum class TableColumnType : unsigned int { |
| 39 | INTERFACE_NAME, |
| 40 | TRANSPORT, |
| 41 | SERVER_PID, |
| 42 | SERVER_CMD, |
| 43 | SERVER_ADDR, |
| 44 | CLIENT_PIDS, |
| 45 | CLIENT_CMDS, |
| 46 | ARCH, |
| 47 | THREADS, |
Yifan Hong | fee209d | 2017-09-14 18:23:38 -0700 | [diff] [blame] | 48 | RELEASED, |
| 49 | HASH, |
Yifan Hong | bdf44f8 | 2018-05-25 14:20:00 -0700 | [diff] [blame] | 50 | VINTF, |
Yifan Hong | 13ba0a9 | 2018-06-25 16:15:56 -0700 | [diff] [blame] | 51 | SERVICE_STATUS, |
Yifan Hong | d4a77e8 | 2017-09-06 19:40:24 -0700 | [diff] [blame] | 52 | }; |
| 53 | |
Yifan Hong | bdf44f8 | 2018-05-25 14:20:00 -0700 | [diff] [blame] | 54 | enum : unsigned int { |
| 55 | VINTF_INFO_EMPTY = 0, |
| 56 | DEVICE_MANIFEST = 1 << 0, |
| 57 | DEVICE_MATRIX = 1 << 1, |
| 58 | FRAMEWORK_MANIFEST = 1 << 2, |
| 59 | FRAMEWORK_MATRIX = 1 << 3, |
| 60 | }; |
| 61 | using VintfInfo = unsigned int; |
| 62 | |
Yifan Hong | 22ea7b8 | 2017-09-14 18:07:43 -0700 | [diff] [blame] | 63 | enum { |
| 64 | NO_PID = -1, |
| 65 | NO_PTR = 0 |
| 66 | }; |
| 67 | |
Yifan Hong | 13ba0a9 | 2018-06-25 16:15:56 -0700 | [diff] [blame] | 68 | enum class ServiceStatus { |
| 69 | UNKNOWN, // For passthrough |
| 70 | ALIVE, |
| 71 | NON_RESPONSIVE, // registered but not respond to calls |
| 72 | DECLARED, // in VINTF manifest |
| 73 | }; |
| 74 | std::string to_string(ServiceStatus s); |
| 75 | |
Yifan Hong | b0dde93 | 2017-02-10 17:49:58 -0800 | [diff] [blame] | 76 | struct TableEntry { |
Yifan Hong | 22ea7b8 | 2017-09-14 18:07:43 -0700 | [diff] [blame] | 77 | std::string interfaceName{}; |
Yifan Hong | 8304e41 | 2018-05-25 15:05:36 -0700 | [diff] [blame] | 78 | vintf::Transport transport{vintf::Transport::EMPTY}; |
Yifan Hong | 22ea7b8 | 2017-09-14 18:07:43 -0700 | [diff] [blame] | 79 | int32_t serverPid{NO_PID}; |
| 80 | uint32_t threadUsage{0}; |
| 81 | uint32_t threadCount{0}; |
| 82 | std::string serverCmdline{}; |
| 83 | uint64_t serverObjectAddress{NO_PTR}; |
| 84 | Pids clientPids{}; |
| 85 | std::vector<std::string> clientCmdlines{}; |
Yifan Hong | 0ad64f5 | 2018-05-25 15:29:17 -0700 | [diff] [blame] | 86 | vintf::Arch arch{vintf::Arch::ARCH_EMPTY}; |
Yifan Hong | fee209d | 2017-09-14 18:23:38 -0700 | [diff] [blame] | 87 | // empty: unknown, all zeros: unreleased, otherwise: released |
| 88 | std::string hash{}; |
Yifan Hong | f31aa05 | 2018-02-02 15:17:51 -0800 | [diff] [blame] | 89 | Partition partition{Partition::UNKNOWN}; |
Yifan Hong | bdf44f8 | 2018-05-25 14:20:00 -0700 | [diff] [blame] | 90 | VintfInfo vintfInfo{VINTF_INFO_EMPTY}; |
Yifan Hong | 13ba0a9 | 2018-06-25 16:15:56 -0700 | [diff] [blame] | 91 | // true iff hwbinder and service started |
| 92 | ServiceStatus serviceStatus{ServiceStatus::UNKNOWN}; |
Yifan Hong | 38d53e0 | 2017-02-13 17:51:59 -0800 | [diff] [blame] | 93 | |
| 94 | static bool sortByInterfaceName(const TableEntry &a, const TableEntry &b) { |
| 95 | return a.interfaceName < b.interfaceName; |
| 96 | }; |
| 97 | static bool sortByServerPid(const TableEntry &a, const TableEntry &b) { |
| 98 | return a.serverPid < b.serverPid; |
| 99 | }; |
Steven Moreland | d8e2019 | 2017-05-24 11:23:08 -0700 | [diff] [blame] | 100 | |
| 101 | std::string getThreadUsage() const { |
| 102 | if (threadCount == 0) { |
| 103 | return "N/A"; |
| 104 | } |
| 105 | |
| 106 | return std::to_string(threadUsage) + "/" + std::to_string(threadCount); |
| 107 | } |
Yifan Hong | d4a77e8 | 2017-09-06 19:40:24 -0700 | [diff] [blame] | 108 | |
Yifan Hong | fee209d | 2017-09-14 18:23:38 -0700 | [diff] [blame] | 109 | std::string isReleased() const; |
| 110 | |
Yifan Hong | bdf44f8 | 2018-05-25 14:20:00 -0700 | [diff] [blame] | 111 | std::string getVintfInfo() const; |
| 112 | |
Yifan Hong | d4a77e8 | 2017-09-06 19:40:24 -0700 | [diff] [blame] | 113 | std::string getField(TableColumnType type) const; |
Yifan Hong | 8bf7316 | 2017-09-07 18:06:13 -0700 | [diff] [blame] | 114 | |
| 115 | bool operator==(const TableEntry& other) const; |
| 116 | std::string to_string() const; |
Yifan Hong | b0dde93 | 2017-02-10 17:49:58 -0800 | [diff] [blame] | 117 | }; |
| 118 | |
Yifan Hong | d4a77e8 | 2017-09-06 19:40:24 -0700 | [diff] [blame] | 119 | using SelectedColumns = std::vector<TableColumnType>; |
Yifan Hong | a3b8709 | 2017-03-02 19:19:29 -0800 | [diff] [blame] | 120 | |
Yifan Hong | d4a77e8 | 2017-09-06 19:40:24 -0700 | [diff] [blame] | 121 | class Table { |
| 122 | public: |
| 123 | using Entries = std::vector<TableEntry>; |
| 124 | |
| 125 | Entries::iterator begin() { return mEntries.begin(); } |
| 126 | Entries::const_iterator begin() const { return mEntries.begin(); } |
| 127 | Entries::iterator end() { return mEntries.end(); } |
| 128 | Entries::const_iterator end() const { return mEntries.end(); } |
Yifan Hong | 8bf7316 | 2017-09-07 18:06:13 -0700 | [diff] [blame] | 129 | size_t size() const { return mEntries.size(); } |
Yifan Hong | d4a77e8 | 2017-09-06 19:40:24 -0700 | [diff] [blame] | 130 | |
| 131 | void add(TableEntry&& entry) { mEntries.push_back(std::move(entry)); } |
| 132 | |
| 133 | void setSelectedColumns(const SelectedColumns& s) { mSelectedColumns = s; } |
| 134 | const SelectedColumns& getSelectedColumns() const { return mSelectedColumns; } |
| 135 | |
| 136 | void setDescription(std::string&& d) { mDescription = std::move(d); } |
| 137 | |
| 138 | // Write table content. |
| 139 | TextTable createTextTable(bool neat = true, |
| 140 | const std::function<std::string(const std::string&)>& emitDebugInfo = nullptr) const; |
| 141 | |
| 142 | private: |
| 143 | std::string mDescription; |
| 144 | Entries mEntries; |
| 145 | SelectedColumns mSelectedColumns; |
Yifan Hong | a3b8709 | 2017-03-02 19:19:29 -0800 | [diff] [blame] | 146 | }; |
| 147 | |
Yifan Hong | 38d53e0 | 2017-02-13 17:51:59 -0800 | [diff] [blame] | 148 | using TableEntryCompare = std::function<bool(const TableEntry &, const TableEntry &)>; |
| 149 | |
Yifan Hong | d4a77e8 | 2017-09-06 19:40:24 -0700 | [diff] [blame] | 150 | class MergedTable { |
| 151 | public: |
Chih-Hung Hsieh | 45e31c7 | 2018-12-20 15:47:01 -0800 | [diff] [blame] | 152 | explicit MergedTable(std::vector<const Table*>&& tables) : mTables(std::move(tables)) {} |
Yifan Hong | d4a77e8 | 2017-09-06 19:40:24 -0700 | [diff] [blame] | 153 | TextTable createTextTable(); |
| 154 | private: |
| 155 | std::vector<const Table*> mTables; |
Yifan Hong | 38d53e0 | 2017-02-13 17:51:59 -0800 | [diff] [blame] | 156 | }; |
| 157 | |
Yifan Hong | b0dde93 | 2017-02-10 17:49:58 -0800 | [diff] [blame] | 158 | } // namespace lshal |
| 159 | } // namespace android |
| 160 | |
| 161 | #endif // FRAMEWORK_NATIVE_CMDS_LSHAL_TABLE_ENTRY_H_ |