~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
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-15
23
 *
24
 * CORE SYSTEM STORAGE
25
 * Basic storage structures.
26
 *
27
 */
28
29
#ifndef __CSSTORAGE_H__
30
#define __CSSTORAGE_H__
31
32
#include <stdio.h>
33
34
#include "CSDefs.h"
35
#include "CSString.h"
36
37
class CSHashTable;
38
39
class CSHashTable : public CSObject {
40
public:
41
	CSHashTable(): iSize(0), iTable(NULL) { }
42
	virtual ~CSHashTable();
43
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.
44
	void setSize(uint32_t size);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
45
46
	void clear();
47
48
	/* Value must be given referenced. */
49
	void add(CSObject *item);
50
51
	/* Value is returned NOT referenced. */
52
	CSObject *find(CSObject *key);
53
	
54
	void remove(CSObject *key);
55
56
private:
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.
57
	uint32_t iSize;
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
58
59
	CSObject **iTable;
60
};
61
62
#define SC_SORT_LIST_INC_SIZE		20
63
64
class CSSortedList : public CSObject {
65
public:
66
	CSSortedList(): iListSize(0), iInUse(0), iList(NULL) { }
67
	virtual ~CSSortedList() { clear(); }
68
69
	void clear();
70
71
	/* Value must be given referenced. */
72
	void add(CSObject *item);
73
	
74
	/* Value is returned NOT referenced. */
75
	CSObject *find(CSObject *key);
76
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.
77
	CSObject *itemAt(uint32_t idx);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
78
	
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.
79
	CSObject *takeItemAt(uint32_t idx); // Takes item off of list.
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
80
	
81
	void remove(CSObject *key);
82
	
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.
83
	uint32_t getSize() { return iInUse; }
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
84
85
86
private:
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.
87
	uint32_t iListSize;
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
88
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.
89
	uint32_t iInUse;
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
90
91
	CSObject **iList;
92
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.
93
	CSObject *search(CSObject *key, uint32_t& idx);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
94
};
95
96
class CSSyncSortedList : public CSSortedList, public CSSync {
97
public:
98
	CSSyncSortedList(): CSSortedList(), CSSync() { }
99
};
100
101
class CSLinkedItem : public CSRefObject {
102
public:
103
	CSLinkedItem(): CSRefObject() { }
104
	virtual ~CSLinkedItem() { }
105
106
	virtual CSObject *getNextLink() { return iNextLink; }
107
	virtual CSObject *getPrevLink() { return iPrevLink; }
108
	virtual void setNextLink(CSObject *link) { iNextLink = link; }
109
	virtual void setPrevLink(CSObject *link) { iPrevLink = link; }
110
111
private:
112
	CSObject		*iNextLink;
113
	CSObject		*iPrevLink;
114
};
115
116
/*
117
 * Items are linked so that following the previous pointers
118
 * you move from front to back.
119
 * Following the next pointers you move from back to front.
120
 */
