Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

BlackBox Class Reference

#include <BlackBox.h>

List of all members.

Public Methods

 BlackBox (const Chars &startCommand, const Chars &restartCommand)
 BlackBox (const Chars &startCommand)
 ~BlackBox ()
Bool start (const char *greeting=NULL)
Bool restart (const char *greeting=NULL)
Bool stillRunning ()
ostream& toCommand ()
istream& fromCommand ()

Private Methods

void initialize (const Chars &startCommand, const Chars &restartCommand)
Bool doStart (const Chars &command, const char *greeting)
void closeStreams ()
Bool checkGreeting (const char *greeting)
 BlackBox (const BlackBox &)
 Copy constructor is prohibited.

BlackBox& operator= (const BlackBox &)
 Assignment operator is prohibited.

Private Attributes

int status
 1 means good, 0 means bad.

Bool started_p
 Set to TRUE when start is attempted.

Chars theStartCmd
 sh command to start executable.

Chars theRestartCmd
 sh command to restart executable.

ofstream* streamToCommand
 Bound to command's cin, or NULL.

ifstream* streamFromCommand
 Bound to command's cout, or NULL.

char fyle_in [100]
 Name of pipe bound to command's cin.

char fyle_out [100]
 Name of pipe bound to command's cout.

Detailed Description

A BlackBox is a wrapper for an external binary which communicates exclusively through its standard I/O. The binary must accept some sort of `quit' command from its standard input.

Definition at line 49 of file BlackBox.h.

Constructor & Destructor Documentation

BlackBox::BlackBox ( const Chars & startCommand,
const Chars & restartCommand )

Instantiate a BlackBox by supplying sh commands which start and restart the executable. The executable is actually invoked by the start and restart methods.

BlackBox::BlackBox ( const Chars & startCommand )

A version of the above where the restart command is the same as the start command, or undesired.

BlackBox::~BlackBox ( )

Unlink the pipes, thus killing the executable.

BlackBox::BlackBox ( const BlackBox & ) [inline, private]

Copy constructor is prohibited.

Definition at line 122 of file BlackBox.h.

Member Function Documentation

Bool BlackBox::start ( const char * greeting = NULL )

Invoke the executable with the startCommand argument to the constructor. This attaches named pipes to the executable's standard i/o. The arg is a (possibly proper) prefix of the first non-blank line you expect the binary to write to cout. We might use regexps some day. This returns TRUE iff it finds the greeting (if not NULL), and all other initialization was successful. If you call this a second time, it just returns the status: TRUE == good.

Bool BlackBox::restart ( const char * greeting = NULL )

Unlink the pipes which were attached by start or any previous restart, thus killing the executable. Invoke the executable again with the restartCommand argument to the constructor, and re-attach the pipes. The arg is the same as for start. If you call this before you call start, it fails and returns FALSE.

Bool BlackBox::stillRunning ( )

This attempts to determine whether the executable is still running.

ostream & BlackBox::toCommand ( )

Returns an ostream bound to the binary's standard input.

istream & BlackBox::fromCommand ( )

Returns an istream bound to the binary's standard output.

void BlackBox::initialize ( const Chars & startCommand,
const Chars & restartCommand ) [private]

Bool BlackBox::doStart ( const Chars & command,
const char * greeting ) [private]

void BlackBox::closeStreams ( ) [private]

Bool BlackBox::checkGreeting ( const char * greeting ) [private]

BlackBox & BlackBox::operator= ( const BlackBox & ) [inline, private]

Assignment operator is prohibited.

Definition at line 126 of file BlackBox.h.

Member Data Documentation

int BlackBox::status [private]

1 means good, 0 means bad.

Definition at line 98 of file BlackBox.h.

Bool BlackBox::started_p [private]

Set to TRUE when start is attempted.

Definition at line 99 of file BlackBox.h.

Chars BlackBox::theStartCmd [private]

sh command to start executable.

Definition at line 101 of file BlackBox.h.

Chars BlackBox::theRestartCmd [private]

sh command to restart executable.

Definition at line 102 of file BlackBox.h.

ofstream * BlackBox::streamToCommand [private]

Bound to command's cin, or NULL.

Definition at line 104 of file BlackBox.h.

ifstream * BlackBox::streamFromCommand [private]

Bound to command's cout, or NULL.

Definition at line 105 of file BlackBox.h.

char BlackBox::fyle_in [private]

Name of pipe bound to command's cin.

Definition at line 109 of file BlackBox.h.

char BlackBox::fyle_out [private]

Name of pipe bound to command's cout.

Definition at line 110 of file BlackBox.h.

The documentation for this class was generated from the following file:
Generated at Tue Jun 19 09:49:48 2001 for Magnus Classes by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001