Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/bluez/BaseInterface.py
blob: 3de3908d0b89973c7d6ef547c39f5bde77ea1495 (plain)
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
# BaseInterface.py
#
# Copyright (C) 2008 Vinicius Gomes <vcgomes [at] gmail [dot] com>
# Copyright (C) 2008 Li Dongyang <Jerry87905 [at] gmail [dot] com>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

import dbus
import xml.dom.minidom

from BlueZInterface import BlueZInterface
from ServiceInterface import ServiceInterface

class BaseInterface(BlueZInterface):

    def __init__(self, interface_name, obj_path):
        super(BaseInterface, self).__init__(interface_name, obj_path)
    # __init__

    def ListServiceInterfaces(self):
        '''
        Returns a list of available service interfaces under current object path,
        for available methods for each interface, check BlueZ4 documents.
        '''
        interfaces = []
        dbus_object = dbus.SystemBus().get_object('org.bluez', self.GetObjectPath())
        dbus_introspect = dbus.Interface(dbus_object, 'org.freedesktop.DBus.Introspectable')
        introspect_xml = dbus_introspect.Introspect()
        root_node = xml.dom.minidom.parseString(introspect_xml)
        for interface in root_node.getElementsByTagName('interface'):
            interface_name = interface.getAttribute('name')
            if interface_name != self.GetInterfaceName():
                methods = []
                for method in interface.getElementsByTagName('method'):
                    methods.append(method.getAttribute('name'))
                interfaces.append(ServiceInterface(interface_name, self.GetObjectPath(), methods))
        return interfaces
    # ListServiceInterfaces
# BaseInterface