121
class CSLinkedList : public CSObject {
122
public:
123
	CSLinkedList(): iSize(0), iListFront(NULL), iListBack(NULL) { }
124
	virtual ~CSLinkedList() { clear(); }
125
126
	void clear();
127
	
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.
128
	uint32_t getSize() { return iSize; }
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
129
130
	/* Value must be given referenced. */
131
	void addFront(CSObject *item);
132
133
	bool remove(CSObject *item);
134
135
	/* Value is returned referenced. */
136
	CSObject *removeBack();
137
138
	/* Value is returned NOT referenced. */
139
	CSObject *getBack();
140
141
	/* Value is returned NOT referenced. */
142
	CSObject *getFront();
143
144
	/* Value is returned referenced. */
145
	CSObject *removeFront();
146
private:
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.
147
	uint32_t iSize;
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
148
	CSObject *iListFront;
149
	CSObject *iListBack;
150
};
151
152
class CSVector : public CSObject {
153
public:
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.
154
	CSVector(uint32_t growSize): iGrowSize(growSize), iMaxSize(0), iUsage(0), iArray(NULL) { }
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
155
	virtual ~CSVector() { free(); }
156
157
	void free();
158
159
	void clear();
160
161
	/*
162
	 * Remove and object from the vector, and
163
	 * The object is rfemoved from the list.
164
	 * return a reference.
165
	 */
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.
166
	CSObject *take(uint32_t idx);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
167
168
	/*
169
	 * Remove an object from the vector.
170
	 */
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.
171
	void remove(uint32_t idx);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
172
173
	/*
174
	 * Get a reference to an object in the vector.
175
	 * A reference to the object remains on the list.
176
	 * Value returned is NOT referenced!
177
	 */
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.
178
	CSObject *get(uint32_t idx);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
179
180
	/* Set a specific index: */
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.
181
	void set(uint32_t idx, CSObject *);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
182
183
	/*
184
	 * Add an object to the end of the vector.
185
	 * Value must be referenced.
186
	 */
187
	void add(CSObject *);
188
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.
189
	uint32_t size() { return iUsage; }
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
190
191
private:
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
	uint32_t iGrowSize;
193
	uint32_t iMaxSize;
194
	uint32_t iUsage;
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
195
196
	CSObject **iArray;
197
};
198
199
class CSSyncVector : public CSVector, public CSSync {
200
public:
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.
201
	CSSyncVector(uint32_t growSize): CSVector(growSize), CSSync() { }
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
202
};
203
204
typedef struct CSSpareArrayItem {
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.
205
	uint32_t		sa_index;
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
206
	CSObject	*sa_object;
207
} CSSpareArrayItemRec, *CSSpareArrayItemPtr;
208
209
class CSSparseArray : public CSObject {
210
public:
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.
211
	CSSparseArray(uint32_t growSize): iGrowSize(growSize), iMaxSize(0), iUsage(0), iArray(NULL) { }
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
212
	CSSparseArray(): iGrowSize(10), iMaxSize(0), iUsage(0), iArray(NULL) { }
213
	virtual ~CSSparseArray() { free(); }
214
215
	void free();
216
217
	void clear();
218
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.
219
	CSObject *take(uint32_t idx);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
220
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.
221
	void remove(uint32_t idx);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
222
223
	void removeFirst();
224
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.
225
	CSObject *itemAt(uint32_t idx);
226
227
	CSObject *get(uint32_t idx);
228
	
229
	uint32_t getIndex(uint32_t idx);
230
	
231
	void set(uint32_t idx, CSObject *);
232
233
	uint32_t size() { return iUsage; }
234
235
	uint32_t minIndex() {
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
236
		if (iUsage == 0)
237
			return 0;
238
		return iArray[0].sa_index;
239
	}
240
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.
241
	uint32_t maxIndex() {
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
242
		if (iUsage == 0)
243
			return 0;
244
		return iArray[iUsage-1].sa_index;
245
	}
246
247
	CSObject *first();
248
249
	CSObject *last();
250
251
private:
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.
252
	uint32_t				iGrowSize;
253
	uint32_t				iMaxSize;
254
	uint32_t				iUsage;
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
255
	CSSpareArrayItemPtr	iArray;
256
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.
257
	CSObject *search(uint32_t idx, uint32_t& pos);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
258
};
259
260
class CSSyncSparseArray : public CSSparseArray, public CSSync {
261
public:
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.
262
	CSSyncSparseArray(uint32_t growSize): CSSparseArray(growSize), CSSync() { }
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
263
};
264
265
class CSOrderKey : public CSObject {
266
public:
267
	virtual int compareKey(CSOrderKey *key) = 0;
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.
268
	int compareKey(CSObject *key) {return CSObject::compareKey(key);}
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
269
};
270
271
typedef struct CSOrderedListItem {
272
	CSOrderKey	*li_key;
273
	CSObject	*li_item;
274
} CSOrderedListItemRec, *CSOrderedListItemPtr;
275
276
class CSOrderedList : public CSObject {
277
public:
278
	CSOrderedList(): iListSize(0), iInUse(0), iList(NULL) { }
279
	virtual ~CSOrderedList() { clear(); }
280
281
	void clear();
282
283
	/* Value must be given referenced. */
284
	void add(CSOrderKey *key, CSObject *item);
285
	
286
	/* Value is returned NOT referenced. */
287
	CSObject *find(CSOrderKey *key);
288
	
289
	/* Value is returned NOT referenced. */
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.
290
	CSObject *itemAt(uint32_t idx);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
291
	
292
	void remove(CSOrderKey *key);
293
294
private:
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.
295
	uint32_t iListSize;
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
296
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.
297
	uint32_t iInUse;
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
298
299
	CSOrderedListItemPtr iList;
300
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.
301
	CSOrderedListItemPtr search(CSOrderKey *key, uint32_t *idx);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
302
};
303
304
class CSSyncOrderedList : public CSOrderedList, public CSSync {
305
public:
306
	CSSyncOrderedList(): CSOrderedList(), CSSync() { }
307
};
308
309
class CSQueue;
310
311
typedef struct CSQueueItem {
312
	CSObject			*qi_object;
313
	CSQueue				*qi_next;
314
} CSQueueItemRec, *CSQueueItemPtr;
315
316
class CSQueue : public CSObject {
317
public:
318
	CSQueue(): iQueueSize(0), iHighWater(0), iFront(NULL), iBack(NULL), iFree(NULL) { }
319
	virtual ~CSQueue() { clear(); }
320
321
	void clear();
322
323
	/* Value must be given referenced. */
324
	void add(CSObject *item);
325
326
	/* Returns a referenced value, on a FIFO basis. */
327
	CSObject *remove();
328
329
private:
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.
330
	uint32_t iQueueSize;
331
	uint32_t iHighWater;
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
332
333
	CSQueueItemPtr	iFront;
334
	CSQueueItemPtr	iBack;
335
	CSQueueItemPtr	iFree;
336
};
337
338
#endif