diff options
author | Benoit Foucher <benoit@zeroc.com> | 2016-12-14 18:14:36 +0100 |
---|---|---|
committer | Benoit Foucher <benoit@zeroc.com> | 2016-12-14 18:14:36 +0100 |
commit | ad1920541b5a9501c398f22bbeaa42d8856524d4 (patch) | |
tree | 7aea861c26276074a9c82836860b5357a8034a90 /cpp/test/ios/controller/Classes/ViewController.m | |
parent | Fixed a few warnings (diff) | |
download | ice-ad1920541b5a9501c398f22bbeaa42d8856524d4.tar.bz2 ice-ad1920541b5a9501c398f22bbeaa42d8856524d4.tar.xz ice-ad1920541b5a9501c398f22bbeaa42d8856524d4.zip |
Fixes to JS test scripts and more work on iOS C++ controller
Diffstat (limited to 'cpp/test/ios/controller/Classes/ViewController.m')
-rw-r--r-- | cpp/test/ios/controller/Classes/ViewController.m | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/cpp/test/ios/controller/Classes/ViewController.m b/cpp/test/ios/controller/Classes/ViewController.m new file mode 100644 index 00000000000..10f99f408c6 --- /dev/null +++ b/cpp/test/ios/controller/Classes/ViewController.m @@ -0,0 +1,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 |