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

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 enviroment
00004 
00005    $Id: wefts_coffee_base.h,v 1.3 2004/03/08 20:28:53 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 shuold not be locked */
00059    LM_SHARED,
00060    /* The file shuold not be locked against writes, but read may occour */
00061    LM_SHARED_RO,
00062    /* The file shuold 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 
00468 } // namespace
00469 
00470 #endif
00471 
00472 /* end of wefts_coffee_base.h */

Generated on Sat Mar 13 21:05:43 2004 for Wefts by doxygen 1.3.5