efl: make efl.model use of eina_value and eina_future instead of efl_future.

This commit is contained in:
Cedric Bail 2017-10-25 15:13:32 -07:00 committed by Cedric BAIL
parent 04c63cb489
commit 8f00bf5681
3 changed files with 95 additions and 105 deletions

View File

@ -20,15 +20,11 @@ EAPI extern Eina_Error EFL_MODEL_ERROR_INVALID_OBJECT; /**< @since 1.19 */
*/
struct _Efl_Model_Children_Event
{
Eo *child; /**< child, for child_add */
/**
* index is a hint and is intended
* to provide a way for applications
* to control/know children relative
* positions through listings.
*
* NOTE: If listing is performed asynchronously
* exact order may not be guaranteed.
*/
unsigned int index;
};
@ -42,20 +38,6 @@ typedef struct _Efl_Model_Children_Event Efl_Model_Children_Event;
EAPI int efl_model_init(void);
/**
* @brief Slices a list
*
* If the @p start and @p count are 0, a new accessor of the entire list is returned
*
* @param list The list to get the slice
* @param start The nth element to start the slice
* @param count The number of elements
* @return The accessor to the sliced elements or @c NULL if error
*
* @since 1.17
*/
EAPI Eina_Accessor *efl_model_list_slice(Eina_List *list, unsigned start, unsigned count) EINA_ARG_NONNULL(1);
/**
* @brief Notifies a property changed event with an @c EFL_MODEL_EVENT_PROPERTIES_CHANGED
@ -65,7 +47,9 @@ EAPI Eina_Accessor *efl_model_list_slice(Eina_List *list, unsigned start, unsign
*
* @since 1.17
*/
EAPI void efl_model_property_changed_notify(Efl_Model *model, const char *property);
EAPI void _efl_model_properties_changed_internal(const Efl_Model *model, ...);
#define efl_model_properties_changed(Model, ...) _efl_model_properties_changed_internal(Model, ##__VA_ARGS__, NULL)
/**
* @brief Notifies a property invalidated event with an @c EFL_MODEL_EVENT_PROPERTIES_CHANGED
@ -107,4 +91,34 @@ EAPI Eina_Value_Struct_Desc *efl_model_value_struct_description_new(unsigned int
*/
EAPI void efl_model_value_struct_description_free(Eina_Value_Struct_Desc *desc);
static inline Eina_Value
efl_model_list_value_get(Eina_List *childrens,
unsigned int start,
unsigned int count)
{
Eina_Value v = EINA_VALUE_EMPTY;
Eina_List *l;
Eo *child;
eina_value_array_setup(&v, EINA_VALUE_TYPE_OBJECT, eina_list_count(childrens));
EINA_LIST_FOREACH(childrens, l, child)
{
if (start != 0)
{
start--;
continue;
}
if (count == 0)
continue;
count--;
eina_value_array_append(&v, child);
}
return v;
}
#endif

View File

@ -24,10 +24,11 @@ interface Efl.Model ()
]]
}
values {
properties: const(array<string>); [[Array of current properties]]
properties: array<string>; [[Array of current properties]]
}
}
property_set {
@property property {
set {
[[Set a property value of a given property name.
The caller must ensure to call at least efl_model_prop_list
@ -41,17 +42,13 @@ interface Efl.Model ()
possibilities, either raise an error or create the new
property in model
See @.property_get, \@ref EFL_MODEL_EVENT_PROPERTIES_CHANGED
See @.property.get, \@ref EFL_MODEL_EVENT_PROPERTIES_CHANGED
@since 1.14
]]
params {
@in property: string; [[Property name]]
@in value: const(any_value_ptr); [[New value]]
return: ptr(Eina.Future); [[Return an error in case the property could not be set, the value that was set otherwise.]]
}
return: future<any_value>; [[Future returning the recorded value or error]]
}
property_get {
get {
[[Retrieve the value of a given property name.
At this point the caller is free to get values from properties.
@ -62,10 +59,13 @@ interface Efl.Model ()
@since 1.14
]]
params {
@in property: string; [[Property name]]
}
return: future<any_value>; [[Future of the value that was got]]
keys {
property: string; [[Property name]]
}
values {
value: any_value_ptr; [[Property value]]
}
}
children_slice_get {
[[Get children slice OR full range.
@ -89,7 +89,7 @@ interface Efl.Model ()
Optionally the user can call children_count_get to know the
number of children so a valid range can be known in advance.
See @.children_count_get
See @.children_count.get
@since 1.14
]]
@ -98,9 +98,10 @@ interface Efl.Model ()
@in count: uint; [[Range size. If count is 0, start is
ignored.]]
}
return: future<accessor<Efl.Object> >; [[Future of the children]]
return: ptr(Eina.Future); [[Array of childrens]]
}
children_count_get {
@property children_count {
get {
[[Get children count.
When efl_model_load is completed efl_model_coildren_count_get
@ -113,7 +114,10 @@ interface Efl.Model ()
@since 1.14
]]
return: future<uint>; [[Future of the children count]]
}
values {
count: uint; [[Current known children count]]
}
}
child_add {
[[Add a new child.
@ -147,8 +151,8 @@ interface Efl.Model ()
properties,changed: Efl.Model_Property_Event; [[Event dispatched when
properties list is
available.]]
child,added: Efl.Object; [[Event dispatched when new child is added.]]
child,removed: Efl.Object; [[Event dispatched when child is removed.]]
child,added; [[Event dispatched when new child is added.]]
child,removed; [[Event dispatched when child is removed.]]
children,count,changed; [[Event dispatched when children count is finished.]]
}
}

View File

@ -54,56 +54,28 @@ efl_model_init(void)
return EINA_TRUE;
}
EAPI Eina_Accessor*
efl_model_list_slice(Eina_List *list, unsigned start, unsigned count)
{
if (!list) return NULL;
if ((start == 0) && (count == 0)) /* this is full data */
{
/*
* children_accessor will be set to NULL by
* eina_list_accessor_new if the later fails.
*/
return eina_list_accessor_new(list);
}
Eo *child;
Eina_List *l, *ln, *lr = NULL;
ln = eina_list_nth_list(list, (start));
if (!ln)
{
return NULL;
}
EINA_LIST_FOREACH(ln, l, child)
{
efl_ref(child);
lr = eina_list_append(lr, child);
if (eina_list_count(lr) == count)
break;
}
if (!lr) return NULL;
// This may leak the children Eina_List.
return eina_list_accessor_new(lr);
}
EAPI void
efl_model_property_changed_notify(Efl_Model *model, const char *property)
_efl_model_properties_changed_internal(const Efl_Model *model, ...)
{
Eina_Array *changed_properties = eina_array_new(1);
EINA_SAFETY_ON_NULL_RETURN(changed_properties);
Efl_Model_Property_Event ev = { 0 };
Eina_Array *properties = eina_array_new(1);
const char *property;
va_list args;
Eina_Bool ret = eina_array_push(changed_properties, property);
EINA_SAFETY_ON_FALSE_GOTO(ret, on_error);
va_start(args, model);
Efl_Model_Property_Event evt = {.changed_properties = changed_properties};
efl_event_callback_call(model, EFL_MODEL_EVENT_PROPERTIES_CHANGED, &evt);
while ((property = (const char*) va_arg(args, const char*)))
{
eina_array_push(properties, property);
}
on_error:
eina_array_free(changed_properties);
va_end(args);
ev.changed_properties = properties;
efl_event_callback_call((Efl_Model *) model, EFL_MODEL_EVENT_PROPERTIES_CHANGED, &ev);
eina_array_free(properties);
}
EAPI void