Title: [commits] (vajda) [11433] - implemented 'afterChange' attribute aspect to replace onValueChanged()

Diff

Modified: trunk/internal/chandlerdb/Makefile (11432 => 11433)

--- trunk/internal/chandlerdb/Makefile	2006-08-17 00:09:49 UTC (rev 11432)
+++ trunk/internal/chandlerdb/Makefile	2006-08-17 10:14:54 UTC (rev 11433)
@@ -1,5 +1,5 @@
 
-RELVER=0.6-$(BRANCH_REV_PREFIX)35
+RELVER=0.6-$(BRANCH_REV_PREFIX)36
 CHANDLERDB=$(INTERNAL)/chandlerdb
 DB_VER=4.4
 SRC=""

Modified: trunk/internal/chandlerdb/chandlerdb/item/c.c (11432 => 11433)

--- trunk/internal/chandlerdb/chandlerdb/item/c.c	2006-08-17 00:09:49 UTC (rev 11432)
+++ trunk/internal/chandlerdb/chandlerdb/item/c.c	2006-08-17 10:14:54 UTC (rev 11433)
@@ -34,6 +34,7 @@
 CView_invokeMonitors_fn CView_invokeMonitors;
 PyUUID_Check_fn PyUUID_Check;
 PyCFunction _countAccess;
+CAttribute_invokeAfterChange_fn CAttribute_invokeAfterChange;
 
 
 static PyObject *isitem(PyObject *self, PyObject *obj)
@@ -137,6 +138,7 @@
     LOAD_TYPE(m, CKind);
     LOAD_TYPE(m, CAttribute);
     LOAD_TYPE(m, CDescriptor);
+    LOAD_FN(m, CAttribute_invokeAfterChange);
     LOAD_CFUNC(m, _countAccess);
     Py_DECREF(m);
 

Modified: trunk/internal/chandlerdb/chandlerdb/item/c.h (11432 => 11433)

--- trunk/internal/chandlerdb/chandlerdb/item/c.h	2006-08-17 00:09:49 UTC (rev 11432)
+++ trunk/internal/chandlerdb/chandlerdb/item/c.h	2006-08-17 10:14:54 UTC (rev 11433)
@@ -18,6 +18,7 @@
 #include "item.h"
 #include "../util/uuid.h"
 #include "../persistence/view.h"
+#include "../schema/attribute.h"
 
 #define LOAD_TYPE(m, name) \
     name = (PyTypeObject *) PyObject_GetAttrString(m, #name);
@@ -48,8 +49,8 @@
 extern CView_invokeMonitors_fn CView_invokeMonitors;
 extern PyUUID_Check_fn PyUUID_Check;
 extern PyCFunction _countAccess;
+extern CAttribute_invokeAfterChange_fn CAttribute_invokeAfterChange;
 
-
 void _init_item(PyObject *m);
 void _init_values(PyObject *m);
 void _init_indexes(PyObject *m);

Modified: trunk/internal/chandlerdb/chandlerdb/item/item.c (11432 => 11433)

--- trunk/internal/chandlerdb/chandlerdb/item/item.c	2006-08-17 00:09:49 UTC (rev 11432)
+++ trunk/internal/chandlerdb/chandlerdb/item/item.c	2006-08-17 10:14:54 UTC (rev 11433)
@@ -21,7 +21,6 @@
 #include "../util/singleref.h"
 #include "../schema/kind.h"
 #include "../schema/descriptor.h"
-#include "../schema/attribute.h"
 
 static void t_item_dealloc(t_item *self);
 static int t_item_traverse(t_item *self, visitproc visit, void *arg);
@@ -87,7 +86,6 @@
 static PyObject *redirectTo_NAME;
 static PyObject *persisted_NAME;
 static PyObject *_redirectTo_NAME;
-static PyObject *onValueChanged_NAME;
 static PyObject *logger_NAME;
 static PyObject *_verifyAssignment_NAME;
 static PyObject *_setDirty_NAME;
@@ -782,22 +780,41 @@
     Py_RETURN_FALSE;
 }
 
