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

Side by Side Diff: runtime/bin/process.h

Issue 21816002: Add Process.runSync for running processe synchronously. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fixed Mac OS issue Created 7 years, 4 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 // 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 BIN_PROCESS_H_ 5 #ifndef BIN_PROCESS_H_
6 #define BIN_PROCESS_H_ 6 #define BIN_PROCESS_H_
7 7
8 #include "bin/builtin.h" 8 #include "bin/builtin.h"
9 #include "bin/thread.h" 9 #include "bin/thread.h"
10 #include "platform/globals.h" 10 #include "platform/globals.h"
11 11
12 12
13 namespace dart { 13 namespace dart {
14 namespace bin { 14 namespace bin {
15 15
16 class ProcessResult {
17 public:
18 ProcessResult()
19 : stdout_data_(NULL), stdout_length_(0),
20 stderr_data_(NULL), stderr_length_(0), exit_code_(0) {}
21
22 void SetStdoutData(uint8_t* buffer, intptr_t length) {
23 stdout_data_ = buffer;
24 stdout_length_ = length;
25 }
26
27 void SetStderrData(uint8_t* buffer, intptr_t length) {
28 stderr_data_ = buffer;
29 stderr_length_ = length;
30 }
31
32 void set_exit_code(intptr_t exit_code) { exit_code_ = exit_code; }
33
34 uint8_t* stdout_data() { return stdout_data_; }
35 intptr_t stdout_length() { return stdout_length_; }
36 uint8_t* stderr_data() { return stderr_data_; }
37 intptr_t stderr_length() { return stderr_length_; }
38 intptr_t exit_code() { return exit_code_; }
39
40 private:
41 uint8_t* stdout_data_;
42 intptr_t stdout_length_;
43 uint8_t* stderr_data_;
44 intptr_t stderr_length_;
45 intptr_t exit_code_;
46
47 DISALLOW_ALLOCATION();
48 };
49
50
16 class Process { 51 class Process {
17 public: 52 public:
18 // Start a new process providing access to stdin, stdout, stderr and 53 // Start a new process providing access to stdin, stdout, stderr and
19 // process exit streams. 54 // process exit streams.
20 static int Start(const char* path, 55 static int Start(const char* path,
21 char* arguments[], 56 char* arguments[],
22 intptr_t arguments_length, 57 intptr_t arguments_length,
23 const char* working_directory, 58 const char* working_directory,
24 char* environment[], 59 char* environment[],
25 intptr_t environment_length, 60 intptr_t environment_length,
26 intptr_t* in, 61 intptr_t* in,
27 intptr_t* out, 62 intptr_t* out,
28 intptr_t* err, 63 intptr_t* err,
29 intptr_t* id, 64 intptr_t* id,
30 intptr_t* exit_handler, 65 intptr_t* exit_handler,
31 char** os_error_message); 66 char** os_error_message);
32 67
68 static bool Wait(intptr_t id,
69 intptr_t in,
70 intptr_t out,
71 intptr_t err,
72 intptr_t exit_handler,
73 ProcessResult* result);
74
33 // Kill a process with a given pid. 75 // Kill a process with a given pid.
34 static bool Kill(intptr_t id, int signal); 76 static bool Kill(intptr_t id, int signal);
35 77
36 // Terminate the exit code handler thread. Does not return before 78 // Terminate the exit code handler thread. Does not return before
37 // the thread has terminated. 79 // the thread has terminated.
38 static void TerminateExitCodeHandler(); 80 static void TerminateExitCodeHandler();
39 81
40 static int GlobalExitCode() { 82 static int GlobalExitCode() {
41 MutexLocker ml(global_exit_code_mutex_); 83 MutexLocker ml(global_exit_code_mutex_);
42 return global_exit_code_; 84 return global_exit_code_;
(...skipping 16 matching lines...) Expand all
59 static dart::Mutex* global_exit_code_mutex_; 101 static dart::Mutex* global_exit_code_mutex_;
60 102
61 DISALLOW_ALLOCATION(); 103 DISALLOW_ALLOCATION();
62 DISALLOW_IMPLICIT_CONSTRUCTORS(Process); 104 DISALLOW_IMPLICIT_CONSTRUCTORS(Process);
63 }; 105 };
64 106
65 } // namespace bin 107 } // namespace bin
66 } // namespace dart 108 } // namespace dart
67 109
68 #endif // BIN_PROCESS_H_ 110 #endif // BIN_PROCESS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698