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
|
/*
* parrot.c
*/
#include "eina_model_04_parrot.h"
#include "eina_model_04_whistler.h"
static Eina_Bool initialized = EINA_FALSE;
static void
_parrot_fly(Eina_Model *m)
{
printf("%s\t%s", eina_model_type_name_get(eina_model_type_get(m)),
__func__);
printf("\t\t Fly Parrot\n");
}
static void
_parrot_eat(Eina_Model *m)
{
printf("%s\t%s", eina_model_type_name_get(eina_model_type_get(m)),
__func__);
printf("\t\t Grain \n");
}
static void
_parrot_whistle(Eina_Model *m)
{
printf("%s\t%s", eina_model_type_name_get(eina_model_type_get(m)),
__func__);
printf("\t\t Whistle Parrot\n");
}
/*
* defining Parrot Model Instance
* defining Whistler Interface instance
*/
const char *PARROT_MODEL_TYPE_NAME = NULL;
static Parrot_Type _PARROT_TYPE;
const Eina_Model_Type * const PARROT_TYPE = (Eina_Model_Type *) &_PARROT_TYPE;
static const Whistler_Interface _WHISTLER_INTERFACE;
static const Eina_Model_Interface * const WHISTLER_INTERFACE =
(Eina_Model_Interface *) &_WHISTLER_INTERFACE;
static const Eina_Model_Interface * MODEL_INTERFACES_ARRAY[] =
{ &_WHISTLER_INTERFACE.base_interface, NULL }; //this array is for model
void
parrot_init()
{
Eina_Model_Type *type;
if (initialized) return;
initialized = EINA_TRUE;
animal_init();
/*
*overriding Whistler Interface (creating instance of Whistler Interface)
*/
Eina_Model_Interface *iface = (Eina_Model_Interface *) &_WHISTLER_INTERFACE;
iface->version = EINA_MODEL_INTERFACE_VERSION;
iface->interface_size = sizeof(Whistler_Interface);
iface->name = WHISTLER_INTERFACE_NAME;
WHISTLER_INTERFACE(iface)->whistle = _parrot_whistle;
PARROT_MODEL_TYPE_NAME = "Parrot_Model_Type";
type = (Eina_Model_Type *)&_PARROT_TYPE;
type->version = EINA_MODEL_TYPE_VERSION;
type->name = PARROT_MODEL_TYPE_NAME;
type->private_size = 0;
eina_model_type_subclass_setup(type, ANIMAL_TYPE);
type->type_size = sizeof(Parrot_Type);
type->interfaces = MODEL_INTERFACES_ARRAY;
ANIMAL_TYPE(type)->eat = _parrot_eat;
PARROT_TYPE(type)->fly = _parrot_fly;
}
void
parrot_fly(Eina_Model *m)
{
EINA_SAFETY_ON_FALSE_RETURN(eina_model_instance_check(m, PARROT_TYPE));
void (*pf)(Eina_Model *m);
pf = eina_model_method_resolve(m, Parrot_Type, fly);
EINA_SAFETY_ON_NULL_RETURN(pf);
printf("%s() \t", __func__);
pf(m);
}
|