Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(134)

Side by Side Diff: samples/total/src/TotalRunner.dart

Issue 8317006: Added builtin native call to exit the running vm (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 #!/usr/bin/env dart 1 #!/usr/bin/env dart
2 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 2 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
3 // for details. All rights reserved. Use of this source code is governed by a 3 // for details. All rights reserved. Use of this source code is governed by a
4 // BSD-style license that can be found in the LICENSE file. 4 // BSD-style license that can be found in the LICENSE file.
5 5
6 #library("total:runner"); 6 #library("total:runner");
7 7
8 typedef void ExitCallback(int status, String exitString); 8 typedef void ExitCallback(int status, String exitString);
9 9
10 void main() { 10 void main() {
11 String SERVER_EXEC_PATH = './TotalServer.dart'; 11 String SERVER_EXEC_PATH = './TotalServer.dart';
12 String RESTART = "GRACEFUL RESTART!!"; 12 final int RESTART_STATUS = 42;
13 String EXIT = "GRACEFUL EXIT!!"; 13 final int EXIT_STATUS = 0;
14 14
15 void keepServerRunning(int status, ServerRunner runner) { 15 void keepServerRunning(int status, ServerRunner runner) {
16 switch (runner.lastExitString) { 16 switch (status) {
17 case RESTART: 17 case RESTART_STATUS:
18 runner.run(keepServerRunning); 18 runner.run(keepServerRunning);
19 break; 19 break;
20 case EXIT: 20 case EXIT_STATUS:
21 break; 21 break;
22 default: 22 default:
23 print("ERROR: exiting due to unknown condition. Exit status: $status." 23 print("ERROR: exiting due to unknown condition. Exit status: $status.");
24 + " Exit string: '${runner.lastExitString}'");
25 break; 24 break;
26 } 25 }
27 } 26 }
28 27
29 new ServerRunner(SERVER_EXEC_PATH, [RESTART, EXIT]).run(keepServerRunning); 28 new ServerRunner(SERVER_EXEC_PATH).run(keepServerRunning);
30 } 29 }
31 30
32 class ServerRunner { 31 class ServerRunner {
33 List<String> _exitStrings;
34 String _serverMain; 32 String _serverMain;
35 33
36 // TODO: fix this to use a bigger buffer when streams work better 34 // TODO: fix this to use a bigger buffer when streams work better
37 int _BUFSIZE = 1; 35 int _BUFSIZE = 1;
38 36
39 String lastExitString;
40
41 // TODO: Release or Debug? We should be able to find automatically 37 // TODO: Release or Debug? We should be able to find automatically
42 static final DART_EXEC_PATH = '../../../runtime/out/Release_ia32/dart_bin'; 38 static final DART_EXEC_PATH = '../../../runtime/out/Release_ia32/dart_bin';
43 static final CR = 0x0d; 39 static final CR = 0x0d;
44 static final LF = 0x0a; 40 static final LF = 0x0a;
45 41
46 ServerRunner(String this._serverMain, List<String> this._exitStrings); 42 ServerRunner(String this._serverMain);
47 43
48 void run(ExitCallback exitCallback) { 44 void run(ExitCallback exitCallback) {
49 Process dart = new Process(DART_EXEC_PATH, [_serverMain]); 45 Process dart = new Process(DART_EXEC_PATH, [_serverMain]);
50 46
51 dart.setExitHandler((int status) { 47 dart.setExitHandler((int status) {
52 dart.close(); 48 dart.close();
53 exitCallback(status, this); 49 exitCallback(status, this);
54 }); 50 });
55 51
56 dart.start(); 52 dart.start();
(...skipping 13 matching lines...) Expand all
70 66
71 void processBuffer(List<int> buf, StringBuffer readSoFar) { 67 void processBuffer(List<int> buf, StringBuffer readSoFar) {
72 buf.forEach((int i) { 68 buf.forEach((int i) {
73 if (i != CR && i != LF) { 69 if (i != CR && i != LF) {
74 readSoFar.add(new String.fromCharCodes([i])); 70 readSoFar.add(new String.fromCharCodes([i]));
75 } else { 71 } else {
76 String line = readSoFar.toString(); 72 String line = readSoFar.toString();
77 readSoFar.clear(); 73 readSoFar.clear();
78 if (line.length != 0) { 74 if (line.length != 0) {
79 print(line); 75 print(line);
80 _updateLastExitString(line);
81 } 76 }
82 } 77 }
83 }); 78 });
84 } 79 }
85
86 void _updateLastExitString(String line) {
87 _exitStrings.some((String e) {
88 if (line.contains(e, 0)) {
89 lastExitString = e;
90 return true;
91 } else {
92 return false;
93 }
94 });
95 }
96
97 } 80 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698