Operator Console
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Protected Attributes | Private Attributes | List of all members
StdoutRedirect Class Reference

Defines functions for redirecting stdout through a buffered pipe. More...

#include <StdoutRedirect.h>

Inheritance diagram for StdoutRedirect:
[legend]

Public Member Functions

 StdoutRedirect ()
 
virtual ~StdoutRedirect ()
 
void Close ()
 
int Init (int bufferSize)
 
int Start ()
 
int Stop ()
 
int GetBuffer (char *buffer, int size)
 
 StdoutRedirect ()
 
virtual ~StdoutRedirect ()
 
void Close ()
 
int Init (int bufferSize)
 
int Start ()
 
int Stop ()
 
int GetBuffer (char *buffer, int size)
 

Protected Attributes

FILE * file
 stdout (subclasses can set this to something else, e.g. stderr) More...
 

Private Attributes

int fdStdOutPipe [2]
 
int fdStdOut
 
bool isOpen
 

Detailed Description

Defines functions for redirecting stdout through a buffered pipe.

Constructor & Destructor Documentation

StdoutRedirect::StdoutRedirect ( )
51 {
52  isOpen = false;
53  file = stdout;
54 }
bool isOpen
Definition: StdoutRedirect.h:47
FILE * file
stdout (subclasses can set this to something else, e.g. stderr)
Definition: StdoutRedirect.h:42
StdoutRedirect::~StdoutRedirect ( )
virtual

References READ_FD, and WRITE_FD.

40 {
41 #if 0
42  _close(fdStdOut);
43  _close(fdStdOutPipe[WRITE_FD]);
44  _close(fdStdOutPipe[READ_FD]);
45 #else
46  Close();
47 #endif
48 }
#define READ_FD
Definition: StdoutRedirect.cpp:33
#define WRITE_FD
Definition: StdoutRedirect.cpp:34
void Close()
Definition: StdoutRedirect.cpp:64
int fdStdOut
Definition: StdoutRedirect.h:46
int fdStdOutPipe[2]
Definition: StdoutRedirect.h:45
StdoutRedirect::StdoutRedirect ( )
virtual StdoutRedirect::~StdoutRedirect ( )
virtual

Member Function Documentation

void StdoutRedirect::Close ( )

References READ_FD, and WRITE_FD.

Referenced by StdoutThread::Quit().

65 {
66  if (isOpen)
67  {
68  _close(fdStdOut);
69  _close(fdStdOutPipe[WRITE_FD]);
70  _close(fdStdOutPipe[READ_FD]);
71  isOpen = false;
72  }
73 }
#define READ_FD
Definition: StdoutRedirect.cpp:33
#define WRITE_FD
Definition: StdoutRedirect.cpp:34
int fdStdOut
Definition: StdoutRedirect.h:46
bool isOpen
Definition: StdoutRedirect.h:47
int fdStdOutPipe[2]
Definition: StdoutRedirect.h:45

Here is the caller graph for this function:

void StdoutRedirect::Close ( )
int StdoutRedirect::GetBuffer ( char *  buffer,
int  size 
)

References READ_FD.

Referenced by StdoutThread::ThreadProc().

108 {
109  int nOutRead = _read(fdStdOutPipe[READ_FD], buffer, size); // this will block until there is data to read (could cause thread to hang)
110  buffer[nOutRead] = '\0';
111 
112  return nOutRead;
113 }
#define READ_FD
Definition: StdoutRedirect.cpp:33
int fdStdOutPipe[2]
Definition: StdoutRedirect.h:45

Here is the caller graph for this function:

int StdoutRedirect::GetBuffer ( char *  buffer,
int  size 
)
int StdoutRedirect::Init ( int  bufferSize)
int StdoutRedirect::Init ( int  bufferSize)

Referenced by StdoutThread::InitThread().

76 {
77  int error = _pipe(fdStdOutPipe, bufferSize, O_TEXT);
78 
79  if (!error)
80  {
81  fdStdOut = _dup(_fileno(file));
82  isOpen = true;
83  }
84 
85  return error;
86 
87 }
int fdStdOut
Definition: StdoutRedirect.h:46
bool isOpen
Definition: StdoutRedirect.h:47
int fdStdOutPipe[2]
Definition: StdoutRedirect.h:45
FILE * file
stdout (subclasses can set this to something else, e.g. stderr)
Definition: StdoutRedirect.h:42

Here is the caller graph for this function:

int StdoutRedirect::Start ( )
int StdoutRedirect::Start ( )

References CHECK, and WRITE_FD.

Referenced by StdoutThread::InitThread().

90 {
91 #if 0
92  fflush( file );
93 #endif
94  CHECK(_dup2(fdStdOutPipe[WRITE_FD], _fileno(file)));
95  ios::sync_with_stdio();
96  setvbuf( file, NULL, _IONBF, 0 ); // absolutely needed
97  return 0;
98 }
#define CHECK(a)
Definition: StdoutRedirect.cpp:36
#define WRITE_FD
Definition: StdoutRedirect.cpp:34
int fdStdOutPipe[2]
Definition: StdoutRedirect.h:45
FILE * file
stdout (subclasses can set this to something else, e.g. stderr)
Definition: StdoutRedirect.h:42

Here is the caller graph for this function:

int StdoutRedirect::Stop ( )

References CHECK.

Referenced by StdoutThread::Quit().

101 {
102  CHECK(_dup2(fdStdOut, _fileno(file)));
103  ios::sync_with_stdio();
104  return 0;
105 }
#define CHECK(a)
Definition: StdoutRedirect.cpp:36
int fdStdOut
Definition: StdoutRedirect.h:46
FILE * file
stdout (subclasses can set this to something else, e.g. stderr)
Definition: StdoutRedirect.h:42

Here is the caller graph for this function:

int StdoutRedirect::Stop ( )

Member Data Documentation

int StdoutRedirect::fdStdOut
private
int StdoutRedirect::fdStdOutPipe
private
FILE * StdoutRedirect::file
protected

stdout (subclasses can set this to something else, e.g. stderr)

Referenced by StderrRedirect::StderrRedirect(), and StderrThread::StderrThread().

bool StdoutRedirect::isOpen
private

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