Author: dmeyer
Date: Fri Mar 30 19:34:31 2007
New Revision: 9421
Added:
trunk/ui/src/application/resources.py
Modified:
trunk/ui/src/application/__init__.py
trunk/ui/src/application/base.py
Log:
Move get_resources and free_resources to an extra file and import it
in __init__.py. This makes it possible for other parts like plugins
to reserve a resource (e.g. lirc, joystick)
Modified: trunk/ui/src/application/__init__.py
==============================================================================
--- trunk/ui/src/application/__init__.py (original)
+++ trunk/ui/src/application/__init__.py Fri Mar 30 19:34:31 2007
@@ -29,6 +29,7 @@
#
# -----------------------------------------------------------------------------
+from resources import get_resources, free_resources
from base import Application, STATUS_RUNNING, STATUS_STOPPING, \
STATUS_STOPPED, STATUS_IDLE, CAPABILITY_TOGGLE, CAPABILITY_PAUSE, \
CAPABILITY_FULLSCREEN
Modified: trunk/ui/src/application/base.py
==============================================================================
--- trunk/ui/src/application/base.py (original)
+++ trunk/ui/src/application/base.py Fri Mar 30 19:34:31 2007
@@ -42,6 +42,7 @@
# application imports
from handler import handler
+from resources import get_resources, free_resources
# get logging object
log = logging.getLogger()
@@ -59,9 +60,6 @@
"""
A basic application
"""
-
- _global_resources = {}
-
def __init__(self, name, eventmap, capabilities=[]):
"""
Init the Application object.
@@ -186,17 +184,7 @@
reserved, the whole operation fails. The function will return the
list of failed resources with the application having this resource.
"""
- blocked = {}
- for r in resources:
- if r in self._global_resources:
- blocked[r] = self._global_resources[r]
- if blocked:
- # failed to reserve
- return blocked
- # reserve all resources
- for r in resources:
- self._global_resources[r] = self
- return {}
+ return get_resources(self, *resources)
def free_resources(self, *resources):
@@ -204,9 +192,7 @@
Free all resources blocked by this application. If not resources are
provided, free all resources.
"""
- for res, app in self._global_resources.items()[:]:
- if app == self and (not resources or res in resources):
- del self._global_resources[res]
+ return free_resources(self, *resources)
def __repr__(self):
Added: trunk/ui/src/application/resources.py
==============================================================================
--- (empty file)
+++ trunk/ui/src/application/resources.py Fri Mar 30 19:34:31 2007
@@ -0,0 +1,60 @@
+# -*- coding: iso-8859-1 -*-
+# -----------------------------------------------------------------------------
+# resources.py - Ressource Management
+# -----------------------------------------------------------------------------
+# $Id$
+#
+# -----------------------------------------------------------------------------
+# Freevo - A Home Theater PC framework
+# Copyright (C) 2007 Dirk Meyer, et al.
+#
+# First Edition: Dirk Meyer <[EMAIL PROTECTED]>
+# Maintainer: Dirk Meyer <[EMAIL PROTECTED]>
+#
+# Please see the file AUTHORS for a complete list of authors.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of MER-
+# CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+# Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# -----------------------------------------------------------------------------
+
+_resources = {}
+
+def get_resources(instance, *resources):
+ """
+ Reserve a list of resources. If one or more resources can not be
+ reserved, the whole operation fails. The function will return the
+ list of failed resources with the instance having this resource.
+ """
+ blocked = {}
+ for r in resources:
+ if r in _resources:
+ blocked[r] = _resources[r]
+ if blocked:
+ # failed to reserve
+ return blocked
+ # reserve all resources
+ for r in resources:
+ _resources[r] = instance
+ return {}
+
+
+def free_resources(instance, *resources):
+ """
+ Free all resources blocked by the instance. If not resources are
+ provided, free all resources.
+ """
+ for res, app in _resources.items()[:]:
+ if app == instance and (not resources or res in resources):
+ del _resources[res]
-------------------------------------------------------------------------
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