-static PyObject *t_item__fireChanges(t_item *self, PyObject *args)
+static PyObject *_t_item__fireChanges(t_item *self,
+                                      PyObject *op, PyObject *name)
 {
-    PyObject *op, *name;
+    if (self->kind != Py_None)
+    {
+        PyObject *attribute =
+            PyObject_CallMethodObjArgs(self->kind, getAttribute_NAME,
+                                       name, Py_False, self, NULL);
 
-    if (!PyArg_ParseTuple(args, "OO", &op, &name))
-        return NULL;
+        if (attribute)
+        {
+            PyObject *c = PyObject_GetAttr(attribute, c_NAME);
 
-    if (PyObject_HasAttr((PyObject *) self->ob_type, onValueChanged_NAME))
-    {
-        PyObject *result = PyObject_CallMethodObjArgs((PyObject *) self,
-                                                      onValueChanged_NAME,
-                                                      name, NULL);
-        if (result == NULL)
+            Py_DECREF(attribute);
+            if (!c)
+                return NULL;
+
+            if (!PyObject_TypeCheck(c, CAttribute))
+            {
+                PyErr_SetObject(PyExc_TypeError, c);
+                Py_DECREF(c);
+                return NULL;
+            }
+
+            if (CAttribute_invokeAfterChange((t_attribute *) c,
+                                             (PyObject *) self, name) < 0)
+            {
+                Py_DECREF(c);
+                return NULL;
+            }
+
+            Py_DECREF(c);
+        }
+        else
             return NULL;
-
-        Py_DECREF(result);
     }
 
     {
@@ -825,6 +842,16 @@
     Py_RETURN_NONE;
 }
 
+static PyObject *t_item__fireChanges(t_item *self, PyObject *args)
+{
+    PyObject *op, *name;
+
+    if (!PyArg_ParseTuple(args, "OO", &op, &name))
+        return NULL;
+
+    return _t_item__fireChanges(self, op, name);
+}
+
 static PyObject *t_item__fillItem(t_item *self, PyObject *args)
 {
     PyObject *name, *parent, *kind, *uuid, *values, *references, *hooks;
@@ -993,10 +1020,7 @@
 
             if (!noMonitors)
             {
-                PyObject *args = PyTuple_Pack(2, set_NAME, attribute);
-
-                result = t_item__fireChanges(self, args);
-                Py_DECREF(args);
+                result = _t_item__fireChanges(self, set_NAME, attribute);
                 if (result == NULL)
                     return NULL;
                 Py_DECREF(result);
@@ -1495,7 +1519,6 @@
             redirectTo_NAME = PyString_FromString("redirectTo");
             persisted_NAME = PyString_FromString("persisted");
             _redirectTo_NAME = PyString_FromString("_redirectTo");
-            
             logger_NAME = PyString_FromString("logger");
             _verifyAssignment_NAME = PyString_FromString("_verifyAssignment");
             _setDirty_NAME = PyString_FromString("_setDirty");

Modified: trunk/internal/chandlerdb/chandlerdb/persistence/view.h (11432 => 11433)

--- trunk/internal/chandlerdb/chandlerdb/persistence/view.h	2006-08-17 00:09:49 UTC (rev 11432)
+++ trunk/internal/chandlerdb/chandlerdb/persistence/view.h	2006-08-17 10:14:54 UTC (rev 11433)
@@ -60,7 +60,3 @@
 
 
 typedef PyObject *(*CView_invokeMonitors_fn)(t_view *, PyObject *);
-typedef int (*CView_invokeWatchers_fn)(t_view *, PyObject *,
-                                       PyObject *, PyObject *,
-                                       PyObject *, PyObject *,
-                                       PyObject *);

Modified: trunk/internal/chandlerdb/chandlerdb/schema/attribute.c (11432 => 11433)

--- trunk/internal/chandlerdb/chandlerdb/schema/attribute.c	2006-08-17 00:09:49 UTC (rev 11432)
+++ trunk/internal/chandlerdb/chandlerdb/schema/attribute.c	2006-08-17 10:14:54 UTC (rev 11433)
@@ -29,6 +29,9 @@
 
 static PyObject *t_attribute_getAspect(t_attribute *self, PyObject *args);
 
+static PyObject *t_attribute_invokeAfterChange(t_attribute *self,
+                                               PyObject *args);
+
 static PyObject *t_attribute__getCardinality(t_attribute *self, void *data);
 static int t_attribute__setCardinality(t_attribute *self, t_values *values,
                                        void *data);
@@ -47,6 +50,9 @@
 static PyObject *t_attribute__getDefaultValue(t_attribute *self, void *data);
 static int t_attribute__setDefaultValue(t_attribute *self, t_values *values,
                                         void *data);
+static PyObject *t_attribute__getAfterChange(t_attribute *self, void *data);
+static int t_attribute__setAfterChange(t_attribute *self, t_values *values,
+                                       void *data);
 static PyObject *t_attribute__getRedirectTo(t_attribute *self, void *data);
 static int t_attribute__setRedirectTo(t_attribute *self, PyObject *value,
                                       void *data);
@@ -69,6 +75,7 @@
 static PyObject *redirectTo_NAME;
 static PyObject *inheritFrom_NAME;
 static PyObject *defaultValue_NAME;
+static PyObject *afterChange_NAME;
 static PyObject *type_NAME;
 
 static PyMemberDef t_attribute_members[] = {
@@ -81,6 +88,7 @@
 
 static PyMethodDef t_attribute_methods[] = {
     { "getAspect", (PyCFunction) t_attribute_getAspect, METH_VARARGS, "" },
+    { "invokeAfterChange", (PyCFunction) t_attribute_invokeAfterChange, METH_VARARGS, "" },
     { NULL, NULL, 0, NULL }
 };
 
@@ -109,6 +117,10 @@
       (getter) t_attribute__getDefaultValue,
       (setter) t_attribute__setDefaultValue,
       "defaultValue property", NULL },
+    { "afterChange",
+      (getter) t_attribute__getAfterChange,
+      (setter) t_attribute__setAfterChange,
+      "afterChange property", NULL },
     { "redirectTo",
       (getter) t_attribute__getRedirectTo,
       (setter) t_attribute__setRedirectTo,
@@ -186,6 +198,7 @@
     Py_VISIT(self->redirectTo);
     Py_VISIT(self->defaultValue);
     Py_VISIT(self->typeID);
+    Py_VISIT(self->afterChange);
 
     return 0;
 }
@@ -197,6 +210,7 @@
     Py_CLEAR(self->redirectTo);
     Py_CLEAR(self->defaultValue);
     Py_CLEAR(self->typeID);
+    Py_CLEAR(self->afterChange);
 
     return 0;
 }
@@ -212,7 +226,9 @@
         self->attrID = NULL;
         self->otherName = NULL;
         self->redirectTo = NULL;
+        self->defaultValue = NULL;
         self->typeID = NULL;
+        self->afterChange = NULL;
     }
 
     return (PyObject *) self;
@@ -232,6 +248,7 @@
         PyObject *inheritFrom = PyDict_GetItem(dict, inheritFrom_NAME);
         PyObject *defaultValue = PyDict_GetItem(dict, defaultValue_NAME);
         PyObject *redirectTo = PyDict_GetItem(dict, redirectTo_NAME);
+        PyObject *afterChange = PyDict_GetItem(dict, afterChange_NAME);
         int flags = NOINHERIT;
 
         if (!cardinality)
@@ -264,6 +281,13 @@
             self->defaultValue = defaultValue;
         }
 
+        if (afterChange != NULL)
+        {
+            flags |= AFTERCHANGE;
+            Py_INCREF(afterChange);
+            self->afterChange = afterChange;
+        }
+
         if (redirectTo != NULL && redirectTo != Py_None)
         {
             flags |= REDIRECT | PROCESS;
@@ -398,6 +422,15 @@
                 }
             }
 
