Eo: Implemented eo_isa(). It checks if an object implements a class.
[profile/ivi/eobj.git] / src / lib / Eo.h
1 #ifndef EO_H
2 #define EO_H
3
4 #include <stdarg.h>
5 #include <Eina.h>
6
7 #ifdef EAPI
8 # undef EAPI
9 #endif
10
11 #ifdef _WIN32
12 # ifdef EFL_EO_BUILD
13 #  ifdef DLL_EXPORT
14 #   define EAPI __declspec(dllexport)
15 #  else
16 #   define EAPI
17 #  endif /* ! DLL_EXPORT */
18 # else
19 #  define EAPI __declspec(dllimport)
20 # endif /* ! EFL_EO_BUILD */
21 #else
22 # ifdef __GNUC__
23 #  if __GNUC__ >= 4
24 #   define EAPI __attribute__ ((visibility("default")))
25 #  else
26 #   define EAPI
27 #  endif
28 # else
29 #  define EAPI
30 # endif
31 #endif /* ! _WIN32 */
32
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36
37 /**
38  * @def EO_OP_CLASS_OFFSET
39  * The bit offset of the class inside the ops.
40  * @internal
41  */
42 #define EO_OP_CLASS_OFFSET 16
43
44 /**
45  * @def EO_CLASS_ID_TO_BASE_ID(class_id)
46  * Translates a class id to an op base id.
47  * @internal
48  */
49 #define EO_CLASS_ID_TO_BASE_ID(class_id) ((class_id) << EO_OP_CLASS_OFFSET)
50
51 /**
52  * @var _eo_class_creation_lock
53  * This variable is used for locking purposes in the class_get function
54  * defined in #EO_DEFINE_CLASS.
55  * This is just to work around the fact that we need to init locks before
56  * using them.
57  * Don't touch it if you don't know what you are doing.
58  * @internal
59  */
60 EAPI extern Eina_Lock _eo_class_creation_lock;
61
62 /**
63  * @internal
64  * An enum representing the possible types of an Op.
65  */
66 enum _Eo_Op_Type
67 {
68    EO_OP_TYPE_INVALID = -1, /**< Invalid op. */
69    EO_OP_TYPE_REGULAR = 0, /**< Regular op. */
70    EO_OP_TYPE_CONST, /**< Const op - object should not change. */
71    EO_OP_TYPE_CLASS, /**< Class op - a class op. Like static in Java/C++. */
72 };
73
74 /**
75  * @internal
76  * @typedef Eo_Op_Type
77  * A convenience typedef for #_Eo_Op_Type.
78  */
79 typedef enum _Eo_Op_Type Eo_Op_Type;
80
81 /**
82  * @defgroup Eo Eo Generic Object System
83  *
84  * The Eo generic object system. It was designed to be the base object
85  * system for the EFL.
86  *
87  * @{
88  */
89
90 /**
91  * @def EO_TYPECHECK(type, x)
92  *
93  * Checks x is castable to type "type" and casts it to it.
94  * @param type The C type to check against.
95  * @param x the variable to test and cast.
96  */
97 #define EO_TYPECHECK(type, x) \
98    ({ \
99     type __x; \
100     __x = x; \
101     (type) __x; \
102     })
103
104 /**
105  * @typedef Eo
106  * The basic Object type.
107  */
108 typedef struct _Eo Eo;
109 /**
110  * @typedef Eo_Op
111  * The Eo operation type id.
112  */
113 typedef unsigned int Eo_Op;
114
115 /**
116  * @typedef Eo_Class
117  * The basic Object class type.
118  * @ingroup Eo_Class
119  */
120 typedef struct _Eo_Class Eo_Class;
121
122 /**
123  * @typedef Eo_Class_Id
124  * An Id of a class.
125  * @ingroup Eo_Class
126  */
127 typedef size_t Eo_Class_Id;
128
129 /**
130  * @def EO_NOOP
131  * A special #Eo_Op meaning "No operation".
132  */
133 #define EO_NOOP ((Eo_Op) 0)
134
135 /**
136  * @typedef eo_op_func_type
137  * The type of the Op functions. This is the type of the functions used by
138  * Eo.
139  *
140  * @see eo_op_func_type_const
141  */
142 typedef void (*eo_op_func_type)(Eo *, void *class_data, va_list *list);
143
144 /**
145  * @typedef eo_op_func_type_const
146  * The type of the const Op functions. This is the type of the functions used
147  * by Eo. This is the same as #eo_op_func_type, except that this should
148  * be used with functions that don't modify the data.
149  *
150  * @see eo_op_func_type
151  */
152 typedef void (*eo_op_func_type_const)(const Eo *, const void *class_data, va_list *list);
153
154 /**
155  * @typedef eo_op_func_type_class
156  * The type of the class Op functions. This is the same as #eo_op_func_type,\
157  * exepct that it's for usage with class functions, and not with object
158  * functions.
159  *
160  * @see eo_op_func_type
161  */
162 typedef void (*eo_op_func_type_class)(const Eo_Class *, va_list *list);
163
164 /**
165  * @addtogroup Eo_Events Eo's Event Handling
166  * @{
167  */
168
169 /**
170  * @struct _Eo_Event_Description
171  * This struct holds the description of a specific event.
172  */
173 struct _Eo_Event_Description
174 {
175    const char *name; /**< name of the event. */
176    const char *doc; /**< Explanation about the event. */
177 };
178
179 /**
180  * @typedef Eo_Event_Description
181  * A convenience typedef for #_Eo_Event_Description
182  */
183 typedef struct _Eo_Event_Description Eo_Event_Description;
184
185 /**
186  * @def EO_EVENT_DESCRIPTION(name, doc)
187  * An helper macro to help populating #Eo_Event_Description
188  * @param name The name of the event.
189  * @param doc Additional doc for the event.
190  * @see Eo_Event_Description
191  */
192 #define EO_EVENT_DESCRIPTION(name, doc) { name, doc }
193
194 /**
195  * @}
196  */
197
198 /**
199  * @addtogroup Eo_Class Eo Class
200  * @{
201  */
202
203 /**
204  * @def EO_DEFINE_CLASS(class_get_func_name, class_desc, parent_class, ...)
205  * A convenience macro to be used for creating the class_get function. This
206  * macro is fairly simple but should still be used as it'll let us improve
207  * things easily.
208  * @param class_get_func_name the name of the wanted class_get function name.
209  * @param class_desc the class description.
210  * @param parent_class The parent class for the function. Look at eo_class_new() for more information.
211  * @param ... List of etxensions. Look at eo_class_new() for more information.
212  *
213  * You must use this macro if you want thread safety in class creation.
214  */
215 #define EO_DEFINE_CLASS(class_get_func_name, class_desc, parent_class, ...) \
216    EO_DEFINE_CLASS_STATIC(class_get_func_name, 0, class_desc, parent_class, __VA_ARGS__)
217
218 /**
219  * @def EO_DEFINE_CLASS_STATIC(class_get_func_name, id, class_desc, parent_class, ...)
220  * *** DO NOT USE UNLESS YOU REALLY KNOW WHAT YOU ARE DOING ***
221  * @param id a positive number to serve as the id of the class. 0 means dynamic. See eo_class_new() for details.
222  * @param class_get_func_name the name of the wanted class_get function name.
223  * @param class_desc the class description.
224  * @param parent_class The parent class for the function. Look at eo_class_new() for more information.
225  * @param ... List of etxensions. Look at eo_class_new() for more information.
226  *
227  * This macro should only be used if you know what you are doing and you want
228  * to create a class with a static id.
229  * Use #EO_DEFINE_CLASS instead.
230  *
231  * @see #EO_DEFINE_CLASS
232  */
233 #define EO_DEFINE_CLASS_STATIC(class_get_func_name, id, class_desc, parent_class, ...) \
234 EAPI const Eo_Class * \
235 class_get_func_name(void) \
236 { \
237    static volatile char lk_init = 0; \
238    static Eina_Lock _my_lock; \
239    static const Eo_Class * volatile _my_class = NULL; \
240    if (EINA_LIKELY(!!_my_class)) return _my_class; \
241    \
242    eina_lock_take(&_eo_class_creation_lock); \
243    if (!lk_init) \
244       eina_lock_new(&_my_lock); \
245    if (lk_init < 2) eina_lock_take(&_my_lock); \
246    if (!lk_init) \
247       lk_init = 1; \
248    else \
249      { \
250         if (lk_init < 2) eina_lock_release(&_my_lock); \
251         eina_lock_release(&_eo_class_creation_lock); \
252         return _my_class; \
253      } \
254    eina_lock_release(&_eo_class_creation_lock); \
255    (void) parent_class; \
256    _my_class = eo_class_new(class_desc, id, parent_class, __VA_ARGS__); \
257    eina_lock_release(&_my_lock); \
258    \
259    eina_lock_take(&_eo_class_creation_lock); \
260    eina_lock_free(&_my_lock); \
261    lk_init = 2; \
262    eina_lock_release(&_eo_class_creation_lock); \
263    return _my_class; \
264 }
265
266
267 /**
268  * An enum representing the possible types of an Eo class.
269  */
270 enum _Eo_Class_Type
271 {
272    EO_CLASS_TYPE_REGULAR = 0, /**< Regular class. */
273    EO_CLASS_TYPE_REGULAR_NO_INSTANT, /**< Regular non instant-able class. */
274    EO_CLASS_TYPE_INTERFACE, /**< Interface */
275    EO_CLASS_TYPE_MIXIN /**< Mixin */
276 };
277
278 /**
279  * @typedef Eo_Class_Type
280  * A convenience typedef for #_Eo_Class_Type.
281  */
282 typedef enum _Eo_Class_Type Eo_Class_Type;
283
284 /**
285  * @struct _Eo_Op_Func_Description
286  * Used to associate an Op with a func.
287  * @see eo_class_funcs_set
288  */
289 struct _Eo_Op_Func_Description
290 {
291    Eo_Op op; /**< The op */
292    eo_op_func_type func; /**< The function to call for the op. */
293    Eo_Op_Type op_type; /**< The type of the op */
294 };
295
296 /**
297  * @typedef Eo_Op_Func_Description
298  * A convenience typedef for #_Eo_Op_Func_Description
299  */
300 typedef struct _Eo_Op_Func_Description Eo_Op_Func_Description;
301
302 /**
303  * @def EO_OP_FUNC(op, func)
304  * A convenience macro to be used when populating the #Eo_Op_Func_Description
305  * array.
306  *
307  * @see EO_OP_FUNC_CONST
308  */
309 #define EO_OP_FUNC(op, func) { op, EO_TYPECHECK(eo_op_func_type, func), EO_OP_TYPE_REGULAR }
310
311 /**
312  * @def EO_OP_FUNC_CONST(op, func)
313  * A convenience macro to be used when populating the #Eo_Op_Func_Description
314  * array.
315  * The same as #EO_OP_FUNC but for const functions.
316  *
317  * @see EO_OP_FUNC
318  */
319 #define EO_OP_FUNC_CONST(op, func) { op, (eo_op_func_type) EO_TYPECHECK(eo_op_func_type_const, func), EO_OP_TYPE_CONST }
320
321 /**
322  * @def EO_OP_FUNC_CLASS(op, func)
323  * A convenience macro to be used when populating the #Eo_Op_Func_Description
324  * array.
325  * The same as #EO_OP_FUNC but for class functions.
326  *
327  * @see EO_OP_FUNC
328  */
329 #define EO_OP_FUNC_CLASS(op, func) { op, (eo_op_func_type) EO_TYPECHECK(eo_op_func_type_class, func), EO_OP_TYPE_CLASS }
330
331 /**
332  * @def EO_OP_FUNC_SENTINEL
333  * A convenience macro to be used when populating the #Eo_Op_Func_Description
334  * array. It must appear at the end of the ARRAY.
335  */
336 #define EO_OP_FUNC_SENTINEL { 0, NULL, EO_OP_TYPE_INVALID }
337
338 /**
339  * @struct _Eo_Op_Description
340  * This struct holds the description of a specific op.
341  */
342 struct _Eo_Op_Description
343 {
344    Eo_Op sub_op; /**< The sub_id of the op in it's class. */
345    const char *name; /**< The name of the op. */
346    const char *doc; /**< Explanation about the Op. */
347    Eo_Op_Type op_type; /**< The type of the Op. */
348 };
349
350 /**
351  * @typedef Eo_Op_Description
352  * A convenience typedef for #_Eo_Op_Description
353  */
354 typedef struct _Eo_Op_Description Eo_Op_Description;
355
356 /**
357  * @struct _Eo_Class_Description
358  * This struct holds the description of a class.
359  * This description should be passed to eo_class_new.
360  * Please use the #EO_CLASS_DESCRIPTION_OPS macro when populating it.
361  */
362 struct _Eo_Class_Description
363 {
364    const char *name; /**< The name of the class. */
365    Eo_Class_Type type; /**< The type of the class. */
366    struct {
367         Eo_Op *base_op_id;
368         const Eo_Op_Description *descs;
369         size_t count;
370    } ops; /**< The ops description, should be filled using #EO_CLASS_DESCRIPTION_OPS */
371    const Eo_Event_Description **events; /**< The event descriptions for this class. */
372    size_t data_size; /**< The size of data (private + protected + public) this class needs per object. */
373    void (*class_constructor)(Eo_Class *klass); /**< The constructor of the class. */
374    void (*class_destructor)(Eo_Class *klass); /**< The destructor of the class. */
375 };
376
377 /**
378  * @typedef Eo_Class_Description
379  * A convenience typedef for #_Eo_Class_Description
380  */
381 typedef struct _Eo_Class_Description Eo_Class_Description;
382
383 /**
384  * @def EO_CLASS_DESCRIPTION_OPS(base_op_id, op_descs, count)
385  * An helper macro to help populating #Eo_Class_Description.
386  * @param base_op_id A pointer to the base op id of the class.
387  * @param op_descs the op descriptions array.
388  * @param count the number of ops in the op descriptions array.
389  */
390 #define EO_CLASS_DESCRIPTION_OPS(base_op_id, op_descs, count) { base_op_id, op_descs, count }
391
392 /**
393  * @def EO_OP_DESCRIPTION(op, doc)
394  * An helper macro to help populating #Eo_Op_Description
395  * @param sub_id The sub id of the op being described.
396  * @param doc Additional doc for the op.
397  * @see Eo_Op_Description
398  * @see EO_OP_DESCRIPTION_CLASS
399  * @see EO_OP_DESCRIPTION_CONST
400  * @see EO_OP_DESCRIPTION_SENTINEL
401  */
402 #define EO_OP_DESCRIPTION(sub_id, doc) { sub_id, #sub_id, doc, EO_OP_TYPE_REGULAR }
403
404 /**
405  * @def EO_OP_DESCRIPTION_CONST(op, doc)
406  * An helper macro to help populating #Eo_Op_Description
407  * This macro is the same as EO_OP_DESCRIPTION but indicates that the op's
408  * implementation should not change the object.
409  * @param sub_id The sub id of the op being described.
410  * @param doc Additional doc for the op.
411  * @see Eo_Op_Description
412  * @see EO_OP_DESCRIPTION
413  * @see EO_OP_DESCRIPTION_SENTINEL
414  */
415 #define EO_OP_DESCRIPTION_CONST(sub_id, doc) { sub_id, #sub_id, doc, EO_OP_TYPE_CONST }
416
417 /**
418  * @def EO_OP_DESCRIPTION_CLASS(op, doc)
419  * An helper macro to help populating #Eo_Op_Description
420  * This macro is the same as EO_OP_DESCRIPTION but indicates that the op's
421  * implementation is of type CLASS.
422  * @param sub_id The sub id of the op being described.
423  * @param doc Additional doc for the op.
424  * @see Eo_Op_Description
425  * @see EO_OP_DESCRIPTION
426  * @see EO_OP_DESCRIPTION_SENTINEL
427  */
428 #define EO_OP_DESCRIPTION_CLASS(sub_id, doc) { sub_id, #sub_id, doc, EO_OP_TYPE_CLASS }
429
430 /**
431  * @def EO_OP_DESCRIPTION_SENTINEL
432  * An helper macro to help populating #Eo_Op_Description
433  * Should be placed at the end of the array.
434  * @see Eo_Op_Description
435  * @see EO_OP_DESCRIPTION
436  */
437 #define EO_OP_DESCRIPTION_SENTINEL { 0, NULL, NULL, EO_OP_TYPE_INVALID }
438
439 /**
440  * @brief Create a new class.
441  * @param desc the class description to create the class with.
442  * @param id a positive number to serve as the id of the class. 0 means dynamic allocation. The number of static Ids is limited and regular users should not use static ids.
443  * @param parent the class to inherit from.
444  * @param ... A NULL terminated list of extensions (interfaces, mixins and the classes of any composite objects).
445  * @return The new class's handle on success, or NULL otherwise.
446  *
447  * You should use #EO_DEFINE_CLASS. It'll provide thread safety and other
448  * features easily.
449  *
450  * @see #EO_DEFINE_CLASS
451  */
452 EAPI const Eo_Class *eo_class_new(const Eo_Class_Description *desc, Eo_Class_Id id, const Eo_Class *parent, ...);
453
454 /**
455  * @brief Check if an object "is a" klass.
456  * @param obj The object to check
457  * @param klass The klass to check against.
458  * @return @c EINA_TRUE if obj implements klass, @c EINA_FALSE otherwise.
459  *
460  * Notice: This function does not support composite objects.
461  */
462 EAPI Eina_Bool eo_isa(const Eo *obj, const Eo_Class *klass);
463
464 /**
465  * @brief Sets the OP functions for a class.
466  * @param klass the class to set the functions to.
467  * @param func_descs a NULL terminated array of #Eo_Op_Func_Description
468  *
469  * Should be called from within the class constructor.
470  */
471 EAPI void eo_class_funcs_set(Eo_Class *klass, const Eo_Op_Func_Description *func_descs);
472
473 /**
474  * @brief Gets the name of the passed class.
475  * @param klass the class to work on.
476  * @return The class's name.
477  *
478  * @see eo_class_get()
479  */
480 EAPI const char *eo_class_name_get(const Eo_Class *klass);
481
482 /**
483  * @}
484  */
485
486 /**
487  * @brief Init the eo subsystem
488  * @return @c EINA_TRUE on success.
489  *
490  * @see eo_shutfown()
491  */
492 EAPI Eina_Bool eo_init(void);
493
494 /**
495  * @brief Shutdown the eo subsystem
496  * @return @c EINA_TRUE on success.
497  *
498  * @see eo_init()
499  */
500 EAPI Eina_Bool eo_shutdown(void);
501
502 /**
503  * @def eo_do
504  * A convenience wrapper around eo_do_internal()
505  * @see eo_do_internal
506  */
507 #define eo_do(obj, ...) eo_do_internal(obj, EO_OP_TYPE_REGULAR, __VA_ARGS__, EO_NOOP)
508
509 /**
510  * @def eo_query
511  * Same as #eo_do but only for const ops.
512  * @see eo_do
513  */
514 #define eo_query(obj, ...) eo_do_internal((Eo *) EO_TYPECHECK(const Eo *, obj), EO_OP_TYPE_CONST, __VA_ARGS__, EO_NOOP)
515
516 /**
517  * @def eo_class_do
518  * A convenience wrapper around eo_class_do_internal()
519  * @see eo_class_do_internal
520  */
521 #define eo_class_do(klass, ...) eo_class_do_internal(klass, __VA_ARGS__, EO_NOOP)
522
523 /**
524  * @brief Calls op functions of an object
525  * @param obj The object to work on
526  * @param op_type The type of the ops that are passed.
527  * @param ... NULL terminated list of OPs and parameters.
528  * @return @c EINA_TRUE on success.
529  *
530  * Use the helper macros, don't pass the parameters manually.
531  * Use #eo_do instead of this function.
532  *
533  * @see #eo_do
534  */
535 EAPI Eina_Bool eo_do_internal(Eo *obj, Eo_Op_Type op_type, ...);
536
537 /**
538  * @brief Calls op functions of a class.
539  * @param klass The class to work on
540  * @param ... NULL terminated list of OPs and parameters.
541  * @return @c EINA_TRUE on success.
542  *
543  * Use the helper macros, don't pass the parameters manually.
544  * Use #eo_do instead of this function.
545  *
546  * @see #eo_class_do
547  */
548 EAPI Eina_Bool eo_class_do_internal(const Eo_Class *klass, ...);
549
550 /**
551  * @brief Calls the super function for the specific op.
552  * @param obj The object to work on
553  * @param ... list of parameters.
554  * @return @c EINA_TRUE on success.
555  *
556  * Unlike eo_do() and eo_query(), this function only accepts one op.
557  *
558  * Use the helper macros, don't pass the parameters manually.
559  *
560  * Same as eo_do_super() just for const objects.
561  *
562  * @see #eo_query
563  * @see eo_do_super()
564  */
565 #define eo_query_super(obj, ...) eo_do_super_internal((Eo *) EO_TYPECHECK(const Eo *, obj), EO_OP_TYPE_CONST, __VA_ARGS__)
566
567 /**
568  * @brief Calls the super function for the specific op.
569  * @param obj The object to work on
570  * @param ... list of parameters.
571  * @return @c EINA_TRUE on success.
572  *
573  * Unlike eo_do() and eo_query(), this function only accepts one op.
574  *
575  * @see #eo_do
576  * @see eo_query_super()
577  */
578 #define eo_do_super(obj, ...) eo_do_super_internal(obj, EO_OP_TYPE_REGULAR, __VA_ARGS__)
579
580 /**
581  * @brief Calls the super function for the specific op.
582  * @param klass The klass to work on
583  * @param ... list of parameters.
584  * @return @c EINA_TRUE on success.
585  *
586  * Unlike eo_class_do(), this function only accepts one op.
587  *
588  * @see #eo_class_do
589  */
590 #define eo_class_do_super(klass, ...) eo_class_do_super_internal(klass, __VA_ARGS__)
591
592 /**
593  * @brief Calls the super function for the specific op.
594  * @param obj The object to work on
595  * @param op_type The type of the ops that are passed.
596  * @param op The wanted op.
597  * @param ... list of parameters.
598  * @return @c EINA_TRUE on success.
599  *
600  * Don't use this function, use the wrapping macros instead.
601  *
602  * @see #eo_do
603  * @see #eo_do_super
604  * @see #eo_query_super
605  */
606 EAPI Eina_Bool eo_do_super_internal(Eo *obj, Eo_Op_Type op_type, Eo_Op op, ...);
607
608 /**
609  * @brief Calls the super function for the specific op.
610  * @param klass The klass to work on
611  * @param op The wanted op.
612  * @param ... list of parameters.
613  * @return @c EINA_TRUE on success.
614  *
615  * Don't use this function, use the wrapping macros instead.
616  *
617  * @see #eo_class_do
618  * @see #eo_class_do_super
619  */
620 EAPI Eina_Bool eo_class_do_super_internal(const Eo_Class *klass, Eo_Op op, ...);
621
622 /**
623  * @brief Gets the class of the object.
624  * @param obj The object to work on
625  * @return The object's class.
626  *
627  * @see eo_class_name_get()
628  */
629 EAPI const Eo_Class *eo_class_get(const Eo *obj);
630
631 /**
632  * @def eo_error_set
633  * @brief Notify eo that there was an error when constructing, destructing or calling a function of the object.
634  * @param obj the object to work on.
635  *
636  * @see eo_error_get()
637  */
638 #define eo_error_set(obj) eo_error_set_internal(obj, __FILE__, __LINE__)
639
640 /* @cond 0 */
641 EAPI void eo_error_set_internal(const Eo *obj, const char *file, int line);
642 /* @endcond */
643
644 /**
645  * @brief Create a new object.
646  * @param klass the class of the object to create.
647  * @param parent the parent to set to the object.
648  * @return An handle to the new object on success, NULL otherwise.
649  */
650 EAPI Eo *eo_add(const Eo_Class *klass, Eo *parent);
651
652 /**
653  * @brief Get the parent of an object
654  * @param obj the object to get the parent of.
655  * @return a pointer to the parent object.
656  *
657  * @see eo_parent_set()
658  */
659 EAPI Eo *eo_parent_get(const Eo *obj);
660
661 /**
662  * @brief Set the parent of an object
663  * @param obj the object to get the parent of.
664  * @param parent the new parent.
665  * @return @c EINA_TRUE on success, @c EINA_FALSE on failure.
666  *
667  * Parents keep references to their children so in order to delete objects
668  * that have parents you need to set parent to NULL or use eo_del() that
669  * does that for you (and also unrefs the object).
670  *
671  * @see eo_del()
672  * @see eo_parent_get()
673  */
674 EAPI Eina_Bool eo_parent_set(Eo *obj, const Eo *parent);
675
676 /**
677  * @brief Get a pointer to the data of an object for a specific class.
678  * @param obj the object to work on.
679  * @param klass the klass associated with the data.
680  * @return a pointer to the data.
681  */
682 EAPI void *eo_data_get(const Eo *obj, const Eo_Class *klass);
683
684 /**
685  * @brief Increment the object's reference count by 1.
686  * @param obj the object to work on.
687  * @return The object passed.
688  *
689  * It's very easy to get a refcount leak and start leaking memory because
690  * of a forgotten unref or an extra ref. That is why there are eo_xref
691  * and eo_xunref that will make debugging easier in such a case.
692  * Therefor, these functions should only be used in small scopes, i.e at the
693  * start of some section in which the object may get freed, or if you know
694  * what you are doing.
695  *
696  * @see eo_unref()
697  * @see eo_ref_get()
698  */
699 EAPI Eo *eo_ref(const Eo *obj);
700
701 /**
702  * @brief Decrement the object's reference count by 1 and free it if needed.
703  * @param obj the object to work on.
704  *
705  * @see eo_ref()
706  * @see eo_ref_get()
707  */
708 EAPI void eo_unref(const Eo *obj);
709
710 /**
711  * @brief Return the ref count of the object passed.
712  * @param obj the object to work on.
713  * @return the ref count of the object.
714  *
715  * @see eo_ref()
716  * @see eo_unref()
717  */
718 EAPI int eo_ref_get(const Eo *obj);
719
720 /**
721  * @brief Unrefs the object and reparents it to NULL.
722  * @param obj the object to work on.
723  *
724  * Because eo_del() unrefs and reparents to NULL, it doesn't really delete the
725  * object.
726  *
727  * @see eo_unref()
728  * @see eo_parent_set()
729  */
730 EAPI void eo_del(const Eo *obj);
731
732 /**
733  * @def eo_xref(obj, ref_obj)
734  * Convenience macro around eo_xref_internal()
735  * @see eo_xref()
736  */
737 #define eo_xref(obj, ref_obj) eo_xref_internal(obj, ref_obj, __FILE__, __LINE__)
738
739 /**
740  * @brief Increment the object's reference count by 1 (and associate the ref with ref_obj)
741  * @param obj the object to work on.
742  * @param ref_obj the object that references obj.
743  * @param file the call's filename.
744  * @param line the call's line number.
745  * @return The object passed (obj)
746  *
747  * People should not use this function, use #eo_xref instead.
748  * A compile flag my make it and eobj_xunref() behave the same as eobj_ref()
749  * and eobj_unref() respectively. So this should be used wherever possible.
750  *
751  * @see eo_xunref()
752  */
753 EAPI Eo *eo_xref_internal(Eo *obj, const Eo *ref_obj, const char *file, int line);
754
755 /**
756  * @brief Decrement the object's reference count by 1 and free it if needed. Will free the ref associated with ref_obj).
757  * @param obj the object to work on.
758  * @param ref_obj the object that references obj.
759  *
760  * This function only enforces the checks for object association. I.e don't rely
761  * on it. If such enforces are compiled out, this function behaves the same as
762  * eo_unref().
763  *
764  * @see eo_xref_internal()
765  */
766 EAPI void eo_xunref(Eo *obj, const Eo *ref_obj);
767
768 /**
769  * @brief Enable or disable the manual free feature.
770  * @param obj the object to work on.
771  * @param manual_free indicates if the free is manual (EINA_TRUE) or automatic (EINA_FALSE).
772  *
773  * The developer is in charge to call the function eo_manual_free to free the memory allocated for this object.
774  *
775  * Do not use, unless you really know what you are doing. It's used by Evas
776  * because evas wants to keep its private data available even after the object
777  * is deleted. Setting this to true makes Eo destruct the object but not free
778  * the private data or the object itself.
779  *
780  * @see eo_manual_free()
781  */
782 EAPI void eo_manual_free_set(Eo *obj, Eina_Bool manual_free);
783
784 /**
785  * @brief Frees the object.
786  * @param obj the object to work on.
787  * This function must be called by the developer if the function
788  * eo_manual_free_set has been called before with the parameter EINA_TRUE.
789  * An error will be printed if this function is called when the manual
790  * free option is not set to EINA_TRUE or the number of refs is not 0.
791  *
792  * @see eo_manual_free_set()
793  */
794 EAPI void eo_manual_free(Eo *obj);
795
796 /**
797  * @addtogroup Eo_Composite_Objects Composite Objects.
798  * @{
799  */
800
801 /**
802  * @brief Make an object a composite object of another.
803  * @param comp_obj the object that will be used to composite parent.
804  * @param parent the "parent" object.
805  *
806  * This functions also sets the parent of comp_obj to parent.
807  *
808  * @see eo_composite_detach()
809  * @see eo_composite_is()
810  */
811 EAPI void eo_composite_attach(Eo *comp_obj, Eo *parent);
812
813 /**
814  * @brief Detach a composite object from another object.
815  * @param comp_obj the object attached to parent.
816  * @param parent the "parent" object.
817  *
818  * This functions also sets the parent of comp_obj to @c NULL.
819  *
820  * @see eo_composite_attach()
821  * @see eo_composite_is()
822  */
823 EAPI void eo_composite_detach(Eo *comp_obj, Eo *parent);
824
825 /**
826  * @brief Check if an object is a composite object.
827  * @param comp_obj the object to be checked.
828  * @return @c EINA_TRUE if it is, @c EINA_FALSE otherwise.
829  *
830  * @see eo_composite_attach()
831  * @see eo_composite_detach()
832  */
833 EAPI Eina_Bool eo_composite_is(const Eo *comp_obj);
834
835 /**
836  * @}
837  */
838
839 /**
840  * @addtogroup Eo_Class_Base Eo's Base class.
841  * @{
842  */
843
844 /**
845  * @def EO_BASE_CLASS
846  * The class type for the Eo base class.
847  */
848 #define EO_BASE_CLASS eo_base_class_get()
849 /**
850  * @brief Use #EO_BASE_CLASS
851  * @internal
852  * */
853 EAPI const Eo_Class *eo_base_class_get(void);
854
855 /**
856  * @typedef eo_base_data_free_func
857  * Data free func prototype.
858  */
859 typedef void (*eo_base_data_free_func)(void *);
860
861 /**
862  * @def EO_BASE_CLASS_ID
863  * #EO_BASE_CLASS 's class id.
864  */
865 #define EO_BASE_CLASS_ID 1
866
867 /**
868  * @def EO_BASE_BASE_ID
869  * #EO_BASE_CLASS 's base id.
870  */
871 #define EO_BASE_BASE_ID EO_CLASS_ID_TO_BASE_ID(EO_BASE_CLASS_ID)
872
873 enum {
874      EO_BASE_SUB_ID_CONSTRUCTOR,
875      EO_BASE_SUB_ID_DESTRUCTOR,
876      EO_BASE_SUB_ID_DATA_SET,
877      EO_BASE_SUB_ID_DATA_GET,
878      EO_BASE_SUB_ID_DATA_DEL,
879      EO_BASE_SUB_ID_WREF_ADD,
880      EO_BASE_SUB_ID_WREF_DEL,
881      EO_BASE_SUB_ID_EVENT_CALLBACK_PRIORITY_ADD,
882      EO_BASE_SUB_ID_EVENT_CALLBACK_DEL,
883      EO_BASE_SUB_ID_EVENT_CALLBACK_CALL,
884      EO_BASE_SUB_ID_EVENT_CALLBACK_FORWARDER_ADD,
885      EO_BASE_SUB_ID_EVENT_CALLBACK_FORWARDER_DEL,
886      EO_BASE_SUB_ID_EVENT_FREEZE,
887      EO_BASE_SUB_ID_EVENT_THAW,
888      EO_BASE_SUB_ID_EVENT_FREEZE_GET,
889      EO_BASE_SUB_ID_EVENT_GLOBAL_FREEZE,
890      EO_BASE_SUB_ID_EVENT_GLOBAL_THAW,
891      EO_BASE_SUB_ID_EVENT_GLOBAL_FREEZE_GET,
892      EO_BASE_SUB_ID_LAST
893 };
894
895 /**
896  * @def EO_BASE_ID(sub_id)
897  * Helper macro to get the full Op ID out of the sub_id for EO_BASE.
898  * @param sub_id the sub id inside EO_BASE.
899  */
900 #define EO_BASE_ID(sub_id) (EO_BASE_BASE_ID + (sub_id))
901
902 /**
903  * @def eo_base_data_set(key, data, free_func)
904  * Set generic data to object.
905  * @param[in] key the key associated with the data
906  * @param[in] data the data to set.
907  * @param[in] free_func the func to free data with (NULL means "do nothing").
908  *
909  * @see #eo_base_data_get
910  * @see #eo_base_data_del
911  */
912 #define eo_base_data_set(key, data, free_func) EO_BASE_ID(EO_BASE_SUB_ID_DATA_SET), EO_TYPECHECK(const char *, key), EO_TYPECHECK(const void *, data), EO_TYPECHECK(eo_base_data_free_func, free_func)
913
914 /**
915  * @def eo_base_data_get(key, data)
916  * Get generic data from object.
917  * @param[in] key the key associated with the data
918  * @param[out] data the data for the key
919  *
920  * @see #eo_base_data_set
921  * @see #eo_base_data_del
922  */
923 #define eo_base_data_get(key, data) EO_BASE_ID(EO_BASE_SUB_ID_DATA_GET), EO_TYPECHECK(const char *, key), EO_TYPECHECK(void **, data)
924
925 /**
926  * @def eo_base_data_del(key)
927  * Del generic data from object.
928  * @param[in] key the key associated with the data
929  *
930  * @see #eo_base_data_set
931  * @see #eo_base_data_get
932  */
933 #define eo_base_data_del(key) EO_BASE_ID(EO_BASE_SUB_ID_DATA_DEL), EO_TYPECHECK(const char *, key)
934
935 /**
936  * @def eo_wref_add
937  * @brief Add a new weak reference to obj.
938  * @param wref The pointer to use for the weak ref.
939  *
940  * This function registers the object handle pointed by wref to obj so when
941  * obj is deleted it'll be updated to NULL. This functions should be used
942  * when you want to keep track of an object in a safe way, but you don't want
943  * to prevent it from being freed.
944  *
945  * @see #eo_wref_del
946  */
947 #define eo_wref_add(wref) EO_BASE_ID(EO_BASE_SUB_ID_WREF_ADD), EO_TYPECHECK(Eo **, wref)
948
949 /**
950  * @def eo_wref_del
951  * @brief Delete the weak reference passed.
952  * @param wref the weak reference to free.
953  *
954  * @see #eo_wref_add
955  */
956 #define eo_wref_del(wref) EO_BASE_ID(EO_BASE_SUB_ID_WREF_DEL), EO_TYPECHECK(Eo **, wref)
957
958 /**
959  * @def eo_wref_del_safe
960  * @brief Delete the weak reference passed.
961  * @param wref the weak reference to free.
962  *
963  * Same as eo_wref_del(), with the different that it's not called from eobj_do()
964  * so you don't need to check if *wref is not NULL.
965  *
966  * @see #eo_wref_del
967  */
968 #define eo_wref_del_safe(wref) \
969    do { \
970         if (*wref) eo_do(*wref, eo_wref_del(wref)); \
971    } while (0)
972
973 /**
974  * @def eo_constructor
975  * @brief Call the object's constructor.
976  *
977  * Should not be used with #eo_do. Only use it with #eo_do_super.
978  *
979  * @see #eo_destructor
980  */
981 #define eo_constructor() EO_BASE_ID(EO_BASE_SUB_ID_CONSTRUCTOR)
982
983 /**
984  * @def eo_destructor
985  * @brief Call the object's destructor.
986  *
987  * Should not be used with #eo_do. Only use it with #eo_do_super.
988  *
989  * @see #eo_constructor
990  */
991 #define eo_destructor() EO_BASE_ID(EO_BASE_SUB_ID_DESTRUCTOR)
992
993 /**
994  * @addtogroup Eo_Events Eo's Event Handling
995  * @{
996  */
997
998 /**
999  * @def EO_CALLBACK_PRIORITY_BEFORE
1000  * Slightly more prioritized than default.
1001  */
1002 #define EO_CALLBACK_PRIORITY_BEFORE -100
1003 /**
1004  * @def EO_CALLBACK_PRIORITY_DEFAULT
1005  * Default callback priority level
1006  */
1007 #define EO_CALLBACK_PRIORITY_DEFAULT 0
1008 /**
1009  * @def EO_CALLBACK_PRIORITY_AFTER
1010  * Slightly less prioritized than default.
1011  */
1012 #define EO_CALLBACK_PRIORITY_AFTER 100
1013
1014 /**
1015  * @typedef Eo_Callback_Priority
1016  *
1017  * Callback priority value. Range is -32k - 32k. The lower the number, the
1018  * higher the priority.
1019  *
1020  * @see EO_CALLBACK_PRIORITY_AFTER
1021  * @see EO_CALLBACK_PRIORITY_BEFORE
1022  * @see EO_CALLBACK_PRIORITY_DEFAULT
1023  */
1024 typedef short Eo_Callback_Priority;
1025
1026 /**
1027  * @def EO_CALLBACK_STOP
1028  * Stop calling callbacks for the even of which the callback was called for.
1029  * @see EO_CALLBACK_CONTINUE
1030  */
1031 #define EO_CALLBACK_STOP EINA_FALSE
1032
1033 /**
1034  * @def EO_CALLBACK_CONTINUE
1035  * Continue calling callbacks for the even of which the callback was called for.
1036  * @see EO_CALLBACK_STOP
1037  */
1038 #define EO_CALLBACK_CONTINUE EINA_TRUE
1039
1040 /**
1041  * @typedef Eo_Event_Cb
1042  *
1043  * An event callback prototype.
1044  *
1045  * @param data The user data registered with the callback.
1046  * @param obj The object which initiated the event.
1047  * @param desc The event's description.
1048  * @param event_info additional data passed with the event.
1049  * @return #EO_CALLBACK_STOP to stop calling additional callbacks for the event, #EO_CALLBACK_CONTINUE to continue.
1050  */
1051 typedef Eina_Bool (*Eo_Event_Cb)(void *data, Eo *obj, const Eo_Event_Description *desc, void *event_info);
1052
1053 /**
1054  * @def eo_event_callback_forwarder_add
1055  * @brief Add an event callback forwarder for an event and an object.
1056  * @param[in] desc The description of the event to listen to.
1057  * @param[in] new_obj The object to emit events from.
1058  *
1059  * @see eo_event_callback_forwarder_del()
1060  */
1061 #define eo_event_callback_forwarder_add(desc, new_obj) EO_BASE_ID(EO_BASE_SUB_ID_EVENT_CALLBACK_FORWARDER_ADD), EO_TYPECHECK(const Eo_Event_Description *, desc), EO_TYPECHECK(Eo *, new_obj)
1062
1063 /**
1064  * @def eo_event_callback_forwarder_del
1065  * @brief Remove an event callback forwarder for an event and an object.
1066  * @param[in] desc The description of the event to listen to.
1067  * @param[in] new_obj The object to emit events from.
1068  *
1069  * @see eo_event_callback_forwarder_add()
1070  */
1071 #define eo_event_callback_forwarder_del(desc, new_obj) EO_BASE_ID(EO_BASE_SUB_ID_EVENT_CALLBACK_FORWARDER_DEL), EO_TYPECHECK(const Eo_Event_Description *, desc), EO_TYPECHECK(Eo *, new_obj)
1072
1073 /**
1074  * @def eo_event_freeze
1075  * @brief freeze events of object.
1076  *
1077  * Prevents event callbacks from being called for the object.
1078  *
1079  * @see #eo_event_thaw
1080  */
1081 #define eo_event_freeze() EO_BASE_ID(EO_BASE_SUB_ID_EVENT_FREEZE)
1082
1083 /**
1084  * @def eo_event_thaw
1085  * @brief thaw events of object.
1086  *
1087  * Lets event callbacks be called for the object.
1088  *
1089  * @see #eo_event_freeze
1090  */
1091 #define eo_event_thaw() EO_BASE_ID(EO_BASE_SUB_ID_EVENT_THAW)
1092
1093 /**
1094  * @def eo_event_freeze_get
1095  * @brief return freeze events of object.
1096  *
1097  * @param[out] fcount The event freeze count of the object.
1098  *
1099  * Return event freeze count.
1100  *
1101  * @see #eo_event_freeze
1102  * @see #eo_event_thaw
1103  */
1104 #define eo_event_freeze_get(fcount) EO_BASE_ID(EO_BASE_SUB_ID_EVENT_FREEZE_GET), EO_TYPECHECK(int *, fcount)
1105
1106 /**
1107  * @def eo_event_global_freeze
1108  * @brief freeze events of object.
1109  *
1110  * Prevents event callbacks from being called for the object.
1111  *
1112  * @see #eo_event_freeze
1113  * @see #eo_event_global_thaw
1114  */
1115 #define eo_event_global_freeze() EO_BASE_ID(EO_BASE_SUB_ID_EVENT_GLOBAL_FREEZE)
1116
1117 /**
1118  * @def eo_event_global_thaw
1119  * @brief thaw events of object.
1120  *
1121  * Lets event callbacks be called for the object.
1122  *
1123  * @see #eo_event_thaw
1124  * @see #eo_event_global_freeze
1125  */
1126 #define eo_event_global_thaw() EO_BASE_ID(EO_BASE_SUB_ID_EVENT_GLOBAL_THAW)
1127
1128 /**
1129  * @def eo_event_global_freeze_get
1130  * @brief return freeze events of object.
1131  *
1132  * @param[out] fcount The event freeze count of the object.
1133  *
1134  * Return event freeze count.
1135  *
1136  * @see #eo_event_freeze_get
1137  * @see #eo_event_global_freeze
1138  * @see #eo_event_global_thaw
1139  */
1140 #define eo_event_global_freeze_get(fcount) EO_BASE_ID(EO_BASE_SUB_ID_EVENT_GLOBAL_FREEZE_GET), EO_TYPECHECK(int *, fcount)
1141
1142 /**
1143  * @def eo_event_callback_add(obj, desc, cb, data)
1144  * Add a callback for an event.
1145  * @param[in] desc The description of the event to listen to.
1146  * @param[in] cb the callback to call.
1147  * @param[in] data additional data to pass to the callback.
1148  *
1149  * callbacks of the same priority are called in reverse order of creation.
1150  *
1151  * @see eo_event_callback_priority_add()
1152  */
1153 #define eo_event_callback_add(desc, cb, data) \
1154    eo_event_callback_priority_add(desc, \
1155          EO_CALLBACK_PRIORITY_DEFAULT, cb, data)
1156
1157 /**
1158  * @def eo_event_callback_priority_add
1159  * @brief Add a callback for an event with a specific priority.
1160  * @param[in] desc The description of the event to listen to.
1161  * @param[in] priority The priority of the callback.
1162  * @param[in] cb the callback to call.
1163  * @param[in] data additional data to pass to the callback.
1164  *
1165  * callbacks of the same priority are called in reverse order of creation.
1166  *
1167  * @see #eo_event_callback_add
1168  */
1169 #define eo_event_callback_priority_add(desc, priority, cb, data) EO_BASE_ID(EO_BASE_SUB_ID_EVENT_CALLBACK_PRIORITY_ADD), EO_TYPECHECK(const Eo_Event_Description *, desc), EO_TYPECHECK(Eo_Callback_Priority, priority), EO_TYPECHECK(Eo_Event_Cb, cb), EO_TYPECHECK(const void *, data)
1170
1171
1172 /**
1173  * @def eo_event_callback_del
1174  * @brief Del a callback with a specific data associated to it for an event.
1175  * @param[in] desc The description of the event to listen to.
1176  * @param[in] func the callback to delete.
1177  * @param[in] user_data The data to compare.
1178  *
1179  */
1180 #define eo_event_callback_del(desc, func, user_data) EO_BASE_ID(EO_BASE_SUB_ID_EVENT_CALLBACK_DEL), EO_TYPECHECK(const Eo_Event_Description *, desc), EO_TYPECHECK(Eo_Event_Cb, func), EO_TYPECHECK(const void *, user_data)
1181
1182 /**
1183  * @def eo_event_callback_call
1184  * @brief Call the callbacks for an event of an object.
1185  * @param[in] desc The description of the event to call.
1186  * @param[in] event_info Extra event info to pass to the callbacks.
1187  * @param[out] aborted @c EINA_TRUE if one of the callbacks aborted the call, @c EINA_FALSE otherwise.
1188  */
1189 #define eo_event_callback_call(desc, event_info, aborted) EO_BASE_ID(EO_BASE_SUB_ID_EVENT_CALLBACK_CALL), EO_TYPECHECK(const Eo_Event_Description *, desc), EO_TYPECHECK(const void *, event_info), EO_TYPECHECK(Eina_Bool *, aborted)
1190
1191 /**
1192  * @}
1193  */
1194
1195 /**
1196  * @var _EO_EV_CALLBACK_ADD
1197  * see EO_EV_CALLBACK_ADD
1198  */
1199 EAPI extern const Eo_Event_Description _EO_EV_CALLBACK_ADD;
1200
1201 /**
1202  * @def EO_EV_CALLBACK_ADD
1203  * The event description (of type #Eo_Event_Description) for
1204  * The "Callback listener added" event.
1205  */
1206 #define EO_EV_CALLBACK_ADD (&(_EO_EV_CALLBACK_ADD))
1207
1208 /**
1209  * @var _EO_EV_CALLBACK_DEL
1210  * see EO_EV_CALLBACK_DEL
1211  */
1212 EAPI extern const Eo_Event_Description _EO_EV_CALLBACK_DEL;
1213
1214 /**
1215  * @def EO_EV_CALLBACK_DEL
1216  * The event description (of type #Eo_Event_Description) for
1217  * The "Callback listener deleted" event.
1218  */
1219 #define EO_EV_CALLBACK_DEL (&(_EO_EV_CALLBACK_DEL))
1220
1221 /**
1222  * @var _EO_EV_DEL
1223  * see #EO_EV_DEL
1224  */
1225 EAPI extern const Eo_Event_Description _EO_EV_DEL;
1226
1227 /**
1228  * @def EO_EV_DEL
1229  * Object is being deleted.
1230  */
1231 #define EO_EV_DEL (&(_EO_EV_DEL))
1232
1233 /**
1234  * @}
1235  */
1236
1237 /**
1238  * @}
1239  */
1240
1241 #ifdef __cplusplus
1242 }
1243 #endif
1244
1245 #endif