Edje_External_Type: break abi, add abi checker.

- add preview_get() and description_get(), breaking ABI badly.
 - add abi_version field to be fileld with EDJE_EXTERNAL_TYPE_ABI_VERSION
   and checked with edje_external_type_abi_version_get()




SVN revision: 44135
This commit is contained in:
Gustavo Sverzut Barbieri 2009-12-02 21:41:28 +00:00
parent aedc584923
commit 778cc70719
2 changed files with 64 additions and 2 deletions

View File

@ -311,6 +311,12 @@ typedef struct _Edje_External_Param_Info Edje_External_Param_Info;
struct _Edje_External_Type
{
#define EDJE_EXTERNAL_TYPE_ABI_VERSION (1)
unsigned int abi_version; /**< always use:
* - #EDJE_EXTERNAL_TYPE_ABI_VERSION to declare.
* - edje_external_type_abi_version_get() to check.
*/
const char *module;
Evas_Object *(*add) (void *data, Evas *evas, Evas_Object *parent, const Eina_List *params);
void (*state_set) (void *data, Evas_Object *obj, const void *from_params, const void *to_params, float pos);
@ -318,8 +324,10 @@ struct _Edje_External_Type
void *(*params_parse) (void *data, Evas_Object *obj, const Eina_List *params);
void (*params_free) (void *params);
Evas_Object *(*icon_get) (void *data, Evas *e);
const char *(*label_get) (void *data);
const char *(*description_get) (void *data);
Evas_Object *(*icon_get) (void *data, Evas *e);
Evas_Object *(*preview_get) (void *data, Evas *e);
Edje_External_Param_Info *parameters_info;
@ -495,6 +503,9 @@ extern "C" {
EAPI void edje_external_type_array_register(const Edje_External_Type_Info *array);
EAPI void edje_external_type_array_unregister(const Edje_External_Type_Info *array);
EAPI unsigned int edje_external_type_abi_version_get(void) EINA_CONST;
EAPI Eina_Iterator *edje_external_iterator_get(void);
EAPI Edje_External_Param *edje_external_param_find(const Eina_List *params, const char *key);
EAPI Eina_Bool edje_external_param_int_get(const Eina_List *params, const char *key, int *ret);

View File

@ -22,6 +22,20 @@ static int init_count = 0;
EAPI Eina_Bool
edje_external_type_register(const char *type_name, const Edje_External_Type *type_info)
{
if (!type_name)
return EINA_FALSE;
if (!type_info)
return EINA_FALSE;
if (type_info->abi_version != EDJE_EXTERNAL_TYPE_ABI_VERSION)
{
printf("EDJE ERROR: external type '%s' (%p) has incorrect abi version. "
"got %#x where %#x was expected.\n",
type_name, type_info,
type_info->abi_version, EDJE_EXTERNAL_TYPE_ABI_VERSION);
return EINA_FALSE;
}
if (eina_hash_find(type_registry, type_name))
{
printf("EDJE ERROR: external type '%s' already registered\n", type_name);
@ -44,6 +58,8 @@ edje_external_type_register(const char *type_name, const Edje_External_Type *typ
EAPI Eina_Bool
edje_external_type_unregister(const char *type_name)
{
if (!type_name)
return EINA_FALSE;
return eina_hash_del_by_key(type_registry, type_name);
}
@ -78,7 +94,18 @@ edje_external_type_array_register(const Edje_External_Type_Info *array)
return;
for (itr = array; itr->name; itr++)
eina_hash_direct_add(type_registry, itr->name, itr->info);
{
if (itr->info->abi_version != EDJE_EXTERNAL_TYPE_ABI_VERSION)
{
printf("EDJE ERROR: external type '%s' (%p) has incorrect abi "
"version. got %#x where %#x was expected.\n",
itr->name, itr->info,
itr->info->abi_version, EDJE_EXTERNAL_TYPE_ABI_VERSION);
continue;
}
eina_hash_direct_add(type_registry, itr->name, itr->info);
}
}
/**
@ -101,6 +128,30 @@ edje_external_type_array_unregister(const Edje_External_Type_Info *array)
eina_hash_del(type_registry, itr->name, itr->info);
}
/**
* Return the current ABI version for Edje_External_Type structure.
*
* Always check this number before accessing Edje_External_Type in
* your own software. If the number is not the same, your software may
* access invalid memory and crash, or just get garbage values.
*
* @warning @b NEVER, EVER define your own Edje_External_Type using the
* return of this function as it will change as Edje library
* (libedje.so) changes, but your type definition will
* not. Instead, use #EDJE_EXTERNAL_TYPE_ABI_VERSION.
*
* Summary:
* - use edje_external_type_abi_version_get() to check.
* - use #EDJE_EXTERNAL_TYPE_ABI_VERSION to define/declare.
*
* @return version this edje library was compiled.
*/
EAPI unsigned int
edje_external_type_abi_version_get(void)
{
return EDJE_EXTERNAL_TYPE_ABI_VERSION;
}
EAPI Eina_Iterator *
edje_external_iterator_get(void)
{