EFL 1.7 svn doobies
[profile/ivi/eina.git] / src / examples / eina_model_04_child.c
1 /*
2  * child.c
3  */
4
5 #include "eina_model_04_child.h"
6 #include "eina_model_04_whistler.h"
7
8 static Eina_Bool initialized = EINA_FALSE;
9
10 static void
11 _child_cry(Eina_Model *m)
12 {
13    printf("%s\t%s", eina_model_type_name_get(eina_model_type_get(m)),
14          __func__);
15    printf("\t\t Cry Child\n");
16 }
17
18 static void
19 _child_dive(Eina_Model *m)
20 {
21    printf("%s\t%s", eina_model_type_name_get(eina_model_type_get(m)),
22          __func__);
23    printf("\t\t Dive Child\n");
24 }
25
26 const char *CHILD_MODEL_TYPE_NAME = NULL;
27
28 static Child_Type _CHILD_TYPE;
29 const Eina_Model_Type * const CHILD_TYPE = (Eina_Model_Type *) &_CHILD_TYPE;
30
31 static const Diver_Interface _DIVER_INTERFACE;
32 static const Eina_Model_Interface * const DIVER_INTERFACE =
33    (Eina_Model_Interface *) &_DIVER_INTERFACE;
34
35 static const Eina_Model_Interface * CLASS_INTERFACE_ARRAY[] =
36    { &_DIVER_INTERFACE.base_interface, NULL }; //this array is for model
37
38 void
39 child_init()
40 {
41    Eina_Model_Type *type;
42
43    if (initialized) return;
44    initialized = EINA_TRUE;
45
46    human_init();
47
48    //overriding Diver Interface
49    Eina_Model_Interface * iface = (Eina_Model_Interface *) &_DIVER_INTERFACE;
50    iface->version = EINA_MODEL_INTERFACE_VERSION;
51    iface->interface_size = sizeof(Diver_Interface);
52    iface->name = DIVER_INTERFACE_NAME;
53    DIVER_INTERFACE(iface)->dive = _child_dive;
54
55    //creating instance of Child type
56    CHILD_MODEL_TYPE_NAME = "Child_Model_Type";
57
58    type = (Eina_Model_Type *) &_CHILD_TYPE;
59    type->version = EINA_MODEL_TYPE_VERSION;
60    type->name = CHILD_MODEL_TYPE_NAME;
61
62    eina_model_type_subclass_setup(type, HUMAN_TYPE);
63
64    type->type_size = sizeof(Child_Type);
65    type->interfaces = CLASS_INTERFACE_ARRAY;
66
67    CHILD_TYPE(type)->cry = _child_cry;
68 }
69
70 //call for implemented Child Class function
71 void
72 child_cry(Eina_Model *m)
73 {
74    EINA_SAFETY_ON_FALSE_RETURN(eina_model_instance_check(m, CHILD_TYPE));
75
76    void (*pf)(Eina_Model *m);
77    pf = eina_model_method_resolve(m, Child_Type, cry);
78    EINA_SAFETY_ON_NULL_RETURN(pf);
79    printf("%s() \t\t", __func__);
80    pf(m);
81 }