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>
24 #include <iostream>
25 
26 namespace android {
27 namespace lshal {
28 
29 using Pids = std::vector<int32_t>;
30 
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 
38 enum : unsigned int {
39     ARCH_UNKNOWN = 0,
40     ARCH32       = 1 << 0,
41     ARCH64       = 1 << 1,
42     ARCH_BOTH    = ARCH32 | ARCH64
43 };
44 using Architecture = unsigned int;
45 
46 struct TableEntry {
47     std::string interfaceName;
48     std::string transport;
49     int32_t serverPid;
50     std::string serverCmdline;
51     uint64_t serverObjectAddress;
52     Pids clientPids;
53     std::vector<std::string> clientCmdlines;
54     Architecture arch;
55 
sortByInterfaceNameTableEntry56     static bool sortByInterfaceName(const TableEntry &a, const TableEntry &b) {
57         return a.interfaceName < b.interfaceName;
58     };
sortByServerPidTableEntry59     static bool sortByServerPid(const TableEntry &a, const TableEntry &b) {
60         return a.serverPid < b.serverPid;
61     };
62 };
63 
64 struct Table {
65     using Entries = std::vector<TableEntry>;
66     std::string description;
67     Entries entries;
68 
beginTable69     Entries::iterator begin() { return entries.begin(); }
beginTable70     Entries::const_iterator begin() const { return entries.begin(); }
endTable71     Entries::iterator end() { return entries.end(); }
endTable72     Entries::const_iterator end() const { return entries.end(); }
73 };
74 
75 using TableEntryCompare = std::function<bool(const TableEntry &, const TableEntry &)>;
76 
77 enum : unsigned int {
78     ENABLE_INTERFACE_NAME = 1 << 0,
79     ENABLE_TRANSPORT      = 1 << 1,
80     ENABLE_SERVER_PID     = 1 << 2,
81     ENABLE_SERVER_ADDR    = 1 << 3,
82     ENABLE_CLIENT_PIDS    = 1 << 4,
83     ENABLE_ARCH           = 1 << 5
84 };
85 
86 using TableEntrySelect = unsigned int;
87 
88 enum {
89     NO_PID = -1,
90     NO_PTR = 0
91 };
92 
93 }  // namespace lshal
94 }  // namespace android
95 
96 #endif  // FRAMEWORK_NATIVE_CMDS_LSHAL_TABLE_ENTRY_H_
97