Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

RWPipe Class Reference

#include <rwpipe.h>

Inheritance diagram for RWPipe:

Inheritance graph
[legend]
List of all members.

Public Member Functions

 RWPipe ()
 ~RWPipe ()
bool run (string command)
bool isRunning ()
int readData (void *data, int size)
int readLine (char *text, int max)
int writeData (void *data, int size)
void stop ()

Protected Attributes

int m_reader
int m_writer
GError * m_error

Private Attributes

int m_pid

Constructor & Destructor Documentation

RWPipe::RWPipe  ) 
 

Definition at line 33 of file rwpipe.cc.

00033                 : m_pid( -1 ), m_error( NULL )
00034 {}

RWPipe::~RWPipe  ) 
 

Definition at line 36 of file rwpipe.cc.

References stop().

00037 {
00038     stop( );
00039 }


Member Function Documentation

bool RWPipe::isRunning  ) 
 

Definition at line 53 of file rwpipe.cc.

References m_pid.

00054 {
00055     return m_pid != -1;
00056 }

int RWPipe::readData void *  data,
int  size
 

Definition at line 58 of file rwpipe.cc.

References m_pid, and m_reader.

Referenced by PipeImport::Get(), PipeImport::Open(), and readLine().

00059 {
00060     if ( m_pid != -1 )
00061     {
00062         int bytes = 0;
00063         int len;
00064         uint8_t *p = ( uint8_t * ) data;
00065 
00066         while ( size > 0 )
00067         {
00068             len = read( m_reader, p, size );
00069             if ( len <= 0 )
00070                 break;
00071             p += len;
00072             size -= len;
00073             bytes += len;
00074         }
00075 
00076         return bytes;
00077     }
00078     else
00079         return -1;
00080 }

int RWPipe::readLine char *  text,
int  max
 

Definition at line 82 of file rwpipe.cc.

References m_pid, and readData().

Referenced by DVPipeTool::load(), and DVDTool::load().

00083 {
00084     int len = -1;
00085     strcpy( text, "" );
00086     if ( m_pid != -1 )
00087     {
00088         while ( len < max - 1 && readData( &text[ ++ len ], 1 ) )
00089             if ( text[ len ] == '\n' )
00090                 break;
00091         text[ len ] = '\0';
00092     }
00093     return len;
00094 }

bool RWPipe::run string  command  ) 
 

Definition at line 41 of file rwpipe.cc.

References m_error, m_pid, m_reader, and m_writer.

Referenced by DVPipeTool::execute(), DVPipeTool::load(), DVDTool::load(), and PipeImport::Open().

00042 {
00043     char * args[ 4 ];
00044 
00045     args[ 0 ] = "/bin/sh";
00046     args[ 1 ] = "-c";
00047     args[ 2 ] = ( char * ) command.c_str( );
00048     args[ 3 ] = NULL;
00049 
00050     return g_spawn_async_with_pipes( ".", args, NULL, G_SPAWN_LEAVE_DESCRIPTORS_OPEN, NULL, NULL, &m_pid, &m_writer, &m_reader, NULL, &m_error );
00051 }

void RWPipe::stop  ) 
 

Definition at line 104 of file rwpipe.cc.

References m_pid, m_reader, and m_writer.

Referenced by DVPipeTool::close(), DVDTool::close(), PipeImport::Close(), DVPipeTool::load(), DVDTool::load(), PipeImport::Open(), PipeImport::~PipeImport(), and ~RWPipe().

00105 {
00106     if ( m_pid != -1 )
00107     {
00108         close( m_reader );
00109         close( m_writer );
00110         waitpid( m_pid, NULL, 0 );
00111         m_pid = -1;
00112     }
00113 }

int RWPipe::writeData void *  data,
int  size
 

Definition at line 96 of file rwpipe.cc.

References m_pid, and m_writer.

Referenced by DVPipeTool::output().

00097 {
00098     if ( m_pid != -1 )
00099         return write( m_writer, ( uint8_t * ) data, size );
00100     else
00101         return -1;
00102 }


Member Data Documentation

GError* RWPipe::m_error [protected]
 

Definition at line 39 of file rwpipe.h.

Referenced by run().

int RWPipe::m_pid [private]
 

Definition at line 34 of file rwpipe.h.

Referenced by isRunning(), readData(), readLine(), run(), stop(), and writeData().

int RWPipe::m_reader [protected]
 

Definition at line 37 of file rwpipe.h.

Referenced by readData(), run(), and stop().

int RWPipe::m_writer [protected]
 

Definition at line 38 of file rwpipe.h.

Referenced by run(), stop(), and writeData().


The documentation for this class was generated from the following files:
Generated on Sun Mar 11 22:13:24 2007 for Kino by  doxygen 1.4.2