Enlightenment CVS committal

Author  : barbieri
Project : e17
Module  : libs/etk

Dir     : e17/libs/etk/src/lib


Modified Files:
        etk_signal.c etk_signal.h etk_type.c etk_type.h etk_types.h 


Log Message:
Refinements to new ETK signal system.

 * Etk_Callback and Etk_Callback_Swapped now returns Etk_Bool, to make it
   clear.
 * Etk_Signal_Description->name is marked as const: we don't mess it.
 * Add more comments to etk_signal_connect_full_by_code().
 * Remove now useless etk_type_signal_add(), etk_type_signal_remove().
 * Rework etk_type_signal_get_by_name() to use the signal array.
 * etk_signal_lookup() and etk_signal_lookup_code() are now internal (static).
 * Check for type->hierarchy before free()ing it.
 * Use memcpy() to copy parent's hierarchy.


===================================================================
RCS file: /cvs/e/e17/libs/etk/src/lib/etk_signal.c,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -3 -r1.35 -r1.36
--- etk_signal.c        28 Sep 2007 20:11:29 -0000      1.35
+++ etk_signal.c        29 Sep 2007 22:42:03 -0000      1.36
@@ -56,7 +56,6 @@
    new_signal->code = type->signals_count;
    new_signal->handler_offset = handler_offset;
    new_signal->marshaller = marshaller;
-   etk_type_signal_add(type, new_signal);
 
    type->signals_count++;
 
@@ -135,28 +134,20 @@
 }
 
 /**
- * @brief Gets the the signal corresponding to the name and the object type
- *
- * @param signal_name the name of the signal to return
- * @param type the object type of the signal to return
- *
- * @return Returns the signal called @a signal_name, for the object type
- *         @a type, or NULL on failure
+ * @brief Gets the signal corresponding to the name and the object type.
+ * @internal
+ * assumes @a signal_name and @a type to be valid.
  */
-Etk_Signal *etk_signal_lookup(const char *signal_name, Etk_Type *type)
+static Etk_Signal *etk_signal_lookup(const char *signal_name, Etk_Type *type)
 {
-   Etk_Type *t;
-   Etk_Signal *signal;
+   unsigned i;
 
-   if (!signal_name)
+   if (!type->signals)
       return NULL;
 
-   for (t = type; t; t = etk_type_parent_type_get(t))
-   {
-      signal = etk_type_signal_get_by_name(t, signal_name);
-      if (signal != NULL)
-         return signal;
-   }
+   for (i = 0; i < type->signals_count; i++)
+      if (strcmp(type->signals[i]->name, signal_name) == 0)
+         return type->signals[i];
 
    return NULL;
 }
@@ -164,21 +155,18 @@
 
 /**
  * @brief Gets the signal code corresponding to the name and the object type.
+ * @internal
+ * assumes @a signal_name and @a type to be valid.
  */
-int etk_signal_lookup_code(const char *signal_name, Etk_Type *type)
+static int etk_signal_lookup_code(const char *signal_name, Etk_Type *type)
 {
-   Etk_Type *t;
    Etk_Signal *signal;
 
-   if (!signal_name)
-      return -1;
-
-   for (t = type; t; t = etk_type_parent_type_get(t))
-   {
-      if ((signal = etk_type_signal_get_by_name(t, signal_name)))
-         return signal->code;
-   }
-   return -1;
+   signal = etk_signal_lookup(signal_name, type);
+   if (signal)
+     return signal->code;
+   else
+     return -1;
 }
 
 
@@ -200,7 +188,10 @@
  *
  * @param signal_code the signal code to connect to the callback
  * @param object the object to connect to the callback
- * @param callback the callback to call when the signal is emitted
+ * @param callback the callback to call when the signal is emitted. This
+ *        callback should return Etk_Bool with ETK_TRUE to continue
+ *        and ETK_FALSE to stop signal propagation to next callbacks
+ *        during the current emission.
  * @param data the data to pass to the callback
  * @param swapped if @a swapped == ETK_TRUE, the callback will be called
  *        with @a data as the only argument. It can be useful to set it to
===================================================================
RCS file: /cvs/e/e17/libs/etk/src/lib/etk_signal.h,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -3 -r1.22 -r1.23
--- etk_signal.h        29 Sep 2007 20:59:15 -0000      1.22
+++ etk_signal.h        29 Sep 2007 22:42:03 -0000      1.23
@@ -36,10 +36,10 @@
 
 typedef struct Etk_Signal_Description
 {
-   int *signal_code_store;
-   char *name;
-   long handler_offset;
-   Etk_Marshaller marshaller;
+  int *signal_code_store; /**< where to store signal code. */
+  const char *name; /**< signal name */
+  long handler_offset; /**<  */
+  Etk_Marshaller marshaller;
 } Etk_Signal_Description;
 
 #define ETK_SIGNAL_DESCRIPTION_SENTINEL {NULL, NULL, 0, NULL}
@@ -73,8 +73,6 @@
                               const Etk_Signal_Description *desc);
 void        etk_signal_delete(Etk_Signal *signal);
 
-Etk_Signal    *etk_signal_lookup(const char *signal_name, Etk_Type *type);
-int            etk_signal_lookup_code(const char *signal_name, Etk_Type *type);
 const char    *etk_signal_name_get(Etk_Signal *signal);
 Etk_Marshaller etk_signal_marshaller_get(Etk_Signal *signal);
 
