6 #include "eina_model_04_human.h"
7 #include "eina_model_04_whistler.h"
9 static Eina_Bool initialized = EINA_FALSE;
12 _human_eat(Eina_Model *m)
14 printf("%s\t%s", eina_model_type_name_get(eina_model_type_get(m)),
16 printf("\t\t Salad\n");
20 _human_walk(Eina_Model *m)
22 printf("%s\t%s", eina_model_type_name_get(eina_model_type_get(m)),
24 printf("\t\t Walk\n");
28 _human_whistle(Eina_Model *m)
30 printf("%s\t%s", eina_model_type_name_get(eina_model_type_get(m)),
32 printf("\t\t Whistle Human\n");
36 _human_swim(Eina_Model *m)
38 printf("%s\t%s", eina_model_type_name_get(eina_model_type_get(m)),
40 printf("\t\t Swim Human\n");
44 _human_dive(Eina_Model *m)
46 printf("%s\t%s", eina_model_type_name_get(eina_model_type_get(m)),
48 printf("\t\t Dive Human\n");
51 * defining Human Model Instance
52 * defining Whistler Interface instance
53 * defining Swimmer Interface instance
54 * defining Diver Interface instance
57 const char *HUMAN_MODEL_TYPE_NAME = NULL;
59 static Human_Type _HUMAN_TYPE;
60 const Eina_Model_Type * const HUMAN_TYPE = (Eina_Model_Type *) &_HUMAN_TYPE;
62 static const Whistler_Interface _WHISTLER_INTERFACE;
63 static const Eina_Model_Interface * const WHISTLER_INTERFACE =
64 (Eina_Model_Interface *) &_WHISTLER_INTERFACE;
66 static const Swimmer_Interface _SWIMMER_INTERFACE;
67 static const Eina_Model_Interface * const SWIMMER_INTERFACE =
68 (Eina_Model_Interface *) &_SWIMMER_INTERFACE;
70 static const Diver_Interface _DIVER_INTERFACE;
71 static const Eina_Model_Interface * const DIVER_INTERFACE =
72 (Eina_Model_Interface *) &_DIVER_INTERFACE;
75 * defining parent interfaces for Diver Interface instance
76 * defining Interfaces for Human Model instance
78 static const Eina_Model_Interface * PARENT_INTERFACES_ARRAY[] =
79 { &_SWIMMER_INTERFACE.base_interface, NULL }; //this array is for model
80 static const Eina_Model_Interface * MODEL_INTERFACES_ARRAY[] =
81 { &_WHISTLER_INTERFACE.base_interface, &_DIVER_INTERFACE.base_interface,
82 NULL }; //this array is for model
87 Eina_Model_Type *type;
89 if (initialized) return;
90 initialized = EINA_TRUE;
95 * Initializing Whistler Interface Instance
97 Eina_Model_Interface *iface = (Eina_Model_Interface *) &_WHISTLER_INTERFACE;
98 iface->version = EINA_MODEL_INTERFACE_VERSION;
99 iface->interface_size = sizeof(Whistler_Interface);
100 iface->name = WHISTLER_INTERFACE_NAME;
101 WHISTLER_INTERFACE(iface)->whistle = _human_whistle;
104 * Initializing Swimmer Interface Instance
106 iface = (Eina_Model_Interface *) &_SWIMMER_INTERFACE;
107 iface->version = EINA_MODEL_INTERFACE_VERSION;
108 iface->interface_size = sizeof(Swimmer_Interface);
109 iface->name = SWIMMER_INTERFACE_NAME;
110 SWIMMER_INTERFACE(iface)->swim = _human_swim;
113 * Initializing Diver Interface Instance
114 * Diver_Interface is inherited from Swimmer
116 iface = (Eina_Model_Interface *) &_DIVER_INTERFACE;
117 iface->version = EINA_MODEL_INTERFACE_VERSION;
118 iface->interface_size = sizeof(Diver_Interface);
119 iface->name = DIVER_INTERFACE_NAME;
120 iface->interfaces = PARENT_INTERFACES_ARRAY;
121 DIVER_INTERFACE(iface)->dive = _human_dive;
124 * Initializing instance of Human Model
127 HUMAN_MODEL_TYPE_NAME = "Human_Model_Type";
129 type = (Eina_Model_Type *) &_HUMAN_TYPE;
130 type->version = EINA_MODEL_TYPE_VERSION;
131 type->name = HUMAN_MODEL_TYPE_NAME;
132 type->private_size = 0;
134 eina_model_type_subclass_setup(type, ANIMAL_TYPE);
136 type->type_size = sizeof(Human_Type);
137 type->interfaces = MODEL_INTERFACES_ARRAY;
139 ANIMAL_TYPE(type)->eat = _human_eat;
140 HUMAN_TYPE(type)->walk =_human_walk;
145 * call for implemented Human Class function
148 human_walk(Eina_Model *m)
150 EINA_SAFETY_ON_FALSE_RETURN(eina_model_instance_check(m, HUMAN_TYPE));
152 void (*pf)(Eina_Model *m);
153 pf = eina_model_method_resolve(m, Human_Type, walk);
154 EINA_SAFETY_ON_NULL_RETURN(pf);
155 printf("%s() \t", __func__);