~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

Reverted 1103

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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
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
 
 
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
 
 
51
 
class CSObject {
52
 
public:
53
 
        CSObject() { }
54
 
        virtual ~CSObject() { finalize(); }
55
 
 
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
60
 
        virtual void retain();
61
 
        virtual void release();
62
 
#endif
63
 
 
64
 
        /*
65
 
         * All objects are sortable, hashable and linkable,
66
 
         * as long as these methods are implemented:
67
 
         */
68
 
        virtual void finalize() { }
69
 
        virtual CSObject *getKey();
70
 
        virtual int compareKey(CSObject *);
71
 
        virtual uint32_t hashKey();
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
80
 
        static void *operator new(size_t size, const char *func, const char *file, uint32_t line) {
81
 
                return cs_mm_malloc(func, file, line, size);
82
 
        }
83
 
 
84
 
        static void operator delete(void *ptr, size_t size) {
85
 
                UNUSED(size);
86
 
                cs_mm_free(ptr);
87
 
        }
88
 
 
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();
101
 
#endif
102
 
};
103
 
 
104
 
class CSRefObject : public CSObject {
105
 
public:
106
 
        CSRefObject();
107
 
        virtual ~CSRefObject();
108
 
 
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
116
 
        virtual void retain();
117
 
        virtual void release();
118
 
#endif
119
 
 
120
 
        uint32_t getRefCount() { return iRefCount;}
121
 
 
122
 
private:
123
 
        uint32_t        iRefCount;
124
 
};
125
 
 
126
 
class CSSharedRefObject : public CSObject, public CSSync {
127
 
public:
128
 
        CSSharedRefObject();
129
 
        virtual ~CSSharedRefObject();
130
 
 
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
138
 
        virtual void retain();
139
 
        virtual void release();
140
 
#endif
141
 
 
142
 
        uint32_t getRefCount() { return iRefCount;}
143
 
 
144
 
private:
145
 
        uint32_t        iRefCount;
146
 
};
147
 
 
148
 
#ifdef DEBUG
149
 
#define new                    new(__FUNC__, __FILE__, __LINE__)
150
 
 
151
 
#define retain()        retain(__FUNC__, __FILE__, __LINE__)
152
 
#define release()       release(__FUNC__, __FILE__, __LINE__)
153
 
#endif
154
 
 
155
 
class CSPooled {
156
 
public:
157
 
        virtual ~CSPooled() {}
158
 
        virtual void returnToPool() = 0;
159
 
};
160
 
 
161
 
#endif