Eobj: Added eobj_super_do instead of class_do.
[profile/ivi/eobj.git] / lib / Eobj.h
1 #ifndef EOBJ_H
2 #define EOBJ_H
3
4 #include <stdarg.h>
5 #include <Eina.h>
6
7 /* Check that the types are castable and cast them. */
8 #define EOBJ_TYPECHECK(type, x) \
9    ({ \
10     type __x; \
11     __x = x; \
12     (void) __x; \
13     (type) x; \
14     })
15
16 #define EOBJ_ARRAY_SIZE(arr) (sizeof(arr) / sizeof(*arr))
17
18 typedef struct _Eobj Eobj;
19 typedef uintptr_t Eobj_Op;
20
21 typedef struct _Eobj_Class Eobj_Class;
22 typedef int Eobj_Class_Id;
23
24 typedef enum
25 {
26    EOBJ_CLASS_TYPE_REGULAR = 0,
27    EOBJ_CLASS_TYPE_REGULAR_NO_INSTANT,
28    EOBJ_CLASS_TYPE_INTERFACE,
29    EOBJ_CLASS_TYPE_MIXIN
30 } Eobj_Class_Type;
31
32 typedef void (*eobj_op_func_type)(Eobj *, Eobj_Op, va_list *list);
33
34 typedef struct
35 {
36    Eobj_Op op;
37    eobj_op_func_type func;
38 } Eobj_Op_Func_Description;
39
40 #define EOBJ_OP_FUNC_DESCRIPTION(op, func) { op, func }
41 #define EOBJ_OP_FUNC_DESCRIPTION_SENTINEL { 0, NULL }
42
43 typedef struct
44 {
45    const char *name; /**< name used for lookups */
46    const char *type; /**< used for introspection purposes, documents what goes as callback event information (@c event_info) */
47    const char *doc; /**< documentation for introspection purposes */
48 } Eobj_Event_Description;
49
50
51 typedef struct
52 {
53    Eobj_Op sub_op;
54    const char *name;
55    /* FIXME: properly define the type so it'll support get/set and etc.
56     * Do I even need/want type? If so, do I need/want it here? docs aren't
57     * enough? */
58    const char *type;
59    const char *doc;
60 } Eobj_Op_Description;
61
62 typedef struct
63 {
64    const char *name;
65    Eobj_Class_Type type;
66    struct {
67         Eobj_Op *base_op_id;
68         const Eobj_Op_Description *descs;
69         size_t count;
70    } ops;
71    const Eobj_Event_Description **events;
72    size_t private_size;
73    void (*constructor)(Eobj *obj);
74    void (*destructor)(Eobj *obj);
75    void (*class_constructor)(Eobj_Class *klass);
76    void (*class_destructor)(Eobj_Class *klass);
77 } Eobj_Class_Description;
78
79 #define EOBJ_CLASS_DESCRIPTION_OPS(base_op_id, op_descs, count) { base_op_id, op_descs, count }
80
81 #define EOBJ_OP_DESCRIPTION(op, type, doc) { op, #op, type, doc }
82 #define EOBJ_OP_DESCRIPTION_SENTINEL { 0, NULL, NULL, NULL }
83
84 #define EOBJ_EVENT_DESCRIPTION(name, type, doc) { name, type, doc }
85
86 EAPI Eina_Bool eobj_init(void);
87 EAPI Eina_Bool eobj_shutdown(void);
88
89 #define eobj_do(object, ...) eobj_do_internal(object, __VA_ARGS__, NULL)
90
91 EAPI Eina_Bool eobj_do_internal(Eobj *obj, ...);
92
93 EAPI Eina_Bool eobj_super_do(Eobj *obj, Eobj_Op op, ...);
94
95 EAPI const Eobj_Class *eobj_class_get(Eobj *obj);
96 EAPI const Eobj_Class *eobj_class_parent_get(const Eobj_Class *klass);
97 EAPI const char *eobj_class_name_get(const Eobj_Class *klass);
98
99 EAPI void eobj_constructor_super(Eobj *obj);
100 EAPI void eobj_destructor_super(Eobj *obj);
101 EAPI void eobj_constructor_error_set(Eobj *obj);
102 EAPI Eina_Bool eobj_constructor_error_get(const Eobj *obj);
103
104 EAPI Eobj_Class *eobj_class_new(const Eobj_Class_Description *desc, const Eobj_Class *parent, ...);
105 EAPI void eobj_class_free(Eobj_Class *klass);
106 EAPI void eobj_class_funcs_set(Eobj_Class *klass, const Eobj_Op_Func_Description *func_descs);
107
108 EAPI Eobj *eobj_add(const Eobj_Class *klass, Eobj *parent);
109 EAPI Eobj *eobj_parent_get(Eobj *obj);
110 EAPI void *eobj_data_get(Eobj *obj, const Eobj_Class *klass);
111 EAPI Eobj *eobj_ref(Eobj *obj);
112 EAPI void eobj_unref(Eobj *obj);
113 EAPI void eobj_del(Eobj *obj);
114 EAPI void *eobj_generic_data_set(Eobj *obj, const char *key, const void *data);
115 EAPI void *eobj_generic_data_get(const Eobj *obj, const char *key);
116 EAPI void *eobj_generic_data_del(Eobj *obj, const char *key);
117
118 #define EOBJ_CLASS_BASE eobj_base_class_get()
119 EAPI const Eobj_Class *eobj_base_class_get(void) EINA_CONST;
120
121 EAPI void eobj_composite_object_attach(Eobj *obj, Eobj *emb_obj);
122 EAPI void eobj_composite_object_detach(Eobj *obj, Eobj *emb_obj);
123 EAPI Eina_Bool eobj_composite_is(Eobj *emb_obj);
124
125 /* Events */
126 /**
127  * @def EOBJ_CALLBACK_PRIORITY_BEFORE
128  * Slightly more prioritized than default.
129  */
130 #define EOBJ_CALLBACK_PRIORITY_BEFORE -100
131 /**
132  * @def EOBJ_CALLBACK_PRIORITY_DEFAULT
133  * Default callback priority level
134  */
135 #define EOBJ_CALLBACK_PRIORITY_DEFAULT 0
136 /**
137  * @def EOBJ_CALLBACK_PRIORITY_AFTER
138  * Slightly less prioritized than default.
139  */
140 #define EOBJ_CALLBACK_PRIORITY_AFTER 100
141 typedef short Eobj_Callback_Priority;
142
143 /* True meaning continue, False meaning stop callbacks. - Make it an enum? */
144 typedef Eina_Bool (*Eobj_Event_Cb)(void *data, Eobj *obj, const Eobj_Event_Description *desc, void *event_info);
145
146 EAPI Eina_Bool eobj_event_callback_forwarder_add(Eobj *obj, const Eobj_Event_Description *desc, Eobj *new_obj);
147 EAPI Eina_Bool eobj_event_callback_forwarder_del(Eobj *obj, const Eobj_Event_Description *desc, Eobj *new_obj);
148
149 /* callbacks of the same priority are called in reverse order of creation. */
150 EAPI Eina_Bool eobj_event_callback_add(Eobj *obj, const Eobj_Event_Description *desc, Eobj_Event_Cb cb, const void *data);
151 EAPI Eina_Bool eobj_event_callback_priority_add(Eobj *obj, const Eobj_Event_Description *desc, Eobj_Callback_Priority priority, Eobj_Event_Cb cb, const void *data);
152 EAPI void *eobj_event_callback_del(Eobj *obj, const Eobj_Event_Description *desc, Eobj_Event_Cb func);
153 EAPI void *eobj_event_callback_del_full(Eobj *obj, const Eobj_Event_Description *desc, Eobj_Event_Cb func, const void *user_data);
154 EAPI Eina_Bool eobj_event_callback_call(Eobj *obj, const Eobj_Event_Description *desc, const void *event_info);
155
156 EAPI extern const Eobj_Event_Description _EOBJ_SIG_CALLBACK_ADD;
157 #define EOBJ_SIG_CALLBACK_ADD (&(_EOBJ_SIG_CALLBACK_ADD))
158 EAPI extern const Eobj_Event_Description _EOBJ_SIG_CALLBACK_DEL;
159 #define EOBJ_SIG_CALLBACK_DEL (&(_EOBJ_SIG_CALLBACK_DEL))
160
161 #endif