summaryrefslogtreecommitdiff
path: root/src/lib/efl
diff options
context:
space:
mode:
authorCedric Bail <cedric@osg.samsung.com>2017-10-25 15:13:32 -0700
committerCedric BAIL <cedric@osg.samsung.com>2018-04-30 14:21:11 -0700
commit8f00bf568112fdc913099ce5fc67fb4b2324f5d8 (patch)
tree8181803c29a1cf7e761bd100204b0f1cd9a4ac9f /src/lib/efl
parent04c63cb489b2dda2f738df2435ef183209d06ead (diff)
efl: make efl.model use of eina_value and eina_future instead of efl_future.
Diffstat (limited to 'src/lib/efl')
-rw-r--r--src/lib/efl/Efl_Model_Common.h52
-rw-r--r--src/lib/efl/interfaces/efl_model.eo94
-rw-r--r--src/lib/efl/interfaces/efl_model_common.c54
3 files changed, 95 insertions, 105 deletions
diff --git a/src/lib/efl/Efl_Model_Common.h b/src/lib/efl/Efl_Model_Common.h
index 5c565c64ab..b4b5690917 100644
--- a/src/lib/efl/Efl_Model_Common.h
+++ b/src/lib/efl/Efl_Model_Common.h
@@ -20,15 +20,11 @@ EAPI extern Eina_Error EFL_MODEL_ERROR_INVALID_OBJECT; /**< @since 1.19 */
20 */ 20 */
21struct _Efl_Model_Children_Event 21struct _Efl_Model_Children_Event
22{ 22{
23 Eo *child; /**< child, for child_add */
24 /** 23 /**
25 * index is a hint and is intended 24 * index is a hint and is intended
26 * to provide a way for applications 25 * to provide a way for applications
27 * to control/know children relative 26 * to control/know children relative
28 * positions through listings. 27 * positions through listings.
29 *
30 * NOTE: If listing is performed asynchronously
31 * exact order may not be guaranteed.
32 */ 28 */
33 unsigned int index; 29 unsigned int index;
34}; 30};
@@ -42,20 +38,6 @@ typedef struct _Efl_Model_Children_Event Efl_Model_Children_Event;
42 38
43EAPI int efl_model_init(void); 39EAPI int efl_model_init(void);
44 40
45/**
46 * @brief Slices a list
47 *
48 * If the @p start and @p count are 0, a new accessor of the entire list is returned
49 *
50 * @param list The list to get the slice
51 * @param start The nth element to start the slice
52 * @param count The number of elements
53 * @return The accessor to the sliced elements or @c NULL if error
54 *
55 * @since 1.17
56 */
57EAPI Eina_Accessor *efl_model_list_slice(Eina_List *list, unsigned start, unsigned count) EINA_ARG_NONNULL(1);
58
59 41
60/** 42/**
61 * @brief Notifies a property changed event with an @c EFL_MODEL_EVENT_PROPERTIES_CHANGED 43 * @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
65 * 47 *
66 * @since 1.17 48 * @since 1.17
67 */ 49 */
68EAPI void efl_model_property_changed_notify(Efl_Model *model, const char *property); 50EAPI void _efl_model_properties_changed_internal(const Efl_Model *model, ...);
51
52#define efl_model_properties_changed(Model, ...) _efl_model_properties_changed_internal(Model, ##__VA_ARGS__, NULL)
69 53
70/** 54/**
71 * @brief Notifies a property invalidated event with an @c EFL_MODEL_EVENT_PROPERTIES_CHANGED 55 * @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
107 */ 91 */
108EAPI void efl_model_value_struct_description_free(Eina_Value_Struct_Desc *desc); 92EAPI void efl_model_value_struct_description_free(Eina_Value_Struct_Desc *desc);
109 93
94
95static inline Eina_Value
96efl_model_list_value_get(Eina_List *childrens,
97 unsigned int start,
98 unsigned int count)
99{
100 Eina_Value v = EINA_VALUE_EMPTY;
101 Eina_List *l;
102 Eo *child;
103
104 eina_value_array_setup(&v, EINA_VALUE_TYPE_OBJECT, eina_list_count(childrens));
105
106 EINA_LIST_FOREACH(childrens, l, child)
107 {
108 if (start != 0)
109 {
110 start--;
111 continue;
112 }
113 if (count == 0)
114 continue;
115 count--;
116
117 eina_value_array_append(&v, child);
118 }
119
120 return v;
121}
122
123
110#endif 124#endif
diff --git a/src/lib/efl/interfaces/efl_model.eo b/src/lib/efl/interfaces/efl_model.eo
index 06477f9fdf..2fae595baa 100644
--- a/src/lib/efl/interfaces/efl_model.eo
+++ b/src/lib/efl/interfaces/efl_model.eo
@@ -22,50 +22,50 @@ interface Efl.Model ()
22 22
23 @since 1.14 23 @since 1.14
24 ]] 24 ]]
25 } 25 }
26 values { 26 values {
27 properties: const(array<string>); [[Array of current properties]] 27 properties: array<string>; [[Array of current properties]]
28 } 28 }
29 } 29 }
30 property_set { 30 @property property {
31 [[Set a property value of a given property name. 31 set {
32 32 [[Set a property value of a given property name.
33 The caller must ensure to call at least efl_model_prop_list 33
34 before being able to see/set properties. This function sets 34 The caller must ensure to call at least efl_model_prop_list
35 a new property value into given property name. Once the 35 before being able to see/set properties. This function sets
36 operation is completed the concrete implementation should 36 a new property value into given property name. Once the
37 raise EFL_MODEL_EVENT_PROPERTIES_CHANGED event in order to 37 operation is completed the concrete implementation should
38 notify listeners of the new value of the property. 38 raise EFL_MODEL_EVENT_PROPERTIES_CHANGED event in order to
39 39 notify listeners of the new value of the property.
40 If the model doesn't have the property then there are two 40
41 possibilities, either raise an error or create the new 41 If the model doesn't have the property then there are two
42 property in model 42 possibilities, either raise an error or create the new
43 43 property in model
44 See @.property_get, \@ref EFL_MODEL_EVENT_PROPERTIES_CHANGED 44
45 45 See @.property.get, \@ref EFL_MODEL_EVENT_PROPERTIES_CHANGED
46 @since 1.14 46
47 ]] 47 @since 1.14
48 params { 48 ]]
49 @in property: string; [[Property name]] 49 return: ptr(Eina.Future); [[Return an error in case the property could not be set, the value that was set otherwise.]]
50 @in value: const(any_value_ptr); [[New value]]
51 } 50 }
52 return: future<any_value>; [[Future returning the recorded value or error]] 51 get {
53 } 52 [[Retrieve the value of a given property name.
54 property_get {
55 [[Retrieve the value of a given property name.
56 53
57 At this point the caller is free to get values from properties. 54 At this point the caller is free to get values from properties.
58 The event EFL_MODEL_EVENT_PROPERTIES_CHANGED may be raised to 55 The event EFL_MODEL_EVENT_PROPERTIES_CHANGED may be raised to
59 notify listeners of the property/value. 56 notify listeners of the property/value.
60 57
61 See @.properties.get, \@ref EFL_MODEL_EVENT_PROPERTIES_CHANGED 58 See @.properties.get, \@ref EFL_MODEL_EVENT_PROPERTIES_CHANGED
62 59
63 @since 1.14 60 @since 1.14
64 ]] 61 ]]
65 params { 62 }
66 @in property: string; [[Property name]] 63 keys {
64 property: string; [[Property name]]
65 }
66 values {
67 value: any_value_ptr; [[Property value]]
67 } 68 }
68 return: future<any_value>; [[Future of the value that was got]]
69 } 69 }
70 children_slice_get { 70 children_slice_get {
71 [[Get children slice OR full range. 71 [[Get children slice OR full range.
@@ -89,7 +89,7 @@ interface Efl.Model ()
89 Optionally the user can call children_count_get to know the 89 Optionally the user can call children_count_get to know the
90 number of children so a valid range can be known in advance. 90 number of children so a valid range can be known in advance.
91 91
92 See @.children_count_get 92 See @.children_count.get
93 93
94 @since 1.14 94 @since 1.14
95 ]] 95 ]]
@@ -98,10 +98,11 @@ interface Efl.Model ()
98 @in count: uint; [[Range size. If count is 0, start is 98 @in count: uint; [[Range size. If count is 0, start is
99 ignored.]] 99 ignored.]]
100 } 100 }
101 return: future<accessor<Efl.Object> >; [[Future of the children]] 101 return: ptr(Eina.Future); [[Array of childrens]]
102 } 102 }
103 children_count_get { 103 @property children_count {
104 [[Get children count. 104 get {
105 [[Get children count.
105 106
106 When efl_model_load is completed efl_model_coildren_count_get 107 When efl_model_load is completed efl_model_coildren_count_get
107 can be used to get the number of children. children_count_get 108 can be used to get the number of children. children_count_get
@@ -112,8 +113,11 @@ interface Efl.Model ()
112 See also @.children_slice_get. 113 See also @.children_slice_get.
113 114
114 @since 1.14 115 @since 1.14
115 ]] 116 ]]
116 return: future<uint>; [[Future of the children count]] 117 }
118 values {
119 count: uint; [[Current known children count]]
120 }
117 } 121 }
118 child_add { 122 child_add {
119 [[Add a new child. 123 [[Add a new child.
@@ -147,8 +151,8 @@ interface Efl.Model ()
147 properties,changed: Efl.Model_Property_Event; [[Event dispatched when 151 properties,changed: Efl.Model_Property_Event; [[Event dispatched when
148 properties list is 152 properties list is
149 available.]] 153 available.]]
150 child,added: Efl.Object; [[Event dispatched when new child is added.]] 154 child,added; [[Event dispatched when new child is added.]]
151 child,removed: Efl.Object; [[Event dispatched when child is removed.]] 155 child,removed; [[Event dispatched when child is removed.]]
152 children,count,changed; [[Event dispatched when children count is finished.]] 156 children,count,changed; [[Event dispatched when children count is finished.]]
153 } 157 }
154} 158}
diff --git a/src/lib/efl/interfaces/efl_model_common.c b/src/lib/efl/interfaces/efl_model_common.c
index 6bf825819f..dabc388338 100644
--- a/src/lib/efl/interfaces/efl_model_common.c
+++ b/src/lib/efl/interfaces/efl_model_common.c
@@ -54,56 +54,28 @@ efl_model_init(void)
54 return EINA_TRUE; 54 return EINA_TRUE;
55} 55}
56 56
57EAPI Eina_Accessor* 57EAPI void
58efl_model_list_slice(Eina_List *list, unsigned start, unsigned count) 58_efl_model_properties_changed_internal(const Efl_Model *model, ...)
59{ 59{
60 if (!list) return NULL; 60 Efl_Model_Property_Event ev = { 0 };
61 Eina_Array *properties = eina_array_new(1);
62 const char *property;
63 va_list args;
61 64
62 if ((start == 0) && (count == 0)) /* this is full data */ 65 va_start(args, model);
63 {
64 /*
65 * children_accessor will be set to NULL by
66 * eina_list_accessor_new if the later fails.
67 */
68 return eina_list_accessor_new(list);
69 }
70 66
71 Eo *child; 67 while ((property = (const char*) va_arg(args, const char*)))
72 Eina_List *l, *ln, *lr = NULL;
73 ln = eina_list_nth_list(list, (start));
74 if (!ln)
75 { 68 {
76 return NULL; 69 eina_array_push(properties, property);
77 } 70 }
78 71
79 EINA_LIST_FOREACH(ln, l, child) 72 va_end(args);
80 {
81 efl_ref(child);
82 lr = eina_list_append(lr, child);
83 if (eina_list_count(lr) == count)
84 break;
85 }
86
87 if (!lr) return NULL;
88
89 // This may leak the children Eina_List.
90 return eina_list_accessor_new(lr);
91}
92 73
93EAPI void 74 ev.changed_properties = properties;
94efl_model_property_changed_notify(Efl_Model *model, const char *property)
95{
96 Eina_Array *changed_properties = eina_array_new(1);
97 EINA_SAFETY_ON_NULL_RETURN(changed_properties);
98 75
99 Eina_Bool ret = eina_array_push(changed_properties, property); 76 efl_event_callback_call((Efl_Model *) model, EFL_MODEL_EVENT_PROPERTIES_CHANGED, &ev);
100 EINA_SAFETY_ON_FALSE_GOTO(ret, on_error);
101 77
102 Efl_Model_Property_Event evt = {.changed_properties = changed_properties}; 78 eina_array_free(properties);
103 efl_event_callback_call(model, EFL_MODEL_EVENT_PROPERTIES_CHANGED, &evt);
104
105on_error:
106 eina_array_free(changed_properties);
107} 79}
108 80
109EAPI void 81EAPI void