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.6 2004/03/17 11:52:19 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 00033 namespace Wefts { 00034 00035 00052 class OSFileFuncUnix : public OSFileFuncBase 00053 { 00054 protected: 00055 /* Unix file descriptor to the open field */ 00056 int m_fd; 00057 00058 #ifndef HAVE_PSELECT 00059 int pselect(int n, fd_set *r, fd_set *w, fd_set *e, struct timespec * ti, void * mask) 00060 { 00061 struct timeval to; 00062 00063 to.tv_sec = ti->tv_sec; 00064 to.tv_usec = ti->tv_nsec / 1000; 00065 return select(n, r, w, e, &to); 00066 } 00067 #endif // ifndef HAVE_PSELECT 00068 00069 bool waitForWrite() 00070 { 00071 if ( m_timeout < 0 ) return true; 00072 fd_set set; 00073 struct timespec timeout; 00074 00075 FD_ZERO( &set ); 00076 FD_SET( m_fd, &set); 00077 timeout.tv_sec = static_cast<long>(m_timeout); 00078 timeout.tv_nsec = static_cast<long>( 00079 (m_timeout - static_cast<long>(m_timeout)) *1000000000); 00080 pselect(m_fd + 1, NULL, &set, NULL, &timeout, NULL); 00081 00082 return FD_ISSET( m_fd, &set ); 00083 } 00084 00085 00086 bool waitForRead() 00087 { 00088 if ( m_timeout < 0 ) return true; 00089 fd_set set; 00090 struct timespec timeout; 00091 00092 FD_ZERO( &set ); 00093 FD_SET( m_fd, &set); 00094 timeout.tv_sec = static_cast<long>(m_timeout); 00095 timeout.tv_nsec = static_cast<long>( 00096 (m_timeout - static_cast<long>(m_timeout)) *1000000000); 00097 pselect(m_fd + 1, &set, NULL, NULL, &timeout, NULL); 00098 00099 return FD_ISSET( m_fd, &set ); 00100 } 00101 00102 00103 public: 00104 OSFileFuncUnix( void *descriptor = 0) : 00105 OSFileFuncBase() 00106 { 00107 if ( descriptor != 0 ) 00108 setDescriptor( descriptor ); 00109 } 00110 00111 virtual CffStatus open( 00112 std::string filespec, // the file name 00113 OpenMode openMode = OM_RO, // open mode 00114 LockMode lockMode = LM_SHARED // the file lock mode 00115 ); 00116 00117 virtual CffStatus create( 00118 std::string filespec, // the file name 00119 CreateMode cMode = CM_ARCHIVE, // system atrribute 00120 LockMode lockMode = LM_EXCLUSIVE // the file lock mode 00121 ); 00122 00123 00127 inline virtual void getDescriptor( void *data ) const 00128 { 00129 *static_cast<int *>(data) = m_fd; 00130 } 00131 00134 inline virtual void setDescriptor( void *data ) 00135 { 00136 m_fd = *static_cast<int *>(data); 00137 } 00138 00139 virtual file_size_t read( void *buffer, const file_size_t len ); 00140 virtual file_size_t write( void *buffer, const file_size_t len ); 00141 virtual file_size_t seek( 00142 const file_size_t position, 00143 const SeekWhence swFrom= SW_FROM_BEGIN 00144 ); 00145 virtual CffStatus close(); 00146 00147 inline virtual void setStdIn() { m_fd = 0; } 00148 inline virtual void setStdOut(){ m_fd = 1; } 00149 inline virtual void setStdErr(){ m_fd = 2; } 00150 00151 }; 00152 00154 typedef OSFileFuncUnix OSFileFunc; 00155 00157 } // namespace 00158 00159 #endif 00160 00161 /* end of wefts_coffee_unix.h */

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