| 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 "bin/dartutils.h" | 5 #include "bin/dartutils.h" |
| 6 #include "bin/process.h" | 6 #include "bin/process.h" |
| 7 #include "bin/socket.h" | 7 #include "bin/socket.h" |
| 8 | 8 |
| 9 #include "include/dart_api.h" | 9 #include "include/dart_api.h" |
| 10 | 10 |
| 11 | 11 |
| 12 static const int kProcessIdNativeField = 0; |
| 13 |
| 14 |
| 12 // Extract an array of C strings from a list of Dart strings. | 15 // Extract an array of C strings from a list of Dart strings. |
| 13 static char** ExtractCStringList(Dart_Handle strings, | 16 static char** ExtractCStringList(Dart_Handle strings, |
| 14 Dart_Handle status_handle, | 17 Dart_Handle status_handle, |
| 15 const char* error_msg, | 18 const char* error_msg, |
| 16 intptr_t* length) { | 19 intptr_t* length) { |
| 17 static const intptr_t kMaxArgumentListLength = 1024 * 1024; | 20 static const intptr_t kMaxArgumentListLength = 1024 * 1024; |
| 18 ASSERT(Dart_IsList(strings)); | 21 ASSERT(Dart_IsList(strings)); |
| 19 intptr_t len = 0; | 22 intptr_t len = 0; |
| 20 Dart_Handle result = Dart_ListLength(strings, &len); | 23 Dart_Handle result = Dart_ListLength(strings, &len); |
| 21 if (Dart_IsError(result)) { | 24 if (Dart_IsError(result)) { |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 &out, | 134 &out, |
| 132 &err, | 135 &err, |
| 133 &pid, | 136 &pid, |
| 134 &exit_event, | 137 &exit_event, |
| 135 os_error_message, kMaxChildOsErrorMessageLength); | 138 os_error_message, kMaxChildOsErrorMessageLength); |
| 136 if (error_code == 0) { | 139 if (error_code == 0) { |
| 137 Socket::SetSocketIdNativeField(in_handle, in); | 140 Socket::SetSocketIdNativeField(in_handle, in); |
| 138 Socket::SetSocketIdNativeField(out_handle, out); | 141 Socket::SetSocketIdNativeField(out_handle, out); |
| 139 Socket::SetSocketIdNativeField(err_handle, err); | 142 Socket::SetSocketIdNativeField(err_handle, err); |
| 140 Socket::SetSocketIdNativeField(exit_handle, exit_event); | 143 Socket::SetSocketIdNativeField(exit_handle, exit_event); |
| 141 DartUtils::SetIntegerField(process, "_pid", pid); | 144 Process::SetProcessIdNativeField(process, pid); |
| 142 } else { | 145 } else { |
| 143 DartUtils::SetIntegerField( | 146 DartUtils::SetIntegerField( |
| 144 status_handle, "_errorCode", error_code); | 147 status_handle, "_errorCode", error_code); |
| 145 DartUtils::SetStringField( | 148 DartUtils::SetStringField( |
| 146 status_handle, "_errorMessage", os_error_message); | 149 status_handle, "_errorMessage", os_error_message); |
| 147 } | 150 } |
| 148 delete[] string_args; | 151 delete[] string_args; |
| 149 delete[] string_environment; | 152 delete[] string_environment; |
| 150 Dart_SetReturnValue(args, Dart_NewBoolean(error_code == 0)); | 153 Dart_SetReturnValue(args, Dart_NewBoolean(error_code == 0)); |
| 151 Dart_ExitScope(); | 154 Dart_ExitScope(); |
| 152 } | 155 } |
| 153 | 156 |
| 154 | 157 |
| 155 void FUNCTION_NAME(Process_Kill)(Dart_NativeArguments args) { | 158 void FUNCTION_NAME(Process_Kill)(Dart_NativeArguments args) { |
| 156 Dart_EnterScope(); | 159 Dart_EnterScope(); |
| 157 intptr_t pid = DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 1)); | 160 Dart_Handle process = Dart_GetNativeArgument(args, 1); |
| 161 intptr_t pid = -1; |
| 162 Process::GetProcessIdNativeField(process, &pid); |
| 158 int signal = DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 2)); | 163 int signal = DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 2)); |
| 159 bool success = Process::Kill(pid, signal); | 164 bool success = Process::Kill(pid, signal); |
| 160 Dart_SetReturnValue(args, Dart_NewBoolean(success)); | 165 Dart_SetReturnValue(args, Dart_NewBoolean(success)); |
| 161 Dart_ExitScope(); | 166 Dart_ExitScope(); |
| 162 } | 167 } |
| 168 |
| 169 |
| 170 Dart_Handle Process::GetProcessIdNativeField(Dart_Handle process, |
| 171 intptr_t* pid) { |
| 172 return Dart_GetNativeInstanceField(process, kProcessIdNativeField, pid); |
| 173 } |
| 174 |
| 175 |
| 176 Dart_Handle Process::SetProcessIdNativeField(Dart_Handle process, |
| 177 intptr_t pid) { |
| 178 return Dart_SetNativeInstanceField(process, kProcessIdNativeField, pid); |
| 179 } |
| OLD | NEW |