1
# BlueZInterface.py - the base class of other BlueZ interface classes
3
# Copyright (C) 2008 Vinicius Gomes <vcgomes [at] gmail [dot] com>
4
# Copyright (C) 2008 Li Dongyang <Jerry87905 [at] gmail [dot] com>
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.
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.
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
2
from blueman.Functions import dprint
23
from utils import raise_type_error
25
5
class BlueZInterface(object):
27
'''the base class of other BlueZ interface classes.'''
6
interface_version = None
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]
20
raise Exception('Could not find any compatible version of BlueZ')
22
return BlueZInterface.interface_version
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)
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)
37
def GetObjectPath(self):
32
def get_object_path(self):
38
33
return self.__obj_path
41
def GetInterface(self):
35
def get_interface_name(self):
36
return self.__interface_name
41
def get_dbus_proxy(self):
42
return self.__dbus_proxy
44
def get_interface(self):
42
45
return self.__interface
45
def GetInterfaceName(self):
46
return self.__interface_name
49
def HandleSignal(self, handler, signal, **kwargs):
51
The handler function will be called when specific signal is emmited.
52
For available signals of each interface, check BlueZ4 documents.
54
# raise_type_error(handler, types.FunctionType)
55
raise_type_error(signal, types.StringType)
56
self.__bus.add_signal_receiver(handler,
58
self.__interface_name,
60
self.__obj_path, **kwargs)
61
def UnHandleSignal(self, handler, signal, **kwargs):
63
The handler function will be called when specific signal is emmited.
64
For available signals of each interface, check BlueZ4 documents.
66
# raise_type_error(handler, types.FunctionType)
67
raise_type_error(signal, types.StringType)
68
self.__bus.remove_signal_receiver(handler,
70
self.__interface_name,
72
self.__obj_path, **kwargs)