Author: dmeyer
Date: Mon Apr  9 18:26:37 2007
New Revision: 9428

Modified:
   trunk/core/src/resources.py

Log:
some cleanup

Modified: trunk/core/src/resources.py
==============================================================================
--- trunk/core/src/resources.py (original)
+++ trunk/core/src/resources.py Mon Apr  9 18:26:37 2007
@@ -1,6 +1,6 @@
 # -*- coding: iso-8859-1 -*-
 # -----------------------------------------------------------------------------
-# resources.py - Ressource Management
+# resources.py - Resource Management
 # -----------------------------------------------------------------------------
 # $Id$
 #
@@ -32,14 +32,14 @@
 # kaa imports
 from kaa.notifier import InProgress, Callback, yield_execution
 
-_resources = {}
 
 class ResourceHandler(object):
     """
     The ResourceHandler inherit from it if you want to use resources that need
     a specific access rights.
     """
-    suspended_handler = []
+    __suspended = []
+    __resources = {}
 
     def get_resources(self, *resources):
         """
@@ -49,9 +49,9 @@
         """
         blocked = {}
         for r in resources:
-            if r in _resources:
-                if _resources[r].can_suspend():
-                    blocked[r] = _resources[r]
+            if r in ResourceHandler.__resources:
+                if ResourceHandler.__resources[r].can_suspend():
+                    blocked[r] = ResourceHandler.__resources[r]
                 else:
                     return False
         if blocked:
@@ -59,55 +59,48 @@
             return blocked
         # reserve all resources
         for r in resources:
-            _resources[r] = self
+            ResourceHandler.__resources[r] = self
         return {}
 
 
-    def free_resources(self, *resources):
+    def free_resources(self):
         """
-        Free all resources blocked by this instance. If no resources are
-        provided, free all resources.
+        Free all resources blocked by this instance.
         """
-        for res, app in _resources.items()[:]:
-            if app == self and (not resources or res in resources):
-                del _resources[res]
-
-
-    def _handler_suspended(self, t, blocked, callback):
-        """
-        Callback for handler that need some more time to release a resource.
-        """
-        for resource in blocked.keys():
-            if resource in _resources:
-                # not yet all resources are free yet
-                return
-
-        # all resource are free now call the handler
-        callback()
+        for res, app in ResourceHandler.__resources.items()[:]:
+            if app == self:
+                del ResourceHandler.__resources[res]
 
 
     @yield_execution()
     def suspend_all(self, blocked):
         """
-        Suspend all handler that block a resource if done call the callback
-        method.
+        Suspend all handler that block a resource. Can return an InProgress
+        object if this takes a while.
         """
-        for handler in blocked:
-            self.suspended_handler.append(blocked[handler])
-            answer = blocked[handler].suspend()
+        # create list of modules to suspend
+        modules = []
+        for m in blocked.values():
+            if not m in modules:
+                modules.append(m)
+        # suspend modules
+        for module in modules:
+            if not module in self.__suspended:
+                self.__suspended.append(module)
+            answer = module.suspend()
             if isinstance(answer, InProgress):
                 yield answer
 
 
-    def resume_all(self):   
+    def resume_all(self):
         """
         Resume all handler suspended by this handler. Clear list at the end.
         """
-        # resume suspended handlers
-        for handler in self.suspended_handler:
+        # resume suspended modules
+        for handler in self.__suspended:
             handler.resume()
-        # clear list with suspended handler since all resumed
-        self.suspended_handler = []
+        # clear list with suspended since all resumed
+        self.__suspended = []
 
 
     def can_suspend(self):

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog

Reply via email to