wefts_coffee_base.h

Go to the documentation of this file.
00001 /* 00002 wefts_coffee_base.h 00003 Abstract base class for cooperative file functions enlarged environment 00004 00005 $Id: wefts_coffee_base.h,v 1.6 2004/04/01 04:30:17 jonnymind Exp $ 00006 --------------------------------------------- 00007 Begin : 2003-08-15 16:30 00008 Author : Giancarlo Niccolai 00009 00010 Last modified because: 00011 00012 */ 00013 00014 /************************************************************************** 00015 * This program is free software; you can redistribute it and/or modify * 00016 * it under the terms of the GNU Library General Public License as * 00017 * published by the Free Software Foundation; either version 2.1 of the * 00018 * License, or (at your option) any later version. * 00019 ***************************************************************************/ 00020 00021 00022 #ifndef WT_COFFEE_BASE_H 00023 #define WT_COFFEE_BASE_H 00024 00025 #include <wefts_cleanup.h> 00026 #include <string> 00027 00043 namespace Wefts { 00044 00050 #if defined(_MSC_VER) || defined(__BORLANDC__) 00051 typedef unsigned __int64 file_size_t; 00052 #else 00053 typedef long long file_size_t; 00054 #endif 00055 00057 typedef enum { 00058 /* The file should not be locked */ 00059 LM_SHARED, 00060 /* The file should not be locked against writes, but read may occur */ 00061 LM_SHARED_RO, 00062 /* The file should not be locked against both reads & writes */ 00063 LM_EXCLUSIVE, 00064 } LockMode; 00065 00066 00068 typedef enum { 00070 OM_RO, 00072 OM_WO, 00074 OM_RW, 00079 OM_TRUNC_WO, 00084 OM_TRUNC_RW, 00086 OM_APPEND_WO, 00088 OM_APPEND_RW 00089 } OpenMode; 00090 00109 typedef enum { 00111 CM_ARCHIVE, 00113 CM_SYSTEM, 00120 CM_EXECUTABLE, 00122 CM_PRIVATE, 00124 CM_PRIVATE_EX 00125 } CreateMode; 00126 00127 00143 typedef enum { 00145 CFF_DONE, 00148 CFF_WAITING, 00158 CFF_TIMEDOUT, 00159 00165 CFF_SOFTERROR, 00166 00170 CFF_HARDERROR, 00171 00188 CFF_PROGERROR 00189 }CffStatus; 00190 00192 typedef enum { 00194 SW_FROM_BEGIN=0, 00196 SW_FROM_CUR=1, 00198 SW_FROM_CURENT=1, 00200 SW_FROM_END=2 00201 } SeekWhence; 00202 00225 class OSFileFuncBase { 00226 protected: 00237 OSFileFuncBase() { 00238 m_timeout = -1.0; 00239 m_osError = 0; 00240 m_status = CFF_DONE; 00241 } 00242 00243 double m_timeout; 00244 CffStatus m_status; 00245 int m_osError; 00246 00247 public: 00280 virtual inline CffStatus open( 00281 std::string filespec, // the file name 00282 OpenMode openMode = OM_RO, // open mode 00283 LockMode lockMode = LM_SHARED // the file lock mode 00284 ) = 0; 00285 00315 virtual inline CffStatus create( 00316 std::string filespec, // the file name 00317 CreateMode cMode = CM_ARCHIVE, // system atrribute 00318 LockMode lockMode = LM_EXCLUSIVE // the file lock mode 00319 ) = 0; 00320 00333 inline virtual void getDescriptor( void *data ) const = 0; 00334 00347 inline virtual void setDescriptor( void *data ) = 0; 00348 00349 00351 inline CffStatus status() const { return m_status; } 00352 00357 inline void status(const CffStatus st ) { m_status = st ; } 00358 00367 inline int osError() const { return m_osError; } 00368 00372 inline void osError( const int osError ) { m_osError = osError; } 00373 00374 00376 inline double timeout() const { return m_timeout; } 00377 00388 inline void timeout( const double to ) { m_timeout = to; } 00389 00390 /* Clears the timeout. 00391 All the operations on this class will be blocking. 00392 */ 00393 inline void clearTimeout() { timeout( -1.0 ); } 00394 00395 /* Set all operations on this class to be non-blocking. 00396 Functions will return immediately if the operation cannot be 00397 compelted without any wait. 00398 */ 00399 inline void dontBlock() { timeout( 0.0 ); } 00400 00414 virtual file_size_t read( void *buffer, const file_size_t len ) = 0; 00415 00430 virtual file_size_t write( void *buffer, const file_size_t len ) = 0; 00431 00439 virtual file_size_t seek( 00440 const file_size_t position, 00441 const SeekWhence swFrom= SW_FROM_BEGIN 00442 ) = 0; 00443 00445 virtual CffStatus close()=0; 00446 00451 inline virtual void setStdIn() = 0; 00452 00457 inline virtual void setStdOut() = 0; 00458 00463 inline virtual void setStdErr() = 0; 00464 00465 }; 00466 00488 class OSProcessBase: public CleanupHandler 00489 { 00490 private: 00491 void internal_init() 00492 { 00493 m_started = false; 00494 m_ended = false; 00495 m_mergeStdErr = false; 00496 m_retval = -1; 00497 m_osError = 0; 00498 m_detached = false; 00499 } 00500 00501 protected: 00503 int m_osError; 00504 bool m_started; 00505 bool m_ended; 00506 bool m_mergeStdErr; 00507 int m_retval; 00508 bool m_detached; 00510 OSProcessBase() 00511 :CleanupHandler() 00512 { 00513 internal_init(); 00514 } 00515 00516 public: 00517 00521 virtual bool running()=0; 00522 00545 virtual bool wait( const double seconds=-1.0 )=0; 00546 00558 virtual bool start( const std::string process, bool useShell=false, bool usePath=true )=0; 00559 00565 virtual bool stop()=0; 00566 00571 virtual bool getProcessValue( int &retvalue ) const=0; 00572 00574 int osError() const { return m_osError; } 00575 00593 virtual file_size_t getProcessId() const =0; 00594 00604 virtual int write( const void *data, const int size, const double seconds=-1.0 )=0; 00605 00620 virtual int read( void *data, const int size, const double seconds=-1.0 )=0; 00621 00639 virtual int readStdErr( void *data, const int size, const double seconds=-1.0 )=0; 00640 00648 virtual void mergeStdErr()=0; 00649 00658 virtual void detach()=0; 00659 00663 virtual void sinkInput() = 0; 00667 virtual void sinkOutput() = 0; 00671 virtual void sinkError() = 0; 00672 00673 virtual bool closeRead()=0; 00674 virtual bool closeWrite()=0; 00675 virtual bool closeStdErr()=0; 00676 00677 virtual void handleCleanup( int code, void *caller=0 ) = 0; 00678 }; 00679 00681 } // namespace 00682 00683 #endif 00684 00685 /* end of wefts_coffee_base.h */

Generated on Tue Oct 5 14:57:00 2004 for Wefts by doxygen 1.3.7