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)
downloadefl-cb2cea98cdad2a76098139b1cf40b2b61dcbe4f0.tar.gz
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
lib_efl_libefl_la_SOURCES = \
lib/efl/interfaces/efl_interfaces_main.c \
+lib/efl/interfaces/efl_model_common.c \
lib/efl/interfaces/efl_gfx_shape.c
lib_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
#ifdef EFL_BETA_API_SUPPORT
#include <Efl_Model_Common.h>
-
+
/* Interfaces */
#include "interfaces/efl_control.eo.h"
#include "interfaces/efl_file.eo.h"
@@ -147,7 +147,6 @@ typedef enum _Efl_Gfx_Fill_Spread
#include "interfaces/efl_player.eo.h"
#include "interfaces/efl_text.eo.h"
#include "interfaces/efl_text_properties.eo.h"
-#include "interfaces/efl_model_base.eo.h"
EAPI extern const Eo_Event_Description _EFL_GFX_CHANGED;
EAPI 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 @@
-#ifndef _EFL_MODEL_COMMON_H
-#define _EFL_MODEL_COMMON_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
/**
* @struct _Efl_Model_Children_Event
* Every time a child id added the event
@@ -31,8 +24,74 @@ struct _Efl_Model_Children_Event
*/
typedef struct _Efl_Model_Children_Event Efl_Model_Children_Event;
+#include "interfaces/efl_model_base.eo.h"
+
+ /**
+ * @brief Sets the new load status signaling an event if changed
+ *
+ * @param model The model to call the event @c EFL_MODEL_EVENT_LOAD_STATUS
+ * @param load The load status to be changed
+ * @param status The new status
+ */
+EAPI void efl_model_load_set(Efl_Model_Base *model, Efl_Model_Load *load, Efl_Model_Load_Status status) EINA_ARG_NONNULL(1, 2);
+
+/**
+ * @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
+ */
+EAPI Eina_Accessor *efl_model_list_slice(Eina_List *list, unsigned start, unsigned count) EINA_ARG_NONNULL(1);
+
+/**
+ * @brief Notifies an error with an @c EFL_MODEL_EVENT_LOAD_STATUS
+ *
+ * @param model The model to be notified
+ */
+EAPI void efl_model_error_notify(Efl_Model_Base *model) EINA_ARG_NONNULL(1);
+
+/**
+ * @brief Notifies a property changed event with an @c EFL_MODEL_EVENT_PROPERTIES_CHANGED
+ *
+ * @param model The model to be notified
+ * @param property The changed property
+ */
+EAPI void efl_model_property_changed_notify(Efl_Model_Base *model, const char *property);
-#ifdef __cplusplus
-}
-#endif
-#endif
+/**
+ * @brief Notifies a property invalidated event with an @c EFL_MODEL_EVENT_PROPERTIES_CHANGED
+ *
+ * @param model The model to be notified
+ * @param property The invalidated property
+ */
+EAPI void efl_model_property_invalidated_notify(Efl_Model_Base *model, const char *property);
+
+/**
+ * @brief Callback to setup a member of @c Eina_Value_Struct
+ *
+ * @param data The user data
+ * @param index The member index
+ * @param member The member to fill its name and type. Must use @c Eina_Stringshare for name.
+ */
+typedef void (*Efl_Model_Value_Struct_Member_Setup_Cb)(void *data, int index, Eina_Value_Struct_Member *member);
+
+/**
+ * @brief Creates a new struct description
+ *
+ * @param member_count The number of struct members
+ * @param setup_cb The callback to setup struct members
+ * @param data The user data
+ * @return Returns the struct description
+ */
+EAPI 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);
+
+/**
+ * @brief Frees the memory allocated to the struct description.
+ *
+ * @param desc The struct description. If @c NULL, the function returns immediately.
+ */
+EAPI 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 @@
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "Efl.h"
+
+void
+efl_model_load_set(Efl_Model_Base *model, Efl_Model_Load *load, Efl_Model_Load_Status status)
+{
+ Efl_Model_Load new_load = {.status = status};
+
+ if ((load->status & (EFL_MODEL_LOAD_STATUS_LOADED | EFL_MODEL_LOAD_STATUS_LOADING)) &&
+ (new_load.status & (EFL_MODEL_LOAD_STATUS_LOADED | EFL_MODEL_LOAD_STATUS_LOADING)))
+ {
+ // Merge status
+ new_load.status = load->status | new_load.status;
+
+ // Removes incompatible statuses (LOADING vs LOADED)
+ switch (status)
+ {
+ case EFL_MODEL_LOAD_STATUS_LOADED_PROPERTIES:
+ new_load.status &= ~EFL_MODEL_LOAD_STATUS_LOADING_PROPERTIES;
+ break;
+ case EFL_MODEL_LOAD_STATUS_LOADING_PROPERTIES:
+ new_load.status &= ~EFL_MODEL_LOAD_STATUS_LOADED_PROPERTIES;
+ break;
+ case EFL_MODEL_LOAD_STATUS_LOADED_CHILDREN:
+ new_load.status &= ~EFL_MODEL_LOAD_STATUS_LOADING_CHILDREN;
+ break;
+ case EFL_MODEL_LOAD_STATUS_LOADING_CHILDREN:
+ new_load.status &= ~EFL_MODEL_LOAD_STATUS_LOADED_CHILDREN;
+ break;
+ case EFL_MODEL_LOAD_STATUS_LOADED:
+ new_load.status &= ~EFL_MODEL_LOAD_STATUS_LOADING;
+ break;
+ case EFL_MODEL_LOAD_STATUS_LOADING:
+ new_load.status &= ~EFL_MODEL_LOAD_STATUS_LOADED;
+ break;
+ default: break;
+ }
+ }
+
+ if (load->status != new_load.status)
+ {
+ load->status = new_load.status;
+ eo_do(model, eo_event_callback_call(EFL_MODEL_BASE_EVENT_LOAD_STATUS, load));
+ }
+}
+
+Eina_Accessor *
+efl_model_list_slice(Eina_List *list, unsigned start, unsigned count)
+{
+ fprintf(stderr, "efl_model_list_slice\n");
+ if ((start == 0) && (count == 0))
+ {
+ fprintf(stderr, "efl_model_list_slice start == 0 count == 0\n");
+ return eina_list_accessor_new(list);
+ }
+
+ Eina_List *nth_list = eina_list_nth_list(list, (start - 1));
+ if (!nth_list)
+ return NULL;
+
+ Eina_List *it, *result = NULL;
+ const void *data;
+ EINA_LIST_FOREACH(nth_list, it, data)
+ {
+ result = eina_list_append(result, data);
+ if (eina_list_count(result) == count)
+ break;
+ }
+
+ return eina_list_accessor_new(result);
+}
+
+void
+efl_model_error_notify(Efl_Model_Base *model)
+{
+ Efl_Model_Load load = {.status = EFL_MODEL_LOAD_STATUS_ERROR};
+ eo_do(model, eo_event_callback_call(EFL_MODEL_BASE_EVENT_LOAD_STATUS, &load));
+}
+
+EAPI void
+efl_model_property_changed_notify(Efl_Model_Base *model, const char *property)
+{
+ Eina_Array *changed_properties = eina_array_new(1);
+ EINA_SAFETY_ON_NULL_RETURN(changed_properties);
+
+ Eina_Bool ret = eina_array_push(changed_properties, property);
+ EINA_SAFETY_ON_FALSE_GOTO(ret, on_error);
+
+ Efl_Model_Property_Event evt = {.changed_properties = changed_properties};
+ eo_do(model, eo_event_callback_call(EFL_MODEL_BASE_EVENT_PROPERTIES_CHANGED, &evt));
+
+on_error:
+ eina_array_free(changed_properties);
+}
+
+EAPI void
+efl_model_property_invalidated_notify(Efl_Model_Base *model, const char *property)
+{
+ Eina_Array *invalidated_properties = eina_array_new(1);
+ EINA_SAFETY_ON_NULL_RETURN(invalidated_properties);
+
+ Eina_Bool ret = eina_array_push(invalidated_properties, property);
+ EINA_SAFETY_ON_FALSE_GOTO(ret, on_error);
+
+ Efl_Model_Property_Event evt = {.invalidated_properties = invalidated_properties};
+ eo_do(model, eo_event_callback_call(EFL_MODEL_BASE_EVENT_PROPERTIES_CHANGED, &evt));
+
+on_error:
+ eina_array_free(invalidated_properties);
+}
+
+typedef struct _Efl_Model_Value_Struct_Desc
+{
+ Eina_Value_Struct_Desc base;
+ void *data;
+ Eina_Value_Struct_Member members[];
+} Efl_Model_Value_Struct_Desc;
+
+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_SAFETY_ON_FALSE_RETURN_VAL(member_count > 0, NULL);
+ EINA_SAFETY_ON_NULL_RETURN_VAL(setup_cb, NULL);
+ EINA_SAFETY_ON_NULL_RETURN_VAL(data, NULL);
+
+ Efl_Model_Value_Struct_Desc *desc = malloc(sizeof(Efl_Model_Value_Struct_Desc) + member_count * sizeof(Eina_Value_Struct_Member));
+ EINA_SAFETY_ON_NULL_RETURN_VAL(desc, NULL);
+
+ desc->base.version = EINA_VALUE_STRUCT_DESC_VERSION;
+ desc->base.ops = EINA_VALUE_STRUCT_OPERATIONS_STRINGSHARE;
+ desc->base.members = desc->members;
+ desc->base.member_count = member_count;
+ desc->base.size = 0;
+ desc->data = data;
+
+ unsigned int offset = 0;
+ for (size_t i = 0; i < member_count; ++i)
+ {
+ Eina_Value_Struct_Member *m = (Eina_Value_Struct_Member *)desc->members + i;
+
+ m->offset = offset;
+ setup_cb(data, i, m);
+
+ unsigned int size = m->type->value_size;
+ if (size % sizeof(void *) != 0)
+ size += size - (size % sizeof(void *));
+
+ offset += size;
+ }
+
+ desc->base.size = offset;
+ return &desc->base;
+}
+
+void
+efl_model_value_struct_desc_free(Eina_Value_Struct_Desc *desc)
+{
+ if (!desc) return;
+
+ for (size_t i = 0; i < desc->member_count; i++)
+ eina_stringshare_del(desc->members[i].name);
+ free(desc);
+}