Redirects I/O for a newly launched application. More...
#include <redirecter.h>


Public Types | |
| enum | outcomes { OKAY = basis::common::OKAY, NOT_FOUND = basis::common::NOT_FOUND, NONE_READY = basis::common::NONE_READY, PARTIAL = basis::common::PARTIAL, ACCESS_DENIED = basis::common::ACCESS_DENIED } |
Public Member Functions | |
| stdio_redirecter (const basis::astring &command, const basis::astring ¶meters) | |
| controls the I/O for a program started with "command" and "parameters". | |
| stdio_redirecter () | |
| creates a blank redirecter which should be started up with reset(). | |
| ~stdio_redirecter () | |
| shuts down the program that was launched, if it's still running. | |
| basis::outcome | reset (const basis::astring &command, const basis::astring ¶meters) |
| shuts down the active program and starts with new parameters. | |
| DEFINE_CLASS_NAME ("stdio_redirecter") | |
| basis::outcome | health () const |
| if the object constructed successfully, this returns OKAY. | |
| bool | running () |
| returns true if the application is still running. | |
| int | exit_value () const |
| returns the exit value from the app after it was launched. | |
| int | process_id () const |
| the process id of the launched application. | |
| void | zap_program () |
| attempts to force a shutdown of the launched application. | |
| basis::outcome | read (basis::byte_array &received) |
| attempts to read bytes from the program's standard output. | |
| basis::outcome | write (const basis::byte_array &to_write, int &written) |
| writes the bytes in "to_write" into the program's standard input. | |
| basis::outcome | write (const basis::astring &to_write, int &written) |
| sends a string "to_write" to the launched program's standard input. | |
| basis::outcome | read_stderr (basis::byte_array &received) |
| reads from the program's standard error stream similarly to read(). | |
| void | close_input () |
| shuts down the standard input to the program. | |
| void | std_thread_action (bool is_stdout) |
| invoked by our threads when data becomes available. | |
Redirects I/O for a newly launched application.
Definition at line 26 of file redirecter.h.
| OKAY | |
| NOT_FOUND |
the file to launch was not found. |
| NONE_READY |
there was no data available. |
| PARTIAL |
only some of the bytes could be stored. |
| ACCESS_DENIED |
the OS told us we could not. |
Definition at line 47 of file redirecter.h.
| application::stdio_redirecter::stdio_redirecter | ( | const basis::astring & | command, | |
| const basis::astring & | parameters | |||
| ) |
controls the I/O for a program started with "command" and "parameters".
this creates an io redirecter that will trap the inputs and outputs of a program called "command" that is launched with the "parameters". the program can be communicated with via the read and write methods below.
Definition at line 104 of file redirecter.cpp.
References OKAY.
| application::stdio_redirecter::stdio_redirecter | ( | ) |
creates a blank redirecter which should be started up with reset().
Definition at line 84 of file redirecter.cpp.
| application::stdio_redirecter::~stdio_redirecter | ( | ) |
shuts down the program that was launched, if it's still running.
Definition at line 129 of file redirecter.cpp.
References basis::WHACK(), and zap_program().
| void application::stdio_redirecter::close_input | ( | ) |
shuts down the standard input to the program.
this simulates when the program receives an end of file on its main input.
Definition at line 351 of file redirecter.cpp.
Referenced by zap_program().
| application::stdio_redirecter::DEFINE_CLASS_NAME | ( | "stdio_redirecter" | ) |
| int application::stdio_redirecter::exit_value | ( | ) | const [inline] |
returns the exit value from the app after it was launched.
this is only valid if the launch succeeded, the app ran, and now the running() method is returning false because the application exited.
Definition at line 63 of file redirecter.h.
Referenced by running().
| basis::outcome application::stdio_redirecter::health | ( | ) | const [inline] |
if the object constructed successfully, this returns OKAY.
otherwise an error occurred during the pipe creation or process fork.
Definition at line 55 of file redirecter.h.
| int application::stdio_redirecter::process_id | ( | ) | const [inline] |
the process id of the launched application.
this is only valid if the app is still running.
Definition at line 67 of file redirecter.h.
| outcome application::stdio_redirecter::read | ( | basis::byte_array & | received | ) |
attempts to read bytes from the program's standard output.
if any bytes were found, OKAY is returned and the bytes are stored in "received".
Definition at line 421 of file redirecter.cpp.
References basis::array< contents >::length(), NONE_READY, OKAY, and basis::array< contents >::reset().
Referenced by std_thread_action().
| outcome application::stdio_redirecter::read_stderr | ( | basis::byte_array & | received | ) |
reads from the program's standard error stream similarly to read().
Definition at line 459 of file redirecter.cpp.
References basis::array< contents >::length(), NONE_READY, OKAY, and basis::array< contents >::reset().
| outcome application::stdio_redirecter::reset | ( | const basis::astring & | command, | |
| const basis::astring & | parameters | |||
| ) |
shuts down the active program and starts with new parameters.
Definition at line 143 of file redirecter.cpp.
References OKAY, and zap_program().
| bool application::stdio_redirecter::running | ( | ) |
returns true if the application is still running.
if it exited on its own, then this will return false.
Definition at line 310 of file redirecter.cpp.
References exit_value().
| void application::stdio_redirecter::std_thread_action | ( | bool | is_stdout | ) |
invoked by our threads when data becomes available.
if "is_stdout" is true, then that's the pipe we get data from. otherwise we will try to get data from stderr.
Definition at line 471 of file redirecter.cpp.
References basis::array< contents >::access(), application::BUFFER_SIZE, NIL, read(), and basis::array< contents >::subarray().
| outcome application::stdio_redirecter::write | ( | const basis::astring & | to_write, | |
| int & | written | |||
| ) |
sends a string "to_write" to the launched program's standard input.
Definition at line 433 of file redirecter.cpp.
References basis::astring::length(), basis::astring::observe(), and write().
| outcome application::stdio_redirecter::write | ( | const basis::byte_array & | to_write, | |
| int & | written | |||
| ) |
writes the bytes in "to_write" into the program's standard input.
OKAY is returned if all were successfully written. the number of bytes that were actually sent to the program is put in "written". if only a portion of the bytes could be written, then PARTIAL is returned.
Definition at line 439 of file redirecter.cpp.
References ACCESS_DENIED, basis::array< contents >::length(), NIL, basis::array< contents >::observe(), and OKAY.
Referenced by write().
| void application::stdio_redirecter::zap_program | ( | ) |
attempts to force a shutdown of the launched application.
this also closes out all of our pipes and handles.
Definition at line 361 of file redirecter.cpp.
References processes::ethread::cancel(), close, close_input(), configuration::ini_configurator::delete_entry(), FUNCDEF, LOG, NIL, application::PROCESS_SECTION, application::REDIRECTER_INI, and processes::ethread::stop().
Referenced by reset(), and ~stdio_redirecter().
1.6.3