emodel: api change property_get/set and event modelchange

This commit is contained in:
Larry Jr 2015-04-05 15:19:55 +02:00 committed by Cedric BAIL
parent 23cfd2b4f4
commit 2f53833331
7 changed files with 150 additions and 193 deletions

View File

@ -17,7 +17,6 @@
#define MY_CLASS EIO_MODEL_CLASS
#define MY_CLASS_NAME "Eio_Model"
static Eina_Value_Struct_Desc *EIO_MODEL_PROPERTIES_DESC = NULL;
static void _eio_prop_set_error_cb(void *, Eio_File *, int);
static void _eio_model_emodel_properties_load(Eo *, Eio_Model_Data *);
static void _eio_model_emodel_children_load(Eo *, Eio_Model_Data *);
@ -66,31 +65,18 @@ _eio_stat_done_cb(void *data, Eio_File *handler EINA_UNUSED, const Eina_Stat *st
{
Emodel_Property_Event evt;
Eio_Model_Data *priv = data;
Eina_Bool changed = EINA_FALSE;
Eina_Value_Struct_Desc *desc = EIO_MODEL_PROPERTIES_DESC;
EINA_SAFETY_ON_FALSE_RETURN(eo_ref_get(priv->obj));
priv->stat = stat;
priv->is_dir = eio_file_is_dir(stat);
memset(&evt, 0, sizeof(Emodel_Property_Event));
changed |= eina_value_struct_set(priv->properties,
desc->members[EIO_MODEL_PROP_IS_DIR].name, eio_file_is_dir(stat));
eina_value_set(priv->properties_value[EIO_MODEL_PROP_IS_DIR], eio_file_is_dir(stat));
eina_value_set(priv->properties_value[EIO_MODEL_PROP_IS_LNK], eio_file_is_lnk(stat));
eina_value_set(priv->properties_value[EIO_MODEL_PROP_MTIME], eio_file_mtime(stat));
eina_value_set(priv->properties_value[EIO_MODEL_PROP_SIZE], eio_file_size(stat));
changed |= eina_value_struct_set(priv->properties,
desc->members[EIO_MODEL_PROP_IS_LNK].name, eio_file_is_lnk(stat));
changed |= eina_value_struct_set(priv->properties,
desc->members[EIO_MODEL_PROP_MTIME].name, eio_file_mtime(stat));
changed |= eina_value_struct_set(priv->properties,
desc->members[EIO_MODEL_PROP_SIZE].name, eio_file_size(stat));
if (changed == EINA_TRUE)
{
evt.changed_properties = priv->properties;
eo_do(priv->obj, eo_event_callback_call(EMODEL_EVENT_PROPERTIES_CHANGED, &evt));
}
evt.changed_properties = priv->properties_name;
eo_do(priv->obj, eo_event_callback_call(EMODEL_EVENT_PROPERTIES_CHANGED, &evt));
_load_set(priv, EMODEL_LOAD_STATUS_LOADED_PROPERTIES);
@ -109,7 +95,7 @@ _eio_move_done_cb(void *data, Eio_File *handler EINA_UNUSED)
{
Emodel_Property_Event evt;
Eio_Model_Data *priv = data;
Eina_Value_Struct_Desc *desc = EIO_MODEL_PROPERTIES_DESC;
Eina_Array *properties;
EINA_SAFETY_ON_FALSE_RETURN(eo_ref_get(priv->obj));
@ -119,11 +105,16 @@ _eio_move_done_cb(void *data, Eio_File *handler EINA_UNUSED)
* When mv is executed we update our values and
* notify both path and filename properties listeners.
*/
eina_value_struct_set(priv->properties, desc->members[EIO_MODEL_PROP_PATH].name, priv->path);
eina_value_struct_set(priv->properties, desc->members[EIO_MODEL_PROP_FILENAME].name, basename(priv->path));
evt.changed_properties = priv->properties;
eina_value_set(priv->properties_value[EIO_MODEL_PROP_PATH], priv->path);
eina_value_set(priv->properties_value[EIO_MODEL_PROP_FILENAME], basename(priv->path));
properties = eina_array_new(2);
eina_array_push(properties, _eio_model_prop_names[EIO_MODEL_PROP_PATH]);
eina_array_push(properties, _eio_model_prop_names[EIO_MODEL_PROP_FILENAME]);
evt.changed_properties = properties;
eo_do(priv->obj, eo_event_callback_call(EMODEL_EVENT_PROPERTIES_CHANGED, &evt));
eina_array_free(properties);
}
static void
@ -259,41 +250,43 @@ _eio_error_unlink_cb(void *data EINA_UNUSED, Eio_File *handler EINA_UNUSED, int
* Interfaces impl.
*/
static Emodel_Load_Status
_eio_model_emodel_properties_list_get(Eo *obj EINA_UNUSED,
Eio_Model_Data *_pd, Eina_Array * const* properties_list)
_eio_model_emodel_properties_get(Eo *obj EINA_UNUSED,
Eio_Model_Data *_pd, Eina_Array * const* properties)
{
Eio_Model_Data *priv = _pd;
unsigned int i;
EINA_SAFETY_ON_NULL_RETURN_VAL(priv, EINA_FALSE);
EINA_SAFETY_ON_NULL_RETURN_VAL(priv->obj, EINA_FALSE);
if (priv->properties_array == NULL)
{
Eina_Value_Struct_Desc *desc = EIO_MODEL_PROPERTIES_DESC;
priv->properties_array = eina_array_new(desc->member_count);
for (i = 0; i < desc->member_count; ++i)
eina_array_push(priv->properties_array, desc->members[i].name);
}
*(Eina_Array **)properties_list = priv->properties_array;
*(Eina_Array **)properties = priv->properties_name;
return priv->load.status;
}
/**
* Property Fetch //carlos
* Property Get
*/
static Emodel_Load_Status
_eio_model_emodel_property_get(Eo *obj EINA_UNUSED, Eio_Model_Data *priv, const char *property, Eina_Value *value)
_eio_model_emodel_property_get(Eo *obj EINA_UNUSED, Eio_Model_Data *priv, const char *property, const Eina_Value **value)
{
unsigned int i;
EINA_SAFETY_ON_NULL_RETURN_VAL(property, EMODEL_LOAD_STATUS_ERROR);
EINA_SAFETY_ON_NULL_RETURN_VAL(priv, EMODEL_LOAD_STATUS_ERROR);
//XXX Return error code?
eina_value_struct_value_get(priv->properties, property, value);
*value = NULL;
if (priv->load.status & EMODEL_LOAD_STATUS_LOADED_PROPERTIES)
{
for (i = 0; i < EIO_MODEL_PROP_LAST; ++i)
{
if (!strcmp(property, _eio_model_prop_names[i]))
break;
}
if ( i < EIO_MODEL_PROP_LAST)
{
*value = priv->properties_value[i];
}
}
return priv->load.status;
}
@ -302,25 +295,24 @@ _eio_model_emodel_property_get(Eo *obj EINA_UNUSED, Eio_Model_Data *priv, const
* Property Set
*/
static Emodel_Load_Status
_eio_model_emodel_property_set(Eo *obj EINA_UNUSED, Eio_Model_Data *priv, const char * property, Eina_Value value)
_eio_model_emodel_property_set(Eo *obj EINA_UNUSED, Eio_Model_Data *priv, const char * property, const Eina_Value *value)
{
char *dest;
Eina_Value v = value;
EINA_SAFETY_ON_NULL_RETURN_VAL(property, EINA_FALSE);
if (strcmp(property, "path") != 0)
return EINA_FALSE;
dest = eina_value_to_string(&v);
dest = eina_value_to_string(value);
if (priv->path == NULL)
{
priv->path = dest;
INF("path '%s' with filename '%s'.", priv->path, basename(priv->path));
eina_value_struct_set(priv->properties, "path", priv->path);
eina_value_struct_set(priv->properties, "filename", basename(priv->path));
eina_value_set(priv->properties_value[EIO_MODEL_PROP_PATH], priv->path);
eina_value_set(priv->properties_value[EIO_MODEL_PROP_FILENAME], basename(priv->path));
_eio_monitors_list_load(priv);
@ -328,8 +320,7 @@ _eio_model_emodel_property_set(Eo *obj EINA_UNUSED, Eio_Model_Data *priv, const
if (priv->load_pending & EMODEL_LOAD_STATUS_LOADED_PROPERTIES)
_eio_model_emodel_properties_load(obj, priv);
if (priv->load_pending & EMODEL_LOAD_STATUS_LOADED_CHILDREN)
else if (priv->load_pending & EMODEL_LOAD_STATUS_LOADED_CHILDREN)
_eio_model_emodel_children_load(obj, priv);
return priv->load.status;
@ -460,9 +451,10 @@ _eio_model_emodel_children_load(Eo *obj EINA_UNUSED, Eio_Model_Data *priv)
priv->load_pending |= EMODEL_LOAD_STATUS_LOADED_CHILDREN;
return;
}
priv->load_pending &= ~EMODEL_LOAD_STATUS_LOADED_CHILDREN;
if (priv->children_list == NULL &&
if (priv->children_list == NULL && priv->is_dir &&
!(priv->load.status & (EMODEL_LOAD_STATUS_LOADED_CHILDREN | EMODEL_LOAD_STATUS_LOADING_CHILDREN)))
{
_eio_model_emodel_monitor_add(priv);
@ -571,7 +563,6 @@ _eio_model_emodel_child_del(Eo *obj EINA_UNUSED, Eio_Model_Data *priv, Eo *child
/**
* Children Slice Get
* TODO/XXX/FIXME: Untested code - validate this implementation
*/
static Emodel_Load_Status
_eio_model_emodel_children_slice_get(Eo *obj EINA_UNUSED, Eio_Model_Data *priv,
@ -627,44 +618,6 @@ _eio_model_emodel_children_slice_get(Eo *obj EINA_UNUSED, Eio_Model_Data *priv,
return priv->load.status;
}
static void
_struct_properties_init(void)
{
typedef struct _This_Eio_Properties
{
const char *filename;
const char *path;
struct timeval mtime;
int is_dir;
int is_lnk;
int64_t size;
} This_Eio_Properties;
static Eina_Value_Struct_Member prop_members[] = {
EINA_VALUE_STRUCT_MEMBER(NULL, This_Eio_Properties, filename),
EINA_VALUE_STRUCT_MEMBER(NULL, This_Eio_Properties, path),
EINA_VALUE_STRUCT_MEMBER(NULL, This_Eio_Properties, mtime),
EINA_VALUE_STRUCT_MEMBER(NULL, This_Eio_Properties, is_dir),
EINA_VALUE_STRUCT_MEMBER(NULL, This_Eio_Properties, is_lnk),
EINA_VALUE_STRUCT_MEMBER(NULL, This_Eio_Properties, size)
};
prop_members[EIO_MODEL_PROP_FILENAME].type = EINA_VALUE_TYPE_STRING;
prop_members[EIO_MODEL_PROP_PATH].type = EINA_VALUE_TYPE_STRING;
prop_members[EIO_MODEL_PROP_MTIME].type = EINA_VALUE_TYPE_TIMEVAL;
prop_members[EIO_MODEL_PROP_IS_DIR].type = EINA_VALUE_TYPE_INT;
prop_members[EIO_MODEL_PROP_IS_LNK].type = EINA_VALUE_TYPE_INT;
prop_members[EIO_MODEL_PROP_SIZE].type = EINA_VALUE_TYPE_INT64;
static Eina_Value_Struct_Desc prop_desc = {
EINA_VALUE_STRUCT_DESC_VERSION,
NULL, // no special operations
prop_members,
EINA_C_ARRAY_LENGTH(prop_members),
sizeof(This_Eio_Properties)
};
EIO_MODEL_PROPERTIES_DESC = &prop_desc;
}
/**
* Class definitions
*/
@ -672,10 +625,20 @@ static void
_eio_model_eo_base_constructor(Eo *obj, Eio_Model_Data *priv)
{
eo_do_super(obj, MY_CLASS, eo_constructor());
unsigned int i;
priv->obj = obj;
_struct_properties_init();
priv->properties = eina_value_struct_new(EIO_MODEL_PROPERTIES_DESC);
EINA_SAFETY_ON_NULL_RETURN(priv->properties);
priv->properties_name = eina_array_new(EIO_MODEL_PROP_LAST);
EINA_SAFETY_ON_NULL_RETURN(priv->properties_name);
for (i = 0; i < EIO_MODEL_PROP_LAST; ++i)
eina_array_push(priv->properties_name, _eio_model_prop_names[i]);
priv->properties_value[EIO_MODEL_PROP_FILENAME] = eina_value_new(EINA_VALUE_TYPE_STRING);
priv->properties_value[EIO_MODEL_PROP_PATH] = eina_value_new(EINA_VALUE_TYPE_STRING);
priv->properties_value[EIO_MODEL_PROP_MTIME] = eina_value_new(EINA_VALUE_TYPE_TIMEVAL);
priv->properties_value[EIO_MODEL_PROP_IS_DIR] = eina_value_new(EINA_VALUE_TYPE_INT);
priv->properties_value[EIO_MODEL_PROP_IS_LNK] = eina_value_new(EINA_VALUE_TYPE_INT);
priv->properties_value[EIO_MODEL_PROP_SIZE] = eina_value_new(EINA_VALUE_TYPE_INT64);
priv->load.status = EMODEL_LOAD_STATUS_UNLOADED;
priv->monitor = NULL;
@ -686,8 +649,8 @@ _eio_model_path_set(Eo *obj EINA_UNUSED, Eio_Model_Data *priv, const char *path)
{
priv->path = strdup(path);
eina_value_struct_set(priv->properties, "path", priv->path);
eina_value_struct_set(priv->properties, "filename", basename(priv->path));
eina_value_set(priv->properties_value[EIO_MODEL_PROP_PATH], priv->path);
eina_value_set(priv->properties_value[EIO_MODEL_PROP_FILENAME], basename(priv->path));
priv->monitor = NULL;
_eio_monitors_list_load(priv);
@ -697,15 +660,18 @@ static void
_eio_model_eo_base_destructor(Eo *obj , Eio_Model_Data *priv)
{
Eo *child;
unsigned int i;
if (priv->monitor)
eio_monitor_del(priv->monitor);
if (priv->properties_array)
eina_array_free(priv->properties_array);
if (priv->properties_name)
eina_array_free(priv->properties_name);
if (priv->properties)
eina_value_free(priv->properties);
for (i = 0; i < EIO_MODEL_PROP_LAST; ++i)
{
eina_value_free(priv->properties_value[i]);
}
EINA_LIST_FREE(priv->children_list, child)
eo_unref(child);

View File

@ -33,7 +33,7 @@ class Eio.Model (Eo.Base, Emodel)
implements {
Eo.Base.constructor;
Eo.Base.destructor;
Emodel.properties_list.get;
Emodel.properties.get;
Emodel.properties_load;
Emodel.property.set;
Emodel.property.get;

View File

@ -14,32 +14,38 @@ struct _Eio_Model_Monitor_Data
int mon_event_child_del[3]; /**< plus EIO_MONITOR_ERROR */
};
/**
* !! Warning: Do not change enum's order
* before checking _eio_model_constructor.
* @see Eina_Value_Struct_Member.
*/
enum {
EIO_MODEL_PROP_FILENAME = 0,
EIO_MODEL_PROP_PATH,
EIO_MODEL_PROP_MTIME,
EIO_MODEL_PROP_IS_DIR,
EIO_MODEL_PROP_IS_LNK,
EIO_MODEL_PROP_SIZE
EIO_MODEL_PROP_SIZE,
EIO_MODEL_PROP_LAST
};
static const char* _eio_model_prop_names[] =
{
[EIO_MODEL_PROP_FILENAME] = "filename",
[EIO_MODEL_PROP_PATH] = "path",
[EIO_MODEL_PROP_MTIME] = "mtime",
[EIO_MODEL_PROP_IS_DIR] = "is_dir",
[EIO_MODEL_PROP_IS_LNK] = "is_lnk",
[EIO_MODEL_PROP_SIZE] = "size"
};
struct _Eio_Model_Data
{
Eo *obj;
char *path;
Eina_Array *properties_array;
Eina_Value *properties;
Eina_Array *properties_name;
Eina_Value *properties_value[EIO_MODEL_PROP_LAST];
Emodel_Load load;
int load_pending;
Eina_List *children_list;
/**< EIO data */
Eio_File *file;
const Eina_Stat *stat;
Eina_Bool is_dir;
Eio_Monitor *monitor;
Eio_Model_Monitor_Data mon;
int cb_count_child_add; /**< monitor reference counter for child add event */

View File

@ -50,8 +50,8 @@ typedef struct _Emodel_Load Emodel_Load;
*/
struct _Emodel_Property_Event
{
const Eina_Value *changed_properties; /**< Eina_Value_Struct or Eina_Value_Hash with changed properties values */
Eina_Array *invalidated_properties; /**< array of name */
const Eina_Array *changed_properties; /**< array of property name */
const Eina_Array *invalidated_properties; /**< array of property name */
};
/**

View File

@ -14,16 +14,11 @@
* EMODEL_LOAD_STATUS_UNLOADED = (1 << 5) /*@ Model Unloaded *
* }
*
* type Emodel_Property_Pair: struct _Emodel_Property_Pair
* {
* value: Eina_Value; /*@ the new property value *
* property: const(char)*; /*@ the property name that has been changed *
* }
*
* type Emodel_Property_Event: struct _Emodel_Property_Event
* {
* changed_properties: Eina_List* <Emodel_Property_Pair*>; /*@ List of changed properties *
* invalidated_properties: Eina_List* <const(char)*>; /*@ Removed properties identified by name *
* changed_properties: Eina_Array* <const(char)*>; /*@ List of changed properties *
* invalidated_properties: Eina_Array* <const(char)*>; /*@ Removed properties identified by name *
* }
*/
@ -48,17 +43,17 @@ interface Emodel ()
return: Emodel_Load_Status;
}
}
properties_list {
properties {
get {
/*@
Get properties list from model.
Get properties from model.
@return: @c Emodel_Load_Status
properties_list_get is due to provide callers a way the fetch the current
properties_get is due to provide callers a way the fetch the current
properties implemented/used by the model.
The event EMODEL_EVENT_PROPERTIES_CHANGE will be raised to notify listeners
of any modifications in the properties list.
of any modifications in the properties.
@see EMODEL_EVENT_PROPERTIES_CHANGE
@since 1.11 */
@ -66,7 +61,7 @@ interface Emodel ()
return: Emodel_Load_Status;
}
values {
const(array<const(char*)>*) properties_list; /*@ list of current properties */
const(array<const(char*)>*) properties; /*@ array of current properties */
}
}
property {
@ -105,18 +100,18 @@ interface Emodel ()
The event EMODEL_EVENT_PROPERTIES_CHANGE may be raised to notify
listeners of the property/value.
@see emodel_properties_list_get
@see emodel_properties_get
@see EMODEL_EVENT_PROPERTIES_CHANGE
@since 1.11 */
return: Emodel_Load_Status;
}
keys {
}
keys {
const(char)* property; /*@ Property name */
}
values {
Eina_Value value; /*@ New value */
}
}
values {
const(Eina_Value)* value; /*@ New value */
}
}
children_slice {
get {

View File

@ -77,29 +77,25 @@ _load_status_cb(void *data EINA_UNUSED, Eo *obj, const Eo_Event_Description *des
if ((st->status & EMODEL_LOAD_STATUS_LOADED) == EMODEL_LOAD_STATUS_LOADED)
{
Eina_Accessor *accessor;
Eina_Value value_prop;
Eo *child;
const Eina_Value *value_prop;
Emodel_Load_Status status;
unsigned int total, i;
unsigned int total;
char *str;
printf("Model is Loaded\n");
eo_do(obj, status = emodel_property_get("filename", &value_prop));
str = eina_value_to_string(&value_prop);
str = eina_value_to_string(value_prop);
printf("emodel_loaded filename %s, status=%d\n", str, status);
eina_value_flush(&value_prop);
free(str);
eo_do(obj, status = emodel_property_get("size", &value_prop));
str = eina_value_to_string(&value_prop);
str = eina_value_to_string(value_prop);
printf("emodel_loaded size %s, status=%d\n", str, status);
eina_value_flush(&value_prop);
free(str);
eo_do(obj, status = emodel_property_get("mtime", &value_prop));
str = eina_value_to_string(&value_prop);
str = eina_value_to_string(value_prop);
printf("emodel_loaded mtime %s, status=%d\n", str, status);
eina_value_flush(&value_prop);
free(str);
eo_do(obj, emodel_children_count_get(&total));
@ -107,30 +103,8 @@ _load_status_cb(void *data EINA_UNUSED, Eo *obj, const Eo_Event_Description *des
/**< get full list */
eo_do(obj, status = emodel_children_slice_get(0 ,0 ,(Eina_Accessor **)&accessor));
EINA_ACCESSOR_FOREACH(accessor, i, child)
{
//XXX: check if there is memleak
eo_do(child, status = emodel_property_get("filename", &value_prop));
str = eina_value_to_string(&value_prop);
printf("(full) %d emodel_children_get filename %s\n", i, str);
eina_value_flush(&value_prop);
free(str);
}
i = 0;
eina_accessor_free(accessor);
eo_do(obj, status = emodel_children_slice_get(5 ,5 ,(Eina_Accessor **)&accessor));
EINA_ACCESSOR_FOREACH(accessor, i, child)
{
//XXX: check if there is memleak
eo_do(child, status = emodel_property_get("filename", &value_prop));
str = eina_value_to_string(&value_prop);
printf("(slice) %d emodel_chidlren_property_set filename %s\n", i, str);
eina_value_flush(&value_prop);
free(str);
eo_unref(child);
}
eina_accessor_free(accessor);
ecore_main_loop_quit();
}
@ -141,21 +115,22 @@ static Eina_Bool
_properties_change_cb(void *data EINA_UNUSED, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, void *event_info)
{
const Emodel_Property_Event *evt = (Emodel_Property_Event *)event_info;
Eina_Value v;
const char *prop;
Eina_Array_Iterator it;
unsigned int i;
if (eina_value_type_get(evt->changed_properties) != EINA_VALUE_TYPE_STRUCT)
return EINA_FALSE;
EINA_ARRAY_ITER_NEXT(evt->changed_properties, i, prop, it)
{
if (!strcmp(prop, "is_dir"))
reqs.changed_is_dir = 1;
else if (!strcmp(prop, "is_lnk"))
reqs.changed_is_lnk = 1;
else if (!strcmp(prop, "size"))
reqs.changed_size = 1;
else if (!strcmp(prop, "mtime"))
reqs.changed_mtime = 1;
}
if(eina_value_struct_value_get(evt->changed_properties, "is_dir", &v) == EINA_TRUE)
reqs.changed_is_dir = 1;
if(eina_value_struct_value_get(evt->changed_properties, "is_lnk", &v) == EINA_TRUE)
reqs.changed_is_lnk = 1;
if(eina_value_struct_value_get(evt->changed_properties, "size", &v) == EINA_TRUE)
reqs.changed_size = 1;
if(eina_value_struct_value_get(evt->changed_properties, "mtime", &v) == EINA_TRUE)
reqs.changed_mtime = 1;
eina_value_flush(&v);
reqs.properties = 1;
return EINA_TRUE;
}
@ -178,7 +153,7 @@ _children_count_cb(void *data EINA_UNUSED, Eo *obj EINA_UNUSED, const Eo_Event_D
START_TEST(emodel_test_test_file)
{
Eo *filemodel = NULL;
Eina_Value value_prop;
const Eina_Value *value_prop;
Emodel_Load_Status status;
#ifdef _RUN_LOCAL_TEST
Eina_Value nameset_value;
@ -205,17 +180,14 @@ START_TEST(emodel_test_test_file)
handler = ecore_event_handler_add(ECORE_EVENT_SIGNAL_EXIT, exit_func, NULL);
eina_value_setup(&value_prop, EINA_VALUE_TYPE_STRING);
eo_do(filemodel, status = emodel_property_get("filename", &value_prop));
str = eina_value_to_string(&value_prop);
str = eina_value_to_string(value_prop);
printf("emodel_test filename %s, load status %d\n", str, status);
eina_value_flush(&value_prop);
free(str);
i = 0;
eo_do(filemodel, emodel_properties_list_get(&properties_list));
eo_do(filemodel, emodel_properties_get(&properties_list));
EINA_ARRAY_ITER_NEXT(properties_list, i, str, iterator)
{
fprintf(stdout, "Returned property list %d: %s\n", i, str);
@ -239,11 +211,9 @@ START_TEST(emodel_test_test_file)
eina_value_setup(&nameset_value, EINA_VALUE_TYPE_STRING);
eina_value_setup(&value_prop, EINA_VALUE_TYPE_STRING);
eina_value_set(&nameset_value, "/tmp/emodel_test");
eo_do(filemodel, emodel_property_set("path", nameset_value));
eo_do(filemodel, emodel_property_set("path", &nameset_value));
eina_value_flush(&nameset_value);
//emodel_property_get("path", &value_prop);
eo_do(filemodel, status = emodel_property_get("path", &value_prop));
eina_value_flush(&value_prop);
#endif
sleep(1); /**< EIO is asynchrounous so I must give some time for deletions to execute */

View File

@ -18,24 +18,44 @@
Eina_Bool children_added = EINA_FALSE;
static Eina_Bool
_children_added_cb(void *data EINA_UNUSED, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, void *event_info)
_load_monitor_status_cb(void *data, Eo *obj, const Eo_Event_Description *desc EINA_UNUSED, void *event_info)
{
Emodel_Children_Event* evt = event_info;
Eo* child = evt->child;
Eina_Value value_prop;
const char* str;
Emodel_Load* st = event_info;
Eo* parent = data;
const Eina_Value* value_prop = NULL;
const char* str = NULL;
eo_do(child, emodel_property_get("filename", &value_prop));
str = eina_value_to_string(&value_prop);
if (!(st->status & EMODEL_LOAD_STATUS_LOADED_PROPERTIES))
return EINA_TRUE;
eo_do(obj, emodel_property_get("filename", &value_prop));
fail_if(!value_prop, "ERROR: Cannot get property!\n");
str = eina_value_to_string(value_prop);
fail_if(!str, "ERROR: Cannot convert value to string!\n");
fprintf(stderr, "new children filename %s\n", str);
if(strcmp(str, "test_file_monitor_add") == 0)
{
fprintf(stderr, "is child that we want\n");
eo_do(obj, eo_event_callback_del(EMODEL_EVENT_LOAD_STATUS, _load_monitor_status_cb, data));
children_added = EINA_TRUE;
eo_do(obj, emodel_child_del(child));
eo_do(parent, emodel_child_del(obj));
ecore_main_loop_quit();
}
eina_value_flush(&value_prop);
return EINA_FALSE;
}
static Eina_Bool
_children_added_cb(void *data EINA_UNUSED, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, void *event_info)
{
Emodel_Children_Event* evt = event_info;
if (evt == NULL)
return EINA_TRUE;
eo_do(evt->child, eo_event_callback_add(EMODEL_EVENT_LOAD_STATUS, _load_monitor_status_cb, obj));
eo_do(evt->child, emodel_load());
return EINA_TRUE;
}
@ -76,8 +96,8 @@ START_TEST(emodel_test_test_monitor_add)
filemodel = eo_add(EIO_MODEL_CLASS, NULL, eio_model_path_set(EMODEL_TEST_FILENAME_PATH));
fail_if(!filemodel, "ERROR: Cannot init model!\n");
eo_do(filemodel, eo_event_callback_add(EMODEL_EVENT_CHILDREN_COUNT_CHANGED, _children_count_cb, NULL));
eo_do(filemodel, eo_event_callback_add(EMODEL_EVENT_CHILD_ADDED, _children_added_cb, NULL));
eo_do(filemodel, eo_event_callback_add(EMODEL_EVENT_CHILDREN_COUNT_CHANGED, _children_count_cb, NULL));
eo_do(filemodel, emodel_load());