[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:48 UTC 2009


The following commit has been merged in the master branch:
commit 3f68994d0804eadd2c7a325ddba52985b02b31e0
Author: Michael 'Mickey' Lauer <mickey at vanille-media.de>
Date:   Mon Dec 29 21:38:21 2008 +0100

    First step towards integrating Vala/C subsystems with frameworkd:
    Support external subsystems. If you add a section with an 'external' attribute, then
    the section will be treated as an external subsystem to launch with the path given as attribute:
    [mysubsystem]
    external=/foo/bar
    TODO: Add 'relaunch' attribute.
    NOTE: You can also "override" internal subsystems by giving the 'external' attribute.

diff --git a/ChangeLog b/ChangeLog
index 2d11d61..72e3e64 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2008-12-29	Michael lauer	<mickey at openmoko.org>
+
+	* Support external subsystems. If you add a section with an 'external' attribute, then
+	the section will be treated as an external subsystem to launch with the path given
+	as attribute:
+	[mysubsystem]
+	external=/foo/bar
+	TODO: Add 'relaunch' attribute.
+	NOTE: This is the first step towards integrating Vala/C subsystems to frameworkd.
+	NOTE2: You can also "override" internal subsystems by giving the 'external' attribute.
+
 2008-12-27	Michael Lauer	<mickey at openmoko.org>
 
 	* [ogsmd] Refactored Modem.dataOptions() into "pppd-configuration" attribute in modem data storage.
diff --git a/framework/controller.py b/framework/controller.py
index 7a13842..1e638a3 100644
--- a/framework/controller.py
+++ b/framework/controller.py
@@ -10,7 +10,7 @@ Package: framework
 Module: controller
 """
 
-__version__ = "0.9.4"
+__version__ = "0.9.6"
 
 from framework.config import DBUS_BUS_NAME_PREFIX, debug, config, loggingmap
 from framework.patterns import daemon
@@ -37,7 +37,7 @@ class Controller( daemon.Daemon ):
     """
     Loading and registering plugins.
     """
-    # We store all the DBUs object in a class attribute
+    # We store all DBus objects in a class attribute
     objects = {}
 
     @classmethod
@@ -78,14 +78,22 @@ class Controller( daemon.Daemon ):
         self._subsystems["frameworkd"] = subsystem.Framework( self.bus, path, self )
         Controller.objects.update( self._subsystems["frameworkd"].objects() )
 
-        # walk subsystems and find 'em
         systemstolaunch = self.options.values.subsystems.split( ',' )
 
+        # add internal subsystems
         subsystems = [ entry for entry in os.listdir( path )
                        if os.path.isdir( "%s/%s" % ( path, entry ) ) ]
 
+        # add external subsystems
+        for section in config.sections():
+            external = config.getValue( section, "external", "" )
+            if external and ( external not in subsystems ):
+                subsystems.append( section )
+
+        # walk and launch subsystems
         for s in subsystems:
             disable = config.getBool( s, "disable", False )
+            external = config.getValue( s, "external", "" )
             if disable:
                 logger.info( "skipping subsystem %s as requested via config file." % s )
                 continue
@@ -93,10 +101,11 @@ class Controller( daemon.Daemon ):
                 if s not in systemstolaunch:
                     logger.info( "skipping subsystem %s as requested via command line" % s )
                     continue
-                logger.info( "launching subsystem %s" % s )
-                self._subsystems[s] = subsystem.Subsystem( s, self.bus, path, self )
+            if external:
+                logger.info( "launching external subsystem %s" % s )
+                self._subsystems[s] = subsystem.External( s, external, self )
             else:
-                logger.info( "launching subsystem %s" % s )
+                logger.info( "launching internal subsystem %s" % s )
                 self._subsystems[s] = subsystem.Subsystem( s, self.bus, path, self )
             Controller.objects.update( self._subsystems[s].objects() )
 
diff --git a/framework/patterns/processguard.py b/framework/patterns/processguard.py
index 121aa22..a30dbde 100644
--- a/framework/patterns/processguard.py
+++ b/framework/patterns/processguard.py
@@ -10,14 +10,17 @@ Package: framework.patterns
 Module: processguard
 """
 
-__version__ = "0.0.0"
+__version__ = "0.1.0"
 
 import gobject
 
-import os
+import os, signal
 
 MAX_READ = 4096
 
+import logging
+logger = logging.getLogger( "mppl.processguard" )
+
 #============================================================================#
 class ProcessGuard( object ):
 #============================================================================#
@@ -28,6 +31,7 @@ class ProcessGuard( object ):
         """
         Init
         """
+        logger.debug( "Creating process guard for %s" % cmdline )
         self._childwatch = None
         self._stdoutwatch = None
         self._stderrwatch = None
@@ -87,6 +91,7 @@ class ProcessGuard( object ):
         if condition != gobject.IO_IN:
             return False
         data = os.read( source, MAX_READ )
+        logger.debug( "%s got data from child: %s" % ( self, repr(data) ) )
         if self._onOutput is not None:
             self._onOutput( data )
         return True # mainloop: call me again
@@ -98,6 +103,7 @@ class ProcessGuard( object ):
         if condition != gobject.IO_IN:
             return False
         data = os.read( source, MAX_READ )
+        logger.debug( "%s got error from child: %s" % ( self, repr(data) ) )
         if self._onError is not None:
             self._onError( data )
         return True # mainloop: call me again
@@ -117,9 +123,8 @@ class ProcessGuard( object ):
         """
         Cleanup
         """
-        if self.pid is not None:
-            os.kill( self.pid, 1 )
-            self.reset()
+        self.shutdown()
+        self.reset()
 
     #
     # API
@@ -135,6 +140,13 @@ class ProcessGuard( object ):
         self._onError = onError
         self._execute( options )
 
+    def shutdown( self, sig=signal.SIGTERM ):
+        """
+        Shutdown the process.
+        """
+        if self.pid is not None:
+            os.kill( self.pid, sig )
+
 #============================================================================#
 if __name__ == "__main__":
 #============================================================================#
diff --git a/framework/subsystem.py b/framework/subsystem.py
index 55450b4..b2f0dd0 100644
--- a/framework/subsystem.py
+++ b/framework/subsystem.py
@@ -10,10 +10,12 @@ Module: subsystem
 """
 
 MODULE_NAME = "frameworkd.subsystem"
-__version__ = "1.0.1"
+__version__ = "1.1.0"
 
 from .config import config, DBUS_BUS_NAME_PREFIX
 
+from patterns.processguard import ProcessGuard
+
 import dbus
 import os, sys, time
 
@@ -36,6 +38,15 @@ class Subsystem( object ):
         self._objects = {}
         self.busnames = []
 
+        self.launch()
+
+        self.launchTime = time.time() - self.launchTime
+        logger.info( "subsystem %s took %.2f seconds to startup" % ( self.name, self.launchTime ) )
+
+    def launch( self ):
+        """
+        Launch the subsystem.
+        """
         self.busnames.append( self.tryClaimBusName() )
         self.registerModulesInSubsystem()
 
@@ -46,9 +57,6 @@ class Subsystem( object ):
         else:
             logger.debug( "service %s now owning busnames %s" % (self.name, self.busnames) )
 
-        self.launchTime = time.time() - self.launchTime
-        logger.info( "subsystem %s took %.2f seconds to startup" % ( self.name, self.launchTime ) )
-
     def shutdown( self ):
         """
         Shutdown the subsystems, giving objects a chance
@@ -145,3 +153,24 @@ class Framework( Subsystem ):
     def registerModulesInSubsystem( self ):
         import framework.objectquery
         self.registerObjectsFromModule( framework.objectquery )
+
+#----------------------------------------------------------------------------#
+class External( Subsystem ):
+#----------------------------------------------------------------------------#
+    """
+    A Wrapper for an external subsystem.
+
+    An external subsystem is "just" a child process to us.
+    """
+    def __init__( self, name, path, controller ):
+        self._process = ProcessGuard( path )
+        Subsystem.__init__( self, name, None, None, controller )
+
+    def launch( self ):
+        self._process.execute( onExit=self.processExit )
+
+    def processExit( self, pid, exitcode, exitsignal ):
+        print "process has exit :/"
+
+    def shutdown( self ):
+        self._process.shutdown()

-- 
FSO frameworkd Debian packaging



More information about the pkg-fso-commits mailing list