~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/pbms/src/cslib/CSFile.h

  • Committer: Lee Bieber
  • Date: 2010-10-22 16:47:38 UTC
  • mfrom: (1841.1.7 drizzle_pbms)
  • Revision ID: kalebral@gmail.com-20101022164738-vv8w22b8towpb307
Merge Barry - fix bug 657830: PBMS build failure in GCC 4.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
#include "CSDefs.h"
35
35
#include "CSPath.h"
36
36
#include "CSException.h"
37
 
 
38
 
using namespace std;
39
 
 
40
 
extern int unix_file_close(int fh);
 
37
#include "CSSys.h"
41
38
 
42
39
class CSOutputStream;
43
40
class CSInputStream;
44
41
 
45
 
class CSFile : public CSRefObject {
 
42
class CSFile : public CSSysFile, public CSRefObject {
46
43
public:
47
44
        CSPath *myFilePath;
48
45
 
51
48
        static const int CREATE = 2;    // Create if it does not exist
52
49
        static const int TRUNCATE = 4;  // After open, set EOF to zero  
53
50
 
54
 
        CSFile(): myFilePath(NULL), iFH(-1) { }
 
51
        CSFile(): myFilePath(NULL), iMode(-1), iLocked(0) { }
55
52
 
56
53
        virtual ~CSFile(); 
57
54
 
67
64
         */
68
65
        virtual void open(int mode);
69
66
 
 
67
        /* Lock the file. The file will be unlocked
 
68
         * when closed.
 
69
         */
 
70
        virtual void lock();
 
71
 
 
72
        virtual void unlock();
 
73
 
70
74
        /*
71
75
         * Close the file.
72
76
         */
73
77
        virtual void close();
74
78
 
75
79
        /*
 
80
         * Calculate the Md5 digest for the file.
 
81
         */
 
82
        void md5Digest(Md5Digest *digest);
 
83
 
 
84
        /*
76
85
         * Move the current position to
77
86
         * the end of the file.
78
87
         */
101
110
        /* Flush the OS buffers: */
102
111
        virtual void sync() ;
103
112
 
 
113
        /* Resets access and modification times of the file: */
 
114
        virtual void touch();
 
115
 
104
116
        /*
105
117
         * Return a platform specific prefered 
106
118
         * line ending for text files.
109
121
 
110
122
        virtual const char *getPathString() { return myFilePath->getCString(); }
111
123
 
 
124
        bool exists() { return myFilePath->exists(); }
 
125
 
112
126
        friend class CSReadBufferedFile;
113
 
        friend class CSBufferedFile;
114
127
 
115
128
private:
116
 
        int             iFH;
 
129
        int             iMode;
 
130
        int             iLocked;
117
131
 
118
132
        virtual void openFile(int mode);
 
133
        bool try_CreateAndOpen(CSThread *self, int mode, bool retry);
119
134
 
120
135
public:
121
136
        void streamOut(CSOutputStream *dst_stream, off64_t src_offset, off64_t size, char *buffer, size_t buffer_size);
 
137
        void streamIn(CSInputStream *src_stream, off64_t dst_offset, off64_t size, char *buffer, size_t buffer_size);
122
138
 
123
139
        static bool isDirNotFound(CSException *e) { return e->getErrorCode() == ENOENT; }
124
140
        static bool isDirExists(CSException *e) { return e->getErrorCode() == EEXIST; }
128
144
        static CSFile *newFile(CSPath *path);
129
145
 
130
146
        static CSFile *newFile(const char *path);
 
147
 
 
148
        static CSFile *newFile(const char *dir_str, const char *path_str);
131
149
};
132
150
 
 
151
 
 
152
// This stuff needs to be retought.
 
153
 
133
154
#ifdef DEBUG
134
155
#define SC_DEFAULT_FILE_BUFFER_SIZE                     127
135
156
#else
136
157
#define SC_DEFAULT_FILE_BUFFER_SIZE                     (64 * 1024)
137
158
#endif
138
159
 
139
 
class CSReadBufferedFile : public CSFile {
 
160
class CSReadBufferedFile : public CSRefObject {
140
161
public:
 
162
 
 
163
        CSReadBufferedFile();
 
164
 
 
165
        ~CSReadBufferedFile();
 
166
        
 
167
        void setFile(CSFile     *file) {myFile = file;}
 
168
 
 
169
        const char *getPathString() { return myFile->getPathString(); }
 
170
        void open(int mode) {myFile->open(mode); }
 
171
 
 
172
        void close();
 
173
 
 
174
        off64_t getEOF();
 
175
 
 
176
        void setEOF(off64_t offset);
 
177
 
 
178
        size_t read(void *data, off64_t offset, size_t size, size_t min_size);
 
179
 
 
180
        void write(const void *data, off64_t offset, size_t size);
 
181
 
 
182
        void flush();
 
183
 
 
184
        void sync();
 
185
 
 
186
        const char *getEOL();
 
187
 
 
188
private:
141
189
        CSFile  *myFile;
142
190
 
143
 
        CSReadBufferedFile();
144
 
 
145
 
        virtual ~CSReadBufferedFile();
146
 
 
147
 
        virtual void close();
148
 
 
149
 
        virtual off64_t getEOF();
150
 
 
151
 
        virtual void setEOF(off64_t offset);
152
 
 
153
 
        virtual size_t read(void *data, off64_t offset, size_t size, size_t min_size);
154
 
 
155
 
        virtual void write(const void *data, off64_t offset, size_t size);
156
 
 
157
 
        virtual void flush();
158
 
 
159
 
        virtual void sync();
160
 
 
161
 
        virtual const char *getEOL();
162
 
 
163
 
        friend class CSBufferedFile;
164
 
 
165
 
private:
166
191
        char    iFileBuffer[SC_DEFAULT_FILE_BUFFER_SIZE];
167
192
        off64_t iFileBufferOffset;
168
193
        size_t  iBufferDataLen;
169
194
 
170
195
        virtual void openFile(int mode);
171
 
public:
172
 
        static CSFile *newFile(CSFile *file);
173
 
};
174
 
 
175
 
class CSBufferedFile : public CSReadBufferedFile {
176
 
public:
177
 
        CSBufferedFile(): CSReadBufferedFile(), iBufferDirty(false) { }
178
 
 
179
 
        virtual ~CSBufferedFile() { };
180
 
 
181
 
        virtual void write(const void *data, off64_t offset, size_t size);
182
 
 
183
 
        virtual void flush();
184
 
 
185
 
private:
186
 
        bool    iBufferDirty;
187
 
};
 
196
};
 
197
 
188
198
 
189
199
#endif