summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuilherme Lepsch <lepsch@expertisesolutions.com.br>2015-07-30 15:48:41 -0300
committerFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2015-08-29 16:42:27 -0300
commitcb2cea98cdad2a76098139b1cf40b2b61dcbe4f0 (patch)
tree9c1e7da78e7a3dffb4cf652098d24d1910eff1a5
parente0b12153c84446c0588e5f163a3e86f4cb75f620 (diff)
efl_model: Common Efl.Model implementation functions
-rw-r--r--src/Makefile_Efl.am1
-rw-r--r--src/lib/efl/Efl.h3
-rw-r--r--src/lib/efl/Efl_Model_Common.h81
-rw-r--r--src/lib/efl/interfaces/efl_model_common.c166
4 files changed, 238 insertions, 13 deletions
diff --git a/src/Makefile_Efl.am b/src/Makefile_Efl.am
index b64223ee7d..0f237f61b1 100644
--- a/src/Makefile_Efl.am
+++ b/src/Makefile_Efl.am
@@ -40,6 +40,7 @@ lib_LTLIBRARIES += lib/efl/libefl.la
40 40
41lib_efl_libefl_la_SOURCES = \ 41lib_efl_libefl_la_SOURCES = \
42lib/efl/interfaces/efl_interfaces_main.c \ 42lib/efl/interfaces/efl_interfaces_main.c \
43lib/efl/interfaces/efl_model_common.c \
43lib/efl/interfaces/efl_gfx_shape.c 44lib/efl/interfaces/efl_gfx_shape.c
44 45
45lib_efl_libefl_la_CPPFLAGS = -I$(top_builddir)/src/lib/efl -I$(top_srcdir)/src/lib/efl @EFL_CFLAGS@ -DEFL_GFX_FILTER_BETA 46lib_efl_libefl_la_CPPFLAGS = -I$(top_builddir)/src/lib/efl -I$(top_srcdir)/src/lib/efl @EFL_CFLAGS@ -DEFL_GFX_FILTER_BETA
diff --git a/src/lib/efl/Efl.h b/src/lib/efl/Efl.h
index 7a2ea8fa70..6b1a54626c 100644
--- a/src/lib/efl/Efl.h
+++ b/src/lib/efl/Efl.h
@@ -139,7 +139,7 @@ typedef enum _Efl_Gfx_Fill_Spread
139#ifdef EFL_BETA_API_SUPPORT 139#ifdef EFL_BETA_API_SUPPORT
140 140
141#include <Efl_Model_Common.h> 141#include <Efl_Model_Common.h>
142 142
143/* Interfaces */ 143/* Interfaces */
144#include "interfaces/efl_control.eo.h" 144#include "interfaces/efl_control.eo.h"
145#include "interfaces/efl_file.eo.h" 145#include "interfaces/efl_file.eo.h"
@@ -147,7 +147,6 @@ typedef enum _Efl_Gfx_Fill_Spread
147#include "interfaces/efl_player.eo.h" 147#include "interfaces/efl_player.eo.h"
148#include "interfaces/efl_text.eo.h" 148#include "interfaces/efl_text.eo.h"
149#include "interfaces/efl_text_properties.eo.h" 149#include "interfaces/efl_text_properties.eo.h"
150#include "interfaces/efl_model_base.eo.h"
151 150
152EAPI extern const Eo_Event_Description _EFL_GFX_CHANGED; 151EAPI extern const Eo_Event_Description _EFL_GFX_CHANGED;
153EAPI extern const Eo_Event_Description _EFL_GFX_PATH_CHANGED; 152EAPI extern const Eo_Event_Description _EFL_GFX_PATH_CHANGED;
diff --git a/src/lib/efl/Efl_Model_Common.h b/src/lib/efl/Efl_Model_Common.h
index ce1ed3b66b..1ff4356114 100644
--- a/src/lib/efl/Efl_Model_Common.h
+++ b/src/lib/efl/Efl_Model_Common.h
@@ -1,10 +1,3 @@
1#ifndef _EFL_MODEL_COMMON_H
2#define _EFL_MODEL_COMMON_H
3
4#ifdef __cplusplus
5extern "C" {
6#endif
7
8/** 1/**
9 * @struct _Efl_Model_Children_Event 2 * @struct _Efl_Model_Children_Event
10 * Every time a child id added the event 3 * Every time a child id added the event
@@ -31,8 +24,74 @@ struct _Efl_Model_Children_Event
31 */ 24 */
32typedef struct _Efl_Model_Children_Event Efl_Model_Children_Event; 25typedef struct _Efl_Model_Children_Event Efl_Model_Children_Event;
33 26
27#include "interfaces/efl_model_base.eo.h"
28
29 /**
30 * @brief Sets the new load status signaling an event if changed
31 *
32 * @param model The model to call the event @c EFL_MODEL_EVENT_LOAD_STATUS
33 * @param load The load status to be changed
34 * @param status The new status
35 */
36EAPI void efl_model_load_set(Efl_Model_Base *model, Efl_Model_Load *load, Efl_Model_Load_Status status) EINA_ARG_NONNULL(1, 2);
37
38/**
39 * @brief Slices a list
40 *
41 * If the @p start and @p count are 0, a new accessor of the entire list is returned
42 *
43 * @param list The list to get the slice
44 * @param start The nth element to start the slice
45 * @param count The number of elements
46 * @return The accessor to the sliced elements or @c NULL if error
47 */
48EAPI Eina_Accessor *efl_model_list_slice(Eina_List *list, unsigned start, unsigned count) EINA_ARG_NONNULL(1);
49
50/**
51 * @brief Notifies an error with an @c EFL_MODEL_EVENT_LOAD_STATUS
52 *
53 * @param model The model to be notified
54 */
55EAPI void efl_model_error_notify(Efl_Model_Base *model) EINA_ARG_NONNULL(1);
56
57/**
58 * @brief Notifies a property changed event with an @c EFL_MODEL_EVENT_PROPERTIES_CHANGED
59 *
60 * @param model The model to be notified
61 * @param property The changed property
62 */
63EAPI void efl_model_property_changed_notify(Efl_Model_Base *model, const char *property);
34 64
35#ifdef __cplusplus 65/**
36} 66 * @brief Notifies a property invalidated event with an @c EFL_MODEL_EVENT_PROPERTIES_CHANGED
37#endif 67 *
38#endif 68 * @param model The model to be notified
69 * @param property The invalidated property
70 */
71EAPI void efl_model_property_invalidated_notify(Efl_Model_Base *model, const char *property);
72
73/**
74 * @brief Callback to setup a member of @c Eina_Value_Struct
75 *
76 * @param data The user data
77 * @param index The member index
78 * @param member The member to fill its name and type. Must use @c Eina_Stringshare for name.
79 */
80typedef void (*Efl_Model_Value_Struct_Member_Setup_Cb)(void *data, int index, Eina_Value_Struct_Member *member);
81
82/**
83 * @brief Creates a new struct description
84 *
85 * @param member_count The number of struct members
86 * @param setup_cb The callback to setup struct members
87 * @param data The user data
88 * @return Returns the struct description
89 */
90EAPI Eina_Value_Struct_Desc *efl_model_value_struct_desc_new(unsigned int member_count, Efl_Model_Value_Struct_Member_Setup_Cb setup_cb, void *data) EINA_ARG_NONNULL(2);
91
92/**
93 * @brief Frees the memory allocated to the struct description.
94 *
95 * @param desc The struct description. If @c NULL, the function returns immediately.
96 */
97EAPI void efl_model_value_struct_desc_free(Eina_Value_Struct_Desc *desc);
diff --git a/src/lib/efl/interfaces/efl_model_common.c b/src/lib/efl/interfaces/efl_model_common.c
new file mode 100644
index 0000000000..589f50aa1d
--- /dev/null
+++ b/src/lib/efl/interfaces/efl_model_common.c
@@ -0,0 +1,166 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#include "Efl.h"
6
7void
8efl_model_load_set(Efl_Model_Base *model, Efl_Model_Load *load, Efl_Model_Load_Status status)
9{
10 Efl_Model_Load new_load = {.status = status};
11
12 if ((load->status & (EFL_MODEL_LOAD_STATUS_LOADED | EFL_MODEL_LOAD_STATUS_LOADING)) &&
13 (new_load.status & (EFL_MODEL_LOAD_STATUS_LOADED | EFL_MODEL_LOAD_STATUS_LOADING)))
14 {
15 // Merge status
16 new_load.status = load->status | new_load.status;
17
18 // Removes incompatible statuses (LOADING vs LOADED)
19 switch (status)
20 {
21 case EFL_MODEL_LOAD_STATUS_LOADED_PROPERTIES:
22 new_load.status &= ~EFL_MODEL_LOAD_STATUS_LOADING_PROPERTIES;
23 break;
24 case EFL_MODEL_LOAD_STATUS_LOADING_PROPERTIES:
25 new_load.status &= ~EFL_MODEL_LOAD_STATUS_LOADED_PROPERTIES;
26 break;
27 case EFL_MODEL_LOAD_STATUS_LOADED_CHILDREN:
28 new_load.status &= ~EFL_MODEL_LOAD_STATUS_LOADING_CHILDREN;
29 break;
30 case EFL_MODEL_LOAD_STATUS_LOADING_CHILDREN:
31 new_load.status &= ~EFL_MODEL_LOAD_STATUS_LOADED_CHILDREN;
32 break;
33 case EFL_MODEL_LOAD_STATUS_LOADED:
34 new_load.status &= ~EFL_MODEL_LOAD_STATUS_LOADING;
35 break;
36 case EFL_MODEL_LOAD_STATUS_LOADING:
37 new_load.status &= ~EFL_MODEL_LOAD_STATUS_LOADED;
38 break;
39 default: break;
40 }
41 }
42
43 if (load->status != new_load.status)
44 {
45 load->status = new_load.status;
46 eo_do(model, eo_event_callback_call(EFL_MODEL_BASE_EVENT_LOAD_STATUS, load));
47 }
48}
49
50Eina_Accessor *
51efl_model_list_slice(Eina_List *list, unsigned start, unsigned count)
52{
53 fprintf(stderr, "efl_model_list_slice\n");
54 if ((start == 0) && (count == 0))
55 {
56 fprintf(stderr, "efl_model_list_slice start == 0 count == 0\n");
57 return eina_list_accessor_new(list);
58 }
59
60 Eina_List *nth_list = eina_list_nth_list(list, (start - 1));
61 if (!nth_list)
62 return NULL;
63
64 Eina_List *it, *result = NULL;
65 const void *data;
66 EINA_LIST_FOREACH(nth_list, it, data)
67 {
68 result = eina_list_append(result, data);
69 if (eina_list_count(result) == count)
70 break;
71 }
72
73 return eina_list_accessor_new(result);
74}
75
76void
77efl_model_error_notify(Efl_Model_Base *model)
78{
79 Efl_Model_Load load = {.status = EFL_MODEL_LOAD_STATUS_ERROR};
80 eo_do(model, eo_event_callback_call(EFL_MODEL_BASE_EVENT_LOAD_STATUS, &load));
81}
82
83EAPI void
84efl_model_property_changed_notify(Efl_Model_Base *model, const char *property)
85{
86 Eina_Array *changed_properties = eina_array_new(1);
87 EINA_SAFETY_ON_NULL_RETURN(changed_properties);
88
89 Eina_Bool ret = eina_array_push(changed_properties, property);
90 EINA_SAFETY_ON_FALSE_GOTO(ret, on_error);
91
92 Efl_Model_Property_Event evt = {.changed_properties = changed_properties};
93 eo_do(model, eo_event_callback_call(EFL_MODEL_BASE_EVENT_PROPERTIES_CHANGED, &evt));
94
95on_error:
96 eina_array_free(changed_properties);
97}
98
99EAPI void
100efl_model_property_invalidated_notify(Efl_Model_Base *model, const char *property)
101{
102 Eina_Array *invalidated_properties = eina_array_new(1);
103 EINA_SAFETY_ON_NULL_RETURN(invalidated_properties);
104
105 Eina_Bool ret = eina_array_push(invalidated_properties, property);
106 EINA_SAFETY_ON_FALSE_GOTO(ret, on_error);
107
108 Efl_Model_Property_Event evt = {.invalidated_properties = invalidated_properties};
109 eo_do(model, eo_event_callback_call(EFL_MODEL_BASE_EVENT_PROPERTIES_CHANGED, &evt));
110
111on_error:
112 eina_array_free(invalidated_properties);
113}
114
115typedef struct _Efl_Model_Value_Struct_Desc
116{
117 Eina_Value_Struct_Desc base;
118 void *data;
119 Eina_Value_Struct_Member members[];
120} Efl_Model_Value_Struct_Desc;
121
122Eina_Value_Struct_Desc *
123efl_model_value_struct_desc_new(unsigned int member_count, Efl_Model_Value_Struct_Member_Setup_Cb setup_cb, void *data)
124{
125 EINA_SAFETY_ON_FALSE_RETURN_VAL(member_count > 0, NULL);
126 EINA_SAFETY_ON_NULL_RETURN_VAL(setup_cb, NULL);
127 EINA_SAFETY_ON_NULL_RETURN_VAL(data, NULL);
128
129 Efl_Model_Value_Struct_Desc *desc = malloc(sizeof(Efl_Model_Value_Struct_Desc) + member_count * sizeof(Eina_Value_Struct_Member));
130 EINA_SAFETY_ON_NULL_RETURN_VAL(desc, NULL);
131
132 desc->base.version = EINA_VALUE_STRUCT_DESC_VERSION;
133 desc->base.ops = EINA_VALUE_STRUCT_OPERATIONS_STRINGSHARE;
134 desc->base.members = desc->members;
135 desc->base.member_count = member_count;
136 desc->base.size = 0;
137 desc->data = data;
138
139 unsigned int offset = 0;
140 for (size_t i = 0; i < member_count; ++i)
141 {
142 Eina_Value_Struct_Member *m = (Eina_Value_Struct_Member *)desc->members + i;
143
144 m->offset = offset;
145 setup_cb(data, i, m);
146
147 unsigned int size = m->type->value_size;
148 if (size % sizeof(void *) != 0)
149 size += size - (size % sizeof(void *));
150
151 offset += size;
152 }
153
154 desc->base.size = offset;
155 return &desc->base;
156}
157
158void
159efl_model_value_struct_desc_free(Eina_Value_Struct_Desc *desc)
160{
161 if (!desc) return;
162
163 for (size_t i = 0; i < desc->member_count; i++)
164 eina_stringshare_del(desc->members[i].name);
165 free(desc);
166}