Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

filemgr.h

00001 /******************************************************************************
00002  *  filemgr.h   - definition of class FileMgr used for pooling file handles
00003  *
00004  * $Id: filemgr_8h-source.html,v 1.7 2002/06/20 20:23:08 mgruner Exp $
00005  *
00006  * Copyright 1998 CrossWire Bible Society (http://www.crosswire.org)
00007  *      CrossWire Bible Society
00008  *      P. O. Box 2528
00009  *      Tempe, AZ  85280-2528
00010  *
00011  * This program is free software; you can redistribute it and/or modify it
00012  * under the terms of the GNU General Public License as published by the
00013  * Free Software Foundation version 2.
00014  *
00015  * This program is distributed in the hope that it will be useful, but
00016  * WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  * General Public License for more details.
00019  *
00020  */
00021 
00022 #ifndef FILEMGR_H
00023 #define FILEMGR_H
00024 
00025 #include <sys/stat.h>
00026 #include <fcntl.h>
00027 
00028 #include <defs.h>
00029 
00030 class SWDLLEXPORT FileMgr;
00031 
00032 class SWDLLEXPORT FileDesc
00033 {
00034 
00035   friend class FileMgr;
00036 
00037   long offset;
00038   int fd;                       // -77 closed;
00039   FileMgr *parent;
00040   FileDesc *next;
00041 
00042 public:
00043    FileDesc (FileMgr * parent, char *path, int mode, int perms, bool tryDowngrade);
00044    virtual ~FileDesc ();
00045   int getFd ();
00046   char *path;
00047   int mode;
00048   int perms;
00049   bool tryDowngrade;
00050 };
00051 
00052 
00053 class FileMgr
00054 {
00055 
00056   friend class FileDesc;
00057 
00058   FileDesc *files;
00059   int sysOpen (FileDesc * file);
00060 public:
00061 
00062     FileMgr (int maxFiles = 35);
00063    ~FileMgr ();
00064   FileDesc *open (char *path, int mode, bool tryDowngrade);
00065   FileDesc *open (char *path, int mode, int perms = S_IREAD | S_IWRITE, bool tryDowngrade = false);
00066   void close (FileDesc *);
00067 
00068   static signed char existsFile (const char *ipath, const char *ifileName = 0);
00069   static signed char existsDir (const char *ipath, const char *idirName = 0);
00070   // to truncate a file at its current position
00071   // leaving byte at current possition intact
00072   // deleting everything afterward.
00073   signed char trunc (FileDesc *);
00074 
00075   int maxFiles;
00076   static FileMgr systemFileMgr;
00077 };
00078 
00079 
00080 
00081 
00082 #endif

Generated on Thu Jun 20 22:12:59 2002 for The Sword Project by doxygen1.2.15