summaryrefslogtreecommitdiff
path: root/include/filemgr.h
diff options
context:
space:
mode:
authorTeus Benschop <teusjannette@gmail.com>2018-10-28 11:51:26 +0100
committerTeus Benschop <teusjannette@gmail.com>2018-10-28 11:51:26 +0100
commit1d0ff54794b5edea7cdf1d2d66710a0fa885bcc5 (patch)
tree8ece5f9ef437fbb151f2b22ed0c6e1a714879c7c /include/filemgr.h
parentc7dbdc9161a7c460526b80fe01af49d714856126 (diff)
New upstream version 1.8.1
Diffstat (limited to 'include/filemgr.h')
-rw-r--r--include/filemgr.h121
1 files changed, 76 insertions, 45 deletions
diff --git a/include/filemgr.h b/include/filemgr.h
index eedfbcc..8d0e511 100644
--- a/include/filemgr.h
+++ b/include/filemgr.h
@@ -2,7 +2,7 @@
*
* filemgr.h - definition of class FileMgr used for pooling file handles
*
- * $Id: filemgr.h 2833 2013-06-29 06:40:28Z chrislit $
+ * $Id: filemgr.h 3515 2017-11-01 11:38:09Z scribe $
*
* Copyright 1998-2013 CrossWire Bible Society (http://www.crosswire.org)
* CrossWire Bible Society
@@ -32,7 +32,7 @@
SWORD_NAMESPACE_START
-class SWDLLEXPORT FileMgr;
+class SWDLLEXPORT FileDesc;
struct SWDLLEXPORT DirEntry {
public:
@@ -40,49 +40,23 @@ public:
unsigned long size;
bool isDirectory;
};
-/**
-* This class represents one file. It works with the FileMgr object.
-*/
-class SWDLLEXPORT FileDesc {
-
- friend class FileMgr;
-
- long offset;
- int fd; // -77 closed;
- FileMgr *parent;
- FileDesc *next;
-
- FileDesc(FileMgr * parent, const char *path, int mode, int perms, bool tryDowngrade);
- virtual ~FileDesc();
-
-public:
- /** @return File handle.
- */
- int getFd();
-
- long seek(long offset, int whence);
- long read(void *buf, long count);
- long write(const void *buf, long count);
-
- /** Path to file.
- */
- char *path;
- /** File access mode.
- */
- int mode;
- /** File permissions.
- */
- int perms;
- /**
- */
- bool tryDowngrade;
-};
/**
-* This class ist used make file access operations easier.
-* It keeps a list of all open files internally and closes them
-* when the destructor is called.
-*/
+ * This class isolates all file io for SWORD, making OS
+ * level quirks easier to fix. This class is typically
+ * copied and replaced if necessary to get SWORD to run on
+ * a specific platform (e.g., Windows Mobile), but in
+ * the future, statics should be removed to make possible to
+ * instead simply subclass and override necessary methods.
+ *
+ * This class also provides many convenience methods which
+ * make working with data storage easier.
+ *
+ * Conceptually, this factory exposes an interface which
+ * allows SWORD to 'open' every file it wants, without
+ * worrying about OS limits, and takes care of opening and
+ * closing the actual file descriptors when necessary.
+ */
class SWDLLEXPORT FileMgr : public SWCacher {
friend class FileDesc;
@@ -151,13 +125,13 @@ public:
virtual void flush();
virtual long resourceConsumption();
- /** Checks for the existence of a file.
+ /** Checks for the existence and readability of a file.
* @param ipath Path to file.
* @param ifileName Name of file to check for.
*/
static signed char existsFile(const char *ipath, const char *ifileName = 0);
- /** Checks for the existence of a directory.
+ /** Checks for the existence and readability of a directory.
* @param ipath Path to directory.
* @param idirName Name of directory to check for.
*/
@@ -184,6 +158,63 @@ public:
static int removeFile(const char *fName);
static char getLine(FileDesc *fDesc, SWBuf &line);
+ /**
+ * Determines where SWORD looks for the user's home folder. This is
+ * typically used as a place to find any additional personal SWORD
+ * modules which a user might wish to be added to a system-wide
+ * library (e.g., added from ~/.sword/mods.d/ or ~/sword/mods.d/)
+ *
+ * or if a user or UI wishes to override SWORD system configuration
+ * settings (e.g., /etc/sword.conf) with a custom configuration
+ * (e.g., ~/.sword/sword.conf)
+ */
+ SWBuf getHomeDir();
+
+};
+
+/**
+* This class represents one file. It works with the FileMgr object.
+*/
+class SWDLLEXPORT FileDesc {
+
+ friend class FileMgr;
+
+ long offset;
+ int fd; // -77 closed;
+ FileMgr *parent;
+ FileDesc *next;
+
+ FileDesc(FileMgr * parent, const char *path, int mode, int perms, bool tryDowngrade);
+ virtual ~FileDesc();
+
+public:
+ /** @return File handle.
+ * NOTE: magic file descriptor -77 = closed to avoid os limits
+ */
+ inline int getFd() {
+ if (fd == -77)
+ fd = parent->sysOpen(this);
+// if ((fd < -1) && (fd != -77)) // kludge to handle ce
+// return 777;
+ return fd;
+ }
+
+ long seek(long offset, int whence);
+ long read(void *buf, long count);
+ long write(const void *buf, long count);
+
+ /** Path to file.
+ */
+ char *path;
+ /** File access mode.
+ */
+ int mode;
+ /** File permissions.
+ */
+ int perms;
+ /**
+ */
+ bool tryDowngrade;
};