| OLD | NEW |
| 1 // Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE.md file. |
| 4 | 4 |
| 5 import fletch.*; | 5 import dartino.*; |
| 6 | 6 |
| 7 import java.io.FileInputStream; | 7 import java.io.FileInputStream; |
| 8 import java.io.FileNotFoundException; | 8 import java.io.FileNotFoundException; |
| 9 import java.io.IOException; | 9 import java.io.IOException; |
| 10 | 10 |
| 11 class SimpleTodo { | 11 class SimpleTodo { |
| 12 | 12 |
| 13 public static void main(String args[]) { | 13 public static void main(String args[]) { |
| 14 // Expecting a snapshot of the dart service code on the command line. | 14 // Expecting a snapshot of the dart service code on the command line. |
| 15 if (args.length != 1) { | 15 if (args.length != 1) { |
| 16 System.out.println("Usage: java SimpleTodo <snapshot>"); | 16 System.out.println("Usage: java SimpleTodo <snapshot>"); |
| 17 System.exit(1); | 17 System.exit(1); |
| 18 } | 18 } |
| 19 | 19 |
| 20 // Load libfletch.so. | 20 // Load libdartino.so. |
| 21 System.loadLibrary("fletch"); | 21 System.loadLibrary("dartino"); |
| 22 | 22 |
| 23 // Setup Fletch. | 23 // Setup Dartino. |
| 24 FletchApi.Setup(); | 24 DartinoApi.Setup(); |
| 25 FletchServiceApi.Setup(); | 25 DartinoServiceApi.Setup(); |
| 26 FletchApi.AddDefaultSharedLibrary("libfletch.so"); | 26 DartinoApi.AddDefaultSharedLibrary("libdartino.so"); |
| 27 | 27 |
| 28 try { | 28 try { |
| 29 // Load snapshot and start dart code on a separate thread. | 29 // Load snapshot and start dart code on a separate thread. |
| 30 FileInputStream snapshotStream = new FileInputStream(args[0]); | 30 FileInputStream snapshotStream = new FileInputStream(args[0]); |
| 31 int available = snapshotStream.available(); | 31 int available = snapshotStream.available(); |
| 32 byte[] snapshot = new byte[available]; | 32 byte[] snapshot = new byte[available]; |
| 33 snapshotStream.read(snapshot); | 33 snapshotStream.read(snapshot); |
| 34 Thread dartThread = new Thread(new SnapshotRunner(snapshot)); | 34 Thread dartThread = new Thread(new SnapshotRunner(snapshot)); |
| 35 dartThread.start(); | 35 dartThread.start(); |
| 36 } catch (FileNotFoundException e) { | 36 } catch (FileNotFoundException e) { |
| 37 System.err.println("Failed loading snapshot: file not found."); | 37 System.err.println("Failed loading snapshot: file not found."); |
| 38 System.exit(1); | 38 System.exit(1); |
| 39 } catch (IOException e) { | 39 } catch (IOException e) { |
| 40 System.err.println("Failed loading snapshot: unknown error."); | 40 System.err.println("Failed loading snapshot: unknown error."); |
| 41 System.exit(1); | 41 System.exit(1); |
| 42 } | 42 } |
| 43 | 43 |
| 44 TodoController.InteractWithService(); | 44 TodoController.InteractWithService(); |
| 45 } | 45 } |
| 46 } | 46 } |
| OLD | NEW |