TSDuck Version 3.16-1064 (TSDuck - The MPEG Transport Stream Toolkit)
ts::ForkPipe Class Reference

Fork a process and create an optional pipe to its standard input. More...

Inheritance diagram for ts::ForkPipe:

Public Types

enum  InputMode {
  STDIN_PARENT,
  STDIN_PIPE,
  STDIN_NONE
}
 How to standard input in the created process. More...
 
enum  OutputMode {
  KEEP_BOTH,
  STDOUT_ONLY,
  STDERR_ONLY,
  STDOUT_PIPE,
  STDOUTERR_PIPE
}
 How to merge standard output and standard error in the created process. More...
 
enum  WaitMode {
  ASYNCHRONOUS,
  SYNCHRONOUS,
  EXIT_PROCESS
}
 How to wait for the created process when close() is invoked. More...
 

Public Member Functions

 ForkPipe ()
 Default constructor.
 
 ~ForkPipe ()
 Destructor.
 
void abortPipeReadWrite ()
 Abort any currenly input/output operation in the pipe. More...
 
bool close (Report &report)
 Close the pipe. More...
 
bool eof () const
 Check if the input pipe is at end of file. More...
 
bool getIgnoreAbort () const
 Get "ignore abort". More...
 
bool isBroken () const
 Check if the pipe was broken. More...
 
bool isOpen () const
 Check if the process is running and the pipe is open (when used). More...
 
bool isSynchronous () const
 Check if synchronous mode is active (ie. More...
 
bool open (const UString &command, WaitMode wait_mode, size_t buffer_size, Report &report, OutputMode out_mode, InputMode in_mode)
 Create the process, open the optional pipe. More...
 
bool read (void *addr, size_t max_size, size_t unit_size, size_t &ret_size, Report &report)
 Read data from the pipe (sent from process' standard output or error). More...
 
void setIgnoreAbort (bool on)
 Set "ignore abort". More...
 
bool write (const void *addr, size_t size, Report &report)
 Write data to the pipe (received at process' standard input). More...
 

Detailed Description

Fork a process and create an optional pipe to its standard input.

Member Enumeration Documentation

◆ WaitMode

How to wait for the created process when close() is invoked.

No pipe can be used with EXIT_PROCESS because there would be nobody on the other end of the pipe.

Enumerator
ASYNCHRONOUS 

Don't wait, close() will return immediately.

SYNCHRONOUS 

Wait for process completion during close().

EXIT_PROCESS 

Exit parent process during open(). UNIX: call exec(), Windows: call exit() after process creation.

◆ InputMode

How to standard input in the created process.

The pipe can be used either on input or output, but not both. So, STDIN_PIPE is also forbidden with output mode is either STDOUT_PIPE or STDOUTERR_PIPE.

Enumerator
STDIN_PARENT 

Keep same stdin as current (parent) process.

STDIN_PIPE 

Use the pipe as stdin.

STDIN_NONE 

No standard input (the null device in fact).

◆ OutputMode

How to merge standard output and standard error in the created process.

Enumerator
KEEP_BOTH 

Keep same stdout and stderr as current (parent) process.

STDOUT_ONLY 

Merge stderr into current stdout.

STDERR_ONLY 

Merge stdout into current stderr.

STDOUT_PIPE 

Use the pipe to receive stdout, keep same stderr as current (parent) process.

STDOUTERR_PIPE 

Use the pipe to receive a merge of stdout and stderr.

Member Function Documentation

◆ open()

bool ts::ForkPipe::open ( const UString command,
WaitMode  wait_mode,
size_t  buffer_size,
Report report,
OutputMode  out_mode,
InputMode  in_mode 
)

Create the process, open the optional pipe.

Parameters
[in]commandThe command to execute.
[in]wait_modeHow to wait for process termination in close().
[in]buffer_sizeThe pipe buffer size in bytes. Used on Windows only. Zero means default.
[in,out]reportWhere to report errors.
[in]out_modeHow to handle stdout and stderr.
[in]in_modeHow to handle stdin. Use the pipe by default. When set to KEEP_STDIN, no pipe is created.
Returns
True on success, false on error. Do not return on success when wait_mode is EXIT_PROCESS.

◆ close()

bool ts::ForkPipe::close ( Report report)

Close the pipe.

Optionally wait for process termination if wait_mode was SYNCHRONOUS on open().

Parameters
[in,out]reportWhere to report errors.
Returns
True on success, false on error.

◆ isOpen()

bool ts::ForkPipe::isOpen ( ) const
inline

Check if the process is running and the pipe is open (when used).

Returns
True if the process is running and the pipe is open.

◆ isBroken()

bool ts::ForkPipe::isBroken ( ) const
inline

Check if the pipe was broken.

Returns
True if was broken (unexpected process termination for instance).

◆ isSynchronous()

bool ts::ForkPipe::isSynchronous ( ) const
inline

Check if synchronous mode is active (ie.

will wait for process termination).

Returns
True if synchronous mode is active.

◆ setIgnoreAbort()

void ts::ForkPipe::setIgnoreAbort ( bool  on)
inline

Set "ignore abort".

Parameters
[in]onIf true and the process aborts, do not report error when writing data. when writing data.

◆ getIgnoreAbort()

bool ts::ForkPipe::getIgnoreAbort ( ) const
inline

Get "ignore abort".

Returns
True if, when the process aborts, do not report error when writing data.

◆ write()

bool ts::ForkPipe::write ( const void *  addr,
size_t  size,
Report report 
)

Write data to the pipe (received at process' standard input).

Parameters
[in]addrAddress of the data to write.
[in]sizeSize in bytes of the data to write.
[in,out]reportWhere to report errors.
Returns
True on success, false on error.

◆ read()

bool ts::ForkPipe::read ( void *  addr,
size_t  max_size,
size_t  unit_size,
size_t &  ret_size,
Report report 
)

Read data from the pipe (sent from process' standard output or error).

Parameters
[out]addrAddress of the buffer for the incoming data.
[in]max_sizeMaximum size in bytes of the buffer.
[in]unit_sizeIf not zero, make sure that the input size is always a multiple of unit_size. If the initial read ends in the middle of a unit, read again and again, up to the end of the current unit or end of file.
[out]ret_sizeReturned input size in bytes.
[in,out]reportWhere to report errors.
Returns
True on success, false on error.

◆ abortPipeReadWrite()

void ts::ForkPipe::abortPipeReadWrite ( )

Abort any currenly input/output operation in the pipe.

The pipe is left in a broken state and can be only closed.

◆ eof()

bool ts::ForkPipe::eof ( ) const
inline

Check if the input pipe is at end of file.

Returns
True if the input pipe is at end of file.

The documentation for this class was generated from the following file: