forked from livecode/livecode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreviphoneproxy.mm
More file actions
280 lines (217 loc) · 9.13 KB
/
reviphoneproxy.mm
File metadata and controls
280 lines (217 loc) · 9.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
/* Copyright (C) 2003-2013 Runtime Revolution Ltd.
This file is part of LiveCode.
LiveCode is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License v3 as published by the Free
Software Foundation.
LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
#include <Cocoa/Cocoa.h>
#include <unistd.h>
////////////////////////////////////////////////////////////////////////////////
static pid_t s_parent_pid;
static BOOL s_keep_running;
static NSBundle *s_simulator_bundle;
static id s_DTiPhoneSimulatorSystemRoot_class = nil;
static id s_DTiPhoneSimulatorApplicationSpecifier_class = nil;
static id s_DTiPhoneSimulatorSessionConfig_class = nil;
static id s_DTiPhoneSimulatorSession_class = nil;
static id s_SimDeviceSet_class = nil;
static id s_SimRuntime_class = nil;
@interface RevIPhoneProxy: NSObject
- (id)init;
- (void)quit;
- (id)getKnownRoots;
@end
@implementation RevIPhoneProxy
- (id)init
{
return [super init];
}
- (BOOL)isValid
{
return
s_simulator_bundle != nil &&
s_DTiPhoneSimulatorSystemRoot_class != nil &&
s_DTiPhoneSimulatorApplicationSpecifier_class != nil &&
s_DTiPhoneSimulatorSessionConfig_class != nil &&
s_DTiPhoneSimulatorSession_class != nil;
}
- (void)quit
{
//NSLog(@"received quit");
s_keep_running = NO;
}
- (id)getKnownRoots
{
//NSLog(@"received getKnownRoots");
return [s_DTiPhoneSimulatorSystemRoot_class knownRoots];
}
- (id)getDefaultRoot
{
//NSLog(@"received getDefaultRoot");
return [s_DTiPhoneSimulatorSystemRoot_class defaultRoot];
}
- (id)specifierWithApplicationPath: (NSString*)path
{
//NSLog(@"received specified with application path");
return [[s_DTiPhoneSimulatorApplicationSpecifier_class specifierWithApplicationPath: path] retain];
}
- (id)newSessionConfig
{
//NSLog(@"received newSessionConfig");
return [[s_DTiPhoneSimulatorSessionConfig_class alloc] init];
}
- (id)newSession
{
//NSLog(@"received newSession");
return [[s_DTiPhoneSimulatorSession_class alloc] init];
}
- (void)checkForParent
{
if (getppid() != s_parent_pid)
s_keep_running = NO;
else
[self performSelector: @selector(checkForParent) withObject: nil afterDelay: 0.1];
}
// MM-2014-09-30: [[ iOS 8 Support ]] Return the array of devices the simulator offers.
// A device type must be choosen when launching the iOS 8 simulator.
- (id)getSimDeviceSet
{
//NSLog(@"received getSimDeviceSet");
if (s_SimDeviceSet_class != nil)
return [[s_SimDeviceSet_class defaultSet] availableDevices];
return nil;
}
// MM-2014-10-07: [[ Bug 13584 ]] Return the set of runtimes that the current sim supports.
- (id)getSimRuntimes
{
//NSLog(@"received getSimRuntimes");
if (s_SimRuntime_class != nil)
return [s_SimRuntime_class supportedRuntimes];
return nil;
}
// MM-2014-10-07: [[ Bug 13584 ]] Return the DTiPhoneSimulatorSystemRoot for the current SimRuntime.
- (id)getRootWithSimRuntime: (id)runtime
{
//NSLog(@"received getRootWithSimRuntime");
return [s_DTiPhoneSimulatorSystemRoot_class rootWithSimRuntime: runtime];
}
@end
////////////////////////////////////////////////////////////////////////////////
int main(int argc, char *argv[])
{
bool t_success;
t_success = true;
s_parent_pid = getppid();
NSAutoreleasePool *t_pool;
t_pool = [[NSAutoreleasePool alloc] init];
RevIPhoneProxy *t_proxy;
t_proxy = [[RevIPhoneProxy alloc] init];
[t_proxy checkForParent];
//NSLog(@"REVIPHONEPROXY start: %s %s", argv[1], argv[2]);
[[NSConnection defaultConnection] setRootObject: t_proxy];
[[NSConnection defaultConnection] registerName: [NSString stringWithUTF8String: argv[2]]];
// MM-2014-03-18: [[ iOS 7.1 Support ]] iPhoneSimulatorRemoteClient.framework is no longer present in Xcode 5.1.
// If the framework cannot be found, use DVTiPhoneSimulatorRemoteClient, which appears to have largley the same API.
if (t_success)
{
NSString *t_sim_bundle_path;
t_sim_bundle_path = [NSString stringWithFormat: @"%s/Platforms/iPhoneSimulator.platform/Developer/Library/PrivateFrameworks/iPhoneSimulatorRemoteClient.framework", argv[1]];
if ([[NSFileManager defaultManager] fileExistsAtPath: t_sim_bundle_path])
{
t_sim_bundle_path = [NSString stringWithFormat: @"%s/Platforms/iPhoneSimulator.platform/Developer/Library/PrivateFrameworks/iPhoneSimulatorRemoteClient.framework", argv[1]];
s_simulator_bundle = [NSBundle bundleWithPath: t_sim_bundle_path];
t_success = [s_simulator_bundle load];
//NSLog(@"Old Style SimBundle %d", t_success);
}
else
{
// MM-2014-03-18: [[ iOS 7.1 Support ]] DVTiPhoneSimulatorRemoteClient.framework requires DVTFoundation and DevToolsFoundation. Load these first.
NSBundle *t_dvt_foundation_bundle;
t_dvt_foundation_bundle = nil;
if (t_success)
{
NSString *t_dvt_foundation_path;
t_dvt_foundation_path = [NSString stringWithFormat: @"%s/../SharedFrameworks/DVTFoundation.framework", argv[1]];
if (![[NSFileManager defaultManager] fileExistsAtPath: t_dvt_foundation_path])
t_dvt_foundation_path = [NSString stringWithFormat: @"%s/Library/PrivateFrameworks/DVTFoundation.framework", argv[1]];
t_dvt_foundation_bundle = [NSBundle bundleWithPath: t_dvt_foundation_path];
t_success = [t_dvt_foundation_bundle load];
//NSLog(@"DVTFoundation %d", t_success);
}
NSBundle *t_dev_tools_bundle;
t_dev_tools_bundle = nil;
if (t_success)
{
NSString *t_dev_tools_path;
t_dev_tools_path = [NSString stringWithFormat: @"%s/../OtherFrameworks/DevToolsFoundation.framework", argv[1]];
if (![[NSFileManager defaultManager] fileExistsAtPath: t_dev_tools_path])
t_dev_tools_path = [NSString stringWithFormat: @"%s/Library/PrivateFrameworks/DevToolsFoundation.framework", argv[1]];
t_dev_tools_bundle = [NSBundle bundleWithPath: t_dev_tools_path];
t_success = [t_dev_tools_bundle load];
//NSLog(@"DevTools %d", t_success);
}
if (t_success)
{
Class t_dvt_platform_class;
t_dvt_platform_class = NSClassFromString(@"DVTPlatform");
NSError* t_error;
t_success = [t_dvt_platform_class loadAllPlatformsReturningError: &t_error];
//NSLog(@"DVTPlatform %d", t_success);
}
// MM-2014-09-30: [[ iOS 8 Support ]] Load the new CoreSimulator bundle if found. Allows us to query the available devices.
NSBundle *t_core_sim_bundle;
if (t_success)
{
NSString *t_core_sim_path;
t_core_sim_path = [NSString stringWithFormat: @"%s/Library/PrivateFrameworks/CoreSimulator.framework", argv[1]];
if ([[NSFileManager defaultManager] fileExistsAtPath: t_core_sim_path])
{
t_core_sim_bundle = [NSBundle bundleWithPath: t_core_sim_path];
t_success = [t_core_sim_bundle load];
//NSLog(@"CoreSimBundle %d", t_success);
}
}
if (t_success)
{
// MM-2014-09-30: [[ iOS 8 Support ]] DVTiPhoneSimulatorRemoteClient has moved in Xcode 6.
t_sim_bundle_path = [NSString stringWithFormat: @"%s/Platforms/iPhoneSimulator.platform/Developer/Library/PrivateFrameworks/DVTiPhoneSimulatorRemoteClient.framework", argv[1]];
if (![[NSFileManager defaultManager] fileExistsAtPath: t_sim_bundle_path])
t_sim_bundle_path = [NSString stringWithFormat: @"%s/../SharedFrameworks/DVTiPhoneSimulatorRemoteClient.framework", argv[1]];
s_simulator_bundle = [NSBundle bundleWithPath: t_sim_bundle_path];
t_success = [s_simulator_bundle load];
//NSLog(@"SimBundle %d", t_success);
}
}
}
if (t_success)
{
s_DTiPhoneSimulatorSystemRoot_class = [s_simulator_bundle classNamed: @"DTiPhoneSimulatorSystemRoot"];
s_DTiPhoneSimulatorApplicationSpecifier_class = [s_simulator_bundle classNamed: @"DTiPhoneSimulatorApplicationSpecifier"];
s_DTiPhoneSimulatorSessionConfig_class = [s_simulator_bundle classNamed: @"DTiPhoneSimulatorSessionConfig"];
s_DTiPhoneSimulatorSession_class = [s_simulator_bundle classNamed: @"DTiPhoneSimulatorSession"];
// MM-2014-09-30: [[ iOS 8 Support ]] Fetch the device set allowing us to query the available devices.
s_SimDeviceSet_class = NSClassFromString(@"SimDeviceSet");
// MM-2014-10-07: [[ Bug 13584 ]] Fetch the SimRuntime class, required to return the set of runtime environments the current sim supports.
// e.g. iOS7 sim, iOS 8 sim etc.
s_SimRuntime_class = NSClassFromString(@"SimRuntime");
s_keep_running = YES;
while(s_keep_running &&
[[NSRunLoop currentRunLoop] runMode: NSDefaultRunLoopMode beforeDate: [NSDate distantFuture]] ||
[NSConnection currentConversation] != nil)
;
// Just linger around a little longer to make sure our connection has closed
// down cleanly.
[[NSRunLoop currentRunLoop] runUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.25]];
[NSObject cancelPreviousPerformRequestsWithTarget: t_proxy];
}
[t_proxy release];
[t_pool release];
//NSLog(@"REVIPHONEPROXY exit %s", argv[1]);
return 0;
}
////////////////////////////////////////////////////////////////////////////////