Commit 1e0baaab authored by Cedric BAIL's avatar Cedric BAIL

* eet: Cleanup Eet_Data_Descriptor API.

	- Provide two functions with a better name (Still need more doc).
	- Deprecating old eet_data_descriptor*_new.
	- Provide helper function for eet when using eina data type.


SVN revision: 41732
parent 819c572d
......@@ -201,3 +201,11 @@
2009-07-29 Carsten Haitzler (The Rasterman)
* Release eet 1.2.2
2009-08-13 Cedric BAIL
* Deprecating eet_data_descriptor*_new.
* Add eet_data_descriptor_stream_new and eet_data_descriptor_file_new.
* Add eina helper.
* Cleanup Eet_Data_Descriptor code.
......@@ -976,15 +976,117 @@ extern "C" {
*
* @since 1.0.0
*/
EAPI Eet_Data_Descriptor *eet_data_descriptor_new(const char *name, int size, void *(*func_list_next) (void *l), void *(*func_list_append) (void *l, void *d), void *(*func_list_data) (void *l), void *(*func_list_free) (void *l), void (*func_hash_foreach) (void *h, int (*func) (void *h, const char *k, void *dt, void *fdt), void *fdt), void *(*func_hash_add) (void *h, const char *k, void *d), void (*func_hash_free) (void *h));
EAPI Eet_Data_Descriptor *eet_data_descriptor_new(const char *name, int size, void *(*func_list_next) (void *l), void *(*func_list_append) (void *l, void *d), void *(*func_list_data) (void *l), void *(*func_list_free) (void *l), void (*func_hash_foreach) (void *h, int (*func) (void *h, const char *k, void *dt, void *fdt), void *fdt), void *(*func_hash_add) (void *h, const char *k, void *d), void (*func_hash_free) (void *h)) EINA_DEPRECATED;
/*
* FIXME:
*
* moving to this api from the old above. this will break things when the
* move happens - but be warned
*/
EAPI Eet_Data_Descriptor *eet_data_descriptor2_new(Eet_Data_Descriptor_Class *eddc);
EAPI Eet_Data_Descriptor *eet_data_descriptor3_new(Eet_Data_Descriptor_Class *eddc);
EAPI Eet_Data_Descriptor *eet_data_descriptor2_new(const Eet_Data_Descriptor_Class *eddc) EINA_DEPRECATED;
EAPI Eet_Data_Descriptor *eet_data_descriptor3_new(const Eet_Data_Descriptor_Class *eddc) EINA_DEPRECATED;
/**
* This function creates a new data descriptore and returns a handle to the
* new data descriptor. On creation it will be empty, containing no contents
* describing anything other than the shell of the data structure.
* @param edd The data descriptor to free.
*
* You add structure members to the data descriptor using the macros
* EET_DATA_DESCRIPTOR_ADD_BASIC(), EET_DATA_DESCRIPTOR_ADD_SUB() and
* EET_DATA_DESCRIPTOR_ADD_LIST(), depending on what type of member you are
* adding to the description.
*
* Once you have described all the members of a struct you want loaded, or
* saved eet can load and save those members for you, encode them into
* endian-independant serialised data chunks for transmission across a
* a network or more.
*
* This function specially ignore str_direct_alloc and str_direct_free. It
* is usefull when the eet_data you are reading don't have a dictionnary
* like network stream or ipc. It also mean that all string will be allocated
* and duplicated in memory.
*
* @since 1.3.0
*/
EAPI Eet_Data_Descriptor *eet_data_descriptor_stream_new(const Eet_Data_Descriptor_Class *eddc);
/**
* This function creates a new data descriptore and returns a handle to the
* new data descriptor. On creation it will be empty, containing no contents
* describing anything other than the shell of the data structure.
* @param edd The data descriptor to free.
*
* You add structure members to the data descriptor using the macros
* EET_DATA_DESCRIPTOR_ADD_BASIC(), EET_DATA_DESCRIPTOR_ADD_SUB() and
* EET_DATA_DESCRIPTOR_ADD_LIST(), depending on what type of member you are
* adding to the description.
*
* Once you have described all the members of a struct you want loaded, or
* saved eet can load and save those members for you, encode them into
* endian-independant serialised data chunks for transmission across a
* a network or more.
*
* This function use str_direct_alloc and str_direct_free. It is usefull when
* the eet_data you are reading come from a file and have a dictionnary. This
* will reduce memory use, improve the possibility for the OS to page this
* string out. But be carrefull all EET_T_STRING are pointer to a mmapped area
* and it will point to nowhere if you close the file. So as long as you use
* this strings, you need to have the Eet_File open.
*
* @since 1.3.0
*/
EAPI Eet_Data_Descriptor *eet_data_descriptor_file_new(const Eet_Data_Descriptor_Class *eddc);
/**
* This function is an helper that set all the parameter of an Eet_Data_Descriptor_Class
* correctly when you use Eina data type with a stream.
* @param class The Eet_Data_Descriptor_Class you want to set.
* @param name The name of the structure described by this class.
* @param size The size of the structure described by this class.
* @return EINA_TRUE if the structure was correctly set (The only reason that could make
* it fail is if you did give wrong parameter).
*
* @since 1.3.0
*/
EAPI Eina_Bool eina_stream_data_descriptor_set(Eet_Data_Descriptor_Class *class, const char *name, int size);
/**
* This macro is an helper that set all the parameter of an Eet_Data_Descriptor_Class
* correctly when you use Eina data type with stream.
* @param class The Eet_Data_Descriptor_Class you want to set.
* @param type The type of the structure described by this class.
* @return EINA_TRUE if the structure was correctly set (The only reason that could make
* it fail is if you did give wrong parameter).
*
* @since 1.3.0
*/
#define EINA_STREAM_DATA_DESCRIPTOR_SET(Class, Type) eina_stream_data_descriptor_set(Class, #Type , sizeof (Type));
/**
* This function is an helper that set all the parameter of an Eet_Data_Descriptor_Class
* correctly when you use Eina data type with a file.
* @param class The Eet_Data_Descriptor_Class you want to set.
* @param name The name of the structure described by this class.
* @param size The size of the structure described by this class.
* @return EINA_TRUE if the structure was correctly set (The only reason that could make
* it fail is if you did give wrong parameter).
*
* @since 1.3.0
*/
EAPI Eina_Bool eina_file_data_descriptor_set(Eet_Data_Descriptor_Class *class, const char *name, int size);
/**
* This macro is an helper that set all the parameter of an Eet_Data_Descriptor_Class
* correctly when you use Eina data type with file.
* @param class The Eet_Data_Descriptor_Class you want to set.
* @param type The type of the structure described by this class.
* @return EINA_TRUE if the structure was correctly set (The only reason that could make
* it fail is if you did give wrong parameter).
*
* @since 1.3.0
*/
#define EINA_FILE_DATA_DESCRIPTOR_SET(Class, Type) eina_file_data_descriptor_set(Class, #Type , sizeof (Type));
/**
* This function frees a data descriptor when it is not needed anymore.
......
......@@ -1011,53 +1011,75 @@ _eet_str_free(const char *str)
free((char *)str);
}
static Eina_Hash *
_eet_eina_hash_add_alloc(Eina_Hash *hash, const char *key, void *data)
{
if (!hash) hash = eina_hash_string_small_new(NULL);
if (!hash) return NULL;
eina_hash_add(hash, key, data);
return hash;
}
static char *
_edje_str_direct_alloc(const char *str)
{
return (char *)str;
}
static void
_edje_str_direct_free(const char *str)
{
}
/*---*/
EAPI Eina_Bool
eina_stream_data_descriptor_set(Eet_Data_Descriptor_Class *class, const char *name, int size)
{
if (!class || !name) return EINA_FALSE;
EAPI Eet_Data_Descriptor *
eet_data_descriptor_new(const char *name,
int size,
void *(*func_list_next) (void *l),
void *(*func_list_append) (void *l, void *d),
void *(*func_list_data) (void *l),
void *(*func_list_free) (void *l),
void (*func_hash_foreach) (void *h, int (*func) (void *h, const char *k, void *dt, void *fdt), void *fdt),
void *(*func_hash_add) (void *h, const char *k, void *d),
void (*func_hash_free) (void *h))
class->name = name;
class->size = size;
class->version = 1;
class->func.mem_alloc = _eet_mem_alloc;
class->func.mem_free = _eet_mem_free;
class->func.str_alloc = (char *(*)(const char *))eina_stringshare_add;
class->func.str_free = eina_stringshare_del;
class->func.list_next = (void *(*)(void *))eina_list_next;
class->func.list_append = (void *(*)(void *, void *))eina_list_append;
class->func.list_data = (void *(*)(void *))eina_list_data_get;
class->func.list_free = (void *(*)(void *))eina_list_free;
class->func.hash_foreach = (void (*)(void *, int (*)(void *, const char *, void *, void *), void *))eina_hash_foreach;
class->func.hash_add = (void* (*)(void *, const char *, void *)) _eet_eina_hash_add_alloc;
class->func.hash_free = (void (*)(void *))eina_hash_free;
return EINA_TRUE;
}
EAPI Eina_Bool
eina_file_data_descriptor_set(Eet_Data_Descriptor_Class *class, const char *name, int size)
{
Eet_Data_Descriptor *edd;
if (!eina_stream_data_descriptor_set(class, name, size))
return EINA_FALSE;
if (!name) return NULL;
edd = calloc(1, sizeof(Eet_Data_Descriptor));
if (!edd) return NULL;
class->version = 2;
edd->name = name;
edd->ed = NULL;
edd->size = size;
edd->func.mem_alloc = _eet_mem_alloc;
edd->func.mem_free = _eet_mem_free;
edd->func.str_alloc = _eet_str_alloc;
edd->func.str_direct_alloc = NULL;
edd->func.str_direct_free = NULL;
edd->func.str_free = _eet_str_free;
edd->func.list_next = func_list_next;
edd->func.list_append = func_list_append;
edd->func.list_data = func_list_data;
edd->func.list_free = func_list_free;
edd->func.hash_foreach = func_hash_foreach;
edd->func.hash_add = func_hash_add;
edd->func.hash_free = func_hash_free;
return edd;
class->func.str_direct_alloc = _edje_str_direct_alloc;
class->func.str_direct_free = _edje_str_direct_free;
return EINA_TRUE;
}
/* new replcement */
EAPI Eet_Data_Descriptor *
eet_data_descriptor2_new(Eet_Data_Descriptor_Class *eddc)
static Eet_Data_Descriptor *
_eet_data_descriptor_new(const Eet_Data_Descriptor_Class *eddc, int version)
{
Eet_Data_Descriptor *edd;
if (!eddc) return NULL;
if (eddc->version < 1) return NULL;
edd = calloc(1, sizeof(Eet_Data_Descriptor));
if (eddc->version < version) return NULL;
edd = calloc(1, sizeof (Eet_Data_Descriptor));
if (!edd) return NULL;
edd->name = eddc->name;
......@@ -1083,45 +1105,69 @@ eet_data_descriptor2_new(Eet_Data_Descriptor_Class *eddc)
edd->func.hash_add = eddc->func.hash_add;
edd->func.hash_free = eddc->func.hash_free;
if (version > 1)
{
edd->func.str_direct_alloc = eddc->func.str_direct_alloc;
edd->func.str_direct_free = eddc->func.str_direct_free;
}
return edd;
}
EAPI Eet_Data_Descriptor *
eet_data_descriptor3_new(Eet_Data_Descriptor_Class *eddc)
eet_data_descriptor_new(const char *name,
int size,
void *(*func_list_next) (void *l),
void *(*func_list_append) (void *l, void *d),
void *(*func_list_data) (void *l),
void *(*func_list_free) (void *l),
void (*func_hash_foreach) (void *h, int (*func) (void *h, const char *k, void *dt, void *fdt), void *fdt),
void *(*func_hash_add) (void *h, const char *k, void *d),
void (*func_hash_free) (void *h))
{
Eet_Data_Descriptor_Class eddc;
if (!name) return NULL;
eddc.name = name;
eddc.size = size;
eddc.version = 0;
memset(&eddc, 0, sizeof (Eet_Data_Descriptor_Class));
eddc.func.list_next = func_list_next;
eddc.func.list_append = func_list_append;
eddc.func.list_data = func_list_data;
eddc.func.list_free = func_list_free;
eddc.func.hash_foreach = func_hash_foreach;
eddc.func.hash_add = func_hash_add;
eddc.func.hash_free = func_hash_free;
return _eet_data_descriptor_new(&eddc, 0);
}
EAPI Eet_Data_Descriptor *
eet_data_descriptor2_new(const Eet_Data_Descriptor_Class *eddc)
{
Eet_Data_Descriptor *edd;
return _eet_data_descriptor_new(eddc, 1);
}
if (!eddc) return NULL;
if (eddc->version < 2) return NULL;
edd = calloc(1, sizeof(Eet_Data_Descriptor));
if (!edd) return NULL;
EAPI Eet_Data_Descriptor *
eet_data_descriptor3_new(const Eet_Data_Descriptor_Class *eddc)
{
return _eet_data_descriptor_new(eddc, 2);
}
edd->name = eddc->name;
edd->ed = NULL;
edd->size = eddc->size;
edd->func.mem_alloc = _eet_mem_alloc;
edd->func.mem_free = _eet_mem_free;
edd->func.str_alloc = _eet_str_alloc;
edd->func.str_free = _eet_str_free;
if (eddc->func.mem_alloc)
edd->func.mem_alloc = eddc->func.mem_alloc;
if (eddc->func.mem_free)
edd->func.mem_free = eddc->func.mem_free;
if (eddc->func.str_alloc)
edd->func.str_alloc = eddc->func.str_alloc;
if (eddc->func.str_free)
edd->func.str_free = eddc->func.str_free;
edd->func.list_next = eddc->func.list_next;
edd->func.list_append = eddc->func.list_append;
edd->func.list_data = eddc->func.list_data;
edd->func.list_free = eddc->func.list_free;
edd->func.hash_foreach = eddc->func.hash_foreach;
edd->func.hash_add = eddc->func.hash_add;
edd->func.hash_free = eddc->func.hash_free;
edd->func.str_direct_alloc = eddc->func.str_direct_alloc;
edd->func.str_direct_free = eddc->func.str_direct_free;
EAPI Eet_Data_Descriptor *
eet_data_descriptor_stream_new(const Eet_Data_Descriptor_Class *eddc)
{
return _eet_data_descriptor_new(eddc, 1);
}
return edd;
EAPI Eet_Data_Descriptor *
eet_data_descriptor_file_new(const Eet_Data_Descriptor_Class *eddc)
{
return _eet_data_descriptor_new(eddc, 2);
}
EAPI void
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment