~ubuntu-branches/debian/squeeze/sword/squeeze

« back to all changes in this revision

Viewing changes to include/filemgr.h

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Marsden, Jonathan Marsden, Dmitrijs Ledkovs, Closed Bugs
  • Date: 2009-05-30 11:55:55 UTC
  • mfrom: (1.3.1 upstream) (6.1.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20090530115555-r427zsn3amivdpfu
Tags: 1.6.0+dfsg-1
[ Jonathan Marsden ]
* New upstream release. (Closes: #507960) (LP: #320558)
* debian/patches/02_libver.diff:
  - Bump SONAME to 8 -- SWORD 1.6 is not backward compatible with 1.5.11.
* debian/patches/series:
  - Remove 10_diatheke.diff -- included in upstream source.
* debian/patches/:
  - Remove several old unused .diff files.
  - Add 11_regex_only_when_needed.diff to conditionally include regex lib.
  - Add 12_fix_compiler_warnings.diff to remove all compiler warnings.
  - Add 13_fix_osis2mod_compression_default.diff from upstream svn.
  - Add 14_closing_section_not_chapter.diff from upstream svn.
* debian/libsword7.*: 
  - Rename to libsword8.*
  - Change libsword7 to libsword8 within files.
* debian/rules: 
  - SONAME bump to 8.
  - Set library version check to >= 1.6
* debian/control:
  - Change libsword7 to libsword8.
  - Add libsword7 to Conflicts.
  - Fix case of sword to SWORD in package descriptions.
  - Bump Standards-Version to 3.8.1 (no changes needed).
  - Fix section for libsword-dbg to avoid lintian warning.
* debian/rules:
  - Add DFSG get-orig-source target.
* debian/copyright:
  - Fix various mistakes in initial attempt to document copyrights.

[ Dmitrijs Ledkovs ]
* debian/rules: Added utils.mk to use missing-files target and call it on
  each build.
* debian/libsword-dev.install: Added libsword.la, previously missing.
* debian/libsword7.install: Added missing libicu translit files.
* debian/control:
  - Updated all uses of SWORD version to 1.6
  - Added libsword-dbg package
* debian/watch: Fixed a small mistake which was resulting in extra "."
  in final version name.
* debian/rules: simplified manpage processing.
* debian/libsword8.lintian-overrides: added override for module
  installation directory.
* debian/copyright: Updated with information about everyfile.
  Closes: #513448 LP: #322638
* debian/diatheke.examples: moved examples here from the diatheke.install
* debian/rules:
  - enabled shell script based testsuite
  - added commented out cppunit testsuite
* debian/patches/40_missing_includes.diff: 
  - added several missing stdio.h includes to prevent FTBFS of testsuite.

[ Closed Bugs ]
* FTBFS on intrepid (LP: #305172)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/******************************************************************************
 
2
*  filemgr.h   - definition of class FileMgr used for pooling file handles
 
3
*
 
4
* $Id: filemgr.h 2295 2009-03-29 17:11:27Z scribe $
 
5
*
 
6
* Copyright 1998 CrossWire Bible Society (http://www.crosswire.org)
 
7
*       CrossWire Bible Society
 
8
*       P. O. Box 2528
 
9
*       Tempe, AZ  85280-2528
 
10
*
 
11
* This program is free software; you can redistribute it and/or modify it
 
12
* under the terms of the GNU General Public License as published by the
 
13
* Free Software Foundation version 2.
 
14
*
 
15
* This program is distributed in the hope that it will be useful, but
 
16
* WITHOUT ANY WARRANTY; without even the implied warranty of
 
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
18
* General Public License for more details.
 
19
*
 
20
*/
 
21
 
 
22
#ifndef FILEMGR_H
 
23
#define FILEMGR_H
 
24
 
 
25
#include <sys/stat.h>
 
26
#include <fcntl.h>
 
27
 
 
28
#include <defs.h>
 
29
#include <swcacher.h>
 
30
#include <swbuf.h>
 
31
 
 
32
SWORD_NAMESPACE_START
 
33
 
 
34
class SWDLLEXPORT FileMgr;
 
35
 
 
36
struct SWDLLEXPORT DirEntry {
 
37
public:
 
38
        SWBuf name;
 
39
        unsigned long size;
 
40
        bool isDirectory;
 
41
};
 
42
/**
 
43
* This class represents one file. It works with the FileMgr object.
 
44
*/
 
45
class SWDLLEXPORT FileDesc {
 
46
 
 
47
        friend class FileMgr;
 
48
 
 
49
        long offset;
 
50
        int fd;                 // -77 closed;
 
51
        FileMgr *parent;
 
52
        FileDesc *next;
 
53
 
 
54
        FileDesc(FileMgr * parent, const char *path, int mode, int perms, bool tryDowngrade);
 
55
        virtual ~FileDesc();
 
56
 
 
57
public:
 
58
        /** @return File handle.
 
59
        */
 
60
        int getFd();
 
61
 
 
62
        long seek(long offset, int whence);
 
63
        long read(void *buf, long count);
 
64
        long write(const void *buf, long count);
 
65
 
 
66
        /** Path to file.
 
67
        */
 
68
        char *path;
 
69
        /** File access mode.
 
70
        */
 
71
        int mode;
 
72
        /** File permissions.
 
73
        */
 
74
        int perms;
 
75
        /**
 
76
        */
 
77
        bool tryDowngrade;
 
78
};
 
79
 
 
80
/**
 
81
*       This class ist used make file access operations easier.
 
82
* It keeps a list of all open files internally and closes them
 
83
* when the destructor is called.
 
84
*/
 
85
class SWDLLEXPORT FileMgr : public SWCacher {
 
86
 
 
87
        friend class FileDesc;
 
88
        friend class __staticsystemFileMgr;
 
89
 
 
90
        FileDesc *files;
 
91
        int sysOpen(FileDesc * file);
 
92
protected:
 
93
        static FileMgr *systemFileMgr;
 
94
public:
 
95
        static int CREAT;
 
96
        static int APPEND;
 
97
        static int TRUNC;
 
98
        static int RDONLY;
 
99
        static int RDWR;
 
100
        static int WRONLY;
 
101
        static int IREAD;
 
102
        static int IWRITE;
 
103
 
 
104
        /** Maximum number of open files set in the constructor.
 
105
        * determines the max number of real system files that
 
106
        * filemgr will open.  Adjust for tuning.
 
107
        */
 
108
        int maxFiles;
 
109
        
 
110
        static FileMgr *getSystemFileMgr();
 
111
        static void setSystemFileMgr(FileMgr *newFileMgr);
 
112
 
 
113
        /** Constructor.
 
114
        * @param maxFiles The number of files that this FileMgr may open in parallel, if necessary.
 
115
        */
 
116
        FileMgr(int maxFiles = 35);
 
117
 
 
118
        /**
 
119
        * Destructor. Clean things up. Will close all files opened by this FileMgr object.
 
120
        */
 
121
        ~FileMgr();
 
122
 
 
123
        /** Open a file and return a FileDesc for it.
 
124
        * The file itself will only be opened when FileDesc::getFd() is called.
 
125
        * @param path Filename.
 
126
        * @param mode File access mode.
 
127
        * @param tryDowngrade
 
128
        * @return FileDesc object for the requested file.
 
129
        */
 
130
        FileDesc *open(const char *path, int mode, bool tryDowngrade);
 
131
 
 
132
        /** Open a file and return a FileDesc for it.
 
133
        * The file itself will only be opened when FileDesc::getFd() is called.
 
134
        * @param path Filename.
 
135
        * @param mode File access mode.
 
136
        * @param perms Permissions.
 
137
        * @param tryDowngrade
 
138
        * @return FileDesc object for the requested file.
 
139
        */
 
140
        FileDesc *open(const char *path, int mode, int perms = IREAD | IWRITE, bool tryDowngrade = false);
 
141
 
 
142
        /** Close a given file and delete its FileDesc object.
 
143
        * Will only close the file if it was created by this FileMgr object.
 
144
        * @param file The file to close.
 
145
        */
 
146
        void close(FileDesc *file);
 
147
 
 
148
        /** Cacher methods overridden
 
149
         */
 
150
        virtual void flush();
 
151
        virtual long resourceConsumption();
 
152
 
 
153
        /** Checks for the existence of a file.
 
154
        * @param ipath Path to file.
 
155
        * @param ifileName Name of file to check for.
 
156
        */
 
157
        static signed char existsFile(const char *ipath, const char *ifileName = 0);
 
158
 
 
159
        /** Checks for the existence of a directory.
 
160
        * @param ipath Path to directory.
 
161
        * @param idirName Name of directory to check for.
 
162
        */
 
163
        static signed char existsDir(const char *ipath, const char *idirName = 0);
 
164
 
 
165
        /** Truncate a file at its current position
 
166
        * leaving byte at current possition intact deleting everything afterward.
 
167
        * @param file The file to operate on.
 
168
        */
 
169
        signed char trunc(FileDesc *file);
 
170
 
 
171
        static char isDirectory(const char *path);
 
172
        static int createParent(const char *pName);
 
173
        static int createPathAndFile(const char *fName);
 
174
 
 
175
        /** attempts to open a file readonly
 
176
         * @param fName filename to open
 
177
         * @return fd; < 0 = error
 
178
         */
 
179
        static int openFileReadOnly(const char *fName);
 
180
        static int copyFile(const char *srcFile, const char *destFile);
 
181
        static int copyDir(const char *srcDir, const char *destDir);
 
182
        static int removeDir(const char *targetDir);
 
183
        static int removeFile(const char *fName);
 
184
        static char getLine(FileDesc *fDesc, SWBuf &line);
 
185
 
 
186
};
 
187
 
 
188
 
 
189
SWORD_NAMESPACE_END
 
190
#endif