blob: 10f99f408c65c472eaf9fad250967bf2cbf94047 (
plain)
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
|
// **********************************************************************
//
// Copyright (c) 2003-2016 ZeroC, Inc. All rights reserved.
//
// This copy of Ice is licensed to you under the terms described in the
// ICE_LICENSE file included in this distribution.
//
// **********************************************************************
#import "ViewController.h"
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
NSString* bundlePath = [[NSBundle mainBundle] privateFrameworksPath];
#ifdef ICE_CPP11_MAPPING
const char* bundle = "Cpp11ControllerBundle.bundle";
#else
const char* bundle = "Cpp98ControllerBundle.bundle";
#endif
bundlePath = [bundlePath stringByAppendingPathComponent:[NSString stringWithUTF8String:bundle]];
NSURL* bundleURL = [NSURL fileURLWithPath:bundlePath];
CFBundleRef handle = CFBundleCreate(NULL, (CFURLRef)bundleURL);
if(!handle)
{
[self println:[NSString stringWithFormat:@"Could not find bundle %@", bundlePath]];
return;
}
CFErrorRef error = nil;
Boolean loaded = CFBundleLoadExecutableAndReturnError(handle, &error);
if(error != nil || !loaded)
{
[self println:[(__bridge NSError *)error description]];
return;
}
void (*startController)(id<ViewController>) = CFBundleGetFunctionPointerForName(handle, CFSTR("startController"));
if(startController == 0)
{
NSString* err = [NSString stringWithFormat:@"Could not get function pointer startController from bundle %@",
bundlePath];
[self println:err];
return;
}
stopController = CFBundleGetFunctionPointerForName(handle, CFSTR("stopController"));
if(stopController == 0)
{
NSString* err = [NSString stringWithFormat:@"Could not get function pointer stopController from bundle %@",
bundlePath];
[self println:err];
return;
}
(*startController)(self);
}
- (void) dealloc
{
(*stopController)(self);
}
-(void) write:(NSString*)msg
{
[output insertText:msg];
[output layoutIfNeeded];
[output scrollRangeToVisible:NSMakeRange([output.text length] - 1, 1)];
}
-(void) print:(NSString*)msg
{
[self performSelectorOnMainThread:@selector(write:) withObject:msg waitUntilDone:NO];
}
-(void) println:(NSString*)msg
{
[self print:[msg stringByAppendingString:@"\n"]];
}
@end
|