Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class 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.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_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 
00050 class OSFileFuncUnix : public OSFileFuncBase
00051 {
00052 protected:
00053    /* Unix file descriptor to the open field */
00054    int m_fd;
00055 
00056    bool waitForWrite()
00057    {
00058       if ( m_timeout < 0 ) return true;
00059       fd_set set;
00060       struct timespec timeout;
00061 
00062       FD_SET( m_fd, &set);
00063       timeout.tv_sec = static_cast<long>(m_timeout);
00064       timeout.tv_nsec = static_cast<long>(
00065          (m_timeout - static_cast<long>(m_timeout)) *1000000000);
00066       pselect(m_fd + 1, NULL, &set, NULL, &timeout, NULL);
00067 
00068       return FD_ISSET( m_fd, &set );
00069    }
00070 
00071 
00072    bool waitForRead()
00073    {
00074       if ( m_timeout < 0 ) return true;
00075       fd_set set;
00076       struct timespec timeout;
00077 
00078       FD_SET( m_fd, &set);
00079       timeout.tv_sec = static_cast<long>(m_timeout);
00080       timeout.tv_nsec = static_cast<long>(
00081          (m_timeout - static_cast<long>(m_timeout)) *1000000000);
00082       pselect(m_fd + 1, &set, NULL, NULL, &timeout, NULL);
00083 
00084       return FD_ISSET( m_fd, &set );
00085    }
00086 
00087 
00088 public:
00089    OSFileFuncUnix( void *descriptor = 0) :
00090          OSFileFuncBase()
00091    {
00092       if ( descriptor != 0 )
00093          setDescriptor( descriptor );
00094    }
00095 
00096    virtual CffStatus open(
00097       std::string filespec,             // the file name
00098       OpenMode openMode = OM_RO,        // open mode
00099       LockMode lockMode = LM_SHARED   // the file lock mode
00100       );
00101 
00102    virtual CffStatus create(
00103       std::string filespec,               // the file name
00104       CreateMode cMode = CM_ARCHIVE,            // system atrribute
00105       LockMode lockMode = LM_EXCLUSIVE  // the file lock mode
00106       );
00107 
00108 
00112    inline virtual void getDescriptor( void *data ) const
00113    {
00114       *static_cast<int *>(data) = m_fd;
00115    }
00116 
00119    inline virtual void setDescriptor( void *data )
00120    {
00121       m_fd = *static_cast<int *>(data);
00122    }
00123 
00124    virtual file_size_t read( void *buffer, const file_size_t len );
00125    virtual file_size_t write( void *buffer, const file_size_t len );
00126    virtual file_size_t seek(
00127       const file_size_t position,
00128       const SeekWhence swFrom= SW_FROM_BEGIN
00129       );
00130    virtual CffStatus close();
00131 
00132    inline virtual void setStdIn() { m_fd = 0; }
00133    inline virtual void setStdOut(){ m_fd = 1; }
00134    inline virtual void setStdErr(){ m_fd = 2; }
00135 
00136 };
00137 
00139 typedef OSFileFuncUnix OSFileFunc;
00140 
00142 } // namespace
00143 
00144 #endif
00145 
00146 /* end of wefts_coffee_unix.h */

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