[pkg-fso-commits] [SCM] FSO frameworkd Debian packaging branch, master, updated. milestone4-368-g700ab82
Michael 'Mickey' Lauer
mickey at vanille-media.de
Mon Feb 2 18:51:56 UTC 2009
The following commit has been merged in the master branch:
commit 52e5614de3cecb7757d34f7932858aa83fa38bdc
Author: Michael 'Mickey' Lauer <mickey at vanille-media.de>
Date: Thu Jan 15 14:34:58 2009 +0100
oeventsd: add QueuedDBusAction and use it for all dbus methods triggered by actions
diff --git a/framework/subsystems/oeventsd/action.py b/framework/subsystems/oeventsd/action.py
index f29ae61..366499b 100644
--- a/framework/subsystems/oeventsd/action.py
+++ b/framework/subsystems/oeventsd/action.py
@@ -14,13 +14,16 @@ Module: action
__version__ = "0.2.0"
MODULE_NAME = "oeventsd.action"
+from parser import AutoFunction
+
+from framework.patterns import decorator
+
import dbus
+import Queue
import logging
logger = logging.getLogger( MODULE_NAME )
-from parser import AutoFunction
-
#============================================================================#
class Action(AutoFunction):
#============================================================================#
@@ -32,35 +35,40 @@ class Action(AutoFunction):
should define it.
"""
- def __init__(self):
+ #
+ # public
+ #
+ def __init__( self ):
AutoFunction.__init__( self )
- def trigger(self, **kargs):
- """Perform the action"""
+
+ def trigger( self, **kwargs ):
pass
- def untrigger(self, **kargs):
- """Undo anything that the action had performed"""
+
+ def untrigger( self, **kwargs ):
pass
- def __repr__(self):
+
+ def __repr__( self ):
return "unamed action"
#============================================================================#
class ListAction(list, Action):
#============================================================================#
"""
- An action that will trigger a list of actions
+ An action that will trigger a sequence of actions
- This is basicaly a script.
+ This is basically a script.
"""
- def __init__(self, actions):
- list.__init__(self, actions)
+ def __init__( self, actions ):
+ list.__init__( self, actions )
Action.__init__( self )
- def trigger(self, **kargs):
- for action in self:
- action.trigger(**kargs)
- def untrigger(self, **kargs):
+
+ def trigger( self, **kwargs ):
for action in self:
- action.untrigger(**kargs)
+ action.trigger( **kwargs )
+ def untrigger( self, **kwargs ):
+ for action in self:
+ action.untrigger( **kwargs )
#============================================================================#
class DebugAction(Action):
@@ -84,6 +92,9 @@ class DBusAction(Action):
"""
A special action that will call a DBus method.
"""
+
+ #FIXME: Add Cache for dbus objects
+
def __init__(self, bus, service, obj, interface, method, *args):
Action.__init__( self )
self.bus = bus
@@ -103,7 +114,7 @@ class DBusAction(Action):
# Get the Dbus object
object = self.bus.get_object(self.service, self.obj)
iface = dbus.Interface(object, dbus_interface=self.interface)
- logger.info("call dbus signal %s %s(%s)", self.obj, self.method, self.args)
+ logger.info("call dbus method %s %s(%s)", self.obj, self.method, self.args)
# Get the method
method = getattr(iface, self.method)
# We make the call asynchronous, cause we don't want to block the main loop
@@ -112,10 +123,49 @@ class DBusAction(Action):
def on_reply(self, *args):
# We don't pass the reply to anything
- logger.info("signal %s responded : %s", self.method, args)
+ logger.info("method %s responded: %s", self.method, args)
def on_error(self, error):
- logger.error("signal %s emited an error %s", self.method, error)
+ logger.error("method %s emited error: %s", self.method, error)
def __repr__(self):
return "%s(%s)" % (self.method, self.args)
+
+#============================================================================#
+class QueuedDBusAction( DBusAction ):
+#============================================================================#
+ q = Queue.Queue()
+
+ def enqueue( self, method, args, kargs ):
+ logger.debug( "enqueing dbus call %s.%s", method, args )
+ relaunch = ( self.q.qsize() == 0 )
+ self.q.put( ( method, args, kargs ) )
+ if relaunch:
+ self.workDaQueue()
+
+ def workDaQueue( self ):
+ logger.debug( "working on queue w/ size %d", self.q.qsize() )
+ if self.q.qsize():
+ method, args, kargs = self.q.get()
+ # async dbus call now
+ method( *args, **kargs )
+
+ def trigger( self, **kargs ):
+ # Get the Dbus object
+ object = self.bus.get_object(self.service, self.obj)
+ iface = dbus.Interface(object, dbus_interface=self.interface)
+ logger.info("call dbus signal %s %s(%s)", self.obj, self.method, self.args)
+ # Get the method
+ method = getattr(iface, self.method)
+ kargs = {'reply_handler':self.on_reply, 'error_handler':self.on_error}
+ # Enqueue / Launch
+ self.enqueue( method, self.args, kargs )
+
+ def on_reply(self, *args):
+ # We don't pass the reply to anything
+ logger.info("signal %s responded : %s", self.method, args)
+ self.workDaQueue()
+
+ def on_error(self, error):
+ logger.error("signal %s emited an error %s", self.method, error)
+ self.workDaQueue()
diff --git a/framework/subsystems/oeventsd/filter.py b/framework/subsystems/oeventsd/filter.py
index 6e839b2..a69552c 100644
--- a/framework/subsystems/oeventsd/filter.py
+++ b/framework/subsystems/oeventsd/filter.py
@@ -31,6 +31,9 @@ class Filter( object ):
number of keywords argument (**kargs) representing the event generated dict
of values. The method returns True if the filter accept the event, False otherwise.
"""
+ def __init__( self, *args, **kwargs ):
+ pass
+
def filter( self, **kargs ):
# The default filter is always True
return True
@@ -69,6 +72,7 @@ class AttributeFilter( Filter ):
call and have the given value
"""
def __init__( self, **kargs ):
+ Filter.__init__( self )
self.kargs = kargs
def filter( self, **kargs ):
diff --git a/framework/subsystems/oeventsd/fso_actions.py b/framework/subsystems/oeventsd/fso_actions.py
index 1171286..459b2f8 100644
--- a/framework/subsystems/oeventsd/fso_actions.py
+++ b/framework/subsystems/oeventsd/fso_actions.py
@@ -18,7 +18,8 @@ MODULE_NAME = "oeventsd"
import framework.patterns.tasklet as tasklet
-from action import Action, DBusAction
+from action import Action
+from action import QueuedDBusAction as DBusAction
from framework.controller import Controller
from framework.config import installprefix
@@ -330,7 +331,7 @@ class ExternalDBusAction(DBusAction):
function_name = "ExternalDBusAction"
"""
- A dbus action on the freesmartphone audio device
+ A flexible dbus action
"""
def __init__(self, bus, service, obj, interface, method, *args):
"""Create the DBus action
diff --git a/framework/subsystems/oeventsd/rule.py b/framework/subsystems/oeventsd/rule.py
index 1d00e13..7ff8723 100644
--- a/framework/subsystems/oeventsd/rule.py
+++ b/framework/subsystems/oeventsd/rule.py
@@ -9,8 +9,11 @@ The freesmartphone Events Module - Python Implementation
GPLv2 or later
"""
+__version__ = "0.2.0"
+MODULE_NAME = "oeventsd.rule"
+
import logging
-logger = logging.getLogger('oeventsd')
+logger = logging.getLogger( MODULE_NAME )
from filter import Filter, AndFilter
from action import Action, ListAction
@@ -64,7 +67,6 @@ class Rule( Trigger, Action ):
# First we check that ALL the filters match the signal
if not self.__filter.filter( **kargs ):
return False
- # FIXME: _trigger ???
self._trigger( **kargs )
return True
@@ -98,10 +100,11 @@ class WhileRule( Rule, Filter ):
if not self._Rule__filter.filter( **kargs ):
self.untrigger( **kargs )
else:
- self.triggered = super( WhileRule, self ).trigger( **kargs )
+ self.triggered = Rule.trigger( self, **kargs )
def untrigger( self, **kargs ):
if not self.triggered:
+ logger.warning( "Untrigger for '%s' called, but not yet triggered. Not untriggering" )
return
self._untrigger( **kargs )
self.triggered = False
diff --git a/framework/subsystems/oeventsd/trigger.py b/framework/subsystems/oeventsd/trigger.py
index cd5abf5..6b61dc0 100644
--- a/framework/subsystems/oeventsd/trigger.py
+++ b/framework/subsystems/oeventsd/trigger.py
@@ -57,7 +57,7 @@ class Trigger(AutoFunction):
"""
logger.debug("trigger %s", self)
for action in self.__listeners:
- action._trigger(**kargs)
+ action.trigger(**kargs)
def _untrigger(self, **kargs):
"""
@@ -65,7 +65,7 @@ class Trigger(AutoFunction):
"""
logger.debug("untrigger %s", self)
for action in self.__listeners:
- action._untrigger(**kargs)
+ action.untrigger(**kargs)
def enable(self):
"""
--
FSO frameworkd Debian packaging
More information about the pkg-fso-commits
mailing list