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

wefts_coffee_unix.h

Go to the documentation of this file.
00001 /*
00002    wefts_coffee_unix.h
00003    Unix implementation for cooperative file functions enlarged enviroment
00004 
00005    $Id: wefts_coffee_unix.h,v 1.2 2003/12/17 17:57:18 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_UNIX_H
00023 #define WT_COFFEE_UNIX_H
00024 
00025 #include <wefts_coffee_base.h>
00026 
00027 #include <sys/select.h>
00028 #include <sys/types.h>
00029 #include <sys/stat.h>
00030 #include <fcntl.h>
00031 
00032 namespace Wefts {
00033 
00041 class OSFileFuncUnix : public OSFileFuncBase
00042 {
00043 protected:
00044    /* Unix file descriptor to the open field */
00045    int m_fd;
00046 
00047    bool waitForWrite()
00048    {
00049       if ( m_timeout < 0 ) return true;
00050       fd_set set;
00051       struct timespec timeout;
00052 
00053       FD_SET( m_fd, &set);
00054       timeout.tv_sec = static_cast<long>(m_timeout);
00055       timeout.tv_nsec = static_cast<long>(
00056          (m_timeout - static_cast<long>(m_timeout)) *1000000000);
00057       pselect(m_fd + 1, NULL, &set, NULL, &timeout, NULL);
00058 
00059       return FD_ISSET( m_fd, &set );
00060    }
00061 
00062 
00063    bool waitForRead()
00064    {
00065       if ( m_timeout < 0 ) return true;
00066       fd_set set;
00067       struct timespec timeout;
00068 
00069       FD_SET( m_fd, &set);
00070       timeout.tv_sec = static_cast<long>(m_timeout);
00071       timeout.tv_nsec = static_cast<long>(
00072          (m_timeout - static_cast<long>(m_timeout)) *1000000000);
00073       pselect(m_fd + 1, &set, NULL, NULL, &timeout, NULL);
00074 
00075       return FD_ISSET( m_fd, &set );
00076    }
00077 
00078 
00079 public:
00080    OSFileFuncUnix( void *descriptor = 0) :
00081          OSFileFuncBase()
00082    {
00083       if ( descriptor != 0 )
00084          setDescriptor( descriptor );
00085    }
00086 
00087    virtual CffStatus open(
00088       std::string filespec,             // the file name
00089       OpenMode openMode = OM_RO,        // open mode
00090       LockMode lockMode = LM_SHARED   // the file lock mode
00091       );
00092 
00093    virtual CffStatus create(
00094       std::string filespec,               // the file name
00095       CreateMode cMode = CM_ARCHIVE,            // system atrribute
00096       LockMode lockMode = LM_EXCLUSIVE  // the file lock mode
00097       );
00098 
00099 
00103    inline virtual void getDescriptor( void *data ) const
00104    {
00105       *static_cast<int *>(data) = m_fd;
00106    }
00107 
00110    inline virtual void setDescriptor( void *data )
00111    {
00112       m_fd = *static_cast<int *>(data);
00113    }
00114 
00115    virtual file_size_t read( void *buffer, const file_size_t len );
00116    virtual file_size_t write( void *buffer, const file_size_t len );
00117    virtual file_size_t seek(
00118       const file_size_t position,
00119       const SeekWhence swFrom= SW_FROM_BEGIN
00120       );
00121    virtual CffStatus close();
00122 
00123    inline virtual void setStdIn() { m_fd = 0; }
00124    inline virtual void setStdOut(){ m_fd = 1; }
00125    inline virtual void setStdErr(){ m_fd = 2; }
00126 
00127 };
00128 
00130 typedef OSFileFuncUnix OSFileFunc;
00131 
00133 } // namespace
00134 
00135 #endif
00136 
00137 /* end of wefts_coffee_unix.h */

Generated on Mon Dec 22 04:12:30 2003 for Wefts by doxygen1.2.18