File: dbuscache.py

package info (click to toggle)
fso-frameworkd 0.9.5.9%2Bgit20110512-5
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 4,988 kB
  • ctags: 5,213
  • sloc: python: 23,770; sh: 160; sql: 4; makefile: 2
file content (58 lines) | stat: -rw-r--r-- 1,849 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env python
"""
freesmartphone.org Framework Daemon

(C) 2009 Michael 'Mickey' Lauer <mlauer@vanille-media.de>
GPLv2 or later

Package: framework
Module: controller
"""

__version__ = "1.0.2"

import dbus

_bus = dbus.SystemBus()
_objects = {}
_ifaces = {}

#----------------------------------------------------------------------------#
def dbusInterfaceForObjectWithInterface( service, object, interface ):
#----------------------------------------------------------------------------#
    """
    Gather dbus.Interface proxy for given triple of service, object, interface
    Try to cache as much as possible.
    """

    try:
        iface = _ifaces[ ( service, object, interface ) ]
    except KeyError:
        try:
            obj = _objects[ ( service, object ) ]
        except KeyError:
            # this call will always succeed, even if the questioned service is not online yet
            obj = _objects[ ( service, object ) ] = _bus.get_object( service, object, introspect=False, follow_name_owner_changes=True )
        iface = _ifaces[ ( service, object, interface ) ] = dbus.Interface( obj, interface )

    return iface

dbus.InterfaceForObjectWithInterface = dbusInterfaceForObjectWithInterface

#----------------------------------------------------------------------------#
def dbusCallAsyncDontCare( method, *args ):
#----------------------------------------------------------------------------#
    """
    Call dbus method async., don't care about any errors or replies.
    """
    method( *args, **dict( reply_handler=nop, error_handler=nop ) )


#----------------------------------------------------------------------------#
def nop( *args, **kwargs ):
#----------------------------------------------------------------------------#
    #print ( "dbusCallAsyncDontCare returned with ", args, kwargs )
    pass