Eobj: Added event callbacks for Object free/del.
authortasn <tasn>
Mon, 16 Apr 2012 14:22:11 +0000 (14:22 +0000)
committertasn <tasn@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Mon, 16 Apr 2012 14:22:11 +0000 (14:22 +0000)
git-svn-id: http://svn.enlightenment.org/svn/e/trunk/PROTO/eobj@70231 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

lib/Eobj.h
lib/eobj.c

index e96ed8b..71cf68f 100644 (file)
@@ -442,6 +442,30 @@ EAPI void *eobj_generic_data_get(const Eobj *obj, const char *key);
 EAPI void *eobj_generic_data_del(Eobj *obj, const char *key);
 
 /**
+ * @var _EOBJ_EV_FREE
+ * see #EOBJ_EV_FREE
+ */
+EAPI extern const Eobj_Event_Description _EOBJ_EV_FREE;
+
+/**
+ * @def EOBJ_EV_FREE
+ * Object is being freed.
+ */
+#define EOBJ_EV_FREE (&(_EOBJ_EV_FREE))
+
+/**
+ * @var _EOBJ_EV_DEL
+ * see #EOBJ_EV_DEL
+ */
+EAPI extern const Eobj_Event_Description _EOBJ_EV_DEL;
+
+/**
+ * @def EOBJ_EV_DEL
+ * Object is being deleted.
+ */
+#define EOBJ_EV_DEL (&(_EOBJ_EV_DEL))
+
+/**
  * @addtogroup Eobj_Composite_Objects Composite Objects.
  * @{
  */
index c5e4abe..f2ad301 100644 (file)
@@ -747,6 +747,18 @@ eobj_unref(Eobj *obj)
 {
    if (--(obj->refcount) == 0)
      {
+        /* We need that for the event callbacks that may ref/unref. */
+        obj->refcount++;
+
+        if (!obj->delete)
+          {
+             eobj_event_callback_call(obj, EOBJ_EV_DEL, NULL);
+             obj->delete = EINA_TRUE;
+          }
+        eobj_event_callback_call(obj, EOBJ_EV_FREE, NULL);
+
+        obj->refcount--;
+
         const Eobj_Class *klass = eobj_class_get(obj);
         _eobj_kls_itr_init(obj, EOBJ_NOOP);
         eobj_constructor_error_unset(obj);
@@ -802,7 +814,11 @@ eobj_ref_get(const Eobj *obj)
 EAPI void
 eobj_del(Eobj *obj)
 {
-   obj->delete = EINA_TRUE;
+   if (!obj->delete)
+     {
+        eobj_event_callback_call(obj, EOBJ_EV_DEL, NULL);
+        obj->delete = EINA_TRUE;
+     }
    eobj_unref(obj);
 }
 
@@ -1254,9 +1270,13 @@ static Eobj_Class *_my_class = NULL;
 
 /* FIXME: Set proper type descriptions. */
 EAPI const Eobj_Event_Description _EOBJ_EV_CALLBACK_ADD =
-   EOBJ_EVENT_DESCRIPTION("callback,add", "?", "Called when a callback was added.");
+   EOBJ_EVENT_DESCRIPTION("callback,add", "?", "A callback was added.");
 EAPI const Eobj_Event_Description _EOBJ_EV_CALLBACK_DEL =
-   EOBJ_EVENT_DESCRIPTION("callback,del", "?", "Called when a callback was deleted.");
+   EOBJ_EVENT_DESCRIPTION("callback,del", "?", "A callback was deleted.");
+EAPI const Eobj_Event_Description _EOBJ_EV_FREE =
+   EOBJ_EVENT_DESCRIPTION("free", "", "Obj is being freed.");
+EAPI const Eobj_Event_Description _EOBJ_EV_DEL =
+   EOBJ_EVENT_DESCRIPTION("del", "", "Obj is being deleted.");
 
 static void
 _constructor(Eobj *obj, void *class_data __UNUSED__)
@@ -1278,6 +1298,8 @@ eobj_base_class_get(void)
    static const Eobj_Event_Description *event_desc[] = {
         EOBJ_EV_CALLBACK_ADD,
         EOBJ_EV_CALLBACK_DEL,
+        EOBJ_EV_FREE,
+        EOBJ_EV_DEL,
         NULL
    };