forked from enlightenment/efl
Summary: Since eina_model was dropped some years ago. Also a few other points where related stuff is just commented out. Reviewers: iscaro, barbieri Reviewed By: barbieri Subscribers: cedric, jpeg Differential Revision: https://phab.enlightenment.org/D4442devs/barbieri/jenkins
parent
887be4d4e5
commit
adb95630ef
22 changed files with 1 additions and 2773 deletions
@ -1,235 +0,0 @@ |
||||
/*
|
||||
* Compile with: |
||||
* gcc -o eina_model_01 eina_model_01.c `pkg-config --cflags --libs eina` |
||||
*/ |
||||
|
||||
/*
|
||||
* This example demonstrates the usage of Eina Model by implementing |
||||
* Bank Account Class, which is inherited from Base Class; |
||||
* and Credit Card Class, which is inherited from Bank Account Class. |
||||
* |
||||
* Base Class(Eina_Model_Type) --> Bank Account Class --> Credit Card Class |
||||
* |
||||
* Bank Account Class implements "bank_account_data_set()" and "print()" methods; |
||||
* Credit Card Class inherits these two and implements "credit_card_data_set()" |
||||
* |
||||
* |
||||
* Bank Account Class::print() calls for "_bank_account_data_print" |
||||
* Credit Card Class ::print() is reloaded with "_credit_card_data_print()" |
||||
* which calls for parent function "_bank_account_data_print" |
||||
* |
||||
*/ |
||||
|
||||
|
||||
#include <Eina.h> |
||||
#include <eina_safety_checks.h> |
||||
|
||||
/*
|
||||
* Defining type for new model type |
||||
* Model will have two methods |
||||
*/ |
||||
typedef struct _Bank_Account_Type |
||||
{ |
||||
Eina_Model_Type parent_class; |
||||
void (*bank_account_data_set)(Eina_Model *, const char *name, const char *number); |
||||
void (*print)(Eina_Model *); |
||||
} Bank_Account_Type; |
||||
|
||||
/*
|
||||
* Defining type for Bank Account private data |
||||
*/ |
||||
typedef struct _Bank_Account_Data |
||||
{ |
||||
char name[30]; |
||||
char number[30]; |
||||
} Bank_Account_Data; |
||||
|
||||
/*
|
||||
* Defining type for Credit Card model type, which will be inherited from Bank Account model type |
||||
* Model will have two parent's methods and additional one |
||||
*/ |
||||
typedef struct _Credit_Card_Type |
||||
{ |
||||
Bank_Account_Type parent_class; |
||||
void (*credit_card_data_set)(Eina_Model *, const char *, const char *, int) ; |
||||
} Credit_Card_Type; |
||||
|
||||
/*
|
||||
* Defining type for Credit Card private data |
||||
*/ |
||||
typedef struct _Credit_Card_Data |
||||
{ |
||||
char number[30]; |
||||
char expiry_date[30]; |
||||
int pin; |
||||
} Credit_Card_Data; |
||||
|
||||
static Bank_Account_Type _BANK_ACCOUNT_TYPE; |
||||
static Credit_Card_Type _CREDIT_CARD_TYPE; |
||||
static Eina_Model_Type *BANK_ACCOUNT_TYPE = (Eina_Model_Type *) &_BANK_ACCOUNT_TYPE; |
||||
static Eina_Model_Type *CREDIT_CARD_TYPE = (Eina_Model_Type *) &_CREDIT_CARD_TYPE; |
||||
|
||||
|
||||
/*
|
||||
* Defining method for for Bank Account data |
||||
*/ |
||||
static void |
||||
_bank_account_data_set(Eina_Model *mdl, const char *name, const char *number) |
||||
{ |
||||
Bank_Account_Data *bdata = eina_model_type_private_data_get(mdl, BANK_ACCOUNT_TYPE); |
||||
|
||||
if (!bdata) |
||||
printf("ERROR\n"); |
||||
|
||||
if (name != NULL) |
||||
{ |
||||
strncpy(bdata->name, name, sizeof(bdata->name)); |
||||
bdata->name[sizeof(bdata->number) - 1] = '\0'; |
||||
} |
||||
|
||||
if (number != NULL) |
||||
{ |
||||
strncpy(bdata->number, number, sizeof(bdata->number)); |
||||
bdata->number[sizeof(bdata->number) - 1] = '\0'; |
||||
} |
||||
|
||||
printf("%s :: %s %p\n", eina_model_type_name_get(eina_model_type_get(mdl)) ,__func__, mdl); |
||||
} |
||||
|
||||
|
||||
static void |
||||
_credit_card_data_set(Eina_Model *mdl, const char *number, const char *expiry_date, int pin) |
||||
{ |
||||
Credit_Card_Data *cdata = eina_model_type_private_data_get(mdl, CREDIT_CARD_TYPE); |
||||
|
||||
if (!cdata) |
||||
printf("ERROR\n"); |
||||
|
||||
if (number != NULL) |
||||
{ |
||||
strncpy(cdata->number, number, sizeof(cdata->number)); |
||||
cdata->number[sizeof(cdata->number) - 1] = '\0'; |
||||
} |
||||
|
||||
if (expiry_date != NULL) |
||||
{ |
||||
strncpy(cdata->expiry_date, expiry_date, sizeof(cdata->expiry_date)); |
||||
cdata->expiry_date[sizeof(cdata->expiry_date) - 1] = '\0'; |
||||
} |
||||
|
||||
cdata->pin = pin; |
||||
printf("%s :: %s %p\n", eina_model_type_name_get(eina_model_type_get(mdl)) ,__func__, mdl); |
||||
} |
||||
|
||||
static void |
||||
_bank_account_data_print(Eina_Model *mdl) |
||||
{ |
||||
const Bank_Account_Data *bdata = eina_model_type_private_data_get(mdl, BANK_ACCOUNT_TYPE); |
||||
|
||||
printf("\n%s :: %s %p \n\tName: %s(%p)\n\tAccount: %s(%p)\n", eina_model_type_name_get(eina_model_type_get(mdl)) ,__func__, mdl |
||||
, bdata->name, bdata->name, bdata->number, bdata->number); |
||||
} |
||||
|
||||
static void |
||||
_credit_card_data_print(Eina_Model *mdl) |
||||
{ |
||||
void (*pf)(Eina_Model *); |
||||
const Eina_Model_Type *ptype = eina_model_type_parent_get(eina_model_type_get(mdl)); |
||||
//const Eina_Model_Type *ptype = eina_model_type_get(mdl);
|
||||
|
||||
pf = eina_model_type_method_resolve(ptype, mdl, Bank_Account_Type, print); |
||||
if (pf) |
||||
pf(mdl); |
||||
else |
||||
printf("ERROR: %d", __LINE__); |
||||
const Credit_Card_Data *cdata = eina_model_type_private_data_get(mdl, CREDIT_CARD_TYPE); |
||||
printf("%s :: %s %p \n\tNumber: %s(%p)\n\tCC Expiry Date: %s(%p)\n\tCC PIN: %d(%p)\n", eina_model_type_name_get(eina_model_type_get(mdl)) ,__func__, mdl |
||||
, cdata->number, cdata->number, cdata->expiry_date, cdata->expiry_date, cdata->pin, &cdata->pin); |
||||
} |
||||
|
||||
#define BANK_ACCOUNT(x) ((Bank_Account_Type *) x) |
||||
#define CREDIT_CARD(x) ((Credit_Card_Type *) x) |
||||
|
||||
void |
||||
bank_account_data_set(Eina_Model *mdl, const char *name, char *number) |
||||
{ |
||||
|
||||
EINA_SAFETY_ON_FALSE_RETURN(eina_model_instance_check(mdl, BANK_ACCOUNT_TYPE)); |
||||
|
||||
void (*pf)(Eina_Model *, const char *, const char *); |
||||
pf = eina_model_method_resolve(mdl, Bank_Account_Type, bank_account_data_set); |
||||
if (pf) |
||||
pf(mdl, name, number); |
||||
else |
||||
printf("ERROR %d\n", __LINE__); |
||||
} |
||||
|
||||
void |
||||
data_print(Eina_Model *mdl) |
||||
{ |
||||
EINA_SAFETY_ON_FALSE_RETURN(eina_model_instance_check(mdl, BANK_ACCOUNT_TYPE)); |
||||
|
||||
void (*pf)(Eina_Model *); |
||||
pf = eina_model_method_resolve(mdl, Bank_Account_Type, print); |
||||
if (pf) |
||||
pf(mdl); |
||||
else |
||||
printf("ERROR %d\n", __LINE__); |
||||
} |
||||
|
||||
void |
||||
credit_card_data_set(Eina_Model *mdl, const char *number, const char *expiry_date, int pin) |
||||
{ |
||||
EINA_SAFETY_ON_FALSE_RETURN(eina_model_instance_check(mdl, CREDIT_CARD_TYPE)); |
||||
|
||||
void (*pf)(Eina_Model *, const char *, const char *, int); |
||||
pf = eina_model_method_resolve(mdl, Credit_Card_Type, credit_card_data_set); |
||||
if (pf) |
||||
pf(mdl, number, expiry_date, pin); |
||||
else |
||||
printf("ERROR %d\n", __LINE__); |
||||
} |
||||
|
||||
int main(void) |
||||
{ |
||||
Eina_Model *b, *cc; |
||||
|
||||
eina_init(); |
||||
|
||||
memset(&_BANK_ACCOUNT_TYPE, 0, sizeof(_BANK_ACCOUNT_TYPE)); |
||||
memset(&_CREDIT_CARD_TYPE, 0, sizeof(_CREDIT_CARD_TYPE)); |
||||
|
||||
BANK_ACCOUNT_TYPE->version = EINA_MODEL_TYPE_VERSION; |
||||
BANK_ACCOUNT_TYPE->type_size = sizeof(Bank_Account_Type); |
||||
BANK_ACCOUNT_TYPE->private_size = sizeof(Bank_Account_Data); |
||||
BANK_ACCOUNT_TYPE->name = "Bank_Account_Model"; |
||||
BANK_ACCOUNT_TYPE->parent = EINA_MODEL_TYPE_GENERIC; |
||||
BANK_ACCOUNT(BANK_ACCOUNT_TYPE)->bank_account_data_set = _bank_account_data_set; |
||||
BANK_ACCOUNT(BANK_ACCOUNT_TYPE)->print = _bank_account_data_print; |
||||
|
||||
CREDIT_CARD_TYPE->version = EINA_MODEL_TYPE_VERSION; |
||||
CREDIT_CARD_TYPE->type_size = sizeof(Credit_Card_Type); |
||||
CREDIT_CARD_TYPE->private_size = sizeof(Credit_Card_Data); |
||||
CREDIT_CARD_TYPE->name = "Credit_Card_Model"; |
||||
CREDIT_CARD_TYPE->parent = BANK_ACCOUNT_TYPE; |
||||
CREDIT_CARD(CREDIT_CARD_TYPE)->credit_card_data_set = _credit_card_data_set; |
||||
BANK_ACCOUNT(CREDIT_CARD_TYPE)->print = _credit_card_data_print; |
||||
|
||||
b = eina_model_new(BANK_ACCOUNT_TYPE); //creating object of bank class
|
||||
cc = eina_model_new(CREDIT_CARD_TYPE); //creating object of credit card class
|
||||
|
||||
bank_account_data_set(b, "Bill Clark", "8569214756"); |
||||
bank_account_data_set(cc, "John Smith", "3154789"); |
||||
|
||||
credit_card_data_set(cc, "5803 6589 4786 3279 9173", "01/01/2015", 1234); |
||||
|
||||
data_print(b); |
||||
data_print(cc); |
||||
|
||||
eina_model_unref(b); |
||||
eina_model_unref(cc); |
||||
|
||||
eina_shutdown(); |
||||
|
||||
return 0; |
||||
} |
@ -1,61 +0,0 @@ |
||||
//Compile with:
|
||||
//gcc -g eina_model_02.c -o eina_model_02 `pkg-config --cflags --libs eina`
|
||||
|
||||
#include <Eina.h> |
||||
|
||||
static void _cb_on_deleted(void *data, Eina_Model *model, const Eina_Model_Event_Description *desc, void *event_info); |
||||
|
||||
int main(void) |
||||
{ |
||||
Eina_Model *m; |
||||
char *s; |
||||
int i; |
||||
|
||||
eina_init(); |
||||
|
||||
m = eina_model_new(EINA_MODEL_TYPE_GENERIC); |
||||
|
||||
eina_model_event_callback_add(m, "deleted", _cb_on_deleted, NULL); |
||||
|
||||
//Adding properties to model
|
||||
for (i = 0; i < 5; i++) |
||||
{ |
||||
Eina_Value val; |
||||
char name[2] = {'a'+ i, 0}; |
||||
eina_value_setup(&val, EINA_VALUE_TYPE_INT); |
||||
eina_value_set(&val, i); |
||||
eina_model_property_set(m, name, &val); |
||||
eina_value_flush(&val); |
||||
} |
||||
|
||||
//Adding children to model
|
||||
for (i = 0; i < 5; i++) |
||||
{ |
||||
Eina_Value val; |
||||
Eina_Model *c = eina_model_new(EINA_MODEL_TYPE_GENERIC); |
||||
eina_value_setup(&val, EINA_VALUE_TYPE_INT); |
||||
eina_value_set(&val, i); |
||||
eina_model_property_set(c, "x", &val); |
||||
|
||||
eina_model_event_callback_add(c, "deleted", _cb_on_deleted, NULL); |
||||
|
||||
eina_model_child_append(m, c); |
||||
//Now that the child has been appended to a model, it's parent will manage it's lifecycle
|
||||
eina_model_unref(c); |
||||
eina_value_flush(&val); |
||||
} |
||||
|
||||
s = eina_model_to_string(m); |
||||
printf("model as string:\n%s\n", s); |
||||
|
||||
free(s); |
||||
eina_model_unref(m); |
||||
eina_shutdown(); |
||||
|
||||
return 0; |
||||
} |
||||
|
||||
static void _cb_on_deleted(void *data, Eina_Model *model, const Eina_Model_Event_Description *desc, void *event_info) |
||||
{ |
||||
printf("deleted %p\n", model); |
||||
} |
@ -1,236 +0,0 @@ |
||||
//Compile with:
|
||||
//gcc -g eina_model_03.c -o eina_model_03 `pkg-config --cflags --libs eina`
|
||||
|
||||
#include <Eina.h> |
||||
#include <string.h> |
||||
#include <stdio.h> |
||||
#include <errno.h> |
||||
|
||||
static Eina_Model_Type *ADDRESS_BOOK_TYPE; |
||||
static Eina_Model_Type *PERSON_TYPE; |
||||
|
||||
static void address_book_init(void); |
||||
|
||||
int main(void) |
||||
{ |
||||
Eina_Model *address_book; |
||||
Eina_Value val; |
||||
int i, count; |
||||
char *s; |
||||
|
||||
eina_init(); |
||||
|
||||
address_book_init(); |
||||
|
||||
address_book = eina_model_new(ADDRESS_BOOK_TYPE); |
||||
|
||||
eina_value_setup(&val, EINA_VALUE_TYPE_STRING); |
||||
eina_value_set(&val, "addr_book.txt"); |
||||
eina_model_property_set(address_book, "filename", &val); |
||||
eina_value_flush(&val); |
||||
|
||||
eina_model_load(address_book); |
||||
s = eina_model_to_string(address_book); |
||||
printf("model as string:\n%s\n\n", s); |
||||
free(s); |
||||
|
||||
count = eina_model_child_count(address_book); |
||||
printf("Address Book with %d entries:\n", count); |
||||
for (i = 0; i < count; i++) |
||||
{ |
||||
Eina_Model *person = eina_model_child_get(address_book, i); |
||||
Eina_Value nameval, emailval; |
||||
const char *name, *email; |
||||
|
||||
eina_model_property_get(person, "name", &nameval); |
||||
eina_model_property_get(person, "email", &emailval); |
||||
|
||||
eina_value_get(&nameval, &name); |
||||
eina_value_get(&emailval, &email); |
||||
|
||||
printf("%02d \"%s\" <%s>\n", i, name, email); |
||||
|
||||
// We don't need property values anymore
|
||||
eina_value_flush(&nameval); |
||||
eina_value_flush(&emailval); |
||||
|
||||
// We don't need our reference to person anymore
|
||||
eina_model_unref(person); |
||||
} |
||||
|
||||
eina_model_unref(address_book); |
||||
eina_shutdown(); |
||||
|
||||
return 0; |
||||
} |
||||
|
||||
// Structure Descriptions are just used internally in the type constructors:
|
||||
static Eina_Value_Struct_Desc *ADDRESS_BOOK_DESC; |
||||
static Eina_Value_Struct_Desc *PERSON_DESC; |
||||
|
||||
static Eina_Bool |
||||
_person_constructor(Eina_Model *model) |
||||
{ |
||||
// call parent type constructor, like "super" in other languages:
|
||||
if (!eina_model_type_constructor(EINA_MODEL_TYPE_STRUCT, model)) |
||||
return EINA_FALSE; |
||||
|
||||
// Do specific setup of our internal structure, letting it know about
|
||||
// our description
|
||||
return eina_model_struct_set(model, PERSON_DESC, NULL); |
||||
} |
||||
|
||||
static Eina_Bool |
||||
_address_book_constructor(Eina_Model *model) |
||||
{ |
||||
// call parent type constructor, like "super" in other languages:
|
||||
if (!eina_model_type_constructor(EINA_MODEL_TYPE_STRUCT, model)) |
||||
return EINA_FALSE; |
||||
|
||||
// Do specific setup of our internal structure, letting it know about
|
||||
// our description
|
||||
return eina_model_struct_set(model, ADDRESS_BOOK_DESC, NULL); |
||||
} |
||||
|
||||
static Eina_Bool |
||||
_address_book_load(Eina_Model *model) |
||||
{ |
||||
const char *filename; |
||||
Eina_Value val; |
||||
char buf[256]; |
||||
FILE *f; |
||||
|
||||
// We retrieve filename from property of same name:
|
||||
eina_model_property_get(model, "filename", &val); |
||||
eina_value_get(&val, &filename); |
||||
|
||||
EINA_SAFETY_ON_NULL_RETURN_VAL(filename, EINA_FALSE); |
||||
|
||||
f = fopen(filename, "rb"); |
||||
|
||||
// Now that we have used filename, we must free its memory holder:
|
||||
eina_value_flush(&val); |
||||
|
||||
EINA_SAFETY_ON_NULL_RETURN_VAL(f, EINA_FALSE); |
||||
|
||||
while (fgets(buf, sizeof(buf), f)) |
||||
{ |
||||
Eina_Model *person; |
||||
char *name, *email; |
||||
|
||||
if (strlen(buf) <= 1) |
||||
continue; |
||||
|
||||
name = strtok(buf, "\t"); |
||||
email = strtok(NULL, "\n"); |
||||
|
||||
if ((!name) || (!email)) continue; |
||||
|
||||
// Create person
|
||||
person = eina_model_new(PERSON_TYPE); |
||||
|
||||
// Setup value type as string, as our properties are strings:
|
||||
eina_value_setup(&val, EINA_VALUE_TYPE_STRING); |
||||
|
||||
// Set string properties:
|
||||
eina_value_set(&val, name); |
||||
eina_model_property_set(person, "name", &val); |
||||
|
||||
eina_value_set(&val, email); |
||||
eina_model_property_set(person, "email", &val); |
||||
|
||||
// Flush value, free string
|
||||
eina_value_flush(&val); |
||||
|
||||
// Add person to the end of model children
|
||||
eina_model_child_append(model, person); |
||||
|
||||
// Model already holds its reference to person, we release ours
|
||||
eina_model_unref(person); |
||||
} |
||||
|
||||
fclose(f); |
||||
return EINA_TRUE; |
||||
} |
||||
|
||||
static void |
||||
address_book_init(void) |
||||
{ |
||||
// Declare type for internal struct, this is just used to easily
|
||||
// create Eina_Value_Struct_Member array for Eina_Value_Struct_Desc.
|
||||
//
|
||||
// We don't need this structure outside address_book_init()
|
||||
// as it is managed automatically by Eina_Value_Struct, used by
|
||||
// Eina_Model_Struct! Handy! :-)
|
||||
typedef struct _Person Person; |
||||
struct _Person |
||||
{ |
||||
const char *name; |
||||
const char *email; |
||||
}; |
||||
static Eina_Value_Struct_Member person_members[] = { |
||||
// no eina_value_type as they are not constant initializers, see below.
|
||||
EINA_VALUE_STRUCT_MEMBER(NULL, Person, name), |
||||
EINA_VALUE_STRUCT_MEMBER(NULL, Person, email) |
||||
}; |
||||
// Values that cannot be set on static declarations since they are not
|
||||
// constant initializers. It is a nitpick from C that we need to deal with
|
||||
// here and on all our other declarations.
|
||||
person_members[0].type = EINA_VALUE_TYPE_STRING; |
||||
person_members[1].type = EINA_VALUE_TYPE_STRING; |
||||
|
||||
static Eina_Value_Struct_Desc person_desc = { |
||||
EINA_VALUE_STRUCT_DESC_VERSION, |
||||
NULL, // no special operations
|
||||
person_members, |
||||
EINA_C_ARRAY_LENGTH(person_members), |
||||
sizeof(Person) |
||||
}; |
||||
static Eina_Model_Type person_type = EINA_MODEL_TYPE_INIT_NOPRIVATE |
||||
("Person_Type", |
||||
Eina_Model_Type, |
||||
NULL, // no type as EINA_MODEL_TYPE_STRUCT is not constant initializer!
|
||||
NULL, // no extra interfaces
|
||||
NULL // no extra events);
|
||||
); |
||||
person_type.parent = EINA_MODEL_TYPE_STRUCT; |
||||
// Set our overloaded methods:
|
||||
person_type.constructor = _person_constructor; |
||||
|
||||
typedef struct _Address_Book Address_Book; |
||||
struct _Address_Book |
||||
{ |
||||
const char *filename; |
||||
}; |
||||
static Eina_Value_Struct_Member address_book_members[] = { |
||||
// no eina_value_type as they are not constant initializers, see below.
|
||||
EINA_VALUE_STRUCT_MEMBER(NULL, Address_Book, filename) |
||||
}; |
||||
address_book_members[0].type = EINA_VALUE_TYPE_STRING; |
||||
static Eina_Value_Struct_Desc address_book_desc = { |
||||
EINA_VALUE_STRUCT_DESC_VERSION, |
||||
NULL, // no special operations
|
||||
address_book_members, |
||||
EINA_C_ARRAY_LENGTH(address_book_members), |
||||
sizeof(Address_Book) |
||||
}; |
||||
static Eina_Model_Type address_book_type = EINA_MODEL_TYPE_INIT_NOPRIVATE |
||||
("Address_Book_Type", |
||||
Eina_Model_Type, |
||||
NULL, // no type as EINA_MODEL_TYPE_STRUCT is not constant initializer!
|
||||
NULL, // no extra interfaces
|
||||
NULL // no extra events);
|
||||
); |
||||
address_book_type.parent = EINA_MODEL_TYPE_STRUCT; |
||||
// Set our overloaded methods:
|
||||
address_book_type.constructor = _address_book_constructor; |
||||
address_book_type.load = _address_book_load; |
||||
|
||||
// Expose the configured pointers to public usage:
|
||||
// NOTE: they are static, so they live after this function returns!
|
||||
PERSON_TYPE = &person_type; |
||||
PERSON_DESC = &person_desc; |
||||
|
||||
ADDRESS_BOOK_TYPE = &address_book_type; |
||||
ADDRESS_BOOK_DESC = &address_book_desc; |
||||
} |
@ -1,76 +0,0 @@ |
||||
/*
|
||||
* animal.c |
||||
*/ |
||||
|
||||
#include "eina_model_04_animal.h" |
||||
|
||||
static Eina_Bool initialized = EINA_FALSE; |
||||
|
||||
static void |
||||
_animal_eat(Eina_Model *m) |
||||
{ |
||||
printf("%s\t%s", eina_model_type_name_get(eina_model_type_get(m)), |
||||
__func__); |
||||
printf("\t\t Eat Animal\n"); |
||||
} |
||||
|
||||
static void |
||||
_animal_breathe(Eina_Model *m) |
||||
{ |
||||
printf("%s\t%s", eina_model_type_name_get(eina_model_type_get(m)), |
||||
__func__); |
||||
printf("\t\t Breathe Animal\n"); |
||||
} |
||||
|
||||
const char *ANIMAL_MODEL_TYPE_NAME = NULL; |
||||
static Animal_Type _ANIMAL_TYPE; |
||||
|
||||
const Eina_Model_Type * const ANIMAL_TYPE = (Eina_Model_Type *) &_ANIMAL_TYPE; |
||||
|
||||
void |
||||
animal_init(void) |
||||
{ |
||||
Eina_Model_Type *type; |
||||
|
||||
if (initialized) return; |
||||
initialized = EINA_TRUE; |
||||
|
||||
ANIMAL_MODEL_TYPE_NAME = "Animal_Model_Type"; |
||||
|
||||
type = (Eina_Model_Type *)&_ANIMAL_TYPE; |
||||
type->version = EINA_MODEL_TYPE_VERSION; |
||||
type->name = ANIMAL_MODEL_TYPE_NAME; |
||||
type->private_size = 0; |
||||
|
||||
eina_model_type_subclass_setup(type, EINA_MODEL_TYPE_GENERIC); |
||||
|
||||
/* define extra methods */ |
||||
|
||||
type->type_size = sizeof(Animal_Type); |
||||
ANIMAL_TYPE(type)->breathe = _animal_breathe; |
||||
ANIMAL_TYPE(type)->eat = _animal_eat; |
||||
} |
||||
|
||||
void |
||||
animal_breathe(Eina_Model *m) |
||||
{ |
||||
EINA_SAFETY_ON_FALSE_RETURN(eina_model_instance_check(m, ANIMAL_TYPE)); |
||||
|
||||
void (*pf)(Eina_Model *m); |
||||
pf = eina_model_method_resolve(m, Animal_Type, breathe); |
||||
EINA_SAFETY_ON_NULL_RETURN(pf); |
||||
printf("%s() \t", __func__); |
||||
pf(m); |
||||
} |
||||
|
||||
void |
||||
animal_eat(Eina_Model *m) |
||||
{ |
||||
EINA_SAFETY_ON_FALSE_RETURN(eina_model_instance_check(m, ANIMAL_TYPE)); |
||||
|
||||
void (*pf)(Eina_Model *m); |
||||
pf = eina_model_method_resolve(m, Animal_Type, eat); |
||||
EINA_SAFETY_ON_NULL_RETURN(pf); |
||||
printf("%s() \t", __func__); |
||||
pf(m); |
||||
} |
@ -1,26 +0,0 @@ |
||||
/*
|
||||
* animal.h |
||||
*/ |
||||
|
||||
#ifndef ANIMAL_H_ |
||||
#define ANIMAL_H_ |
||||
|
||||
#include <Eina.h> |
||||
|
||||
extern const char *ANIMAL_MODEL_TYPE_NAME; |
||||
extern const Eina_Model_Type * const ANIMAL_TYPE; |
||||
|
||||
#define ANIMAL_TYPE(x) ((Animal_Type *) (eina_model_type_subclass_check((x), ANIMAL_TYPE) ? (x) : NULL)) |
||||
|
||||
typedef struct _Animal_Type |
||||
{ |
||||
Eina_Model_Type parent_class; |
||||
void (*eat)(Eina_Model *m); |
||||
void (*breathe)(Eina_Model *m); |
||||
} Animal_Type; |
||||
|
||||
void animal_init(void); |
||||
void animal_breathe(Eina_Model *m); |
||||
void animal_eat(Eina_Model *m); |
||||
|
||||
#endif /* ANIMAL_H_ */ |
@ -1,81 +0,0 @@ |
||||
/*
|
||||
* child.c |
||||
*/ |
||||
|
||||
#include "eina_model_04_child.h" |
||||
#include "eina_model_04_whistler.h" |
||||
|
||||
static Eina_Bool initialized = EINA_FALSE; |
||||
|
||||
static void |
||||
_child_cry(Eina_Model *m) |
||||
{ |
||||
printf("%s\t%s", eina_model_type_name_get(eina_model_type_get(m)), |
||||
__func__); |
||||
printf("\t\t Cry Child\n"); |
||||
} |
||||
|
||||
static void |
||||
_child_dive(Eina_Model *m) |
||||
{ |
||||
printf("%s\t%s", eina_model_type_name_get(eina_model_type_get(m)), |
||||
__func__); |
||||
printf("\t\t Dive Child\n"); |
||||
} |
||||
|
||||
const char *CHILD_MODEL_TYPE_NAME = NULL; |
||||
|
||||
static Child_Type _CHILD_TYPE; |
||||
const Eina_Model_Type * const CHILD_TYPE = (Eina_Model_Type *) &_CHILD_TYPE; |
||||
|
||||
static const Diver_Interface _DIVER_INTERFACE; |
||||
static const Eina_Model_Interface * const DIVER_INTERFACE = |
||||
(Eina_Model_Interface *) &_DIVER_INTERFACE; |
||||
|
||||
static const Eina_Model_Interface * CLASS_INTERFACE_ARRAY[] = |
||||
{ &_DIVER_INTERFACE.base_interface, NULL }; //this array is for model
|
||||
|
||||
void |
||||
child_init() |
||||
{ |
||||
Eina_Model_Type *type; |
||||
|
||||
if (initialized) return; |
||||
initialized = EINA_TRUE; |
||||
|
||||
human_init(); |
||||
|
||||
//overriding Diver Interface
|
||||
Eina_Model_Interface * iface = (Eina_Model_Interface *) &_DIVER_INTERFACE; |
||||
iface->version = EINA_MODEL_INTERFACE_VERSION; |
||||
iface->interface_size = sizeof(Diver_Interface); |
||||
iface->name = DIVER_INTERFACE_NAME; |
||||
DIVER_INTERFACE(iface)->dive = _child_dive; |
||||
|
||||
//creating instance of Child type
|
||||
CHILD_MODEL_TYPE_NAME = "Child_Model_Type"; |
||||
|
||||
type = (Eina_Model_Type *) &_CHILD_TYPE; |
||||
type->version = EINA_MODEL_TYPE_VERSION; |
||||
type->name = CHILD_MODEL_TYPE_NAME; |
||||
|
||||
eina_model_type_subclass_setup(type, HUMAN_TYPE); |
||||
|
||||
type->type_size = sizeof(Child_Type); |
||||
type->interfaces = CLASS_INTERFACE_ARRAY; |
||||
|
||||
CHILD_TYPE(type)->cry = _child_cry; |
||||
} |
||||
|
||||
//call for implemented Child Class function
|
||||
void |
||||
child_cry(Eina_Model *m) |
||||
{ |
||||
EINA_SAFETY_ON_FALSE_RETURN(eina_model_instance_check(m, CHILD_TYPE)); |
||||
|
||||
void (*pf)(Eina_Model *m); |
||||
pf = eina_model_method_resolve(m, Child_Type, cry); |
||||
EINA_SAFETY_ON_NULL_RETURN(pf); |
||||
printf("%s() \t\t", __func__); |
||||
pf(m); |
||||
} |
@ -1,23 +0,0 @@ |
||||
/*
|
||||
* child.h |
||||
*/ |
||||
|
||||
#ifndef CHILD_H_ |
||||
#define CHILD_H_ |
||||
|
||||
#include "eina_model_04_human.h" |
||||
|
||||
extern const char *CHILD_MODEL_TYPE_NAME; |
||||
extern const Eina_Model_Type * const CHILD_TYPE; |
||||
#define CHILD_TYPE(x) ((Child_Type *) (eina_model_type_subclass_check((x), CHILD_TYPE) ? (x) : NULL)) |
||||
|
||||
typedef struct _Child_Type |
||||
{ |
||||
Human_Type parent_class; |
||||
void (*cry)(Eina_Model *m); |
||||
} Child_Type; |
||||
|
||||
void child_init(); |
||||
void child_cry(Eina_Model *m); |
||||
|
||||
#endif /* CHILD_H_ */ |
@ -1,157 +0,0 @@ |
||||
/*
|
||||
* human.c |
||||
* |
||||
*/ |
||||
|
||||
#include "eina_model_04_human.h" |
||||
#include "eina_model_04_whistler.h" |
||||
|
||||
static Eina_Bool initialized = EINA_FALSE; |
||||
|
||||
static void |
||||
_human_eat(Eina_Model *m) |
||||
{ |
||||
printf("%s\t%s", eina_model_type_name_get(eina_model_type_get(m)), |
||||
__func__); |
||||
printf("\t\t Salad\n"); |
||||
} |
||||
|
||||
static void |
||||
_human_walk(Eina_Model *m) |
||||
{ |
||||
printf("%s\t%s", eina_model_type_name_get(eina_model_type_get(m)), |
||||
__func__); |
||||
printf("\t\t Walk\n"); |
||||
} |
||||
|
||||
static void |
||||
_human_whistle(Eina_Model *m) |
||||
{ |
||||
printf("%s\t%s", eina_model_type_name_get(eina_model_type_get(m)), |
||||
__func__); |
||||
printf("\t\t Whistle Human\n"); |
||||
} |
||||
|
||||
static void |
||||
_human_swim(Eina_Model *m) |
||||
{ |
||||
printf("%s\t%s", eina_model_type_name_get(eina_model_type_get(m)), |
||||
__func__); |
||||
printf("\t\t Swim Human\n"); |
||||
} |
||||
|
||||
static void |
||||
_human_dive(Eina_Model *m) |
||||
{ |
||||
printf("%s\t%s", eina_model_type_name_get(eina_model_type_get(m)), |
||||
__func__); |
||||
printf("\t\t Dive Human\n"); |
||||
} |
||||
/*
|
||||
* defining Human Model Instance |
||||
* defining Whistler Interface instance |
||||
* defining Swimmer Interface instance |
||||
* defining Diver Interface instance |
||||
*/ |
||||
|
||||
const char *HUMAN_MODEL_TYPE_NAME = NULL; |
||||
|
||||
static Human_Type _HUMAN_TYPE; |
||||
const Eina_Model_Type * const HUMAN_TYPE = (Eina_Model_Type *) &_HUMAN_TYPE; |
||||
|
||||
static const Whistler_Interface _WHISTLER_INTERFACE; |
||||
static const Eina_Model_Interface * const WHISTLER_INTERFACE = |
||||
(Eina_Model_Interface *) &_WHISTLER_INTERFACE; |
||||
|
||||
static const Swimmer_Interface _SWIMMER_INTERFACE; |
||||
static const Eina_Model_Interface * const SWIMMER_INTERFACE = |
||||
(Eina_Model_Interface *) &_SWIMMER_INTERFACE; |
||||
|
||||
static const Diver_Interface _DIVER_INTERFACE; |
||||
static const Eina_Model_Interface * const DIVER_INTERFACE = |
||||
(Eina_Model_Interface *) &_DIVER_INTERFACE; |
||||
|
||||
/*
|
||||
* defining parent interfaces for Diver Interface instance |
||||
* defining Interfaces for Human Model instance |
||||
*/ |
||||
static const Eina_Model_Interface * PARENT_INTERFACES_ARRAY[] = |
||||
{ &_SWIMMER_INTERFACE.base_interface, NULL }; //this array is for model
|
||||
static const Eina_Model_Interface * MODEL_INTERFACES_ARRAY[] = |
||||
{ &_WHISTLER_INTERFACE.base_interface, &_DIVER_INTERFACE.base_interface, |
||||
NULL }; //this array is for model
|
||||
|
||||
void |
||||
human_init() |
||||
{ |
||||
Eina_Model_Type *type; |
||||
|
||||
if (initialized) return; |
||||
initialized = EINA_TRUE; |
||||
|
||||
animal_init(); |
||||
|
||||
/*
|
||||
* Initializing Whistler Interface Instance |
||||
*/ |
||||
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 = _human_whistle; |
||||
|
||||
/*
|
||||
* Initializing Swimmer Interface Instance |
||||
*/ |
||||
iface = (Eina_Model_Interface *) &_SWIMMER_INTERFACE; |
||||
iface->version = EINA_MODEL_INTERFACE_VERSION; |
||||
iface->interface_size = sizeof(Swimmer_Interface); |
||||
iface->name = SWIMMER_INTERFACE_NAME; |
||||
SWIMMER_INTERFACE(iface)->swim = _human_swim; |
||||
|
||||
/*
|
||||
* Initializing Diver Interface Instance |
||||
* Diver_Interface is inherited from Swimmer |
||||
*/ |
||||
iface = (Eina_Model_Interface *) &_DIVER_INTERFACE; |
||||
iface->version = EINA_MODEL_INTERFACE_VERSION; |
||||
iface->interface_size = sizeof(Diver_Interface); |
||||
iface->name = DIVER_INTERFACE_NAME; |
||||
iface->interfaces = PARENT_INTERFACES_ARRAY; |
||||
DIVER_INTERFACE(iface)->dive = _human_dive; |
||||
|
||||
/*
|
||||
* Initializing instance of Human Model |
||||
*/ |
||||
|
||||
HUMAN_MODEL_TYPE_NAME = "Human_Model_Type"; |
||||
|
||||
type = (Eina_Model_Type *) &_HUMAN_TYPE; |
||||
type->version = EINA_MODEL_TYPE_VERSION; |
||||
type->name = HUMAN_MODEL_TYPE_NAME; |
||||
type->private_size = 0; |
||||
|
||||
eina_model_type_subclass_setup(type, ANIMAL_TYPE); |
||||
|
||||
type->type_size = sizeof(Human_Type); |
||||
type->interfaces = MODEL_INTERFACES_ARRAY; |
||||
|
||||
ANIMAL_TYPE(type)->eat = _human_eat; |
||||
HUMAN_TYPE(type)->walk =_human_walk; |
||||
} |
||||
|
||||
|
||||
/*
|
||||
* call for implemented Human Class function |
||||
*/ |
||||
void |
||||
human_walk(Eina_Model *m) |
||||
{ |
||||
EINA_SAFETY_ON_FALSE_RETURN(eina_model_instance_check(m, HUMAN_TYPE)); |
||||
|
||||
void (*pf)(Eina_Model *m); |
||||
pf = eina_model_method_resolve(m, Human_Type, walk); |
||||
EINA_SAFETY_ON_NULL_RETURN(pf); |
||||
printf("%s() \t", __func__); |
||||
pf(m); |
||||
} |
@ -1,24 +0,0 @@ |
||||
/*
|
||||
* human.h |
||||
*/ |
||||
|
||||
#ifndef HUMAN_H_ |
||||
#define HUMAN_H_ |
||||
|
||||
#include "eina_model_04_animal.h" |
||||
|
||||
extern const char *HUMAN_MODEL_TYPE_NAME; |
||||
extern const Eina_Model_Type * const HUMAN_TYPE; |
||||
|
||||
#define HUMAN_TYPE(x) ((Human_Type *) (eina_model_type_subclass_check((x), ANIMAL_TYPE) ? (x) : NULL)) |
||||
|
||||
typedef struct _Human_Type |
||||
{ |
||||
Animal_Type parent_class; |
||||
void (*walk)(Eina_Model *m); |
||||
} Human_Type; |
||||
|
||||
void human_init(); |
||||
void human_walk(Eina_Model *m); |
||||
|
||||
#endif /* HUMAN_H_ */ |
@ -1,110 +0,0 @@ |
||||
/*
|
||||
* main_animal.c |
||||
* compile with: gcc eina_model_04_*.c -o eina_model_04 `pkg-config --cflags --libs eina` |
||||
*/ |
||||
|
||||
/*
|
||||
* This example demonstrates the extended usage of Eina Model. |
||||
* Class inheritance and interface implementation |
||||
* |
||||
* Animal Class is inherited from BaseClass and implements |
||||
* "_breathe_animal()" and "_eat_animal()" methods. |
||||
* |
||||
* Human Class is inherited from Animal class. |
||||
* Parrot Class is inherited from Animal class. |
||||
* |
||||
* Child Class is inherited from Human class. |
||||
* |
||||
* Human Class and Parrot Class implement Whistler Interface. |
||||
* Human Class implements Diver Interface. Diver Interface inherited from Swimmer Interface |
||||
* |
||||
* |
||||
* Animal Class (inherited from Base Class) |
||||
* + _breathe_animal() |
||||
* + _eat_animal() |
||||
* / -------/ \-------------\
|
||||
* / \
|
||||
* Human Class Parrot Class |
||||
* inherits inherits |
||||
* + animal_breathe() + animal_breathe() |
||||
* overrides overrides |
||||
* + animal_eat(); + animal_eat(); |
||||
* implements implements |
||||
* + human_walk(); + parrot_fly(); |
||||
* |
||||
* implements Whistler, Swimmer, implements Whistler, |
||||
* Diver Interfaces: + whistler_whistle() |
||||
* + whistler_whistle() |
||||
* + swimmer_swim() |
||||
* + diver_dive() |
||||
* |
||||
* ---------------------------------------------------------- |
||||
* | Swim_Interface | |
||||
* | + swim() | |
||||
* | | | |
||||
* | | | |
||||
* | Dive Intarface (inherited from Swim Interface) | |
||||
* | + dive() | |
||||
* --------------------------------------------------------- |
||||
* | |
||||
* | |
||||
* Child Class |
||||
* + inherits all parent's methods |
||||
* + implements cry_child() |
||||
* + overrides dive() interface method |
||||
*/ |
||||
|
||||
#include <Eina.h> |
||||
#include "eina_model_04_human.h" |
||||
#include "eina_model_04_parrot.h" |
||||
#include "eina_model_04_child.h" |
||||
#include "eina_model_04_whistler.h" |
||||
|
||||
int |
||||
main() |
||||
{ |
||||
Eina_Model *h, *p, *c; |
||||
|
||||
eina_init(); |
||||
|
||||
human_init(); |
||||
parrot_init(); |
||||
child_init(); |
||||
|
||||
h = eina_model_new(HUMAN_TYPE); |
||||
p = eina_model_new(PARROT_TYPE); |
||||
c = eina_model_new(CHILD_TYPE); |
||||
|
||||
animal_breathe(p); |
||||
animal_eat(p); |
||||
parrot_fly(p); |
||||
whistler_whistle(p); |
||||
|
||||
printf("\n"); |
||||
animal_breathe(h); |
||||
animal_eat(h); |
||||
human_walk(h); |
||||
whistler_whistle(h); |
||||
swimmer_swim(h); |
||||
diver_dive(h); |
||||
|
||||
printf("\n"); |
||||
animal_breathe(c); |
||||
animal_eat(c); |
||||
human_walk(c); |
||||
whistler_whistle(c); |
||||
swimmer_swim(c); |
||||
diver_dive(c); |
||||
child_cry(c); |
||||
|
||||
eina_model_unref(c); |
||||
eina_model_unref(h); |
||||
eina_model_unref(p); |
||||
|
||||
eina_shutdown(); |
||||
|
||||
return 0; |
||||
} |
||||
|
||||
|
||||
|
@ -1,95 +0,0 @@ |
||||
/*
|
||||
* 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); |
||||
} |
||||
|
@ -1,24 +0,0 @@ |
||||
/*
|
||||
* parrot.h |
||||
*/ |
||||
|
||||
#ifndef PARROT_H_ |
||||
#define PARROT_H_ |
||||
|
||||
#include "eina_model_04_animal.h" |
||||
|
||||
extern const char *PARROT_MODEL_TYPE_NAME; |
||||
extern const Eina_Model_Type * const PARROT_TYPE; |
||||
|
||||
#define PARROT_TYPE(x) ((Parrot_Type *) (eina_model_type_subclass_check((x), PARROT_TYPE) ? (x) : NULL)) |
||||
|
||||
typedef struct _Parrot_Type |
||||
{ |
||||
Animal_Type parent_class; |
||||
void (*fly)(Eina_Model *m); |
||||
} Parrot_Type; |
||||
|
||||
void parrot_init(); |
||||
void parrot_fly(Eina_Model *m); |
||||
|
||||
#endif /* PARROT_H_ */ |
@ -1,59 +0,0 @@ |
||||
/*
|
||||
* whistler.c |
||||
* |
||||
*/ |
||||
|
||||
#include "eina_model_04_whistler.h" |
||||
|
||||
void |
||||
whistler_whistle(Eina_Model *m) |
||||
{ |
||||
const Eina_Model_Interface *iface = NULL; |
||||
iface = eina_model_interface_get(m, WHISTLER_INTERFACE_NAME); |
||||
|
||||
EINA_SAFETY_ON_NULL_RETURN(iface); |
||||
|
||||
void (*pf)(Eina_Model *); |
||||
|
||||
pf = eina_model_interface_method_resolve(iface, m, Whistler_Interface, whistle); |
||||
EINA_SAFETY_ON_NULL_RETURN(pf); |
||||
printf("%s() \t", __func__); |
||||
pf(m); |
||||
} |
||||
/*
|
||||
* call for overridden Swimmer Interface function |
||||
*/ |
||||
void |
||||
swimmer_swim(Eina_Model *m) |
||||
{ |
||||
const Eina_Model_Interface *iface = NULL; |
||||
iface = eina_model_interface_get(m, SWIMMER_INTERFACE_NAME); |
||||
|
||||
EINA_SAFETY_ON_NULL_RETURN(iface); |
||||
|
||||
void (*pf)(Eina_Model *); |
||||
|
||||
pf = eina_model_interface_method_resolve(iface, m, Swimmer_Interface, swim); |
||||
EINA_SAFETY_ON_NULL_RETURN(pf); |
||||
printf("%s() \t", __func__); |
||||
pf(m); |
||||
} |
||||
|
||||
/*
|
||||
* call for overridden Diver Interface function |
||||
*/ |
||||
void |
||||
diver_dive(Eina_Model *m) |
||||
{ |
||||
const Eina_Model_Interface *iface = NULL; |
||||
iface = eina_model_interface_get(m, DIVER_INTERFACE_NAME); |
||||
|
||||
EINA_SAFETY_ON_NULL_RETURN(iface); |
||||
|
||||
void (*pf)(Eina_Model *); |
||||
|
||||
pf = eina_model_interface_method_resolve(iface, m, Diver_Interface, dive); |
||||
EINA_SAFETY_ON_NULL_RETURN(pf); |
||||
printf("%s() \t", __func__); |
||||
pf(m); |
||||
} |
@ -1,45 +0,0 @@ |
||||
/*
|
||||
* whistler.h |
||||
*/ |
||||
|
||||
#ifndef WHISTLER_H_ |
||||
#define WHISTLER_H_ |
||||
|
||||
#include <Eina.h> |
||||
#include <eina_safety_checks.h> |
||||
|
||||
#define WHISTLER_INTERFACE_NAME "Whistler_Interface" |
||||
#define SWIMMER_INTERFACE_NAME "Swimmer_Interface" |
||||
#define DIVER_INTERFACE_NAME "Diver_Interface" |
||||
|
||||
#define WHISTLER_INTERFACE(x) ((Whistler_Interface *) x) |
||||
#define SWIMMER_INTERFACE(x) ((Swimmer_Interface *) x) |
||||
#define DIVER_INTERFACE(x) ((Diver_Interface *) x) |
||||
|
||||
typedef struct _Whistler_Interface |
||||
{ |
||||
Eina_Model_Interface base_interface; |
||||
void (*whistle)(Eina_Model *); |
||||
|
||||
} Whistler_Interface; |
||||
|
||||
typedef struct _Swimmer_Interface |
||||
{ |
||||
Eina_Model_Interface base_interface; |
||||
void (*swim)(Eina_Model *); |
||||
|
||||
} Swimmer_Interface; |
||||
|
||||
//Diver Interface will use Swimmer Interface as a parent
|
||||
typedef struct _Diver_Interface |
||||
{ |
||||
Eina_Model_Interface base_interface; |
||||
void (*dive)(Eina_Model *); |
||||
|
||||
} Diver_Interface; |
||||
|
||||
void whistler_whistle(Eina_Model *m); |
||||
void swimmer_swim(Eina_Model *m); |
||||
void diver_dive(Eina_Model *m); |
||||
|
||||
#endif /* WHISTLER_H_ */ |