blob: c9a6a239530dc1d95947984d25243c8803315197 [file] [log] [blame]
Yifan Hongb0dde932017-02-10 17:49:58 -08001/*
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 Hong38d53e02017-02-13 17:51:59 -080024#include <iostream>
Yifan Hongb0dde932017-02-10 17:49:58 -080025
Yifan Hongf31aa052018-02-02 15:17:51 -080026#include <procpartition/procpartition.h>
Yifan Hong0ad64f52018-05-25 15:29:17 -070027#include <vintf/Arch.h>
Yifan Hong8304e412018-05-25 15:05:36 -070028#include <vintf/Transport.h>
Yifan Hongf31aa052018-02-02 15:17:51 -080029
Yifan Hongd4a77e82017-09-06 19:40:24 -070030#include "TextTable.h"
31
Yifan Hongb0dde932017-02-10 17:49:58 -080032namespace android {
33namespace lshal {
34
Yifan Hongf31aa052018-02-02 15:17:51 -080035using android::procpartition::Partition;
Yifan Hongb0dde932017-02-10 17:49:58 -080036using Pids = std::vector<int32_t>;
37
Yifan Hong4b865492017-02-28 19:38:24 -080038enum : unsigned int {
39 HWSERVICEMANAGER_LIST, // through defaultServiceManager()->list()
40 PTSERVICEMANAGER_REG_CLIENT, // through registerPassthroughClient
41 LIST_DLLIB, // through listing dynamic libraries
42};
43using TableEntrySource = unsigned int;
44
Yifan Hongd4a77e82017-09-06 19:40:24 -070045enum class TableColumnType : unsigned int {
46 INTERFACE_NAME,
47 TRANSPORT,
48 SERVER_PID,
49 SERVER_CMD,
50 SERVER_ADDR,
51 CLIENT_PIDS,
52 CLIENT_CMDS,
53 ARCH,
54 THREADS,
Yifan Hongfee209d2017-09-14 18:23:38 -070055 RELEASED,
56 HASH,
Yifan Hongbdf44f82018-05-25 14:20:00 -070057 VINTF,
Yifan Hongd4a77e82017-09-06 19:40:24 -070058};
59
Yifan Hongbdf44f82018-05-25 14:20:00 -070060enum : unsigned int {
61 VINTF_INFO_EMPTY = 0,
62 DEVICE_MANIFEST = 1 << 0,
63 DEVICE_MATRIX = 1 << 1,
64 FRAMEWORK_MANIFEST = 1 << 2,
65 FRAMEWORK_MATRIX = 1 << 3,
66};
67using VintfInfo = unsigned int;
68
Yifan Hong22ea7b82017-09-14 18:07:43 -070069enum {
70 NO_PID = -1,
71 NO_PTR = 0
72};
73
Yifan Hongb0dde932017-02-10 17:49:58 -080074struct TableEntry {
Yifan Hong22ea7b82017-09-14 18:07:43 -070075 std::string interfaceName{};
Yifan Hong8304e412018-05-25 15:05:36 -070076 vintf::Transport transport{vintf::Transport::EMPTY};
Yifan Hong22ea7b82017-09-14 18:07:43 -070077 int32_t serverPid{NO_PID};
78 uint32_t threadUsage{0};
79 uint32_t threadCount{0};
80 std::string serverCmdline{};
81 uint64_t serverObjectAddress{NO_PTR};
82 Pids clientPids{};
83 std::vector<std::string> clientCmdlines{};
Yifan Hong0ad64f52018-05-25 15:29:17 -070084 vintf::Arch arch{vintf::Arch::ARCH_EMPTY};
Yifan Hongfee209d2017-09-14 18:23:38 -070085 // empty: unknown, all zeros: unreleased, otherwise: released
86 std::string hash{};
Yifan Hongf31aa052018-02-02 15:17:51 -080087 Partition partition{Partition::UNKNOWN};
Yifan Hongbdf44f82018-05-25 14:20:00 -070088 VintfInfo vintfInfo{VINTF_INFO_EMPTY};
Yifan Hong38d53e02017-02-13 17:51:59 -080089
90 static bool sortByInterfaceName(const TableEntry &a, const TableEntry &b) {
91 return a.interfaceName < b.interfaceName;
92 };
93 static bool sortByServerPid(const TableEntry &a, const TableEntry &b) {
94 return a.serverPid < b.serverPid;
95 };
Steven Morelandd8e20192017-05-24 11:23:08 -070096
97 std::string getThreadUsage() const {
98 if (threadCount == 0) {
99 return "N/A";
100 }
101
102 return std::to_string(threadUsage) + "/" + std::to_string(threadCount);
103 }
Yifan Hongd4a77e82017-09-06 19:40:24 -0700104
Yifan Hongfee209d2017-09-14 18:23:38 -0700105 std::string isReleased() const;
106
Yifan Hongbdf44f82018-05-25 14:20:00 -0700107 std::string getVintfInfo() const;
108
Yifan Hongd4a77e82017-09-06 19:40:24 -0700109 std::string getField(TableColumnType type) const;
Yifan Hong8bf73162017-09-07 18:06:13 -0700110
111 bool operator==(const TableEntry& other) const;
112 std::string to_string() const;
Yifan Hongb0dde932017-02-10 17:49:58 -0800113};
114
Yifan Hongd4a77e82017-09-06 19:40:24 -0700115using SelectedColumns = std::vector<TableColumnType>;
Yifan Honga3b87092017-03-02 19:19:29 -0800116
Yifan Hongd4a77e82017-09-06 19:40:24 -0700117class Table {
118public:
119 using Entries = std::vector<TableEntry>;
120
121 Entries::iterator begin() { return mEntries.begin(); }
122 Entries::const_iterator begin() const { return mEntries.begin(); }
123 Entries::iterator end() { return mEntries.end(); }
124 Entries::const_iterator end() const { return mEntries.end(); }
Yifan Hong8bf73162017-09-07 18:06:13 -0700125 size_t size() const { return mEntries.size(); }
Yifan Hongd4a77e82017-09-06 19:40:24 -0700126
127 void add(TableEntry&& entry) { mEntries.push_back(std::move(entry)); }
128
129 void setSelectedColumns(const SelectedColumns& s) { mSelectedColumns = s; }
130 const SelectedColumns& getSelectedColumns() const { return mSelectedColumns; }
131
132 void setDescription(std::string&& d) { mDescription = std::move(d); }
133
134 // Write table content.
135 TextTable createTextTable(bool neat = true,
136 const std::function<std::string(const std::string&)>& emitDebugInfo = nullptr) const;
137
138private:
139 std::string mDescription;
140 Entries mEntries;
141 SelectedColumns mSelectedColumns;
Yifan Honga3b87092017-03-02 19:19:29 -0800142};
143
Yifan Hong38d53e02017-02-13 17:51:59 -0800144using TableEntryCompare = std::function<bool(const TableEntry &, const TableEntry &)>;
145
Yifan Hongd4a77e82017-09-06 19:40:24 -0700146class MergedTable {
147public:
148 MergedTable(std::vector<const Table*>&& tables) : mTables(std::move(tables)) {}
149 TextTable createTextTable();
150private:
151 std::vector<const Table*> mTables;
Yifan Hong38d53e02017-02-13 17:51:59 -0800152};
153
Yifan Hongb0dde932017-02-10 17:49:58 -0800154} // namespace lshal
155} // namespace android
156
157#endif // FRAMEWORK_NATIVE_CMDS_LSHAL_TABLE_ENTRY_H_