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 | |
| 26 | namespace android { |
| 27 | namespace lshal { |
| 28 | |
| 29 | using Pids = std::vector<int32_t>; |
| 30 | |
Yifan Hong | 4b86549 | 2017-02-28 19:38:24 -0800 | [diff] [blame] | 31 | enum : unsigned int { |
| 32 | HWSERVICEMANAGER_LIST, // through defaultServiceManager()->list() |
| 33 | PTSERVICEMANAGER_REG_CLIENT, // through registerPassthroughClient |
| 34 | LIST_DLLIB, // through listing dynamic libraries |
| 35 | }; |
| 36 | using TableEntrySource = unsigned int; |
| 37 | |
Yifan Hong | b447902 | 2017-03-02 16:54:11 -0800 | [diff] [blame] | 38 | enum : unsigned int { |
| 39 | ARCH_UNKNOWN = 0, |
Yifan Hong | 3fdbd9f | 2017-03-08 14:01:58 -0800 | [diff] [blame] | 40 | ARCH32 = 1 << 0, |
| 41 | ARCH64 = 1 << 1, |
Yifan Hong | b447902 | 2017-03-02 16:54:11 -0800 | [diff] [blame] | 42 | ARCH_BOTH = ARCH32 | ARCH64 |
| 43 | }; |
| 44 | using Architecture = unsigned int; |
| 45 | |
Yifan Hong | b0dde93 | 2017-02-10 17:49:58 -0800 | [diff] [blame] | 46 | struct TableEntry { |
| 47 | std::string interfaceName; |
| 48 | std::string transport; |
| 49 | int32_t serverPid; |
Steven Moreland | d8e2019 | 2017-05-24 11:23:08 -0700 | [diff] [blame^] | 50 | uint32_t threadUsage; |
| 51 | uint32_t threadCount; |
Yifan Hong | ae09a3d | 2017-02-14 17:33:50 -0800 | [diff] [blame] | 52 | std::string serverCmdline; |
Yifan Hong | b0dde93 | 2017-02-10 17:49:58 -0800 | [diff] [blame] | 53 | uint64_t serverObjectAddress; |
| 54 | Pids clientPids; |
Yifan Hong | ae09a3d | 2017-02-14 17:33:50 -0800 | [diff] [blame] | 55 | std::vector<std::string> clientCmdlines; |
Yifan Hong | b447902 | 2017-03-02 16:54:11 -0800 | [diff] [blame] | 56 | Architecture arch; |
Yifan Hong | 38d53e0 | 2017-02-13 17:51:59 -0800 | [diff] [blame] | 57 | |
| 58 | static bool sortByInterfaceName(const TableEntry &a, const TableEntry &b) { |
| 59 | return a.interfaceName < b.interfaceName; |
| 60 | }; |
| 61 | static bool sortByServerPid(const TableEntry &a, const TableEntry &b) { |
| 62 | return a.serverPid < b.serverPid; |
| 63 | }; |
Steven Moreland | d8e2019 | 2017-05-24 11:23:08 -0700 | [diff] [blame^] | 64 | |
| 65 | std::string getThreadUsage() const { |
| 66 | if (threadCount == 0) { |
| 67 | return "N/A"; |
| 68 | } |
| 69 | |
| 70 | return std::to_string(threadUsage) + "/" + std::to_string(threadCount); |
| 71 | } |
Yifan Hong | b0dde93 | 2017-02-10 17:49:58 -0800 | [diff] [blame] | 72 | }; |
| 73 | |
Yifan Hong | a3b8709 | 2017-03-02 19:19:29 -0800 | [diff] [blame] | 74 | struct Table { |
| 75 | using Entries = std::vector<TableEntry>; |
| 76 | std::string description; |
| 77 | Entries entries; |
| 78 | |
| 79 | Entries::iterator begin() { return entries.begin(); } |
| 80 | Entries::const_iterator begin() const { return entries.begin(); } |
| 81 | Entries::iterator end() { return entries.end(); } |
| 82 | Entries::const_iterator end() const { return entries.end(); } |
| 83 | }; |
| 84 | |
Yifan Hong | 38d53e0 | 2017-02-13 17:51:59 -0800 | [diff] [blame] | 85 | using TableEntryCompare = std::function<bool(const TableEntry &, const TableEntry &)>; |
| 86 | |
| 87 | enum : unsigned int { |
| 88 | ENABLE_INTERFACE_NAME = 1 << 0, |
| 89 | ENABLE_TRANSPORT = 1 << 1, |
| 90 | ENABLE_SERVER_PID = 1 << 2, |
| 91 | ENABLE_SERVER_ADDR = 1 << 3, |
Yifan Hong | b447902 | 2017-03-02 16:54:11 -0800 | [diff] [blame] | 92 | ENABLE_CLIENT_PIDS = 1 << 4, |
Steven Moreland | d8e2019 | 2017-05-24 11:23:08 -0700 | [diff] [blame^] | 93 | ENABLE_ARCH = 1 << 5, |
| 94 | ENABLE_THREADS = 1 << 6, |
Yifan Hong | 38d53e0 | 2017-02-13 17:51:59 -0800 | [diff] [blame] | 95 | }; |
| 96 | |
| 97 | using TableEntrySelect = unsigned int; |
Yifan Hong | b0dde93 | 2017-02-10 17:49:58 -0800 | [diff] [blame] | 98 | |
| 99 | enum { |
| 100 | NO_PID = -1, |
| 101 | NO_PTR = 0 |
| 102 | }; |
| 103 | |
| 104 | } // namespace lshal |
| 105 | } // namespace android |
| 106 | |
| 107 | #endif // FRAMEWORK_NATIVE_CMDS_LSHAL_TABLE_ENTRY_H_ |