class KProcIO

# class KProcIO | A slightly simpler interface to KProcess. More...
Definition | `#include <kprocio.h>`
Inherits | KProcess [public ]
List of all Methods
Annotated List
Files
Globals
Hierarchy
Index

#### Public Methods

- KProcIO ( QTextCodec *codec = 0 )
- ~KProcIO ()
- bool start (RunMode runmode = NotifyOnExit, bool includeStderr = false)
- bool writeStdin (const QString &line, bool appendnewline=TRUE)
- bool writeStdin (const QCString &line, bool appendnewline)
- bool writeStdin (const QByteArray &data)
- bool fputs (const QString &line, bool AppendNewLine=TRUE)
- void closeWhenDone ()
- int readln (QString &line, bool autoAck=true, bool *partial=0)
- int fgets (QString &line, bool autoAck=false)
- void resetAll ()
- void ackRead ()
- void enableReadSignals (bool enable)

#### Signals

- void readReady (KProcIO *pio)

#### Protected Methods

- void controlledEmission ()
- virtual void virtual_hook ( int id, void* data )

#### Protected Slots

- void received (KProcess *proc, char *buffer, int buflen)
- void sent (KProcess *)

#### Protected Members

- QPtrList outbuffer
- QCString recvbuffer
- QTextCodec *codec
- int rbi
- bool needreadsignal
- bool readsignalon
- bool writeready

## Detailed Description

KProcIO

This class provides a slightly simpler interface to the communication functions provided by KProcess. The simplifications are:

- The buffer for a write is copied to an internal KProcIO buffer and maintained/freed appropriately. There is no need to be concerned with wroteStdin() signals _at_all_.
- readln() reads a line of data and buffers any leftovers.
- Conversion from/to unicode.

Basically, KProcIO gives you buffered I/O similar to fgets()/fputs().

Aside from these, and the fact that start() takes different parameters, use this class just like KProcess.

KProcIO ( QTextCodec *codec = 0 ) | ### KProcIO

~KProcIO () | ### ~KProcIO

bool start (RunMode runmode = NotifyOnExit, bool includeStderr = false) | ### start

Starts the process. It will fail in the following cases:

- The process is already running.
- The command line argument list is empty.
- The starting of the process failed (could not fork).
- The executable was not found.

Parameters:

runmode | For a detailed description of the various run modes, have a look at the general description of the KProcess class.
includeStderr | If true, data from both stdout and stderr is listened to. If false, only stdout is listened to.

Returns: true on success, false on error.

Reimplemented from KProcess.

bool writeStdin (const QString &line, bool appendnewline=TRUE) | ### writeStdin

Writes text to stdin of the process.

Parameters:

line | Text to write.
appendnewline | if true, a newline '\n' is appended.

Returns: true if successful, false otherwise

Reimplemented from KProcess.

bool writeStdin (const QCString &line, bool appendnewline) | ### writeStdin

Writes text to stdin of the process.

Parameters:

line | Text to write.
appendnewline | if true, a newline '\n' is appended.

Returns: true if successful, false otherwise

Reimplemented from KProcess.

bool writeStdin (const QByteArray &data) | ### writeStdin

Writes data to stdin of the process.

Parameters:

data | Data to write.

Returns: true if successful, false otherwise

Reimplemented from KProcess.

bool fputs (const QString &line, bool AppendNewLine=TRUE) | ### fputs

This function just calls writeStdin().

Parameters:

line | Text to write.
AppendNewLine | if true, a newline '\n' is appended.

Returns: true if successful, false otherwise

void closeWhenDone () | ### closeWhenDone

closes stdin after all data has been send.

int readln (QString &line, bool autoAck=true, bool *partial=0) | ### readln

Reads a line of text (up to and including '\n').

Use readln() in response to a readReady() signal. You may use it multiple times if more than one line of data is available. Be sure to use ackRead() when you have finished processing the readReady() signal. This informs KProcIO that you are ready for another readReady() signal.

readln() never blocks.

autoAck==TRUE makes these functions call ackRead() for you.

Parameters:

line | is used to store the line that was read.
autoAck | when true, ackRead() is called for you.
partial | when provided the line is returned even if it does not contain a '\n'. *partial will be set to false if the line contains a '\n' and false otherwise.

Returns: the number of characters read, or -1 if no data is available.

int fgets (QString &line, bool autoAck=false) | ### fgets

This function calls readln().

Parameters:

line | is used to store the line that was read.
autoAck | when true, ackRead() is called for you.
partial | when provided the line is returned even if it does not contain a '\n'. *partial will be set to false if the line contains a '\n' and false otherwise.

Returns: the number of characters read, or -1 if no data is available.

void resetAll () | ### resetAll

Reset the class. Doesn't kill the process.

void ackRead () | ### ackRead

Call this after you have finished processing a readReady() signal. This call need not be made in the slot that was signalled by readReady(). You won't receive any more readReady() signals until you acknowledge with ackRead(). This prevents your slot from being reentered while you are still processing the current data. If this doesn't matter, then call ackRead() right away in your readReady()-processing slot.

void enableReadSignals (bool enable) | ### enableReadSignals

Turns readReady() signals on and off. You can turn this off at will and not worry about losing any data. (as long as you turn it back on at some point...)

Parameters:

enable | true to turn the signals on, false to turn them off

void readReady (KProcIO *pio) | ### readReady

[signal]

Emitted when the process is ready for reading.

Parameters:

pio | the process that emitted the signal

See also: enableReadSignals()

QPtrList<QByteArray> outbuffer | ### outbuffer

[protected]

QCString recvbuffer | ### recvbuffer

[protected]

QTextCodec * codec | ### codec

[protected]

int rbi | ### rbi

[protected]

bool needreadsignal | ### needreadsignal

[protected]

bool readsignalon | ### readsignalon

[protected]

bool writeready | ### writeready

[protected]

void controlledEmission () | ### controlledEmission

[protected]

void received (KProcess *proc, char *buffer, int buflen) | ### received

[protected slots slot]

void sent (KProcess *) | ### sent

[protected slots slot]

void virtual_hook ( int id, void* data ) | ### virtual_hook

[protected virtual]

Reimplemented from KProcess.

- Version: $Id: kprocio.h,v 1.15 2002/09/10 19:17:01 tjansen Exp $
- Author: David Sweet
- Generated: root on macppc.ports.openbsd.org on Sat Sep 6 10:36:15 2003, using kdoc 2.0a54.