OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart 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 file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include <stdlib.h> | 5 #include <stdlib.h> |
6 #include <string.h> | 6 #include <string.h> |
7 #include <stdio.h> | 7 #include <stdio.h> |
8 | 8 |
9 #include "include/dart_api.h" | 9 #include "include/dart_api.h" |
10 #include "include/dart_tools_api.h" | 10 #include "include/dart_tools_api.h" |
(...skipping 841 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
852 Dart_Handle args[] = {paths, keys, values}; | 852 Dart_Handle args[] = {paths, keys, values}; |
853 Dart_Handle result = Dart_Invoke(io_lib, handler_function_name, 3, args); | 853 Dart_Handle result = Dart_Invoke(io_lib, handler_function_name, 3, args); |
854 if (Dart_IsError(result)) return ServiceRequestError(result); | 854 if (Dart_IsError(result)) return ServiceRequestError(result); |
855 const char *json; | 855 const char *json; |
856 result = Dart_StringToCString(result, &json); | 856 result = Dart_StringToCString(result, &json); |
857 if (Dart_IsError(result)) return ServiceRequestError(result); | 857 if (Dart_IsError(result)) return ServiceRequestError(result); |
858 return strdup(json); | 858 return strdup(json); |
859 } | 859 } |
860 | 860 |
861 | 861 |
| 862 extern bool capture_stdio; |
| 863 extern bool capture_stdout; |
| 864 extern bool capture_stderr; |
| 865 static const char* kStdoutStreamId = "Stdout"; |
| 866 static const char* kStderrStreamId = "Stderr"; |
| 867 |
| 868 |
| 869 static bool ServiceStreamListenCallback(const char* stream_id) { |
| 870 if (strcmp(stream_id, kStdoutStreamId) == 0) { |
| 871 capture_stdio = true; |
| 872 capture_stdout = true; |
| 873 return true; |
| 874 } else if (strcmp(stream_id, kStderrStreamId) == 0) { |
| 875 capture_stdio = true; |
| 876 capture_stderr = true; |
| 877 return true; |
| 878 } |
| 879 return false; |
| 880 } |
| 881 |
| 882 |
| 883 static void ServiceStreamCancelCallback(const char* stream_id) { |
| 884 if (strcmp(stream_id, kStdoutStreamId) == 0) { |
| 885 capture_stdout = false; |
| 886 } else if (strcmp(stream_id, kStderrStreamId) == 0) { |
| 887 capture_stderr = false; |
| 888 } |
| 889 capture_stdio = (capture_stdout || capture_stderr); |
| 890 } |
| 891 |
| 892 |
862 void main(int argc, char** argv) { | 893 void main(int argc, char** argv) { |
863 char* script_name; | 894 char* script_name; |
864 const int EXTRA_VM_ARGUMENTS = 2; | 895 const int EXTRA_VM_ARGUMENTS = 2; |
865 CommandLineOptions vm_options(argc + EXTRA_VM_ARGUMENTS); | 896 CommandLineOptions vm_options(argc + EXTRA_VM_ARGUMENTS); |
866 CommandLineOptions dart_options(argc); | 897 CommandLineOptions dart_options(argc); |
867 bool print_flags_seen = false; | 898 bool print_flags_seen = false; |
868 bool verbose_debug_seen = false; | 899 bool verbose_debug_seen = false; |
869 | 900 |
870 vm_options.AddArgument("--no_write_protect_code"); | 901 vm_options.AddArgument("--no_write_protect_code"); |
871 // Perform platform specific initialization. | 902 // Perform platform specific initialization. |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
940 DartUtils::WriteFile, | 971 DartUtils::WriteFile, |
941 DartUtils::CloseFile, | 972 DartUtils::CloseFile, |
942 DartUtils::EntropySource)) { | 973 DartUtils::EntropySource)) { |
943 fprintf(stderr, "%s", "VM initialization failed\n"); | 974 fprintf(stderr, "%s", "VM initialization failed\n"); |
944 fflush(stderr); | 975 fflush(stderr); |
945 exit(kErrorExitCode); | 976 exit(kErrorExitCode); |
946 } | 977 } |
947 | 978 |
948 Dart_RegisterIsolateServiceRequestCallback( | 979 Dart_RegisterIsolateServiceRequestCallback( |
949 "getIO", &ServiceGetIOHandler, NULL); | 980 "getIO", &ServiceGetIOHandler, NULL); |
| 981 Dart_SetServiceStreamCallbacks(&ServiceStreamListenCallback, |
| 982 &ServiceStreamCancelCallback); |
950 | 983 |
951 // Call CreateIsolateAndSetup which creates an isolate and loads up | 984 // Call CreateIsolateAndSetup which creates an isolate and loads up |
952 // the specified application script. | 985 // the specified application script. |
953 char* error = NULL; | 986 char* error = NULL; |
954 int exit_code = 0; | 987 int exit_code = 0; |
955 char* isolate_name = BuildIsolateName(script_name, "main"); | 988 char* isolate_name = BuildIsolateName(script_name, "main"); |
956 Dart_Isolate isolate = CreateIsolateAndSetupHelper(script_name, | 989 Dart_Isolate isolate = CreateIsolateAndSetupHelper(script_name, |
957 "main", | 990 "main", |
958 commandline_package_root, | 991 commandline_package_root, |
959 NULL, | 992 NULL, |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1084 exit(Process::GlobalExitCode()); | 1117 exit(Process::GlobalExitCode()); |
1085 } | 1118 } |
1086 | 1119 |
1087 } // namespace bin | 1120 } // namespace bin |
1088 } // namespace dart | 1121 } // namespace dart |
1089 | 1122 |
1090 int main(int argc, char** argv) { | 1123 int main(int argc, char** argv) { |
1091 dart::bin::main(argc, argv); | 1124 dart::bin::main(argc, argv); |
1092 UNREACHABLE(); | 1125 UNREACHABLE(); |
1093 } | 1126 } |
OLD | NEW |