~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Monty Taylor
  • Date: 2010-08-21 03:34:31 UTC
  • mto: (1725.1.3 build)
  • mto: This revision was merged to the branch mainline in revision 1726.
  • Revision ID: mordred@inaugust.com-20100821033431-e0czq298av2aqx25
Rearranged how we set -fvisibility, allowing us to turn it on on a
library-by-library basis even if we specify skip-visiblity as an argument to
PANDORA_CANONICAL.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (c) 2008 PrimeBase Technologies GmbH, Germany
 
2
 *
 
3
 * PrimeBase Media Stream for MySQL
 
4
 *
 
5
 * This program is free software; you can redistribute it and/or modify
 
6
 * it under the terms of the GNU General Public License as published by
 
7
 * the Free Software Foundation; either version 2 of the License, or
 
8
 * (at your option) any later version.
 
9
 *
 
10
 * This program is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this program; if not, write to the Free Software
 
17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 
18
 *
 
19
 * Original author: Paul McCullagh (H&G2JCtL)
 
20
 * Continued development: Barry Leslie
 
21
 *
 
22
 * 2007-06-07
 
23
 *
 
24
 * CORE SYSTEM:
 
25
 * Basic file I/O.
 
26
 *
 
27
 */
 
28
 
 
29
#ifndef __CSFILE_H__
 
30
#define __CSFILE_H__
 
31
 
 
32
#include <stdio.h>
 
33
 
 
34
#include "CSDefs.h"
 
35
#include "CSPath.h"
 
36
#include "CSException.h"
 
37
 
 
38
using namespace std;
 
39
 
 
40
extern int unix_file_close(int fh);
 
41
 
 
42
class CSOutputStream;
 
43
class CSInputStream;
 
44
 
 
45
class CSFile : public CSRefObject {
 
46
public:
 
47
        CSPath *myFilePath;
 
48
 
 
49
        static const int DEFAULT = 0;   // Open for read/write, error if it does not exist.
 
50
        static const int READONLY = 1;  // Open for readonly
 
51
        static const int CREATE = 2;    // Create if it does not exist
 
52
        static const int TRUNCATE = 4;  // After open, set EOF to zero  
 
53
 
 
54
        CSFile(): myFilePath(NULL), iFH(-1) { }
 
55
 
 
56
        virtual ~CSFile(); 
 
57
 
 
58
        CSOutputStream *getOutputStream();
 
59
        CSOutputStream *getOutputStream(off64_t offset);
 
60
 
 
61
        CSInputStream *getInputStream();
 
62
        CSInputStream *getInputStream(off64_t offset);
 
63
 
 
64
        /*
 
65
         * Open the file in the specified
 
66
         * mode.
 
67
         */
 
68
        virtual void open(int mode);
 
69
 
 
70
        /*
 
71
         * Close the file.
 
72
         */
 
73
        virtual void close();
 
74
 
 
75
        /*
 
76
         * Move the current position to
 
77
         * the end of the file.
 
78
         */
 
79
        virtual off64_t getEOF();
 
80
 
 
81
        virtual void setEOF(off64_t offset);
 
82
 
 
83
        /*
 
84
         * Read a given number of bytes. This function
 
85
         * throws an error if the number of bytes read
 
86
         * ius less than 'min_size'.
 
87
         */
 
88
        virtual size_t read(void *data, off64_t offset, size_t size, size_t min_size);
 
89
 
 
90
        /*
 
91
         * Write the given number of bytes.
 
92
         * Throws IOException if an error occurs.
 
93
         */
 
94
        virtual void write(const void *data, off64_t offset, size_t size);
 
95
 
 
96
        /*
 
97
         * Flush the data written.
 
98
         */
 
99
        virtual void flush();
 
100
 
 
101
        /* Flush the OS buffers: */
 
102
        virtual void sync() ;
 
103
 
 
104
        /*
 
105
         * Return a platform specific prefered 
 
106
         * line ending for text files.
 
107
         */
 
108
        virtual const char *getEOL() { return "\n"; };
 
109
 
 
110
        virtual const char *getPathString() { return myFilePath->getCString(); }
 
111
 
 
112
        friend class CSReadBufferedFile;
 
113
        friend class CSBufferedFile;
 
114
 
 
115
private:
 
116
        int             iFH;
 
117
 
 
118
        virtual void openFile(int mode);
 
119
 
 
120
public:
 
121
        void streamOut(CSOutputStream *dst_stream, off64_t src_offset, off64_t size, char *buffer, size_t buffer_size);
 
122
 
 
123
        static bool isDirNotFound(CSException *e) { return e->getErrorCode() == ENOENT; }
 
124
        static bool isDirExists(CSException *e) { return e->getErrorCode() == EEXIST; }
 
125
 
 
126
        static bool transfer(CSFile *dst_file, off64_t dst_offset, CSFile *src_file, off64_t src_offset, off64_t size, char *buffer, size_t buffer_size);
 
127
 
 
128
        static CSFile *newFile(CSPath *path);
 
129
 
 
130
        static CSFile *newFile(const char *path);
 
131
};
 
132
 
 
133
#ifdef DEBUG
 
134
#define SC_DEFAULT_FILE_BUFFER_SIZE                     127
 
135
#else
 
136
#define SC_DEFAULT_FILE_BUFFER_SIZE                     (64 * 1024)
 
137
#endif
 
138
 
 
139
class CSReadBufferedFile : public CSFile {
 
140
public:
 
141
        CSFile  *myFile;
 
142
 
 
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
        char    iFileBuffer[SC_DEFAULT_FILE_BUFFER_SIZE];
 
167
        off64_t iFileBufferOffset;
 
168
        size_t  iBufferDataLen;
 
169
 
 
170
        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
};
 
188
 
 
189
#endif