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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
# Adapter.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 types
import Device
import Agent
import errors
from utils import raise_dbus_error
from utils import raise_type_error
from BaseInterface import BaseInterface
class Adapter(BaseInterface):
@raise_dbus_error
def __init__(self, obj_path):
super(Adapter, self).__init__('org.bluez.Adapter', obj_path)
# __init__
@raise_dbus_error
def GetProperties(self):
return self.GetInterface().GetProperties()
# GetProperties
@raise_dbus_error
def SetProperty(self, name, value):
if type(value) == types.IntType:
value = dbus.UInt32(value)
self.GetInterface().SetProperty(name, value)
# SetProperty
@raise_dbus_error
def RequestSession(self):
self.GetInterface().RequestSession()
# RequestSession
@raise_dbus_error
def ReleaseSession(self):
self.GetInterface().ReleaseSession()
# ReleaseSession
@raise_dbus_error
def StartDiscovery(self):
self.GetInterface().StartDiscovery()
# StartDiscovery
@raise_dbus_error
def StopDiscovery(self):
self.GetInterface().StopDiscovery()
# StopDiscovery
@raise_dbus_error
def FindDevice(self, address):
obj_path = self.GetInterface().FindDevice(address)
return Device.Device(obj_path)
# FindDevice
@raise_dbus_error
def ListDevices(self):
obj_paths = self.GetInterface().ListDevices()
devices = []
for obj_path in obj_paths:
devices.append(Device.Device(obj_path))
return devices
# ListDevices
@raise_dbus_error
def CreateDevice(self, address):
obj_path = self.GetInterface().CreateDevice(address)
return Device.Device(obj_path)
# CreateDevice
@raise_dbus_error
def CreatePairedDevice(self, address, agent, capability='', reply_handler=None, error_handler=None):
def reply_handler_wrapper(obj_path):
if not callable(reply_handler):
return
reply_handler(Device.Device(obj_path))
def error_handler_wrapper(exception):
exception = errors.parse_dbus_error(exception)
if not callable(error_handler):
raise exception
error_handler(exception)
raise_type_error(agent, Agent.Agent)
if reply_handler is None and error_handler is None:
obj_path = self.GetInterface().CreatePairedDevice(address, agent.GetObjectPath(), capability)
return Device.Device(obj_path)
else:
self.GetInterface().CreatePairedDevice(address,
agent.GetObjectPath(),
capability,
reply_handler=reply_handler_wrapper,
error_handler=error_handler_wrapper)
return None
# CreatePairedDevice
@raise_dbus_error
def CancelDeviceCreation(self, address):
self.GetInterface.CancelDeviceCreation(address)
# CancelDeviceCreation
@raise_dbus_error
def RemoveDevice(self, device):
raise_type_error(device, Device.Device)
self.GetInterface().RemoveDevice(device.GetObjectPath())
# RemoveDevice
@raise_dbus_error
def RegisterAgent(self, agent, capability=''):
raise_type_error(agent, Agent.Agent)
self.GetInterface().RegisterAgent(agent.GetObjectPath(), capability)
# RegisterAgent
@raise_dbus_error
def UnregisterAgent(self, agent):
raise_type_error(agent, Agent.Agent)
self.GetInterface().UnregisterAgent(agent.GetObjectPath())
# UnregisterAgent
# Adapter
|