~ubuntu-branches/ubuntu/vivid/blueman/vivid-proposed

« back to all changes in this revision

Viewing changes to blueman/bluez/BlueZInterface.py

  • Committer: Package Import Robot
  • Author(s): Artur Rona
  • Date: 2014-12-24 18:33:36 UTC
  • mfrom: (2.3.8 sid)
  • Revision ID: package-import@ubuntu.com-20141224183336-cyb82ot0y8tz8flq
Tags: 1.99~alpha1-1ubuntu1
* Merge from Debian unstable.  Remaining changes:
  - debian/patches/01_dont_autostart_lxde.patch:
    + Don't autostart the applet in LXDE.
  - debian/patches/03_filemanager_fix.patch:
    + Add support for more filemanagers.
* debian/patches/02_dont_crash_on_non-bluetooth_card.patch:
  - Dropped, no longer applicable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# BlueZInterface.py - the base class of other BlueZ interface classes
2
 
#
3
 
# Copyright (C) 2008 Vinicius Gomes <vcgomes [at] gmail [dot] com>
4
 
# Copyright (C) 2008 Li Dongyang <Jerry87905 [at] gmail [dot] com>
5
 
#
6
 
# This program is free software; you can redistribute it and/or modify
7
 
# it under the terms of the GNU General Public License as published by
8
 
# the Free Software Foundation; either version 2 of the License, or
9
 
# (at your option) any later version.
10
 
#
11
 
# This program is distributed in the hope that it will be useful,
12
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
# GNU General Public License for more details.
15
 
#
16
 
# You should have received a copy of the GNU General Public License
17
 
# along with this program; if not, write to the Free Software
18
 
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
 
 
20
1
import dbus
21
 
import types
 
2
from blueman.Functions import dprint
22
3
 
23
 
from utils import raise_type_error
24
4
 
25
5
class BlueZInterface(object):
26
 
 
27
 
    '''the base class of other BlueZ interface classes.'''
 
6
    interface_version = None
 
7
 
 
8
    @staticmethod
 
9
    def get_interface_version():
 
10
        if not BlueZInterface.interface_version:
 
11
            object = dbus.SystemBus().get_object('org.bluez', '/')
 
12
            introspection = dbus.Interface(object, 'org.freedesktop.DBus.Introspectable').Introspect()
 
13
            if 'org.freedesktop.DBus.ObjectManager' in introspection:
 
14
                dprint('Detected BlueZ 5')
 
15
                BlueZInterface.interface_version = [5]
 
16
            elif 'org.bluez.Manager' in introspection:
 
17
                dprint('Detected BlueZ 4')
 
18
                BlueZInterface.interface_version = [4]
 
19
            else:
 
20
                raise Exception('Could not find any compatible version of BlueZ')
 
21
 
 
22
        return BlueZInterface.interface_version
28
23
 
29
24
    def __init__(self, interface_name, obj_path):
30
25
        self.__obj_path = obj_path
31
26
        self.__interface_name = interface_name
32
27
        self.__bus = dbus.SystemBus()
33
 
        self.__dbus_proxy = self.__bus.get_object('org.bluez', obj_path, follow_name_owner_changes=True)
34
 
        self.__interface = dbus.Interface(self.__dbus_proxy, interface_name)
35
 
    # __init__
 
28
        if obj_path:
 
29
            self.__dbus_proxy = self.__bus.get_object('org.bluez', obj_path, follow_name_owner_changes=True)
 
30
            self.__interface = dbus.Interface(self.__dbus_proxy, interface_name)
36
31
 
37
 
    def GetObjectPath(self):
 
32
    def get_object_path(self):
38
33
        return self.__obj_path
39
 
    # GetObjectPath
40
 
 
41
 
    def GetInterface(self):
 
34
 
 
35
    def get_interface_name(self):
 
36
        return self.__interface_name
 
37
 
 
38
    def get_bus(self):
 
39
        return self.__bus
 
40
 
 
41
    def get_dbus_proxy(self):
 
42
        return self.__dbus_proxy
 
43
 
 
44
    def get_interface(self):
42
45
        return self.__interface
43
 
    # GetInterface
44
 
 
45
 
    def GetInterfaceName(self):
46
 
        return self.__interface_name
47
 
    # GetInterfaceName
48
 
 
49
 
    def HandleSignal(self, handler, signal, **kwargs):
50
 
        '''
51
 
        The handler function will be called when specific signal is emmited.
52
 
        For available signals of each interface, check BlueZ4 documents.
53
 
        '''
54
 
       # raise_type_error(handler, types.FunctionType)
55
 
        raise_type_error(signal, types.StringType)
56
 
        self.__bus.add_signal_receiver(handler,
57
 
                                       signal,
58
 
                                       self.__interface_name,
59
 
                                       'org.bluez',
60
 
                                       self.__obj_path, **kwargs)
61
 
    def UnHandleSignal(self, handler, signal, **kwargs):
62
 
        '''
63
 
        The handler function will be called when specific signal is emmited.
64
 
        For available signals of each interface, check BlueZ4 documents.
65
 
        '''
66
 
       # raise_type_error(handler, types.FunctionType)
67
 
        raise_type_error(signal, types.StringType)
68
 
        self.__bus.remove_signal_receiver(handler,
69
 
                                       signal,
70
 
                                       self.__interface_name,
71
 
                                       'org.bluez',
72
 
                                       self.__obj_path, **kwargs)
73
 
    # HandleSignal
74
 
# BlueZInterface