WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] xsobj.py:

ChangeSet 1.1713.1.22, 2005/06/17 18:22:24+01:00, cl349@xxxxxxxxxxxxxxxxxxxx

        xsobj.py:
          Cleanup interface to DB.
          Updated watches/event code.
        Signed-off-by: Mike Wray <mike.wray@xxxxxx>
        Signed-off-by: Christian Limpach <Christian.Limpach@xxxxxxxxxxxx>



 xsobj.py |   77 +++++++++++++++++++++++++++++++++++++++------------------------
 1 files changed, 48 insertions(+), 29 deletions(-)


diff -Nru a/tools/python/xen/xend/xenstore/xsobj.py 
b/tools/python/xen/xend/xenstore/xsobj.py
--- a/tools/python/xen/xend/xenstore/xsobj.py   2005-06-17 21:03:41 -04:00
+++ b/tools/python/xen/xend/xenstore/xsobj.py   2005-06-17 21:03:41 -04:00
@@ -55,15 +55,15 @@
 
     getConverter = classmethod(getConverter)
 
-    def convertToDB(cls, val, ty=None):
-        return cls.getConverter(ty).toDB(val)
+    def exportTypeToDB(cls, db, path, val, ty=None):
+        return cls.getConverter(ty).exportToDB(db, path, val)
 
-    convertToDB = classmethod(convertToDB)
+    exportTypeToDB = classmethod(exportTypeToDB)
 
-    def convertFromDB(cls, data, ty=None):
-        return cls.getConverter(ty).fromDB(data.getData())
+    def importTypeFromDB(cls, db, path, ty=None):
+        return cls.getConverter(ty).importFromDB(db, path)
 
-    convertFromDB = classmethod(convertFromDB)
+    importTypeFromDB = classmethod(importTypeFromDB)
 
     # Must define in subclass.
     name = None
@@ -76,6 +76,26 @@
             raise ValueError("invalid converter name: '%s'" % self.name)
         self.converters[self.name] = self
 
+    def exportToDB(self, db, path, val):
+        if val is None:
+            return
+        try:
+            data = self.toDB(val)
+        except Exception, ex:
+            raise
+        setattr(db, path, data)
+
+    def importFromDB(self, db, path):
+        data = getAttr(db, path)
+        if data is None:
+            val = None
+        else:
+            try:
+                val = self.fromDB(data.getData())
+            except Exception, ex:
+                raise
+        return val
+        
     def toDB(self, val):
         raise NotImplementedError()
 
@@ -185,10 +205,12 @@
         self.attr = varpath[-1]
 
     def exportToDB(self, db, obj):
-        self.setDB(db, self.getObj(obj))
+        val = self.getObj(obj)
+        DBConverter.exportTypeToDB(db, self.path, val, ty=self.ty)
 
     def importFromDB(self, db, obj):
-        self.setObj(obj, self.getDB(db))
+        val = DBConverter.importTypeFromDB(db, self.path, ty=self.ty)
+        self.setObj(obj, val)
 
     def getObj(self, obj):
         o = obj
@@ -207,21 +229,6 @@
             return
         setAttr(o, self.attr, val)
 
-    def getDB(self, db):
-        data = getAttr(db, self.path)
-        if data is None:
-            return None
-        return DBConverter.convertFromDB(data, ty=self.ty)
-
-    def setDB(self, db, val):
-        # Don't set in db if val is None.
-        #print 'DBVar>setDB>', self.path, 'val=', val
-        if val is None:
-            return
-        data = DBConverter.convertToDB(val, ty=self.ty)
-        #print 'DBVar>setDB>', self.path, 'data=', data
-        setAttr(db, self.path, data)
-
 class DBMap(dict):
     """A persistent map. Extends dict with persistence.
     Set and get values using the usual map syntax:
@@ -319,6 +326,21 @@
             traceback.print_exc()
             print 'DBMap>releaseDomain>', ex
             pass # todo: don't ignore
+
+    def watch(self, fn, path=""):
+        return self.__db__.watch(fn, path=path)
+
+    def unwatch(self, sid):
+        return self.__db__.unwatch(sid)
+
+    def subscribe(self, event, fn):
+        return self.__db__.subscribe(event, fn)
+
+    def unsubscribe(self, sid):
+        return self.__db__.unsubscribe(sid)
+
+    def sendEvent(self, event, val):
+        return self.__db__.sendEvent(event, val)
         
     def transactionBegin(self):
         # Begin a transaction.
@@ -333,12 +355,6 @@
         # We have changed values, what do we do?
         pass
 
-    def watch(self, fn):
-        pass
-
-    def unwatch(self, watch):
-        pass
-        
     def checkName(self, k):
         if k == "":
             raise ValueError("invalid key, empty string")
@@ -460,6 +476,9 @@
             if x == "": continue
             n = n._addChild(x)
         return n
+
+    def getDB(self):
+        return self.__db__
 
     def setDB(self, db):
         if (db is not None) and not isinstance(db, XenNode):

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog

<Prev in Thread] Current Thread [Next in Thread>