OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROMEOS_PROCESS_PROXY_PROCESS_OUTPUT_WATCHER_H_ | 5 #ifndef CHROMEOS_PROCESS_PROXY_PROCESS_OUTPUT_WATCHER_H_ |
6 #define CHROMEOS_PROCESS_PROXY_PROCESS_OUTPUT_WATCHER_H_ | 6 #define CHROMEOS_PROCESS_PROXY_PROCESS_OUTPUT_WATCHER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 typedef base::Callback<void(ProcessOutputType, const std::string&)> | 21 typedef base::Callback<void(ProcessOutputType, const std::string&)> |
22 ProcessOutputCallback; | 22 ProcessOutputCallback; |
23 | 23 |
24 // Observes output on |out_fd| and invokes |callback| when some output is | 24 // Observes output on |out_fd| and invokes |callback| when some output is |
25 // detected. It assumes UTF8 output. | 25 // detected. It assumes UTF8 output. |
26 // If output is detected in |stop_fd|, the watcher is stopped. | 26 // If output is detected in |stop_fd|, the watcher is stopped. |
27 // This class should live on its own thread because running class makes | 27 // This class should live on its own thread because running class makes |
28 // underlying thread block. It deletes itself when watching is stopped. | 28 // underlying thread block. It deletes itself when watching is stopped. |
29 class CHROMEOS_EXPORT ProcessOutputWatcher { | 29 class CHROMEOS_EXPORT ProcessOutputWatcher { |
30 public: | 30 public: |
| 31 // Verifies that fds that we got are properly set. |
| 32 static bool VerifyFileDescriptor(int fd); |
| 33 |
31 ProcessOutputWatcher(int out_fd, int stop_fd, | 34 ProcessOutputWatcher(int out_fd, int stop_fd, |
32 const ProcessOutputCallback& callback); | 35 const ProcessOutputCallback& callback); |
33 | 36 |
34 // This will block current thread!!!! | 37 // This will block current thread!!!! |
35 void Start(); | 38 void Start(); |
36 | 39 |
37 private: | 40 private: |
38 // The object will destroy itself when it stops watching process output. | 41 // The object will destroy itself when it stops watching process output. |
39 ~ProcessOutputWatcher(); | 42 ~ProcessOutputWatcher(); |
40 | 43 |
41 // Listens to output from supplied fds. It guarantees data written to one fd | 44 // Listens to output from supplied fds. It guarantees data written to one fd |
42 // will be reported in order that it has been written (this is not true across | 45 // will be reported in order that it has been written (this is not true across |
43 // fds, it would be nicer if it was). | 46 // fds, it would be nicer if it was). |
44 void WatchProcessOutput(); | 47 void WatchProcessOutput(); |
45 | 48 |
46 // Verifies that fds that we got are properly set. | |
47 void VerifyFileDescriptor(int fd); | |
48 | |
49 // Reads data from fd, and when it's done, invokes callback function. | 49 // Reads data from fd, and when it's done, invokes callback function. |
50 void ReadFromFd(ProcessOutputType type, int* fd); | 50 void ReadFromFd(ProcessOutputType type, int* fd); |
51 | 51 |
52 // Checks if the read buffer has any trailing incomplete UTF8 characters and | 52 // Checks if the read buffer has any trailing incomplete UTF8 characters and |
53 // returns the read buffer size without them. | 53 // returns the read buffer size without them. |
54 size_t OutputSizeWithoutIncompleteUTF8(); | 54 size_t OutputSizeWithoutIncompleteUTF8(); |
55 | 55 |
56 // Processes new |read_buffer_| state and notifies observer about new process | 56 // Processes new |read_buffer_| state and notifies observer about new process |
57 // output. | 57 // output. |
58 void ReportOutput(ProcessOutputType type, size_t new_bytes_count); | 58 void ReportOutput(ProcessOutputType type, size_t new_bytes_count); |
(...skipping 13 matching lines...) Expand all Loading... |
72 | 72 |
73 // Callback that will be invoked when some output is detected. | 73 // Callback that will be invoked when some output is detected. |
74 ProcessOutputCallback on_read_callback_; | 74 ProcessOutputCallback on_read_callback_; |
75 | 75 |
76 DISALLOW_COPY_AND_ASSIGN(ProcessOutputWatcher); | 76 DISALLOW_COPY_AND_ASSIGN(ProcessOutputWatcher); |
77 }; | 77 }; |
78 | 78 |
79 } // namespace chromeos | 79 } // namespace chromeos |
80 | 80 |
81 #endif // CHROMEOS_PROCESS_PROXY_PROCESS_OUTPUT_WATCHER_H_ | 81 #endif // CHROMEOS_PROCESS_PROXY_PROCESS_OUTPUT_WATCHER_H_ |
OLD | NEW |