+            else if (!PyObject_Compare(aspect, afterChange_NAME))
+            {
+                if (flags & AFTERCHANGE)
+                {
+                    Py_INCREF(self->afterChange);
+                    return self->afterChange;
+                }
+            }
+
             else if (!PyObject_Compare(aspect, indexed_NAME))
             {
                 if (flags & INDEXED)
@@ -417,7 +450,46 @@
     }
 }
 
+static int _t_attribute_invokeAfterChange(t_attribute *self,
+                                          PyObject *item, PyObject *name)
+{
+    if (self->flags & AFTERCHANGE)
+    {
+        int i = -1;
 
+        while (++i < PyList_GET_SIZE(self->afterChange)) {
+            PyObject *method = PyList_GET_ITEM(self->afterChange, i);
+            
+            if (PyObject_HasAttr((PyObject *) item->ob_type, method))
+            {
+                PyObject *result = PyObject_CallMethodObjArgs(item, method,
+                                                              name, NULL);
+
+                if (!result)
+                    return -1;
+                Py_DECREF(result);
+            }
+        }
+    }
+
+    return 0;
+}
+
+static PyObject *t_attribute_invokeAfterChange(t_attribute *self,
+                                               PyObject *args)
+{
+    PyObject *item, *name;
+
+    if (!PyArg_ParseTuple(args, "OO", &item, &name))
+        return NULL;
+
+    if (_t_attribute_invokeAfterChange(self, item, name) < 0)
+        return NULL;
+    
+    Py_RETURN_NONE;
+}
+
+
 /* cardinality */
 
 static PyObject *t_attribute__getCardinality(t_attribute *self, void *data)
@@ -680,6 +752,54 @@
     }
 }
 
