| 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 #ifndef RUNTIME_BIN_PROCESS_H_ | 5 #ifndef RUNTIME_BIN_PROCESS_H_ |
| 6 #define RUNTIME_BIN_PROCESS_H_ | 6 #define RUNTIME_BIN_PROCESS_H_ |
| 7 | 7 |
| 8 #include "bin/builtin.h" | 8 #include "bin/builtin.h" |
| 9 #include "bin/io_buffer.h" | 9 #include "bin/io_buffer.h" |
| 10 #include "bin/lockers.h" | 10 #include "bin/lockers.h" |
| 11 #include "bin/thread.h" | 11 #include "bin/thread.h" |
| 12 #include "platform/globals.h" | 12 #include "platform/globals.h" |
| 13 #include "platform/utils.h" | 13 #include "platform/utils.h" |
| 14 | 14 |
| 15 namespace dart { | 15 namespace dart { |
| 16 namespace bin { | 16 namespace bin { |
| 17 | 17 |
| 18 class ProcessResult { | 18 class ProcessResult { |
| 19 public: | 19 public: |
| 20 ProcessResult() : exit_code_(0) {} | 20 ProcessResult() : exit_code_(0) {} |
| 21 | 21 |
| 22 void set_stdout_data(Dart_Handle stdout_data) { | 22 void set_stdout_data(Dart_Handle stdout_data) { stdout_data_ = stdout_data; } |
| 23 stdout_data_ = stdout_data; | 23 void set_stderr_data(Dart_Handle stderr_data) { stderr_data_ = stderr_data; } |
| 24 } | |
| 25 void set_stderr_data(Dart_Handle stderr_data) { | |
| 26 stderr_data_ = stderr_data; | |
| 27 } | |
| 28 | 24 |
| 29 void set_exit_code(intptr_t exit_code) { exit_code_ = exit_code; } | 25 void set_exit_code(intptr_t exit_code) { exit_code_ = exit_code; } |
| 30 | 26 |
| 31 Dart_Handle stdout_data() { return stdout_data_; } | 27 Dart_Handle stdout_data() { return stdout_data_; } |
| 32 Dart_Handle stderr_data() { return stderr_data_; } | 28 Dart_Handle stderr_data() { return stderr_data_; } |
| 33 intptr_t exit_code() { return exit_code_; } | 29 intptr_t exit_code() { return exit_code_; } |
| 34 | 30 |
| 35 private: | 31 private: |
| 36 Dart_Handle stdout_data_; | 32 Dart_Handle stdout_data_; |
| 37 Dart_Handle stderr_data_; | 33 Dart_Handle stderr_data_; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 MutexLocker ml(global_exit_code_mutex_); | 116 MutexLocker ml(global_exit_code_mutex_); |
| 121 return global_exit_code_; | 117 return global_exit_code_; |
| 122 } | 118 } |
| 123 | 119 |
| 124 static void SetGlobalExitCode(int exit_code) { | 120 static void SetGlobalExitCode(int exit_code) { |
| 125 MutexLocker ml(global_exit_code_mutex_); | 121 MutexLocker ml(global_exit_code_mutex_); |
| 126 global_exit_code_ = exit_code; | 122 global_exit_code_ = exit_code; |
| 127 } | 123 } |
| 128 | 124 |
| 129 typedef void (*ExitHook)(int64_t exit_code); | 125 typedef void (*ExitHook)(int64_t exit_code); |
| 130 static void SetExitHook(ExitHook hook) { | 126 static void SetExitHook(ExitHook hook) { exit_hook_ = hook; } |
| 131 exit_hook_ = hook; | |
| 132 } | |
| 133 static void RunExitHook(int64_t exit_code) { | 127 static void RunExitHook(int64_t exit_code) { |
| 134 if (exit_hook_ != NULL) { | 128 if (exit_hook_ != NULL) { |
| 135 exit_hook_(exit_code); | 129 exit_hook_(exit_code); |
| 136 } | 130 } |
| 137 } | 131 } |
| 138 | 132 |
| 139 static intptr_t CurrentProcessId(); | 133 static intptr_t CurrentProcessId(); |
| 140 | 134 |
| 141 static intptr_t SetSignalHandler(intptr_t signal); | 135 static intptr_t SetSignalHandler(intptr_t signal); |
| 142 static void ClearSignalHandler(intptr_t signal); | 136 static void ClearSignalHandler(intptr_t signal); |
| 143 | 137 |
| 144 static Dart_Handle GetProcessIdNativeField(Dart_Handle process, | 138 static Dart_Handle GetProcessIdNativeField(Dart_Handle process, |
| 145 intptr_t* pid); | 139 intptr_t* pid); |
| 146 static Dart_Handle SetProcessIdNativeField(Dart_Handle process, | 140 static Dart_Handle SetProcessIdNativeField(Dart_Handle process, intptr_t pid); |
| 147 intptr_t pid); | |
| 148 | 141 |
| 149 private: | 142 private: |
| 150 static int global_exit_code_; | 143 static int global_exit_code_; |
| 151 static Mutex* global_exit_code_mutex_; | 144 static Mutex* global_exit_code_mutex_; |
| 152 static ExitHook exit_hook_; | 145 static ExitHook exit_hook_; |
| 153 | 146 |
| 154 DISALLOW_ALLOCATION(); | 147 DISALLOW_ALLOCATION(); |
| 155 DISALLOW_IMPLICIT_CONSTRUCTORS(Process); | 148 DISALLOW_IMPLICIT_CONSTRUCTORS(Process); |
| 156 }; | 149 }; |
| 157 | 150 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 static const intptr_t kBufferSize = 16 * 1024; | 200 static const intptr_t kBufferSize = 16 * 1024; |
| 208 | 201 |
| 209 class BufferListNode { | 202 class BufferListNode { |
| 210 public: | 203 public: |
| 211 explicit BufferListNode(intptr_t size) { | 204 explicit BufferListNode(intptr_t size) { |
| 212 data_ = new uint8_t[size]; | 205 data_ = new uint8_t[size]; |
| 213 if (data_ == NULL) FATAL("Allocation failed"); | 206 if (data_ == NULL) FATAL("Allocation failed"); |
| 214 next_ = NULL; | 207 next_ = NULL; |
| 215 } | 208 } |
| 216 | 209 |
| 217 ~BufferListNode() { | 210 ~BufferListNode() { delete[] data_; } |
| 218 delete[] data_; | |
| 219 } | |
| 220 | 211 |
| 221 uint8_t* data_; | 212 uint8_t* data_; |
| 222 BufferListNode* next_; | 213 BufferListNode* next_; |
| 223 | 214 |
| 224 private: | 215 private: |
| 225 DISALLOW_IMPLICIT_CONSTRUCTORS(BufferListNode); | 216 DISALLOW_IMPLICIT_CONSTRUCTORS(BufferListNode); |
| 226 }; | 217 }; |
| 227 | 218 |
| 228 public: | 219 public: |
| 229 BufferListBase() : head_(NULL), tail_(NULL), data_size_(0), free_size_(0) {} | 220 BufferListBase() : head_(NULL), tail_(NULL), data_size_(0), free_size_(0) {} |
| 230 ~BufferListBase() { | 221 ~BufferListBase() { |
| 231 ASSERT(head_ == NULL); | 222 ASSERT(head_ == NULL); |
| 232 ASSERT(tail_ == NULL); | 223 ASSERT(tail_ == NULL); |
| 233 } | 224 } |
| 234 | 225 |
| 235 // Returns the collected data as a Uint8List. If an error occours an | 226 // Returns the collected data as a Uint8List. If an error occours an |
| 236 // error handle is returned. | 227 // error handle is returned. |
| 237 Dart_Handle GetData() { | 228 Dart_Handle GetData() { |
| 238 uint8_t* buffer; | 229 uint8_t* buffer; |
| 239 intptr_t buffer_position = 0; | 230 intptr_t buffer_position = 0; |
| 240 Dart_Handle result = IOBuffer::Allocate(data_size_, &buffer); | 231 Dart_Handle result = IOBuffer::Allocate(data_size_, &buffer); |
| 241 if (Dart_IsError(result)) { | 232 if (Dart_IsError(result)) { |
| 242 Free(); | 233 Free(); |
| 243 return result; | 234 return result; |
| 244 } | 235 } |
| 245 for (BufferListNode* current = head_; | 236 for (BufferListNode* current = head_; current != NULL; |
| 246 current != NULL; | |
| 247 current = current->next_) { | 237 current = current->next_) { |
| 248 intptr_t to_copy = dart::Utils::Minimum(data_size_, kBufferSize); | 238 intptr_t to_copy = dart::Utils::Minimum(data_size_, kBufferSize); |
| 249 memmove(buffer + buffer_position, current->data_, to_copy); | 239 memmove(buffer + buffer_position, current->data_, to_copy); |
| 250 buffer_position += to_copy; | 240 buffer_position += to_copy; |
| 251 data_size_ -= to_copy; | 241 data_size_ -= to_copy; |
| 252 } | 242 } |
| 253 ASSERT(data_size_ == 0); | 243 ASSERT(data_size_ == 0); |
| 254 Free(); | 244 Free(); |
| 255 return result; | 245 return result; |
| 256 } | 246 } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 intptr_t free_size_; | 289 intptr_t free_size_; |
| 300 | 290 |
| 301 private: | 291 private: |
| 302 DISALLOW_COPY_AND_ASSIGN(BufferListBase); | 292 DISALLOW_COPY_AND_ASSIGN(BufferListBase); |
| 303 }; | 293 }; |
| 304 | 294 |
| 305 } // namespace bin | 295 } // namespace bin |
| 306 } // namespace dart | 296 } // namespace dart |
| 307 | 297 |
| 308 #endif // RUNTIME_BIN_PROCESS_H_ | 298 #endif // RUNTIME_BIN_PROCESS_H_ |
| OLD | NEW |