home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / k3bactivepipe.h < prev    next >
Encoding:
C/C++ Source or Header  |  2008-05-27  |  3.1 KB  |  135 lines

  1. /* 
  2.  *
  3.  * $Id: sourceheader 511311 2006-02-19 14:51:05Z trueg $
  4.  * Copyright (C) 2006 Sebastian Trueg <trueg@k3b.org>
  5.  *
  6.  * This file is part of the K3b project.
  7.  * Copyright (C) 1998-2007 Sebastian Trueg <trueg@k3b.org>
  8.  *
  9.  * This program is free software; you can redistribute it and/or modify
  10.  * it under the terms of the GNU General Public License as published by
  11.  * the Free Software Foundation; either version 2 of the License, or
  12.  * (at your option) any later version.
  13.  * See the file "COPYING" for the exact licensing terms.
  14.  */
  15.  
  16. #ifndef _K3B_ACTIVE_PIPE_H_
  17. #define _K3B_ACTIVE_PIPE_H_
  18.  
  19. #include <qcstring.h>
  20.  
  21. #include <k3b_export.h>
  22.  
  23.  
  24. class QIODevice;
  25.  
  26.  
  27. /**
  28.  * The active pipe pumps data from a source to a sink using an
  29.  * additional thread.
  30.  */
  31. class LIBK3B_EXPORT K3bActivePipe
  32. {
  33.  public:
  34.   K3bActivePipe();
  35.   virtual ~K3bActivePipe();
  36.  
  37.   /**
  38.    * Opens the pipe and thus starts the 
  39.    * pumping.
  40.    *
  41.    * \param closeWhenDone If true the pipes will be closed
  42.    *        once all data has been read.
  43.    */
  44.   virtual bool open( bool closeWhenDone = false );
  45.  
  46.   /**
  47.    * Opens the pipe syncroneously and blocks until all data has been
  48.    * pumped through.
  49.    * The pipe is closed afterwards.
  50.    */
  51.   bool pumpSync();
  52.  
  53.   /**
  54.    * Close the pipe
  55.    */
  56.   virtual void close();
  57.  
  58.   /**
  59.    * Set the file descriptor to read from. If this is -1 (the default) then
  60.    * data has to be piped into the in() file descriptor.
  61.    *
  62.    * \param fd The file descriptor to read from.
  63.    * \param close If true the reading file descriptor will be closed on a call to close()
  64.    */
  65.   void readFromFd( int fd, bool close = false );
  66.  
  67.   /**
  68.    * Set the file descriptor to write to. If this is -1 (the default) then
  69.    * data has to read from the out() file descriptor.
  70.    *
  71.    * \param fd The file descriptor to write to.
  72.    * \param close If true the reading file descriptor will be closed on a call to close()
  73.    */
  74.   void writeToFd( int fd, bool close = false );
  75.  
  76.   /**
  77.    * Read from a QIODevice instead of a file descriptor.
  78.    * The device will be opened IO_ReadOnly and closed
  79.    * afterwards.
  80.    */
  81.   void readFromIODevice( QIODevice* dev );
  82.  
  83.   /**
  84.    * Write to a QIODevice instead of a file descriptor.
  85.    * The device will be opened IO_WriteOnly and closed
  86.    * afterwards.
  87.    */
  88.   void writeToIODevice( QIODevice* dev );
  89.  
  90.   /**
  91.    * The file descriptor to write into
  92.    * Only valid if no source has been set
  93.    */
  94.   int in() const;
  95.  
  96.   /**
  97.    * The file descriptor to read from
  98.    * Only valid if no sink has been set
  99.    */
  100.   int out() const;
  101.  
  102.   /**
  103.    * The number of bytes that have been read.
  104.    */
  105.   Q_UINT64 bytesRead() const;
  106.  
  107.   /**
  108.    * The number of bytes that have been written.
  109.    */
  110.   Q_UINT64 bytesWritten() const;
  111.  
  112.  protected:
  113.   /**
  114.    * Reads the data from the source.
  115.    * The default implementation reads from the file desc
  116.    * set via readFromFd or from in()
  117.    */
  118.   virtual int read( char* data, int max );
  119.  
  120.   /**
  121.    * Write the data to the sink.
  122.    * The default implementation writes to the file desc
  123.    * set via writeToFd or out()
  124.    *
  125.    * Can be reimplememented to further process the data.
  126.    */
  127.   virtual int write( char* data, int max );
  128.  
  129.  private:
  130.   class Private;
  131.   Private* d;
  132. };
  133.  
  134. #endif
  135.