+/* afterChange property */
+
+static PyObject *t_attribute__getAfterChange(t_attribute *self, void *data)
+{
+    if (!(self->flags & REDIRECT) && (self->flags & AFTERCHANGE))
+    {
+        Py_INCREF(self->afterChange);
+        return self->afterChange;
+    }
+            
+    PyErr_SetObject(PyExc_AttributeError, afterChange_NAME);
+    return NULL;
+}
+
+static int t_attribute__setAfterChange(t_attribute *self, t_values *values,
+                                       void *data)
+{
+    if (!PyObject_TypeCheck(values, CValues))
+    {
+        PyErr_SetObject(PyExc_TypeError, (PyObject *) values);
+        return -1;
+    }
+    else
+    {
+        PyObject *afterChange = PyDict_GetItem(values->dict, afterChange_NAME);
+
+        if (afterChange == NULL)
+        {
+            self->flags &= ~AFTERCHANGE;
+            Py_XDECREF(self->afterChange);
+            self->afterChange = NULL;
+        }
+        else if (PyList_Check(afterChange))
+        {
+            self->flags |= AFTERCHANGE;
+            Py_INCREF(afterChange);
+            self->afterChange = afterChange;
+        }
+        else
+        {
+            PyErr_SetObject(PyExc_TypeError, (PyObject *) afterChange);
+            return -1;
+        }
+
+        return 0;
+    }
+}
+
 /* redirectTo property */
 
 static PyObject *t_attribute__getRedirectTo(t_attribute *self, void *data)
@@ -883,7 +1003,7 @@
     {
         if (m)
         {
-            PyObject *dict;
+            PyObject *dict, *cobj;
 
             Py_INCREF(&AttributeType);
             PyModule_AddObject(m, "CAttribute", (PyObject *) &AttributeType);
@@ -926,6 +1046,10 @@
             inheritFrom_NAME = PyString_FromString("inheritFrom");
             defaultValue_NAME = PyString_FromString("defaultValue");
             type_NAME = PyString_FromString("type");
+            afterChange_NAME = PyString_FromString("afterChange");
+
+            cobj = PyCObject_FromVoidPtr(_t_attribute_invokeAfterChange, NULL);
+            PyModule_AddObject(m, "CAttribute_invokeAfterChange", cobj);
         }
     }
 }

Modified: trunk/internal/chandlerdb/chandlerdb/schema/attribute.h (11432 => 11433)

--- trunk/internal/chandlerdb/chandlerdb/schema/attribute.h	2006-08-17 00:09:49 UTC (rev 11432)
+++ trunk/internal/chandlerdb/chandlerdb/schema/attribute.h	2006-08-17 10:14:54 UTC (rev 11433)
@@ -16,22 +16,23 @@
 
 
 enum {
-    VALUE        = 0x0001,
-    REF          = 0x0002,
-    REDIRECT     = 0x0004,
-    REQUIRED     = 0x0008,
-    PROCESS_GET  = 0x0010,
-    PROCESS_SET  = 0x0020,
-    SINGLE       = 0x0040,
-    LIST         = 0x0080,
-    DICT         = 0x0100,
-    SET          = 0x0200,
-    ALIAS        = 0x0400,
-    KIND         = 0x0800,
-    NOINHERIT    = 0x1000,
-    TRANSIENT    = 0x2000,
-    INDEXED      = 0x4000,
-    DEFAULT      = 0x8000,
+    VALUE        = 0x00000001,
+    REF          = 0x00000002,
+    REDIRECT     = 0x00000004,
+    REQUIRED     = 0x00000008,
+    PROCESS_GET  = 0x00000010,
+    PROCESS_SET  = 0x00000020,
+    SINGLE       = 0x00000040,
+    LIST         = 0x00000080,
+    DICT         = 0x00000100,
+    SET          = 0x00000200,
+    ALIAS        = 0x00000400,
+    KIND         = 0x00000800,
+    NOINHERIT    = 0x00001000,
+    TRANSIENT    = 0x00002000,
+    INDEXED      = 0x00004000,
+    DEFAULT      = 0x00008000,
+    AFTERCHANGE  = 0x00010000,
 
     ATTRDICT     = VALUE | REF | REDIRECT,
     CARDINALITY  = SINGLE | LIST | DICT | SET,
@@ -41,13 +42,13 @@
 typedef struct {
     PyObject_HEAD
     PyObject *attrID;
-    int flags;
+    unsigned long flags;
     PyObject *otherName;
     PyObject *redirectTo;
     PyObject *defaultValue;
     PyObject *typeID;
+    PyObject *afterChange;
 } t_attribute;
 
-
-typedef PyObject *(*CAttribute_getAspect_fn)(t_attribute *,
-                                             PyObject *, PyObject *);
+typedef int (*CAttribute_invokeAfterChange_fn)(t_attribute *,
+                                               PyObject *, PyObject *);




_______________________________________________
Commits mailing list
[email protected]
http://lists.osafoundation.org/mailman/listinfo/commits

Reply via email to