| OLD | NEW | 
|---|
|  | (Empty) | 
| 1 // Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file |  | 
| 2 // for details. All rights reserved. Use of this source code is governed by a |  | 
| 3 // BSD-style license that can be found in the LICENSE.md file. |  | 
| 4 |  | 
| 5 #import "AppDelegate.h" |  | 
| 6 |  | 
| 7 #include "include/dartino_api.h" |  | 
| 8 #include "include/service_api.h" |  | 
| 9 |  | 
| 10 #include "todomvc_presenter.h" |  | 
| 11 #include "todomvc_service.h" |  | 
| 12 |  | 
| 13 @interface AppDelegate () |  | 
| 14 |  | 
| 15 @end |  | 
| 16 |  | 
| 17 @implementation AppDelegate |  | 
| 18 |  | 
| 19 static dispatch_queue_t queue; |  | 
| 20 |  | 
| 21 + (void)loadAndRunDartSnapshot { |  | 
| 22   // Get the path for the snapshot in the main application bundle. |  | 
| 23   NSBundle* mainBundle = [NSBundle mainBundle]; |  | 
| 24   NSString* snapshot = |  | 
| 25   [mainBundle pathForResource: @"todomvc" ofType: @"snapshot"]; |  | 
| 26   // Read the snapshot and pass it to dartino. |  | 
| 27   NSData* data = [[NSData alloc] initWithContentsOfFile:snapshot]; |  | 
| 28   unsigned char* bytes = |  | 
| 29   reinterpret_cast<unsigned char*>(const_cast<void*>(data.bytes)); |  | 
| 30   NSLog(@"Dartino execution started\n"); |  | 
| 31   DartinoProgram program = DartinoLoadSnapshot(bytes, data.length); |  | 
| 32   DartinoRunMain(program, 0, NULL); |  | 
| 33   DartinoDeleteProgram(program); |  | 
| 34   NSLog(@"Dartino execution terminated\n"); |  | 
| 35 } |  | 
| 36 |  | 
| 37 - (BOOL)application:(UIApplication *)application |  | 
| 38     didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { |  | 
| 39 |  | 
| 40   // Setup Dartino and the Dartino service API. |  | 
| 41   DartinoSetup(); |  | 
| 42   ServiceApiSetup(); |  | 
| 43   // Create dispatch queue to run the Dartino VM on a separate thread. |  | 
| 44   queue = dispatch_queue_create("com.google.dartino.dartQueue", |  | 
| 45                                 DISPATCH_QUEUE_SERIAL); |  | 
| 46   // Post task to load and run snapshot on a different thread. |  | 
| 47   dispatch_async(queue, ^() { |  | 
| 48     [AppDelegate loadAndRunDartSnapshot]; |  | 
| 49   }); |  | 
| 50   // Setup the concrete todo service. |  | 
| 51   TodoMVCService::setup(); |  | 
| 52 |  | 
| 53   return YES; |  | 
| 54 } |  | 
| 55 |  | 
| 56 - (void)applicationWillResignActive:(UIApplication *)application { |  | 
| 57   // Sent when the application is about to move from active to inactive |  | 
| 58   // state. This can occur for certain types of temporary interruptions (such as |  | 
| 59   // an incoming phone call or SMS message) or when the user quits the |  | 
| 60   // application and it begins the transition to the background state.  Use this |  | 
| 61   // method to pause ongoing tasks, disable timers, and throttle down OpenGL ES |  | 
| 62   // frame rates. Games should use this method to pause the game. |  | 
| 63 } |  | 
| 64 |  | 
| 65 - (void)applicationDidEnterBackground:(UIApplication *)application { |  | 
| 66   // Use this method to release shared resources, save user data, invalidate |  | 
| 67   // timers, and store enough application state information to restore your |  | 
| 68   // application to its current state in case it is terminated later.  If your |  | 
| 69   // application supports background execution, this method is called instead of |  | 
| 70   // applicationWillTerminate: when the user quits. |  | 
| 71 } |  | 
| 72 |  | 
| 73 - (void)applicationWillEnterForeground:(UIApplication *)application { |  | 
| 74   // Called as part of the transition from the background to the inactive state; |  | 
| 75   // here you can undo many of the changes made on entering the background. |  | 
| 76 } |  | 
| 77 |  | 
| 78 - (void)applicationDidBecomeActive:(UIApplication *)application { |  | 
| 79   // Restart any tasks that were paused (or not yet started) while the |  | 
| 80   // application was inactive. If the application was previously in the |  | 
| 81   // background, optionally refresh the user interface. |  | 
| 82 } |  | 
| 83 |  | 
| 84 - (void)applicationWillTerminate:(UIApplication *)application { |  | 
| 85   // Called when the application is about to terminate. Save data if |  | 
| 86   // appropriate. See also applicationDidEnterBackground:. |  | 
| 87 |  | 
| 88   // Tear down the service API structures and Dartino. |  | 
| 89   TodoMVCService::tearDown(); |  | 
| 90   ServiceApiTearDown(); |  | 
| 91   DartinoTearDown(); |  | 
| 92 } |  | 
| 93 |  | 
| 94 @end |  | 
| OLD | NEW | 
|---|