r271 - in trunk/software/py-odeviced/odeviced: . modules

smartphones-commits at lists.linuxtogo.org smartphones-commits at lists.linuxtogo.org
Mon Apr 28 18:02:29 CEST 2008


Author: mickeylauer
Date: 2008-04-28 18:02:29 +0200 (Mon, 28 Apr 2008)
New Revision: 271

Modified:
   trunk/software/py-odeviced/odeviced/modules/kernel26.py
   trunk/software/py-odeviced/odeviced/odeviced
Log:
odeviced: use pyrtc to set RTC current time and wake up time


Modified: trunk/software/py-odeviced/odeviced/modules/kernel26.py
===================================================================
--- trunk/software/py-odeviced/odeviced/modules/kernel26.py	2008-04-28 15:05:11 UTC (rev 270)
+++ trunk/software/py-odeviced/odeviced/modules/kernel26.py	2008-04-28 16:02:29 UTC (rev 271)
@@ -12,6 +12,7 @@
 import dbus.service
 import os
 import sys
+import time
 from syslog import syslog, LOG_ERR, LOG_WARNING, LOG_INFO, LOG_DEBUG
 from helpers import LOG, DBUS_INTERFACE_PREFIX, DBUS_PATH_PREFIX, readFromFile, writeToFile
 
@@ -206,20 +207,45 @@
 
     @dbus.service.method( DBUS_INTERFACE, "", "s" )
     def GetCurrentTime( self ):
-        return readFromFile( "%s/time" % self.node )
+        """Return seconds since epoch (UTC)"""
+        return readFromFile( "%s/since_epoch" % self.node )
 
     @dbus.service.method( DBUS_INTERFACE, "s", "" )
-    def SetCurrentTime( self, time ):
-        writeToFile( "%s/time" % self.node, time )
+    def SetCurrentTime( self, t ):
+        """Set time by seconds since epoch (UTC)"""
+        pyrtc.rtcSetTime( time.gmtime( t ) )
 
     @dbus.service.method( DBUS_INTERFACE, "", "s" )
     def GetWakeupTime( self ):
-        return readFromFile( "%s/wakealarm" % self.node )
+        """Return wakeup time in seconds since epoch (UTC) if a wakeup
+        time has been set. Return 0, otherwise."""
+        # the wakealarm attribute is not always present
+        if os.path.exists( "%s/wakealarm" % self.node ):
+            return readFromFile( "%s/wakealarm" % self.node )
+        else:
+            # use ioctl interface
+            try:
+                import pyrtc
+            except ImportError:
+                LOG( LOG_ERR, "pyrtc not present. Can not operate real time clock" )
+            ( enabled, pending ), t = pyrtc.rtcReadAlarm()
+            return "0" if not enabled else str( mktime.time( t ) )
 
     @dbus.service.method( DBUS_INTERFACE, "s", "" )
-    def SetWakeupTime( self, time ):
-        """Set to 0 to disable"""
-        writeToFile( "%s/wakealarm" % self.node, time )
+    def SetWakeupTime( self, t ):
+        """Set wakeup time in seconds since epoch (UTC). Set 0 to disable."""
+        if os.path.exists( "%s/wakealarm" % self.node ):
+            writeToFile( "%s/wakealarm" % self.node, t )
+        else:
+            # use ioctl interface
+            try:
+                import pyrtc
+            except ImportError:
+                LOG( LOG_ERR, "pyrtc not present. Can not operate real time clock" )
+            if time == "0":
+                pyrtc.rtcDisableAlarm()
+            else:
+                pyrtc.rtcSetAlarm( time.gmtime( t ) )
 
     @dbus.service.method( DBUS_INTERFACE, "", "" )
     def Suspend( self ):

Modified: trunk/software/py-odeviced/odeviced/odeviced
===================================================================
--- trunk/software/py-odeviced/odeviced/odeviced	2008-04-28 15:05:11 UTC (rev 270)
+++ trunk/software/py-odeviced/odeviced/odeviced	2008-04-28 16:02:29 UTC (rev 271)
@@ -23,7 +23,7 @@
         if os.path.exists( path ):
             break
     else:
-        print >>sys.stderr, "did not found a modules path. Exiting."
+        print >>sys.stderr, "did not find a modules path. Exiting."
         sys.exit( -1 )
 
     if "ODEVICED_DEBUG" in os.environ:




More information about the Smartphones-commits mailing list