~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-05-20
23
 *
24
 *
25
 */
26
27
#ifndef __CSOBJECT_H__
28
#define __CSOBJECT_H__
29
30
#include "CSDefs.h"
31
#include "CSMemory.h"
32
#include "CSMutex.h"
33
34
// The RETAIN() macro is useful when passing object references to functions
35
// that you want to retain. For example istead of:
36
// x->retain();
37
// foo(x);
38
// You can do:
39
// foo(RETAIN(x));
40
//
41
// After 20 years of programming I have finally found a use for the 'C' comma
42
// operator out side of a 'for' loop. :)
43
#define RETAIN(x) ((x)->retain(),(x))
44
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
45
// A back reference is a reference stored by an object pointing to it's owner.
46
// Since the owner will free all of it's object when it is released the  object
47
// itself cannot hold a reference to its owner.
48
// Use this macro to make it clear that this is what you intended. 
49
#define BACK_REFERENCE(x) (x)
50
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
51
class CSObject {
52
public:
53
	CSObject() { }
1548.2.11 by Barry.Leslie at PrimeBase
Removed libxml reqirement by using a home grown xml parser.
54
	virtual ~CSObject() { finalize(); }
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
55
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
56
#ifdef DEBUG
57
	virtual void retain(const char *func, const char *file, uint32_t line);
58
	virtual void release(const char *func, const char *file, uint32_t line);
59
#else
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
60
	virtual void retain();
61
	virtual void release();
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
62
#endif
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
63
64
	/*
65
	 * All objects are sortable, hashable and linkable,
66
	 * as long as these methods are implemented:
67
	 */
1548.2.11 by Barry.Leslie at PrimeBase
Removed libxml reqirement by using a home grown xml parser.
68
	virtual void finalize() { }
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
69
	virtual CSObject *getKey();
70
	virtual int compareKey(CSObject *);
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.
71
	virtual uint32_t hashKey();
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
72
	virtual CSObject *getHashLink();
73
	virtual void setHashLink(CSObject *);
74
	virtual CSObject *getNextLink();
75
	virtual CSObject *getPrevLink();
76
	virtual void setNextLink(CSObject *);
77
	virtual void setPrevLink(CSObject *);
78
79
#ifdef DEBUG
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.
80
	static void *operator new(size_t size, const char *func, const char *file, uint32_t line) {
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
81
		return cs_mm_malloc(func, file, line, size);
82
	}
83
1548.2.28 by Barry.Leslie at PrimeBase
Replaced the use of __attribute__((unused)) with my own macro.
84
	static void operator delete(void *ptr, size_t size) {
85
		UNUSED(size);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
86
		cs_mm_free(ptr);
87
	}
88
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
89
#endif
90
};
91
92
class CSStaticObject : public CSObject {
93
#ifdef DEBUG
94
	virtual void retain(const char *func, const char *file, uint32_t line);
95
	virtual void release(const char *func, const char *file, uint32_t line);
96
97
	int		iTrackMe;
98
#else
99
	virtual void retain();
100
	virtual void release();
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
101
#endif
102
};
103
104
class CSRefObject : public CSObject {
105
public:
106
	CSRefObject();
107
	virtual ~CSRefObject();
108
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
109
#ifdef DEBUG
110
	virtual void startTracking();
111
	virtual void retain(const char *func, const char *file, uint32_t line);
112
	virtual void release(const char *func, const char *file, uint32_t line);
113
114
	int		iTrackMe;
115
#else
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
116
	virtual void retain();
117
	virtual void release();
118
#endif
119
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
120
	uint32_t getRefCount() { return iRefCount;}
121
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
122
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.
123
	uint32_t	iRefCount;
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
124
};
125
126
class CSSharedRefObject : public CSObject, public CSSync {
127
public:
128
	CSSharedRefObject();
129
	virtual ~CSSharedRefObject();
130
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
131
#ifdef DEBUG
132
	virtual void startTracking();
133
	virtual void retain(const char *func, const char *file, uint32_t line);
134
	virtual void release(const char *func, const char *file, uint32_t line);
135
136
	int		iTrackMe;
137
#else
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
138
	virtual void retain();
139
	virtual void release();
140
#endif
141
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
142
	uint32_t getRefCount() { return iRefCount;}
143
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
144
private:
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
145
	uint32_t	iRefCount;
146
};
147
148
#ifdef DEBUG
1976.2.22 by Monty Taylor
Fixed the pbms debug build for now.
149
#define new                    new(__FUNC__, __FILE__, __LINE__)
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
150
151
#define retain()	retain(__FUNC__, __FILE__, __LINE__)
152
#define release()	release(__FUNC__, __FILE__, __LINE__)
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
153
#endif
154
155
class CSPooled {
156
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.
157
	virtual ~CSPooled() {}
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
158
	virtual void returnToPool() = 0;
159
};
160
161
#endif