1
# Agent.py - class Agent and decorator AgentMethod
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
1
from blueman.Functions import dprint
4
from blueman.bluez.BlueZInterface import BlueZInterface
25
__SIGNATURES__ = {'Release':('', ''),
26
'RequestPinCode':('o', 's'),
27
'RequestPasskey':('o', 'u'),
28
'DisplayPasskey':('ouu', ''),
29
'RequestConfirmation':('ou', ''),
30
'Authorize':('os', ''),
31
'ConfirmModeChange':('s', ''),
9
'RequestPinCode': ('o', 's'),
10
'RequestPasskey': ('o', 'u'),
11
'DisplayPasskey': ('ouu', ''),
12
'RequestConfirmation': ('ou', ''),
13
'RequestAuthorization': ('o', ''),
14
'Authorize': ('os', ''),
15
'AuthorizeService': ('os', ''),
34
20
def AgentMethod(func):
36
The decorator for customizing the agent methods.
37
To use async callbacks, add two extra parameters for
38
success callback and error callback in the def of the agent method.
40
21
global __SIGNATURES__
42
23
signatures = __SIGNATURES__[func.__name__]
47
28
async_callbacks = (args[-2], args[-1])
49
30
async_callbacks = None
50
warp = dbus.service.method('org.bluez.Agent',
51
in_signature=signatures[0],
52
out_signature=signatures[1],
32
if BlueZInterface.get_interface_version()[0] < 5:
33
interface = 'org.bluez.Agent'
35
interface = 'org.bluez.Agent1'
37
warp = dbus.service.method(interface, in_signature=signatures[0], out_signature=signatures[1],
53
38
async_callbacks=async_callbacks)
57
42
class Agent(dbus.service.Object):
60
Represents the BlueZ dbus API on interface "org.bluez.Agent".
61
Inherit from this class and use AgentMethod decorator
62
to customize the methods.
63
The simple-agent is provided by default.
66
43
def __init__(self, obj_path):
67
44
self.__obj_path = obj_path
68
45
dbus.service.Object.__init__(self, dbus.SystemBus(), obj_path)
71
def GetObjectPath(self):
72
'''Returns the dbus object path of the agent.'''
47
def get_object_path(self):
73
48
return self.__obj_path
79
This method gets called when the service daemon
80
unregisters the agent. An agent can use it to do
81
cleanup tasks. There is no need to unregister the
82
agent, because when this method gets called it has
83
already been unregistered.
89
55
def RequestPinCode(self, device):
91
This method gets called when the service daemon
92
needs to get the passkey for an authentication.
93
The return value should be a string of 1-16 characters
94
length. The string can be alphanumeric.
96
dprint("RequestPinCode (%s)" % (device))
56
dprint('RequestPinCode (%s)' % (device))
101
59
def RequestPasskey(self, device):
103
This method gets called when the service daemon
104
needs to get the passkey for an authentication.
105
The return value should be a numeric value
108
dprint("RequestPasskey (%s)" % (device))
60
dprint('RequestPasskey (%s)' % (device))
113
63
def DisplayPasskey(self, device, passkey, entered):
115
This method gets called when the service daemon
116
needs to display a passkey for an authentication.
117
The entered parameter indicates the number of already
118
typed keys on the remote side.
119
An empty reply should be returned. When the passkey
120
needs no longer to be displayed, the Cancel method
121
of the agent will be called.
122
During the pairing process this method might be
123
called multiple times to update the entered value.
125
dprint("DisplayPasskey (%s, %d)" % (device, passkey))
64
dprint('DisplayPasskey (%s, %d)' % (device, passkey))
129
67
def RequestConfirmation(self, device, passkey):
131
This method gets called when the service daemon
132
needs to confirm a passkey for an authentication.
133
To confirm the value it should return an empty reply
134
or an error in case the passkey is invalid.
136
dprint("RequestConfirmation (%s, %d)" % (device, passkey))
68
dprint('RequestConfirmation (%s, %d)' % (device, passkey))
138
# RequestConfirmation
71
def RequestAuthorization(self, device):
72
dprint('RequestAuthorization (%s)' % device)
141
75
def Authorize(self, device, uuid):
143
This method gets called when the service daemon
144
needs to authorize a connection/service request.
146
dprint("Authorize (%s, %s)" % (device, uuid))
76
dprint('Authorize (%s, %s)' % (device, uuid))
150
def ConfirmModeChange(self, mode):
152
This method gets called if a mode change is requested
153
that needs to be confirmed by the user. An example
154
would be leaving flight mode.
156
dprint("ConfirmModeChange (%s)" % (mode))
79
def AuthorizeService(self, device, uuid):
80
dprint('AuthorizeService (%s, %s)' % (device, uuid))
162
This method gets called to indicate that the agent
163
request failed before a reply was returned.