TableEntry.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. #ifndef FRAMEWORK_NATIVE_CMDS_LSHAL_TABLE_ENTRY_H_
  17. #define FRAMEWORK_NATIVE_CMDS_LSHAL_TABLE_ENTRY_H_
  18. #include <stdint.h>
  19. #include <string>
  20. #include <vector>
  21. #include <iostream>
  22. #include <procpartition/procpartition.h>
  23. #include <vintf/Arch.h>
  24. #include <vintf/Transport.h>
  25. #include "TextTable.h"
  26. namespace android {
  27. namespace lshal {
  28. using android::procpartition::Partition;
  29. using Pids = std::vector<int32_t>;
  30. enum class TableColumnType : unsigned int {
  31. INTERFACE_NAME,
  32. TRANSPORT,
  33. SERVER_PID,
  34. SERVER_CMD,
  35. SERVER_ADDR,
  36. CLIENT_PIDS,
  37. CLIENT_CMDS,
  38. ARCH,
  39. THREADS,
  40. RELEASED,
  41. HASH,
  42. VINTF,
  43. SERVICE_STATUS,
  44. };
  45. enum : unsigned int {
  46. VINTF_INFO_EMPTY = 0,
  47. DEVICE_MANIFEST = 1 << 0,
  48. DEVICE_MATRIX = 1 << 1,
  49. FRAMEWORK_MANIFEST = 1 << 2,
  50. FRAMEWORK_MATRIX = 1 << 3,
  51. };
  52. using VintfInfo = unsigned int;
  53. enum {
  54. NO_PID = -1,
  55. NO_PTR = 0
  56. };
  57. enum class ServiceStatus {
  58. UNKNOWN, // For passthrough
  59. ALIVE,
  60. NON_RESPONSIVE, // registered but not respond to calls
  61. DECLARED, // in VINTF manifest
  62. };
  63. std::string to_string(ServiceStatus s);
  64. struct TableEntry {
  65. std::string interfaceName{};
  66. vintf::Transport transport{vintf::Transport::EMPTY};
  67. int32_t serverPid{NO_PID};
  68. uint32_t threadUsage{0};
  69. uint32_t threadCount{0};
  70. std::string serverCmdline{};
  71. uint64_t serverObjectAddress{NO_PTR};
  72. Pids clientPids{};
  73. std::vector<std::string> clientCmdlines{};
  74. vintf::Arch arch{vintf::Arch::ARCH_EMPTY};
  75. // empty: unknown, all zeros: unreleased, otherwise: released
  76. std::string hash{};
  77. Partition partition{Partition::UNKNOWN};
  78. VintfInfo vintfInfo{VINTF_INFO_EMPTY};
  79. // true iff hwbinder and service started
  80. ServiceStatus serviceStatus{ServiceStatus::UNKNOWN};
  81. static bool sortByInterfaceName(const TableEntry &a, const TableEntry &b) {
  82. return a.interfaceName < b.interfaceName;
  83. };
  84. static bool sortByServerPid(const TableEntry &a, const TableEntry &b) {
  85. return a.serverPid < b.serverPid;
  86. };
  87. std::string getThreadUsage() const {
  88. if (threadCount == 0) {
  89. return "N/A";
  90. }
  91. return std::to_string(threadUsage) + "/" + std::to_string(threadCount);
  92. }
  93. std::string isReleased() const;
  94. std::string getVintfInfo() const;
  95. std::string getField(TableColumnType type) const;
  96. bool operator==(const TableEntry& other) const;
  97. std::string to_string() const;
  98. };
  99. using SelectedColumns = std::vector<TableColumnType>;
  100. class Table {
  101. public:
  102. using Entries = std::vector<TableEntry>;
  103. Entries::iterator begin() { return mEntries.begin(); }
  104. Entries::const_iterator begin() const { return mEntries.begin(); }
  105. Entries::iterator end() { return mEntries.end(); }
  106. Entries::const_iterator end() const { return mEntries.end(); }
  107. size_t size() const { return mEntries.size(); }
  108. void add(TableEntry&& entry) { mEntries.push_back(std::move(entry)); }
  109. void setSelectedColumns(const SelectedColumns& s) { mSelectedColumns = s; }
  110. const SelectedColumns& getSelectedColumns() const { return mSelectedColumns; }
  111. void setDescription(std::string&& d) { mDescription = std::move(d); }
  112. // Write table content.
  113. TextTable createTextTable(bool neat = true,
  114. const std::function<std::string(const std::string&)>& emitDebugInfo = nullptr) const;
  115. private:
  116. std::string mDescription;
  117. Entries mEntries;
  118. SelectedColumns mSelectedColumns;
  119. };
  120. using TableEntryCompare = std::function<bool(const TableEntry &, const TableEntry &)>;
  121. class MergedTable {
  122. public:
  123. explicit MergedTable(std::vector<const Table*>&& tables) : mTables(std::move(tables)) {}
  124. TextTable createTextTable();
  125. private:
  126. std::vector<const Table*> mTables;
  127. };
  128. } // namespace lshal
  129. } // namespace android
  130. #endif // FRAMEWORK_NATIVE_CMDS_LSHAL_TABLE_ENTRY_H_