summaryrefslogtreecommitdiff
path: root/legacy/eobj/src/lib/Eo.h
blob: 08f0a1aa0a3fd3e004e3dbfa2c7eab234b63e616 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
#ifndef EO_H
#define EO_H

#include <stdarg.h>
#include <Eina.h>

#ifdef EAPI
# undef EAPI
#endif

#ifdef _WIN32
# ifdef EFL_EO_BUILD
#  ifdef DLL_EXPORT
#   define EAPI __declspec(dllexport)
#  else
#   define EAPI
#  endif /* ! DLL_EXPORT */
# else
#  define EAPI __declspec(dllimport)
# endif /* ! EFL_EO_BUILD */
#else
# ifdef __GNUC__
#  if __GNUC__ >= 4
#   define EAPI __attribute__ ((visibility("default")))
#  else
#   define EAPI
#  endif
# else
#  define EAPI
# endif
#endif /* ! _WIN32 */

#ifdef __cplusplus
extern "C" {
#endif

/**
 * @var _eo_class_creation_lock
 * This variable is used for locking purposes in the class_get function
 * defined in #EO_DEFINE_CLASS.
 * This is just to work around the fact that we need to init locks before
 * using them.
 * Don't touch it if you don't know what you are doing.
 * @internal
 */
EAPI extern Eina_Lock _eo_class_creation_lock;

/**
 * @internal
 * An enum representing the possible types of an Op.
 */
enum _Eo_Op_Type
{
   EO_OP_TYPE_INVALID = -1, /**< Invalid op. */
   EO_OP_TYPE_REGULAR = 0, /**< Regular op. */
   EO_OP_TYPE_CLASS, /**< Class op - a class op. Like static in Java/C++. */
};

/**
 * @internal
 * @typedef Eo_Op_Type
 * A convenience typedef for #_Eo_Op_Type.
 */
typedef enum _Eo_Op_Type Eo_Op_Type;

/**
 * @defgroup Eo Eo Generic Object System
 *
 * The Eo generic object system. It was designed to be the base object
 * system for the EFL.
 *
 * @{
 */

/**
 * @def EO_TYPECHECK(type, x)
 *
 * Checks x is castable to type "type" and casts it to it.
 * @param type The C type to check against.
 * @param x the variable to test and cast.
 */
#define EO_TYPECHECK(type, x) \
   ({ \
    type __x; \
    __x = x; \
    (type) __x; \
    })

/**
 * @typedef Eo
 * The basic Object type.
 */
typedef struct _Eo Eo;
/**
 * @typedef Eo_Op
 * The Eo operation type id.
 */
typedef unsigned int Eo_Op;

/**
 * @typedef Eo_Class
 * The basic Object class type.
 * @ingroup Eo_Class
 */
typedef struct _Eo_Class Eo_Class;

/**
 * @typedef Eo_Class_Id
 * An Id of a class.
 * @ingroup Eo_Class
 */
typedef size_t Eo_Class_Id;

/**
 * @def EO_NOOP
 * A special #Eo_Op meaning "No operation".
 */
#define EO_NOOP ((Eo_Op) 0)

/**
 * @typedef eo_op_func_type
 * The type of the Op functions. This is the type of the functions used by
 * Eo.
 *
 * @see eo_op_func_type_class
 */
typedef void (*eo_op_func_type)(Eo *, void *class_data, va_list *list);

/**
 * @typedef eo_op_func_type_class
 * The type of the class Op functions. This is the same as #eo_op_func_type,\
 * exepct that it's for usage with class functions, and not with object
 * functions.
 *
 * @see eo_op_func_type
 */
typedef void (*eo_op_func_type_class)(const Eo_Class *, va_list *list);

/**
 * @addtogroup Eo_Events Eo's Event Handling
 * @{
 */

/**
 * @struct _Eo_Event_Description
 * This struct holds the description of a specific event.
 */
struct _Eo_Event_Description
{
   const char *name; /**< name of the event. */
   const char *doc; /**< Explanation about the event. */
};

/**
 * @typedef Eo_Event_Description
 * A convenience typedef for #_Eo_Event_Description
 */
typedef struct _Eo_Event_Description Eo_Event_Description;

/**
 * @def EO_EVENT_DESCRIPTION(name, doc)
 * An helper macro to help populating #Eo_Event_Description
 * @param name The name of the event.
 * @param doc Additional doc for the event.
 * @see Eo_Event_Description
 */
#define EO_EVENT_DESCRIPTION(name, doc) { name, doc }

/**
 * @}
 */

/**
 * @addtogroup Eo_Class Eo Class
 * @{
 */

/**
 * @def EO_DEFINE_CLASS(class_get_func_name, class_desc, parent_class, ...)
 * A convenience macro to be used for creating the class_get function. This
 * macro is fairly simple but should still be used as it'll let us improve
 * things easily.
 * @param class_get_func_name the name of the wanted class_get function name.
 * @param class_desc the class description.
 * @param parent_class The parent class for the function. Look at eo_class_new() for more information.
 * @param ... List of etxensions. Look at eo_class_new() for more information.
 *
 * You must use this macro if you want thread safety in class creation.
 */
#define EO_DEFINE_CLASS(class_get_func_name, class_desc, parent_class, ...) \
EAPI const Eo_Class * \
class_get_func_name(void) \
{ \
   const Eo_Class *_tmp_parent_class; \
   static volatile char lk_init = 0; \
   static Eina_Lock _my_lock; \
   static const Eo_Class * volatile _my_class = NULL; \
   if (EINA_LIKELY(!!_my_class)) return _my_class; \
   \
   eina_lock_take(&_eo_class_creation_lock); \
   if (!lk_init) \
      eina_lock_new(&_my_lock); \
   if (lk_init < 2) eina_lock_take(&_my_lock); \
   if (!lk_init) \
      lk_init = 1; \
   else \
     { \
        if (lk_init < 2) eina_lock_release(&_my_lock); \
        eina_lock_release(&_eo_class_creation_lock); \
        return _my_class; \
     } \
   eina_lock_release(&_eo_class_creation_lock); \
   _tmp_parent_class = parent_class; \
   _my_class = eo_class_new(class_desc, _tmp_parent_class, __VA_ARGS__); \
   eina_lock_release(&_my_lock); \
   \
   eina_lock_take(&_eo_class_creation_lock); \
   eina_lock_free(&_my_lock); \
   lk_init = 2; \
   eina_lock_release(&_eo_class_creation_lock); \
   return _my_class; \
}


/**
 * An enum representing the possible types of an Eo class.
 */
enum _Eo_Class_Type
{
   EO_CLASS_TYPE_REGULAR = 0, /**< Regular class. */
   EO_CLASS_TYPE_REGULAR_NO_INSTANT, /**< Regular non instant-able class. */
   EO_CLASS_TYPE_INTERFACE, /**< Interface */
   EO_CLASS_TYPE_MIXIN /**< Mixin */
};

/**
 * @typedef Eo_Class_Type
 * A convenience typedef for #_Eo_Class_Type.
 */
typedef enum _Eo_Class_Type Eo_Class_Type;

/**
 * @struct _Eo_Op_Func_Description
 * Used to associate an Op with a func.
 * @see eo_class_funcs_set
 */
struct _Eo_Op_Func_Description
{
   Eo_Op op; /**< The op */
   eo_op_func_type func; /**< The function to call for the op. */
   Eo_Op_Type op_type; /**< The type of the op */
};

/**
 * @typedef Eo_Op_Func_Description
 * A convenience typedef for #_Eo_Op_Func_Description
 */
typedef struct _Eo_Op_Func_Description Eo_Op_Func_Description;

/**
 * @def EO_OP_FUNC(op, func)
 * A convenience macro to be used when populating the #Eo_Op_Func_Description
 * array.
 */
#define EO_OP_FUNC(op, func) { op, EO_TYPECHECK(eo_op_func_type, func), EO_OP_TYPE_REGULAR }

/**
 * @def EO_OP_FUNC_CLASS(op, func)
 * A convenience macro to be used when populating the #Eo_Op_Func_Description
 * array.
 * The same as #EO_OP_FUNC but for class functions.
 *
 * @see EO_OP_FUNC
 */
#define EO_OP_FUNC_CLASS(op, func) { op, (eo_op_func_type) EO_TYPECHECK(eo_op_func_type_class, func), EO_OP_TYPE_CLASS }

/**
 * @def EO_OP_FUNC_SENTINEL
 * A convenience macro to be used when populating the #Eo_Op_Func_Description
 * array. It must appear at the end of the ARRAY.
 */
#define EO_OP_FUNC_SENTINEL { 0, NULL, EO_OP_TYPE_INVALID }

/**
 * @struct _Eo_Op_Description
 * This struct holds the description of a specific op.
 */
struct _Eo_Op_Description
{
   Eo_Op sub_op; /**< The sub_id of the op in it's class. */
   const char *name; /**< The name of the op. */
   const char *doc; /**< Explanation about the Op. */
   Eo_Op_Type op_type; /**< The type of the Op. */
};

/**
 * @typedef Eo_Op_Description
 * A convenience typedef for #_Eo_Op_Description
 */
typedef struct _Eo_Op_Description Eo_Op_Description;

/**
 * @def EO_VERSION
 * The current version of EO.
 */
#define EO_VERSION 1

/**
 * @struct _Eo_Class_Description
 * This struct holds the description of a class.
 * This description should be passed to eo_class_new.
 * Please use the #EO_CLASS_DESCRIPTION_OPS macro when populating it.
 */
struct _Eo_Class_Description
{
   unsigned int version; /**< The current version of eo, use #EO_VERSION */
   const char *name; /**< The name of the class. */
   Eo_Class_Type type; /**< The type of the class. */
   struct {
        Eo_Op *base_op_id;
        const Eo_Op_Description *descs;
        size_t count;
   } ops; /**< The ops description, should be filled using #EO_CLASS_DESCRIPTION_OPS */
   const Eo_Event_Description **events; /**< The event descriptions for this class. */
   size_t data_size; /**< The size of data (private + protected + public) this class needs per object. */
   void (*class_constructor)(Eo_Class *klass); /**< The constructor of the class. */
   void (*class_destructor)(Eo_Class *klass); /**< The destructor of the class. */
};

/**
 * @typedef Eo_Class_Description
 * A convenience typedef for #_Eo_Class_Description
 */
typedef struct _Eo_Class_Description Eo_Class_Description;

/**
 * @def EO_CLASS_DESCRIPTION_OPS(base_op_id, op_descs, count)
 * An helper macro to help populating #Eo_Class_Description.
 * @param base_op_id A pointer to the base op id of the class.
 * @param op_descs the op descriptions array.
 * @param count the number of ops in the op descriptions array.
 */
#define EO_CLASS_DESCRIPTION_OPS(base_op_id, op_descs, count) { base_op_id, op_descs, count }

/**
 * @def EO_OP_DESCRIPTION(op, doc)
 * An helper macro to help populating #Eo_Op_Description
 * @param sub_id The sub id of the op being described.
 * @param doc Additional doc for the op.
 * @see Eo_Op_Description
 * @see EO_OP_DESCRIPTION_CLASS
 * @see EO_OP_DESCRIPTION_SENTINEL
 */
#define EO_OP_DESCRIPTION(sub_id, doc) { sub_id, #sub_id, doc, EO_OP_TYPE_REGULAR }

/**
 * @def EO_OP_DESCRIPTION_CLASS(op, doc)
 * An helper macro to help populating #Eo_Op_Description
 * This macro is the same as EO_OP_DESCRIPTION but indicates that the op's
 * implementation is of type CLASS.
 * @param sub_id The sub id of the op being described.
 * @param doc Additional doc for the op.
 * @see Eo_Op_Description
 * @see EO_OP_DESCRIPTION
 * @see EO_OP_DESCRIPTION_SENTINEL
 */
#define EO_OP_DESCRIPTION_CLASS(sub_id, doc) { sub_id, #sub_id, doc, EO_OP_TYPE_CLASS }

/**
 * @def EO_OP_DESCRIPTION_SENTINEL
 * An helper macro to help populating #Eo_Op_Description
 * Should be placed at the end of the array.
 * @see Eo_Op_Description
 * @see EO_OP_DESCRIPTION
 */
#define EO_OP_DESCRIPTION_SENTINEL { 0, NULL, NULL, EO_OP_TYPE_INVALID }

/**
 * @brief Create a new class.
 * @param desc the class description to create the class with.
 * @param parent the class to inherit from.
 * @param ... A NULL terminated list of extensions (interfaces, mixins and the classes of any composite objects).
 * @return The new class's handle on success, or NULL otherwise.
 *
 * You should use #EO_DEFINE_CLASS. It'll provide thread safety and other
 * features easily.
 *
 * @see #EO_DEFINE_CLASS
 */
EAPI const Eo_Class *eo_class_new(const Eo_Class_Description *desc, const Eo_Class *parent, ...);

/**
 * @brief Check if an object "is a" klass.
 * @param obj The object to check
 * @param klass The klass to check against.
 * @return @c EINA_TRUE if obj implements klass, @c EINA_FALSE otherwise.
 *
 * Notice: This function does not support composite objects.
 */
EAPI Eina_Bool eo_isa(const Eo *obj, const Eo_Class *klass);

/**
 * @brief Sets the OP functions for a class.
 * @param klass the class to set the functions to.
 * @param func_descs a NULL terminated array of #Eo_Op_Func_Description
 *
 * Should be called from within the class constructor.
 */
EAPI void eo_class_funcs_set(Eo_Class *klass, const Eo_Op_Func_Description *func_descs);

/**
 * @brief Gets the name of the passed class.
 * @param klass the class to work on.
 * @return The class's name.
 *
 * @see eo_class_get()
 */
EAPI const char *eo_class_name_get(const Eo_Class *klass);

/**
 * @}
 */

/**
 * @brief Init the eo subsystem
 * @return @c EINA_TRUE on success.
 *
 * @see eo_shutfown()
 */
EAPI Eina_Bool eo_init(void);

/**
 * @brief Shutdown the eo subsystem
 * @return @c EINA_TRUE on success.
 *
 * @see eo_init()
 */
EAPI Eina_Bool eo_shutdown(void);

/**
 * @def eo_do
 * A convenience wrapper around eo_do_internal()
 * @see eo_do_internal
 */
#define eo_do(obj, ...) eo_do_internal(obj, EO_OP_TYPE_REGULAR, __VA_ARGS__, EO_NOOP)

/**
 * @def eo_class_do
 * A convenience wrapper around eo_class_do_internal()
 * @see eo_class_do_internal
 */
#define eo_class_do(klass, ...) eo_class_do_internal(klass, __VA_ARGS__, EO_NOOP)

/**
 * @brief Calls op functions of an object
 * @param obj The object to work on
 * @param op_type The type of the ops that are passed.
 * @param ... NULL terminated list of OPs and parameters.
 * @return @c EINA_TRUE on success.
 *
 * Use the helper macros, don't pass the parameters manually.
 * Use #eo_do instead of this function.
 *
 * @see #eo_do
 */
EAPI Eina_Bool eo_do_internal(Eo *obj, Eo_Op_Type op_type, ...);

/**
 * @brief Calls op functions of a class.
 * @param klass The class to work on
 * @param ... NULL terminated list of OPs and parameters.
 * @return @c EINA_TRUE on success.
 *
 * Use the helper macros, don't pass the parameters manually.
 * Use #eo_do instead of this function.
 *
 * @see #eo_class_do
 */
EAPI Eina_Bool eo_class_do_internal(const Eo_Class *klass, ...);

/**
 * @brief Calls the super function for the specific op.
 * @param obj The object to work on
 * @param ... list of parameters.
 * @return @c EINA_TRUE on success.
 *
 * Unlike eo_do(), this function only accepts one op.
 *
 * @see #eo_do
 */
#define eo_do_super(obj, ...) eo_do_super_internal(obj, EO_OP_TYPE_REGULAR, __VA_ARGS__)

/**
 * @brief Calls the super function for the specific op.
 * @param klass The klass to work on
 * @param ... list of parameters.
 * @return @c EINA_TRUE on success.
 *
 * Unlike eo_class_do(), this function only accepts one op.
 *
 * @see #eo_class_do
 */
#define eo_class_do_super(klass, ...) eo_class_do_super_internal(klass, __VA_ARGS__)

/**
 * @brief Calls the super function for the specific op.
 * @param obj The object to work on
 * @param op_type The type of the ops that are passed.
 * @param op The wanted op.
 * @param ... list of parameters.
 * @return @c EINA_TRUE on success.
 *
 * Don't use this function, use the wrapping macros instead.
 *
 * @see #eo_do
 * @see #eo_do_super
 */
EAPI Eina_Bool eo_do_super_internal(Eo *obj, Eo_Op_Type op_type, Eo_Op op, ...);

/**
 * @brief Calls the super function for the specific op.
 * @param klass The klass to work on
 * @param op The wanted op.
 * @param ... list of parameters.
 * @return @c EINA_TRUE on success.
 *
 * Don't use this function, use the wrapping macros instead.
 *
 * @see #eo_class_do
 * @see #eo_class_do_super
 */
EAPI Eina_Bool eo_class_do_super_internal(const Eo_Class *klass, Eo_Op op, ...);

/**
 * @brief Gets the class of the object.
 * @param obj The object to work on
 * @return The object's class.
 *
 * @see eo_class_name_get()
 */
EAPI const Eo_Class *eo_class_get(const Eo *obj);

/**
 * @def eo_error_set
 * @brief Notify eo that there was an error when constructing, destructing or calling a function of the object.
 * @param obj the object to work on.
 *
 * @see eo_error_get()
 */
#define eo_error_set(obj) eo_error_set_internal(obj, __FILE__, __LINE__)

/* @cond 0 */
EAPI void eo_error_set_internal(const Eo *obj, const char *file, int line);
/* @endcond */

/**
 * @def eo_add
 * @brief Create a new object with the default constructor.
 * @param klass the class of the object to create.
 * @param parent the parent to set to the object.
 * @param ... The ops to run.
 * @return An handle to the new object on success, NULL otherwise.
 *
 * @see #eo_add_custom
 */
#define eo_add(klass, parent, ...) \
   ({ \
    const Eo_Class *_tmp_klass = klass; \
    eo_add_internal(_tmp_klass, parent, eo_constructor(), ## __VA_ARGS__, EO_NOOP); \
    })

/**
 * @def eo_add_custom
 * @brief Create a new object with a custom constructor.
 * @param klass the class of the object to create.
 * @param parent the parent to set to the object.
 * @param ... The ops to run. With the constructor being first.
 * @return An handle to the new object on success, NULL otherwise.
 *
 * @see #eo_add
 */
#define eo_add_custom(klass, parent, ...) \
   ({ \
    const Eo_Class *_tmp_klass = klass; \
    eo_add_internal(_tmp_klass, parent, ## __VA_ARGS__, EO_NOOP); \
    })

/**
 * @brief Create a new object.
 * @param klass the class of the object to create.
 * @param parent the parent to set to the object.
 * @param ... The ops to run. With the constructor being first.
 * @return An handle to the new object on success, NULL otherwise.
 *
 * Use the helper macros, don't pass the parameters manually.
 * Use #eo_add or #eo_add_custom instead of this function.
 *
 * @see #eo_add
 */
EAPI Eo *eo_add_internal(const Eo_Class *klass, Eo *parent, ...);

/**
 * @brief Get the parent of an object
 * @param obj the object to get the parent of.
 * @return a pointer to the parent object.
 *
 * @see eo_parent_set()
 */
EAPI Eo *eo_parent_get(const Eo *obj);

/**
 * @brief Set the parent of an object
 * @param obj the object to get the parent of.
 * @param parent the new parent.
 * @return @c EINA_TRUE on success, @c EINA_FALSE on failure.
 *
 * Parents keep references to their children so in order to delete objects
 * that have parents you need to set parent to NULL or use eo_del() that
 * does that for you (and also unrefs the object).
 *
 * @see eo_del()
 * @see eo_parent_get()
 */
EAPI Eina_Bool eo_parent_set(Eo *obj, const Eo *parent);

/**
 * @brief Get a pointer to the data of an object for a specific class.
 * @param obj the object to work on.
 * @param klass the klass associated with the data.
 * @return a pointer to the data.
 */
EAPI void *eo_data_get(const Eo *obj, const Eo_Class *klass);

/**
 * @brief Increment the object's reference count by 1.
 * @param obj the object to work on.
 * @return The object passed.
 *
 * It's very easy to get a refcount leak and start leaking memory because
 * of a forgotten unref or an extra ref. That is why there are eo_xref
 * and eo_xunref that will make debugging easier in such a case.
 * Therefor, these functions should only be used in small scopes, i.e at the
 * start of some section in which the object may get freed, or if you know
 * what you are doing.
 *
 * @see eo_unref()
 * @see eo_ref_get()
 */
EAPI Eo *eo_ref(const Eo *obj);

/**
 * @brief Decrement the object's reference count by 1 and free it if needed.
 * @param obj the object to work on.
 *
 * @see eo_ref()
 * @see eo_ref_get()
 */
EAPI void eo_unref(const Eo *obj);

/**
 * @brief Return the ref count of the object passed.
 * @param obj the object to work on.
 * @return the ref count of the object.
 *
 * @see eo_ref()
 * @see eo_unref()
 */
EAPI int eo_ref_get(const Eo *obj);

/**
 * @brief Unrefs the object and reparents it to NULL.
 * @param obj the object to work on.
 *
 * Because eo_del() unrefs and reparents to NULL, it doesn't really delete the
 * object.
 *
 * @see eo_unref()
 * @see eo_parent_set()
 */
EAPI void eo_del(const Eo *obj);

/**
 * @def eo_xref(obj, ref_obj)
 * Convenience macro around eo_xref_internal()
 * @see eo_xref()
 */
#define eo_xref(obj, ref_obj) eo_xref_internal(obj, ref_obj, __FILE__, __LINE__)

/**
 * @brief Increment the object's reference count by 1 (and associate the ref with ref_obj)
 * @param obj the object to work on.
 * @param ref_obj the object that references obj.
 * @param file the call's filename.
 * @param line the call's line number.
 * @return The object passed (obj)
 *
 * People should not use this function, use #eo_xref instead.
 * A compile flag my make it and eobj_xunref() behave the same as eobj_ref()
 * and eobj_unref() respectively. So this should be used wherever possible.
 *
 * @see eo_xunref()
 */
EAPI Eo *eo_xref_internal(Eo *obj, const Eo *ref_obj, const char *file, int line);

/**
 * @brief Decrement the object's reference count by 1 and free it if needed. Will free the ref associated with ref_obj).
 * @param obj the object to work on.
 * @param ref_obj the object that references obj.
 *
 * This function only enforces the checks for object association. I.e don't rely
 * on it. If such enforces are compiled out, this function behaves the same as
 * eo_unref().
 *
 * @see eo_xref_internal()
 */
EAPI void eo_xunref(Eo *obj, const Eo *ref_obj);

/**
 * @brief Enable or disable the manual free feature.
 * @param obj the object to work on.
 * @param manual_free indicates if the free is manual (EINA_TRUE) or automatic (EINA_FALSE).
 *
 * The developer is in charge to call the function eo_manual_free to free the memory allocated for this object.
 *
 * Do not use, unless you really know what you are doing. It's used by Evas
 * because evas wants to keep its private data available even after the object
 * is deleted. Setting this to true makes Eo destruct the object but not free
 * the private data or the object itself.
 *
 * @see eo_manual_free()
 */
EAPI void eo_manual_free_set(Eo *obj, Eina_Bool manual_free);

/**
 * @brief Frees the object.
 * @param obj the object to work on.
 * This function must be called by the developer if the function
 * eo_manual_free_set has been called before with the parameter EINA_TRUE.
 * An error will be printed if this function is called when the manual
 * free option is not set to EINA_TRUE or the number of refs is not 0.
 *
 * @see eo_manual_free_set()
 */
EAPI void eo_manual_free(Eo *obj);

/**
 * @addtogroup Eo_Composite_Objects Composite Objects.
 * @{
 */

/**
 * @brief Make an object a composite object of another.
 * @param comp_obj the object that will be used to composite parent.
 * @param parent the "parent" object.
 *
 * This functions also sets the parent of comp_obj to parent.
 *
 * @see eo_composite_detach()
 * @see eo_composite_is()
 */
EAPI void eo_composite_attach(Eo *comp_obj, Eo *parent);

/**
 * @brief Detach a composite object from another object.
 * @param comp_obj the object attached to parent.
 * @param parent the "parent" object.
 *
 * This functions also sets the parent of comp_obj to @c NULL.
 *
 * @see eo_composite_attach()
 * @see eo_composite_is()
 */
EAPI void eo_composite_detach(Eo *comp_obj, Eo *parent);

/**
 * @brief Check if an object is a composite object.
 * @param comp_obj the object to be checked.
 * @return @c EINA_TRUE if it is, @c EINA_FALSE otherwise.
 *
 * @see eo_composite_attach()
 * @see eo_composite_detach()
 */
EAPI Eina_Bool eo_composite_is(const Eo *comp_obj);

/**
 * @}
 */

/**
 * @addtogroup Eo_Class_Base Eo's Base class.
 * @{
 */

/**
 * @def EO_BASE_CLASS
 * The class type for the Eo base class.
 */
#define EO_BASE_CLASS eo_base_class_get()
/**
 * @brief Use #EO_BASE_CLASS
 * @internal
 * */
EAPI const Eo_Class *eo_base_class_get(void);

/**
 * @typedef eo_base_data_free_func
 * Data free func prototype.
 */
typedef void (*eo_base_data_free_func)(void *);

/**
 * @var EO_BASE_BASE_ID
 * #EO_BASE_CLASS 's base id.
 */
extern EAPI Eo_Op EO_BASE_BASE_ID;

enum {
     EO_BASE_SUB_ID_CONSTRUCTOR,
     EO_BASE_SUB_ID_DESTRUCTOR,
     EO_BASE_SUB_ID_DATA_SET,
     EO_BASE_SUB_ID_DATA_GET,
     EO_BASE_SUB_ID_DATA_DEL,
     EO_BASE_SUB_ID_WREF_ADD,
     EO_BASE_SUB_ID_WREF_DEL,
     EO_BASE_SUB_ID_EVENT_CALLBACK_PRIORITY_ADD,
     EO_BASE_SUB_ID_EVENT_CALLBACK_DEL,
     EO_BASE_SUB_ID_EVENT_CALLBACK_CALL,
     EO_BASE_SUB_ID_EVENT_CALLBACK_FORWARDER_ADD,
     EO_BASE_SUB_ID_EVENT_CALLBACK_FORWARDER_DEL,
     EO_BASE_SUB_ID_EVENT_FREEZE,
     EO_BASE_SUB_ID_EVENT_THAW,
     EO_BASE_SUB_ID_EVENT_FREEZE_GET,
     EO_BASE_SUB_ID_EVENT_GLOBAL_FREEZE,
     EO_BASE_SUB_ID_EVENT_GLOBAL_THAW,
     EO_BASE_SUB_ID_EVENT_GLOBAL_FREEZE_GET,
     EO_BASE_SUB_ID_LAST
};

/**
 * @def EO_BASE_ID(sub_id)
 * Helper macro to get the full Op ID out of the sub_id for EO_BASE.
 * @param sub_id the sub id inside EO_BASE.
 */
#define EO_BASE_ID(sub_id) (EO_BASE_BASE_ID + (sub_id))

/**
 * @def eo_base_data_set(key, data, free_func)
 * Set generic data to object.
 * @param[in] key the key associated with the data
 * @param[in] data the data to set.
 * @param[in] free_func the func to free data with (NULL means "do nothing").
 *
 * @see #eo_base_data_get
 * @see #eo_base_data_del
 */
#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)

/**
 * @def eo_base_data_get(key, data)
 * Get generic data from object.
 * @param[in] key the key associated with the data
 * @param[out] data the data for the key
 *
 * @see #eo_base_data_set
 * @see #eo_base_data_del
 */
#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)

/**
 * @def eo_base_data_del(key)
 * Del generic data from object.
 * @param[in] key the key associated with the data
 *
 * @see #eo_base_data_set
 * @see #eo_base_data_get
 */
#define eo_base_data_del(key) EO_BASE_ID(EO_BASE_SUB_ID_DATA_DEL), EO_TYPECHECK(const char *, key)

/**
 * @def eo_wref_add
 * @brief Add a new weak reference to obj.
 * @param wref The pointer to use for the weak ref.
 *
 * This function registers the object handle pointed by wref to obj so when
 * obj is deleted it'll be updated to NULL. This functions should be used
 * when you want to keep track of an object in a safe way, but you don't want
 * to prevent it from being freed.
 *
 * @see #eo_wref_del
 */
#define eo_wref_add(wref) EO_BASE_ID(EO_BASE_SUB_ID_WREF_ADD), EO_TYPECHECK(Eo **, wref)

/**
 * @def eo_wref_del
 * @brief Delete the weak reference passed.
 * @param wref the weak reference to free.
 *
 * @see #eo_wref_add
 */
#define eo_wref_del(wref) EO_BASE_ID(EO_BASE_SUB_ID_WREF_DEL), EO_TYPECHECK(Eo **, wref)

/**
 * @def eo_wref_del_safe
 * @brief Delete the weak reference passed.
 * @param wref the weak reference to free.
 *
 * Same as eo_wref_del(), with the different that it's not called from eobj_do()
 * so you don't need to check if *wref is not NULL.
 *
 * @see #eo_wref_del
 */
#define eo_wref_del_safe(wref) \
   do { \
        if (*wref) eo_do(*wref, eo_wref_del(wref)); \
   } while (0)

/**
 * @def eo_constructor
 * @brief Call the object's constructor.
 *
 * Should not be used with #eo_do. Only use it with #eo_do_super.
 *
 * @see #eo_destructor
 */
#define eo_constructor() EO_BASE_ID(EO_BASE_SUB_ID_CONSTRUCTOR)

/**
 * @def eo_destructor
 * @brief Call the object's destructor.
 *
 * Should not be used with #eo_do. Only use it with #eo_do_super.
 *
 * @see #eo_constructor
 */
#define eo_destructor() EO_BASE_ID(EO_BASE_SUB_ID_DESTRUCTOR)

/**
 * @addtogroup Eo_Events Eo's Event Handling
 * @{
 */

/**
 * @def EO_CALLBACK_PRIORITY_BEFORE
 * Slightly more prioritized than default.
 */
#define EO_CALLBACK_PRIORITY_BEFORE -100
/**
 * @def EO_CALLBACK_PRIORITY_DEFAULT
 * Default callback priority level
 */
#define EO_CALLBACK_PRIORITY_DEFAULT 0
/**
 * @def EO_CALLBACK_PRIORITY_AFTER
 * Slightly less prioritized than default.
 */
#define EO_CALLBACK_PRIORITY_AFTER 100

/**
 * @typedef Eo_Callback_Priority
 *
 * Callback priority value. Range is -32k - 32k. The lower the number, the
 * higher the priority.
 *
 * @see EO_CALLBACK_PRIORITY_AFTER
 * @see EO_CALLBACK_PRIORITY_BEFORE
 * @see EO_CALLBACK_PRIORITY_DEFAULT
 */
typedef short Eo_Callback_Priority;

/**
 * @def EO_CALLBACK_STOP
 * Stop calling callbacks for the even of which the callback was called for.
 * @see EO_CALLBACK_CONTINUE
 */
#define EO_CALLBACK_STOP EINA_FALSE

/**
 * @def EO_CALLBACK_CONTINUE
 * Continue calling callbacks for the even of which the callback was called for.
 * @see EO_CALLBACK_STOP
 */
#define EO_CALLBACK_CONTINUE EINA_TRUE

/**
 * @typedef Eo_Event_Cb
 *
 * An event callback prototype.
 *
 * @param data The user data registered with the callback.
 * @param obj The object which initiated the event.
 * @param desc The event's description.
 * @param event_info additional data passed with the event.
 * @return #EO_CALLBACK_STOP to stop calling additional callbacks for the event, #EO_CALLBACK_CONTINUE to continue.
 */
typedef Eina_Bool (*Eo_Event_Cb)(void *data, Eo *obj, const Eo_Event_Description *desc, void *event_info);

/**
 * @def eo_event_callback_forwarder_add
 * @brief Add an event callback forwarder for an event and an object.
 * @param[in] desc The description of the event to listen to.
 * @param[in] new_obj The object to emit events from.
 *
 * @see eo_event_callback_forwarder_del()
 */
#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)

/**
 * @def eo_event_callback_forwarder_del
 * @brief Remove an event callback forwarder for an event and an object.
 * @param[in] desc The description of the event to listen to.
 * @param[in] new_obj The object to emit events from.
 *
 * @see eo_event_callback_forwarder_add()
 */
#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)

/**
 * @def eo_event_freeze
 * @brief freeze events of object.
 *
 * Prevents event callbacks from being called for the object.
 *
 * @see #eo_event_thaw
 */
#define eo_event_freeze() EO_BASE_ID(EO_BASE_SUB_ID_EVENT_FREEZE)

/**
 * @def eo_event_thaw
 * @brief thaw events of object.
 *
 * Lets event callbacks be called for the object.
 *
 * @see #eo_event_freeze
 */
#define eo_event_thaw() EO_BASE_ID(EO_BASE_SUB_ID_EVENT_THAW)

/**
 * @def eo_event_freeze_get
 * @brief return freeze events of object.
 *
 * @param[out] fcount The event freeze count of the object.
 *
 * Return event freeze count.
 *
 * @see #eo_event_freeze
 * @see #eo_event_thaw
 */
#define eo_event_freeze_get(fcount) EO_BASE_ID(EO_BASE_SUB_ID_EVENT_FREEZE_GET), EO_TYPECHECK(int *, fcount)

/**
 * @def eo_event_global_freeze
 * @brief freeze events of object.
 *
 * Prevents event callbacks from being called for the object.
 *
 * @see #eo_event_freeze
 * @see #eo_event_global_thaw
 */
#define eo_event_global_freeze() EO_BASE_ID(EO_BASE_SUB_ID_EVENT_GLOBAL_FREEZE)

/**
 * @def eo_event_global_thaw
 * @brief thaw events of object.
 *
 * Lets event callbacks be called for the object.
 *
 * @see #eo_event_thaw
 * @see #eo_event_global_freeze
 */
#define eo_event_global_thaw() EO_BASE_ID(EO_BASE_SUB_ID_EVENT_GLOBAL_THAW)

/**
 * @def eo_event_global_freeze_get
 * @brief return freeze events of object.
 *
 * @param[out] fcount The event freeze count of the object.
 *
 * Return event freeze count.
 *
 * @see #eo_event_freeze_get
 * @see #eo_event_global_freeze
 * @see #eo_event_global_thaw
 */
#define eo_event_global_freeze_get(fcount) EO_BASE_ID(EO_BASE_SUB_ID_EVENT_GLOBAL_FREEZE_GET), EO_TYPECHECK(int *, fcount)

/**
 * @def eo_event_callback_add(obj, desc, cb, data)
 * Add a callback for an event.
 * @param[in] desc The description of the event to listen to.
 * @param[in] cb the callback to call.
 * @param[in] data additional data to pass to the callback.
 *
 * callbacks of the same priority are called in reverse order of creation.
 *
 * @see eo_event_callback_priority_add()
 */
#define eo_event_callback_add(desc, cb, data) \
   eo_event_callback_priority_add(desc, \
         EO_CALLBACK_PRIORITY_DEFAULT, cb, data)

/**
 * @def eo_event_callback_priority_add
 * @brief Add a callback for an event with a specific priority.
 * @param[in] desc The description of the event to listen to.
 * @param[in] priority The priority of the callback.
 * @param[in] cb the callback to call.
 * @param[in] data additional data to pass to the callback.
 *
 * callbacks of the same priority are called in reverse order of creation.
 *
 * @see #eo_event_callback_add
 */
#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)


/**
 * @def eo_event_callback_del
 * @brief Del a callback with a specific data associated to it for an event.
 * @param[in] desc The description of the event to listen to.
 * @param[in] func the callback to delete.
 * @param[in] user_data The data to compare.
 *
 */
#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)

/**
 * @def eo_event_callback_call
 * @brief Call the callbacks for an event of an object.
 * @param[in] desc The description of the event to call.
 * @param[in] event_info Extra event info to pass to the callbacks.
 * @param[out] aborted @c EINA_TRUE if one of the callbacks aborted the call, @c EINA_FALSE otherwise.
 */
#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)

/**
 * @}
 */

/**
 * @var _EO_EV_CALLBACK_ADD
 * see EO_EV_CALLBACK_ADD
 */
EAPI extern const Eo_Event_Description _EO_EV_CALLBACK_ADD;

/**
 * @def EO_EV_CALLBACK_ADD
 * The event description (of type #Eo_Event_Description) for
 * The "Callback listener added" event.
 */
#define EO_EV_CALLBACK_ADD (&(_EO_EV_CALLBACK_ADD))

/**
 * @var _EO_EV_CALLBACK_DEL
 * see EO_EV_CALLBACK_DEL
 */
EAPI extern const Eo_Event_Description _EO_EV_CALLBACK_DEL;

/**
 * @def EO_EV_CALLBACK_DEL
 * The event description (of type #Eo_Event_Description) for
 * The "Callback listener deleted" event.
 */
#define EO_EV_CALLBACK_DEL (&(_EO_EV_CALLBACK_DEL))

/**
 * @var _EO_EV_DEL
 * see #EO_EV_DEL
 */
EAPI extern const Eo_Event_Description _EO_EV_DEL;

/**
 * @def EO_EV_DEL
 * Object is being deleted.
 */
#define EO_EV_DEL (&(_EO_EV_DEL))

/**
 * @}
 */

/**
 * @}
 */

#ifdef __cplusplus
}
#endif

#endif