1 # ossohelper.py - Helper to osso functions
3 # Copyright (c) 2008 INdT - Instituto Nokia de Tecnologia
5 # This file is part of carman-python.
6 # Modified for inclusion in Panucci (June 2009).
8 # carman-python is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
13 # carman-python is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
24 __log = logging.getLogger(__name__)
28 __osso_imported__ = True
30 __log.warning('osso module not found - are you running on a desktop?')
31 __osso_imported__ = False
33 DEVICE_STATE_NORMAL = "normal"
34 OSSO_DEVSTATE_MODE_FILE = "/tmp/.libosso_device_mode_cache"
36 __osso_context__ = None
37 __osso_application__ = None
38 __osso_device_state__ = None
40 def application_init(app_name, app_version):
42 Osso application init.
45 global __osso_context__, __osso_device_state__, __osso_application__
49 __log.warning('osso application was already called. Ignoring...')
52 __osso_context__ = osso.Context(app_name, app_version, False)
53 except Exception, err:
54 __log.warning('osso module found but could not be initialized: %s',
56 __osso_context__ = None
60 __osso_application__ = osso.Application(__osso_context__)
61 except Exception, err:
62 __log.warning('error creating osso application: %s' % err)
63 __osso_application__ = None
65 __log.info( 'osso application init sent - %s v%s', app_name,
67 __osso_device_state__ = osso.DeviceState(__osso_context__)
70 def application_exit():
72 Osso application exit.
74 if __osso_application__ is not None and __osso_context__ is not None:
76 __osso_application__.close()
77 __osso_context__.close()
78 except Exception, err:
79 __log.warning('application end could not be sent: %s' % err)
80 __log.info('osso application end sent')
83 def application_top(app_name):
87 if __osso_imported__ and __osso_application__:
89 __osso_application__.application_top(app_name)
90 except Exception, err:
91 __log.warning( "Error calling application top for %s: %s",
93 __log.info('osso application top for %s sent', app_name)
99 Return if the osso module was initialized and all objects were created
102 return __osso_imported__ and not None in ( __osso_context__,
103 __osso_device_state__,
104 __osso_application__ )
111 if __osso_device_state__ is not None:
112 __osso_device_state__.display_state_on()
113 __osso_device_state__.display_blanking_pause()
114 __log.info('osso display on')
117 def display_blanking_pause():
119 Keep the backlight on. Should be called every 45 seconds.
121 if __osso_device_state__ is not None:
122 __osso_device_state__.display_blanking_pause()
123 __log.debug('osso blanking screen')
124 #display_blanking_pause
126 def get_device_state():
127 if __osso_device_state__ is not None:
128 cache_file_name = OSSO_DEVSTATE_MODE_FILE + "-" + str(os.getuid())
130 state = os.readlink(cache_file_name)
134 __log.debug( "Failure to read device state from %s",
136 state = DEVICE_STATE_NORMAL
139 return DEVICE_STATE_NORMAL