]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - source/Plugins/Platform/MacOSX/PlatformiOSSimulatorCoreSimulatorSupport.h
Vendor import of lldb trunk r256945:
[FreeBSD/FreeBSD.git] / source / Plugins / Platform / MacOSX / PlatformiOSSimulatorCoreSimulatorSupport.h
1 //===-- PlatformiOSSimulatorCoreSimulatorSupport.h ----------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef liblldb_PlatformiOSSimulatorCoreSimulatorSupport_h_
11 #define liblldb_PlatformiOSSimulatorCoreSimulatorSupport_h_
12
13 // C Includes
14 // C++ Includes
15 #include <functional>
16 #include <string>
17 #include <ostream>
18 #include <vector>
19 // Other libraries and framework includes
20 #ifdef __APPLE__
21 #include <objc/objc.h>
22 #else
23 typedef void *id;
24 #endif
25 // Project includes
26 #include "lldb/Core/ConstString.h"
27 #include "lldb/Core/Error.h"
28 #include "lldb/Interpreter/Args.h"
29 #include "lldb/Target/ProcessLaunchInfo.h"
30
31 #include "llvm/ADT/Optional.h"
32
33 // And now the actual magic
34 namespace CoreSimulatorSupport
35 {
36     class Process
37     {
38     public:
39         lldb::pid_t
40         GetPID ()
41         {
42             return m_pid;
43         }
44         
45         explicit operator bool ()
46         {
47             return m_pid != LLDB_INVALID_PROCESS_ID;
48         }
49         
50         lldb_private::Error
51         GetError ()
52         {
53             return m_error;
54         }
55         
56     private:
57         Process (lldb::pid_t p);
58         
59         Process(lldb_private::Error error);
60
61         Process (lldb::pid_t p, lldb_private::Error error);
62         
63         lldb::pid_t m_pid;
64         lldb_private::Error m_error;
65         
66         friend class Device;
67     };
68     
69     class ModelIdentifier {
70     public:
71         ModelIdentifier (const std::string& mi);
72         ModelIdentifier ();
73         
74         explicit operator bool () const
75         {
76             return !m_versions.empty();
77         }
78         
79         size_t
80         GetNumVersions () const
81         {
82             return m_versions.size();
83         }
84         
85         unsigned int
86         GetVersionAtIndex (size_t idx) const
87         {
88             return m_versions[idx];
89         }
90         
91         std::string
92         GetFamily () const
93         {
94             return m_family.c_str();
95         }
96         
97     private:
98         std::string m_family;
99         std::vector<unsigned int> m_versions;
100     };
101     
102     class DeviceType
103     {
104     public:
105         enum class ProductFamilyID : int32_t
106         {
107             iPhone = 1,
108             iPad = 2,
109             appleTV = 3,
110             appleWatch = 4
111         };
112         
113         DeviceType ();
114         
115         DeviceType (id d);
116         
117         explicit operator bool ();
118         
119         std::string
120         GetName ();
121
122         lldb_private::ConstString
123         GetIdentifier ();
124         
125         ModelIdentifier
126         GetModelIdentifier ();
127         
128         lldb_private::ConstString
129         GetProductFamily ();
130         
131         ProductFamilyID
132         GetProductFamilyID ();
133         
134     private:
135         id m_dev;
136         llvm::Optional<ModelIdentifier> m_model_identifier;
137     };
138     
139     class OSVersion {
140     public:
141         OSVersion (const std::string& ver,
142                    const std::string& build);
143
144         OSVersion ();
145         
146         explicit operator bool () const
147         {
148             return !m_versions.empty();
149         }
150         
151         size_t
152         GetNumVersions () const
153         {
154             return m_versions.size();
155         }
156         
157         unsigned int
158         GetVersionAtIndex (size_t idx) const
159         {
160             return m_versions[idx];
161         }
162         
163         const char*
164         GetBuild () const
165         {
166             return m_build.c_str();
167         }
168         
169     private:
170         std::vector<unsigned int> m_versions;
171         std::string m_build;
172     };
173     
174     class DeviceRuntime
175     {
176     public:
177         DeviceRuntime ();
178         
179         DeviceRuntime (id d);
180         
181         explicit operator bool ();
182         
183         OSVersion
184         GetVersion ();
185         
186         bool
187         IsAvailable ();
188         
189     private:
190         id m_dev;
191         llvm::Optional<OSVersion> m_os_version;
192     };
193     
194     class Device
195     {
196     private:
197         typedef unsigned long int NSUInteger;
198
199     public:
200         enum class State : NSUInteger
201         {
202             Creating,
203             Shutdown,
204             Booting,
205             Booted,
206             ShuttingDown
207         };
208         
209         Device ();
210
211         Device (id d);
212         
213         explicit operator bool ();
214         
215         std::string
216         GetName () const;
217
218         DeviceType
219         GetDeviceType ();
220         
221         DeviceRuntime
222         GetDeviceRuntime ();
223         
224         State
225         GetState ();
226         
227         bool
228         Boot (lldb_private::Error &err);
229         
230         bool
231         Shutdown (lldb_private::Error &err);
232         
233         std::string
234         GetUDID () const;
235         
236         Process
237         Spawn (lldb_private::ProcessLaunchInfo& launch_info);
238         
239     private:
240         id m_dev;
241         llvm::Optional<DeviceType> m_dev_type;
242         llvm::Optional<DeviceRuntime> m_dev_runtime;
243         
244         friend class DeviceSet;
245     };
246     
247     bool
248     operator > (const OSVersion& lhs,
249                 const OSVersion& rhs);
250     
251     bool
252     operator > (const ModelIdentifier& lhs,
253                 const ModelIdentifier& rhs);
254     
255     bool
256     operator < (const OSVersion& lhs,
257                 const OSVersion& rhs);
258     
259     bool
260     operator < (const ModelIdentifier& lhs,
261                 const ModelIdentifier& rhs);
262     
263     bool
264     operator == (const OSVersion& lhs,
265                  const OSVersion& rhs);
266     
267     bool
268     operator == (const ModelIdentifier& lhs,
269                  const ModelIdentifier& rhs);
270     
271     bool
272     operator != (const OSVersion& lhs,
273                  const OSVersion& rhs);
274     
275     bool
276     operator != (const ModelIdentifier& lhs,
277                  const ModelIdentifier& rhs);
278     
279     class DeviceSet
280     {
281     public:
282         static DeviceSet
283         GetAllDevices ();
284         
285         static DeviceSet
286         GetAvailableDevices ();
287         
288         size_t
289         GetNumDevices ();
290         
291         Device
292         GetDeviceAtIndex (size_t idx);
293
294         void
295         ForEach (std::function<bool(const Device &)> f);
296
297         DeviceSet
298         GetDevicesIf (std::function<bool(Device)> f);
299         
300         DeviceSet
301         GetDevices (DeviceType::ProductFamilyID dev_id);
302         
303         Device
304         GetFanciest (DeviceType::ProductFamilyID dev_id);
305
306     private:
307         DeviceSet (id arr) : m_dev(arr)
308         {
309         }
310         
311         id m_dev;
312     };
313 }
314
315 #endif  // liblldb_PlatformiOSSimulatorCoreSimulatorSupport_h_