LLDB  mainline
PlatformiOSSimulatorCoreSimulatorSupport.h
Go to the documentation of this file.
1 //===-- PlatformiOSSimulatorCoreSimulatorSupport.h ----------------*- C++
2 //-*-===//
3 //
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef liblldb_PlatformiOSSimulatorCoreSimulatorSupport_h_
11 #define liblldb_PlatformiOSSimulatorCoreSimulatorSupport_h_
12 
13 #include <functional>
14 #include <ostream>
15 #include <string>
16 #include <vector>
17 #ifdef __APPLE__
18 #include <objc/objc.h>
19 #else
20 typedef void *id;
21 #endif
23 #include "lldb/Utility/Args.h"
25 #include "lldb/Utility/Status.h"
26 
27 #include "llvm/ADT/Optional.h"
28 
29 // And now the actual magic
31 class Process {
32 public:
33  lldb::pid_t GetPID() { return m_pid; }
34 
35  explicit operator bool() { return m_pid != LLDB_INVALID_PROCESS_ID; }
36 
37  lldb_private::Status GetError() { return m_error; }
38 
39 private:
41 
43 
45 
46  lldb::pid_t m_pid;
47  lldb_private::Status m_error;
48 
49  friend class Device;
50 };
51 
53 public:
54  ModelIdentifier(const std::string &mi);
56 
57  explicit operator bool() const { return !m_versions.empty(); }
58 
59  size_t GetNumVersions() const { return m_versions.size(); }
60 
61  unsigned int GetVersionAtIndex(size_t idx) const { return m_versions[idx]; }
62 
63  std::string GetFamily() const { return m_family.c_str(); }
64 
65 private:
66  std::string m_family;
67  std::vector<unsigned int> m_versions;
68 };
69 
70 class DeviceType {
71 public:
72  enum class ProductFamilyID : int32_t {
73  iPhone = 1,
74  iPad = 2,
75  appleTV = 3,
76  appleWatch = 4
77  };
78 
79  DeviceType();
80 
81  DeviceType(id d);
82 
83  explicit operator bool();
84 
85  std::string GetName();
86 
87  lldb_private::ConstString GetIdentifier();
88 
89  ModelIdentifier GetModelIdentifier();
90 
91  lldb_private::ConstString GetProductFamily();
92 
93  ProductFamilyID GetProductFamilyID();
94 
95 private:
96  id m_dev;
97  llvm::Optional<ModelIdentifier> m_model_identifier;
98 };
99 
100 class OSVersion {
101 public:
102  OSVersion(const std::string &ver, const std::string &build);
103 
104  OSVersion();
105 
106  explicit operator bool() const { return !m_versions.empty(); }
107 
108  size_t GetNumVersions() const { return m_versions.size(); }
109 
110  unsigned int GetVersionAtIndex(size_t idx) const { return m_versions[idx]; }
111 
112  const char *GetBuild() const { return m_build.c_str(); }
113 
114 private:
115  std::vector<unsigned int> m_versions;
116  std::string m_build;
117 };
118 
120 public:
121  DeviceRuntime();
122 
123  DeviceRuntime(id d);
124 
125  explicit operator bool();
126 
127  OSVersion GetVersion();
128 
129  bool IsAvailable();
130 
131 private:
132  id m_dev;
133  llvm::Optional<OSVersion> m_os_version;
134 };
135 
136 class Device {
137 private:
138  typedef unsigned long int NSUInteger;
139 
140 public:
141  enum class State : NSUInteger {
142  Creating,
143  Shutdown,
144  Booting,
145  Booted,
146  ShuttingDown
147  };
148 
149  Device();
150 
151  Device(id d);
152 
153  explicit operator bool();
154 
155  std::string GetName() const;
156 
157  DeviceType GetDeviceType();
158 
159  DeviceRuntime GetDeviceRuntime();
160 
161  State GetState();
162 
163  bool Boot(lldb_private::Status &err);
164 
165  bool Shutdown(lldb_private::Status &err);
166 
167  std::string GetUDID() const;
168 
169  Process Spawn(lldb_private::ProcessLaunchInfo &launch_info);
170 
171 private:
172  id m_dev;
173  llvm::Optional<DeviceType> m_dev_type;
174  llvm::Optional<DeviceRuntime> m_dev_runtime;
175 
176  friend class DeviceSet;
177 };
178 
179 bool operator>(const OSVersion &lhs, const OSVersion &rhs);
180 
181 bool operator>(const ModelIdentifier &lhs, const ModelIdentifier &rhs);
182 
183 bool operator<(const OSVersion &lhs, const OSVersion &rhs);
184 
185 bool operator<(const ModelIdentifier &lhs, const ModelIdentifier &rhs);
186 
187 bool operator==(const OSVersion &lhs, const OSVersion &rhs);
188 
189 bool operator==(const ModelIdentifier &lhs, const ModelIdentifier &rhs);
190 
191 bool operator!=(const OSVersion &lhs, const OSVersion &rhs);
192 
193 bool operator!=(const ModelIdentifier &lhs, const ModelIdentifier &rhs);
194 
195 class DeviceSet {
196 public:
197  static DeviceSet GetAllDevices(const char *developer_dir);
198 
199  static DeviceSet GetAvailableDevices(const char *developer_dir);
200 
201  size_t GetNumDevices();
202 
203  Device GetDeviceAtIndex(size_t idx);
204 
205  void ForEach(std::function<bool(const Device &)> f);
206 
207  DeviceSet GetDevicesIf(std::function<bool(Device)> f);
208 
209  DeviceSet GetDevices(DeviceType::ProductFamilyID dev_id);
210 
211  Device GetFanciest(DeviceType::ProductFamilyID dev_id);
212 
213 private:
214  DeviceSet(id arr) : m_dev(arr) {}
215 
216  id m_dev;
217 };
218 }
219 
220 #endif // liblldb_PlatformiOSSimulatorCoreSimulatorSupport_h_
#define LLDB_INVALID_PROCESS_ID
Definition: lldb-defines.h:92
bool operator<(const OSVersion &lhs, const OSVersion &rhs)
bool operator==(const OSVersion &lhs, const OSVersion &rhs)
bool operator!=(const OSVersion &lhs, const OSVersion &rhs)
A uniqued constant string class.
Definition: ConstString.h:38
uint64_t pid_t
Definition: lldb-types.h:85
bool operator>(const OSVersion &lhs, const OSVersion &rhs)
An error handling class.
Definition: Status.h:44