===================================================================
RCS file: /cvs/e/e17/libs/etk/src/lib/etk_type.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -3 -r1.14 -r1.15
--- etk_type.c  29 Sep 2007 20:59:15 -0000      1.14
+++ etk_type.c  29 Sep 2007 22:42:03 -0000      1.15
@@ -70,7 +70,6 @@
    new_type->destructor = destructor;
    new_type->property_set = NULL;
    new_type->property_get = NULL;
-   new_type->signals_hash = NULL;
    new_type->properties_hash = NULL;
    new_type->signals = NULL;
 
@@ -93,14 +92,12 @@
    }
    else
    {
-      int i;
-
       /* Build the type hierarchy */
       new_type->hierarchy_depth = parent_type->hierarchy_depth + 1;
       new_type->hierarchy = malloc(sizeof(Etk_Type *) * 
new_type->hierarchy_depth);
       new_type->hierarchy[0] = parent_type;
-      for (i = 1; i < new_type->hierarchy_depth; i++)
-         new_type->hierarchy[i] = parent_type->hierarchy[i - 1];
+      memcpy(new_type->hierarchy + 1, parent_type->hierarchy,
+            parent_type->hierarchy_depth * sizeof(Etk_Type *));
 
       new_type->signals_count = parent_type->signals_count;
 
@@ -295,34 +292,6 @@
 }
 
 /**
- * @brief Adds a signal associated to the type
- * @param type the type to add the signal to
- * @param signal the signal to add
- */
-void etk_type_signal_add(Etk_Type *type, Etk_Signal *signal)
-{
-   const char *signal_name;
-
-   if (!type || !signal || !(signal_name = etk_signal_name_get(signal)))
-      return;
-   type->signals_hash = evas_hash_add(type->signals_hash, signal_name, signal);
-}
-
-/**
- * @brief Removes the signal from the list of signals of the type
- * @param type the type that is associated to the signal to remove
- * @param signal the signal to remove
- */
-void etk_type_signal_remove(Etk_Type *type, Etk_Signal *signal)
-{
-   const char *signal_name;
-
-   if (!type || !signal || !(signal_name = etk_signal_name_get(signal)))
-      return;
-   type->signals_hash = evas_hash_del(type->signals_hash, signal_name, NULL);
-}
-
-/**
  * @brief Gets the signal corresponding to the type and the signal name
  * @param type the type that is associated to the signal to get
  * @param signal_name the name of the signal to get
@@ -330,9 +299,16 @@
  */
 Etk_Signal *etk_type_signal_get_by_name(Etk_Type *type, const char 
*signal_name)
 {
-   if (!type || !signal_name)
+   unsigned i;
+
+   if (!type || !type->signals || !signal_name)
       return NULL;
-   return evas_hash_find(type->signals_hash, signal_name);
+
+   for (i = 0; i < type->signals_count; i++)
+     if (strcmp(type->signals[i]->name, signal_name) == 0)
+       return type->signals[i];
+
+   return NULL;
 }
 
 Etk_Signal *etk_type_signal_get(Etk_Type *type, int signal_code)
@@ -416,7 +392,6 @@
    if (!type)
       return;
 
-   evas_hash_free(type->signals_hash);
    evas_hash_foreach(type->properties_hash, _etk_type_property_free_cb, NULL);
    evas_hash_free(type->properties_hash);
 
@@ -424,7 +399,8 @@
    if (type->signals)
       free(type->signals);
 
-   free(type->hierarchy);
+   if (type->hierarchy)
+      free(type->hierarchy);
    free(type->name);
    free(type);
 }
===================================================================
RCS file: /cvs/e/e17/libs/etk/src/lib/etk_type.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -3 -r1.9 -r1.10
--- etk_type.h  28 Sep 2007 19:47:52 -0000      1.9
+++ etk_type.h  29 Sep 2007 22:42:03 -0000      1.10
@@ -43,7 +43,6 @@
    unsigned int signals_count;
 
    Etk_Signal **signals;
-   Evas_Hash *signals_hash;
    Evas_Hash *properties_hash;
 };
 
@@ -63,8 +62,6 @@
 const char   *etk_type_name_get(Etk_Type *type);
 Etk_Type     *etk_type_get_from_name(const char *name);
 
-void          etk_type_signal_add(Etk_Type *type, Etk_Signal *signal);
-void          etk_type_signal_remove(Etk_Type *type, Etk_Signal *signal);
 Etk_Signal   *etk_type_signal_get(Etk_Type *type, int signal_code);
 Etk_Signal   *etk_type_signal_get_by_name(Etk_Type *type, const char 
*signal_name);
 
===================================================================
RCS file: /cvs/e/e17/libs/etk/src/lib/etk_types.h,v
retrieving revision 1.70
retrieving revision 1.71
diff -u -3 -r1.70 -r1.71
--- etk_types.h 19 Sep 2007 20:16:26 -0000      1.70
+++ etk_types.h 29 Sep 2007 22:42:03 -0000      1.71
@@ -29,8 +29,8 @@
 typedef void (*Etk_Accumulator)(void *return_value, const void 
*value_to_accum, void *data);
 typedef void (*Etk_Constructor)(Etk_Object *object);
 typedef void (*Etk_Destructor)(Etk_Object *object);
-typedef void (*Etk_Callback)();
-typedef void (*Etk_Callback_Swapped)(void *data);
+typedef Etk_Bool (*Etk_Callback)();
+typedef Etk_Bool (*Etk_Callback_Swapped)(void *data);
 typedef void (*Etk_Marshaller)(Etk_Callback callback, Etk_Object *object, void 
*data, void *return_value, va_list arguments);
 
 typedef struct Etk_Alignment Etk_Alignment;



-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
enlightenment-cvs mailing list
enlightenment-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to