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