default: esd is obsolete, hence don't load it anymore by default
[pulseaudio-mirror.git] / src / pulsecore / object.h
blob1ddce3b4d4978f386ec1eb858ba1e5023ab2e2c0
1 #ifndef foopulseobjecthfoo
2 #define foopulseobjecthfoo
4 /***
5 This file is part of PulseAudio.
7 Copyright 2004-2006 Lennart Poettering
8 Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
10 PulseAudio is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published
12 by the Free Software Foundation; either version 2.1 of the License,
13 or (at your option) any later version.
15 PulseAudio is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
20 You should have received a copy of the GNU Lesser General Public License
21 along with PulseAudio; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 USA.
24 ***/
26 #include <sys/types.h>
28 #include <pulse/xmalloc.h>
29 #include <pulsecore/refcnt.h>
30 #include <pulsecore/macro.h>
32 typedef struct pa_object pa_object;
34 struct pa_object {
35 PA_REFCNT_DECLARE;
36 const char *type_id;
37 void (*free)(pa_object *o);
38 pa_bool_t (*check_type)(const char *type_name);
41 pa_object *pa_object_new_internal(size_t size, const char *type_id, pa_bool_t (*check_type)(const char *type_id));
42 #define pa_object_new(type) ((type*) pa_object_new_internal(sizeof(type), type##_type_id, type##_check_type)
44 #define pa_object_free ((void (*) (pa_object* _obj)) pa_xfree)
46 pa_bool_t pa_object_check_type(const char *type_id);
48 extern const char pa_object_type_id[];
50 static inline pa_bool_t pa_object_isinstance(void *o) {
51 pa_object *obj = (pa_object*) o;
52 return obj ? obj->check_type(pa_object_type_id) : TRUE;
55 pa_object *pa_object_ref(pa_object *o);
56 void pa_object_unref(pa_object *o);
58 static inline int pa_object_refcnt(pa_object *o) {
59 return o ? PA_REFCNT_VALUE(o) : 0;
62 static inline pa_object* pa_object_cast(void *o) {
63 pa_object *obj = (pa_object*) o;
64 pa_assert(!obj || obj->check_type(pa_object_type_id));
65 return obj;
68 #define pa_object_assert_ref(o) pa_assert(pa_object_refcnt(o) > 0)
70 #define PA_OBJECT(o) pa_object_cast(o)
72 #define PA_DECLARE_CLASS_COMMON(c) \
73 static inline pa_bool_t c##_isinstance(void *o) { \
74 pa_object *obj = (pa_object*) o; \
75 return obj ? obj->check_type(c##_type_id) : TRUE; \
76 } \
77 static inline c* c##_cast(void *o) { \
78 pa_assert(c##_isinstance(o)); \
79 return (c*) o; \
80 } \
81 static inline c* c##_ref(c *o) { \
82 return (c*) pa_object_ref(PA_OBJECT(o)); \
83 } \
84 static inline void c##_unref(c* o) { \
85 pa_object_unref(PA_OBJECT(o)); \
86 } \
87 static inline int c##_refcnt(c* o) { \
88 return pa_object_refcnt(PA_OBJECT(o)); \
89 } \
90 static inline void c##_assert_ref(c *o) { \
91 pa_object_assert_ref(PA_OBJECT(o)); \
92 } \
93 struct __stupid_useless_struct_to_allow_trailing_semicolon
95 #define PA_DECLARE_PUBLIC_CLASS(c) \
96 extern const char c##_type_id[]; \
97 PA_DECLARE_CLASS_COMMON(c); \
98 pa_bool_t c##_check_type(const char *type_id)
100 #define PA_DEFINE_PUBLIC_CLASS(c, parent) \
101 const char c##_type_id[] = #c; \
102 pa_bool_t c##_check_type(const char *type_id) { \
103 if (type_id == c##_type_id) \
104 return TRUE; \
105 return parent##_check_type(type_id); \
107 struct __stupid_useless_struct_to_allow_trailing_semicolon
109 #define PA_DEFINE_PRIVATE_CLASS(c, parent) \
110 static const char c##_type_id[] = #c; \
111 PA_DECLARE_CLASS_COMMON(c); \
112 static pa_bool_t c##_check_type(const char *type_id) { \
113 if (type_id == c##_type_id) \
114 return TRUE; \
115 return parent##_check_type(type_id); \
117 struct __stupid_useless_struct_to_allow_trailing_semicolon
120 #endif