~drizzle-trunk/drizzle/development

1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
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
1802.10.2 by Monty Taylor
Update all of the copyright headers to include the correct address.
17
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
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"
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
37
#include "CSSys.h"
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
38
39
class CSOutputStream;
40
class CSInputStream;
41
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
42
class CSFile : public CSSysFile, public CSRefObject {
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
43
public:
44
	CSPath *myFilePath;
45
46
	static const int DEFAULT = 0;	// Open for read/write, error if it does not exist.
47
	static const int READONLY = 1;	// Open for readonly
48
	static const int CREATE = 2;	// Create if it does not exist
49
	static const int TRUNCATE = 4;	// After open, set EOF to zero	
50
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
51
	CSFile(): myFilePath(NULL), iMode(-1), iLocked(0) { }
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
52
53
	virtual ~CSFile(); 
54
55
	CSOutputStream *getOutputStream();
1548.2.2 by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle.
56
	CSOutputStream *getOutputStream(off64_t offset);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
57
58
	CSInputStream *getInputStream();
1548.2.2 by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle.
59
	CSInputStream *getInputStream(off64_t offset);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
60
61
	/*
62
	 * Open the file in the specified
63
	 * mode.
64
	 */
65
	virtual void open(int mode);
66
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
67
	/* Lock the file. The file will be unlocked
68
	 * when closed.
69
	 */
70
	virtual void lock();
71
72
	virtual void unlock();
73
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
74
	/*
75
	 * Close the file.
76
	 */
77
	virtual void close();
78
79
	/*
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
80
	 * Calculate the Md5 digest for the file.
81
	 */
82
	void md5Digest(Md5Digest *digest);
83
84
	/*
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
85
	 * Move the current position to
86
	 * the end of the file.
87
	 */
1548.2.2 by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle.
88
	virtual off64_t getEOF();
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
89
1548.2.2 by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle.
90
	virtual void setEOF(off64_t offset);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
91
92
	/*
93
	 * Read a given number of bytes. This function
94
	 * throws an error if the number of bytes read
95
	 * ius less than 'min_size'.
96
	 */
1548.2.2 by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle.
97
	virtual size_t read(void *data, off64_t offset, size_t size, size_t min_size);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
98
99
	/*
100
	 * Write the given number of bytes.
101
	 * Throws IOException if an error occurs.
102
	 */
1548.2.2 by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle.
103
	virtual void write(const void *data, off64_t offset, size_t size);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
104
105
	/*
106
	 * Flush the data written.
107
	 */
108
	virtual void flush();
109
110
	/* Flush the OS buffers: */
111
	virtual void sync() ;
112
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
113
	/* Resets access and modification times of the file: */
114
	virtual void touch();
115
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
116
	/*
117
	 * Return a platform specific prefered 
118
	 * line ending for text files.
119
	 */
120
	virtual const char *getEOL() { return "\n"; };
121
122
	virtual const char *getPathString() { return myFilePath->getCString(); }
123
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
124
	bool exists() { return myFilePath->exists(); }
125
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
126
	friend class CSReadBufferedFile;
127
128
private:
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
129
	int		iMode;
130
	int		iLocked;
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
131
132
	virtual void openFile(int mode);
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
133
	bool try_CreateAndOpen(CSThread *self, int mode, bool retry);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
134
135
public:
1548.2.11 by Barry.Leslie at PrimeBase
Removed libxml reqirement by using a home grown xml parser.
136
	void streamOut(CSOutputStream *dst_stream, off64_t src_offset, off64_t size, char *buffer, size_t buffer_size);
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
137
	void streamIn(CSInputStream *src_stream, off64_t dst_offset, off64_t size, char *buffer, size_t buffer_size);
1548.2.11 by Barry.Leslie at PrimeBase
Removed libxml reqirement by using a home grown xml parser.
138
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
139
	static bool isDirNotFound(CSException *e) { return e->getErrorCode() == ENOENT; }
140
	static bool isDirExists(CSException *e) { return e->getErrorCode() == EEXIST; }
141
1548.2.2 by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle.
142
	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);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
143
144
	static CSFile *newFile(CSPath *path);
145
146
	static CSFile *newFile(const char *path);
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
147
148
	static CSFile *newFile(const char *dir_str, const char *path_str);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
149
};
150
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
151
152
// This stuff needs to be retought.
153
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
154
#ifdef DEBUG
155
#define SC_DEFAULT_FILE_BUFFER_SIZE			127
156
#else
157
#define SC_DEFAULT_FILE_BUFFER_SIZE			(64 * 1024)
158
#endif
159
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
160
class CSReadBufferedFile : public CSRefObject {
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
161
public:
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
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:
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
189
	CSFile	*myFile;
190
191
	char	iFileBuffer[SC_DEFAULT_FILE_BUFFER_SIZE];
1548.2.2 by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle.
192
	off64_t	iFileBufferOffset;
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
193
	size_t	iBufferDataLen;
194
195
	virtual void openFile(int mode);
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
196
};
197
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
198
199
#endif