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

Side by Side Diff: runtime/bin/file.cc

Issue 1460863002: Redo the interface for capture stdio. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 1 month 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
« no previous file with comments | « runtime/bin/file.h ('k') | runtime/bin/main.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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/file.h" 5 #include "bin/file.h"
6 6
7 #include "bin/builtin.h" 7 #include "bin/builtin.h"
8 #include "bin/dartutils.h" 8 #include "bin/dartutils.h"
9 #include "bin/embedded_dart_io.h"
9 #include "bin/io_buffer.h" 10 #include "bin/io_buffer.h"
10 #include "bin/utils.h" 11 #include "bin/utils.h"
11 12
12 #include "include/dart_api.h" 13 #include "include/dart_api.h"
13 #include "include/dart_tools_api.h" 14 #include "include/dart_tools_api.h"
14 15
15 namespace dart { 16 namespace dart {
16 namespace bin { 17 namespace bin {
17 18
18 static const int kMSPerSecond = 1000; 19 static const int kMSPerSecond = 1000;
19 20
20 // Are we capturing output from stdout for the VM service? 21 // Are we capturing output from stdout for the VM service?
21 bool File::capture_stdout_ = false; 22 static bool capture_stdout = false;
22 23
23 // Are we capturing output from stderr for the VM service? 24 // Are we capturing output from stderr for the VM service?
24 bool File::capture_stderr_ = false; 25 static bool capture_stderr = false;
25 26
26 // Are we capturing output from either stdout or stderr for the VM Service? 27
27 bool File::capture_any_ = false; 28 void SetCaptureStdout(bool value) {
29 capture_stdout = value;
30 }
31
32
33 void SetCaptureStderr(bool value) {
34 capture_stderr = value;
35 }
36
37
38 bool ShouldCaptureStdout() {
39 return capture_stdout;
40 }
41
42
43 bool ShouldCaptureStderr() {
44 return capture_stderr;
45 }
46
28 47
29 48
30 // The file pointer has been passed into Dart as an intptr_t and it is safe 49 // The file pointer has been passed into Dart as an intptr_t and it is safe
31 // to pull it out of Dart as a 64-bit integer, cast it to an intptr_t and 50 // to pull it out of Dart as a 64-bit integer, cast it to an intptr_t and
32 // from there to a File pointer. 51 // from there to a File pointer.
33 static File* GetFilePointer(Dart_Handle handle) { 52 static File* GetFilePointer(Dart_Handle handle) {
34 intptr_t value = DartUtils::GetIntptrValue(handle); 53 intptr_t value = DartUtils::GetIntptrValue(handle);
35 return reinterpret_cast<File*>(value); 54 return reinterpret_cast<File*>(value);
36 } 55 }
37 56
(...skipping 17 matching lines...) Expand all
55 int64_t remaining = num_bytes; 74 int64_t remaining = num_bytes;
56 const char* current_buffer = reinterpret_cast<const char*>(buffer); 75 const char* current_buffer = reinterpret_cast<const char*>(buffer);
57 while (remaining > 0) { 76 while (remaining > 0) {
58 int64_t bytes_written = Write(current_buffer, remaining); 77 int64_t bytes_written = Write(current_buffer, remaining);
59 if (bytes_written < 0) { 78 if (bytes_written < 0) {
60 return false; 79 return false;
61 } 80 }
62 remaining -= bytes_written; // Reduce the number of remaining bytes. 81 remaining -= bytes_written; // Reduce the number of remaining bytes.
63 current_buffer += bytes_written; // Move the buffer forward. 82 current_buffer += bytes_written; // Move the buffer forward.
64 } 83 }
65 if (capture_any_) { 84 if (capture_stdout || capture_stderr) {
66 intptr_t fd = GetFD(); 85 intptr_t fd = GetFD();
67 if (fd == STDOUT_FILENO && capture_stdout_) { 86 if (fd == STDOUT_FILENO && capture_stdout) {
68 Dart_ServiceSendDataEvent("Stdout", "WriteEvent", 87 Dart_ServiceSendDataEvent("Stdout", "WriteEvent",
69 reinterpret_cast<const uint8_t*>(buffer), 88 reinterpret_cast<const uint8_t*>(buffer),
70 num_bytes); 89 num_bytes);
71 } else if (fd == STDERR_FILENO && capture_stderr_) { 90 } else if (fd == STDERR_FILENO && capture_stderr) {
72 Dart_ServiceSendDataEvent("Stderr", "WriteEvent", 91 Dart_ServiceSendDataEvent("Stderr", "WriteEvent",
73 reinterpret_cast<const uint8_t*>(buffer), 92 reinterpret_cast<const uint8_t*>(buffer),
74 num_bytes); 93 num_bytes);
75 } 94 }
76 } 95 }
77 return true; 96 return true;
78 } 97 }
79 98
80 99
81 File::FileOpenMode File::DartModeToFileMode(DartFileOpenMode mode) { 100 File::FileOpenMode File::DartModeToFileMode(DartFileOpenMode mode) {
(...skipping 1196 matching lines...) Expand 10 before | Expand all | Expand 10 after
1278 } 1297 }
1279 } else { 1298 } else {
1280 return CObject::FileClosedError(); 1299 return CObject::FileClosedError();
1281 } 1300 }
1282 } 1301 }
1283 return CObject::IllegalArgumentError(); 1302 return CObject::IllegalArgumentError();
1284 } 1303 }
1285 1304
1286 } // namespace bin 1305 } // namespace bin
1287 } // namespace dart 1306 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/bin/file.h ('k') | runtime/bin/main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698