diff options
Diffstat (limited to 'libraries/eina/src/examples/eina_model_04_human.c')
-rw-r--r-- | libraries/eina/src/examples/eina_model_04_human.c | 157 |
1 files changed, 157 insertions, 0 deletions
diff --git a/libraries/eina/src/examples/eina_model_04_human.c b/libraries/eina/src/examples/eina_model_04_human.c new file mode 100644 index 0000000..d9a10ab --- /dev/null +++ b/libraries/eina/src/examples/eina_model_04_human.c | |||
@@ -0,0 +1,157 @@ | |||
1 | /* | ||
2 | * human.c | ||
3 | * | ||
4 | */ | ||
5 | |||
6 | #include "eina_model_04_human.h" | ||
7 | #include "eina_model_04_whistler.h" | ||
8 | |||
9 | static Eina_Bool initialized = EINA_FALSE; | ||
10 | |||
11 | static void | ||
12 | _human_eat(Eina_Model *m) | ||
13 | { | ||
14 | printf("%s\t%s", eina_model_type_name_get(eina_model_type_get(m)), | ||
15 | __func__); | ||
16 | printf("\t\t Salad\n"); | ||
17 | } | ||
18 | |||
19 | static void | ||
20 | _human_walk(Eina_Model *m) | ||
21 | { | ||
22 | printf("%s\t%s", eina_model_type_name_get(eina_model_type_get(m)), | ||
23 | __func__); | ||
24 | printf("\t\t Walk\n"); | ||
25 | } | ||
26 | |||
27 | static void | ||
28 | _human_whistle(Eina_Model *m) | ||
29 | { | ||
30 | printf("%s\t%s", eina_model_type_name_get(eina_model_type_get(m)), | ||
31 | __func__); | ||
32 | printf("\t\t Whistle Human\n"); | ||
33 | } | ||
34 | |||
35 | static void | ||
36 | _human_swim(Eina_Model *m) | ||
37 | { | ||
38 | printf("%s\t%s", eina_model_type_name_get(eina_model_type_get(m)), | ||
39 | __func__); | ||
40 | printf("\t\t Swim Human\n"); | ||
41 | } | ||
42 | |||
43 | static void | ||
44 | _human_dive(Eina_Model *m) | ||
45 | { | ||
46 | printf("%s\t%s", eina_model_type_name_get(eina_model_type_get(m)), | ||
47 | __func__); | ||
48 | printf("\t\t Dive Human\n"); | ||
49 | } | ||
50 | /* | ||
51 | * defining Human Model Instance | ||
52 | * defining Whistler Interface instance | ||
53 | * defining Swimmer Interface instance | ||
54 | * defining Diver Interface instance | ||
55 | */ | ||
56 | |||
57 | const char *HUMAN_MODEL_TYPE_NAME = NULL; | ||
58 | |||
59 | static Human_Type _HUMAN_TYPE; | ||
60 | const Eina_Model_Type * const HUMAN_TYPE = (Eina_Model_Type *) &_HUMAN_TYPE; | ||
61 | |||
62 | static const Whistler_Interface _WHISTLER_INTERFACE; | ||
63 | static const Eina_Model_Interface * const WHISTLER_INTERFACE = | ||
64 | (Eina_Model_Interface *) &_WHISTLER_INTERFACE; | ||
65 | |||
66 | static const Swimmer_Interface _SWIMMER_INTERFACE; | ||
67 | static const Eina_Model_Interface * const SWIMMER_INTERFACE = | ||
68 | (Eina_Model_Interface *) &_SWIMMER_INTERFACE; | ||
69 | |||
70 | static const Diver_Interface _DIVER_INTERFACE; | ||
71 | static const Eina_Model_Interface * const DIVER_INTERFACE = | ||
72 | (Eina_Model_Interface *) &_DIVER_INTERFACE; | ||
73 | |||
74 | /* | ||
75 | * defining parent interfaces for Diver Interface instance | ||
76 | * defining Interfaces for Human Model instance | ||
77 | */ | ||
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 | ||
83 | |||
84 | void | ||
85 | human_init() | ||
86 | { | ||
87 | Eina_Model_Type *type; | ||
88 | |||
89 | if (initialized) return; | ||
90 | initialized = EINA_TRUE; | ||
91 | |||
92 | animal_init(); | ||
93 | |||
94 | /* | ||
95 | * Initializing Whistler Interface Instance | ||
96 | */ | ||
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; | ||
102 | |||
103 | /* | ||
104 | * Initializing Swimmer Interface Instance | ||
105 | */ | ||
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; | ||
111 | |||
112 | /* | ||
113 | * Initializing Diver Interface Instance | ||
114 | * Diver_Interface is inherited from Swimmer | ||
115 | */ | ||
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; | ||
122 | |||
123 | /* | ||
124 | * Initializing instance of Human Model | ||
125 | */ | ||
126 | |||
127 | HUMAN_MODEL_TYPE_NAME = "Human_Model_Type"; | ||
128 | |||
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; | ||
133 | |||
134 | eina_model_type_subclass_setup(type, ANIMAL_TYPE); | ||
135 | |||
136 | type->type_size = sizeof(Human_Type); | ||
137 | type->interfaces = MODEL_INTERFACES_ARRAY; | ||
138 | |||
139 | ANIMAL_TYPE(type)->eat = _human_eat; | ||
140 | HUMAN_TYPE(type)->walk =_human_walk; | ||
141 | } | ||
142 | |||
143 | |||
144 | /* | ||
145 | * call for implemented Human Class function | ||
146 | */ | ||
147 | void | ||
148 | human_walk(Eina_Model *m) | ||
149 | { | ||
150 | EINA_SAFETY_ON_FALSE_RETURN(eina_model_instance_check(m, HUMAN_TYPE)); | ||
151 | |||
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__); | ||
156 | pf(m); | ||
157 | } | ||