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

« back to all changes in this revision

Viewing changes to blueman/bluez/Agent.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
 
# Agent.py - class Agent and decorator AgentMethod
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
 
 
 
1
from blueman.Functions import dprint
20
2
import inspect
21
 
import dbus
22
3
import dbus.service
 
4
from blueman.bluez.BlueZInterface import BlueZInterface
23
5
import errors
24
6
 
25
 
__SIGNATURES__ = {'Release':('', ''),
26
 
                  'RequestPinCode':('o', 's'),
27
 
                  'RequestPasskey':('o', 'u'),
28
 
                  'DisplayPasskey':('ouu', ''),
29
 
                  'RequestConfirmation':('ou', ''),
30
 
                  'Authorize':('os', ''),
31
 
                  'ConfirmModeChange':('s', ''),
32
 
                  'Cancel':('', '')}
 
7
__SIGNATURES__ = {
 
8
    'Release': ('', ''),
 
9
    'RequestPinCode': ('o', 's'),
 
10
    'RequestPasskey': ('o', 'u'),
 
11
    'DisplayPasskey': ('ouu', ''),
 
12
    'RequestConfirmation': ('ou', ''),
 
13
    'RequestAuthorization': ('o', ''),
 
14
    'Authorize': ('os', ''),
 
15
    'AuthorizeService': ('os', ''),
 
16
    'Cancel': ('', '')
 
17
}
 
18
 
33
19
 
34
20
def AgentMethod(func):
35
 
    '''
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.
39
 
    '''
40
21
    global __SIGNATURES__
41
22
    try:
42
23
        signatures = __SIGNATURES__[func.__name__]
47
28
        async_callbacks = (args[-2], args[-1])
48
29
    else:
49
30
        async_callbacks = None
50
 
    warp = dbus.service.method('org.bluez.Agent',
51
 
                               in_signature=signatures[0],
52
 
                               out_signature=signatures[1],
 
31
 
 
32
    if BlueZInterface.get_interface_version()[0] < 5:
 
33
        interface = 'org.bluez.Agent'
 
34
    else:
 
35
        interface = 'org.bluez.Agent1'
 
36
 
 
37
    warp = dbus.service.method(interface, in_signature=signatures[0], out_signature=signatures[1],
53
38
                               async_callbacks=async_callbacks)
54
39
    return warp(func)
55
 
# AgentMethod
 
40
 
56
41
 
57
42
class Agent(dbus.service.Object):
58
 
 
59
 
    '''
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.
64
 
    '''
65
 
 
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)
69
 
    # __init__
70
46
 
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
74
 
    # GetObjectPath
75
49
 
76
50
    @AgentMethod
77
51
    def Release(self):
78
 
        '''
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.
84
 
        '''
85
 
        dprint("Release")
86
 
    # Release
 
52
        dprint('Release')
87
53
 
88
54
    @AgentMethod
89
55
    def RequestPinCode(self, device):
90
 
        '''
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.
95
 
        '''
96
 
        dprint("RequestPinCode (%s)" % (device))
97
 
 
98
 
    # RequestPinCode
 
56
        dprint('RequestPinCode (%s)' % (device))
99
57
 
100
58
    @AgentMethod
101
59
    def RequestPasskey(self, device):
102
 
        '''
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
106
 
        between 0-999999.
107
 
        '''
108
 
        dprint("RequestPasskey (%s)" % (device))
109
 
 
110
 
    # RequestPasskey
 
60
        dprint('RequestPasskey (%s)' % (device))
111
61
 
112
62
    @AgentMethod
113
63
    def DisplayPasskey(self, device, passkey, entered):
114
 
        '''
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.
124
 
        '''
125
 
        dprint("DisplayPasskey (%s, %d)" % (device, passkey))
126
 
    # DisplayPasskey
 
64
        dprint('DisplayPasskey (%s, %d)' % (device, passkey))
127
65
 
128
66
    @AgentMethod
129
67
    def RequestConfirmation(self, device, passkey):
130
 
        '''
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.
135
 
        '''
136
 
        dprint("RequestConfirmation (%s, %d)" % (device, passkey))
 
68
        dprint('RequestConfirmation (%s, %d)' % (device, passkey))
137
69
 
138
 
    # RequestConfirmation
 
70
    @AgentMethod
 
71
    def RequestAuthorization(self, device):
 
72
        dprint('RequestAuthorization (%s)' % device)
139
73
 
140
74
    @AgentMethod
141
75
    def Authorize(self, device, uuid):
142
 
        '''
143
 
        This method gets called when the service daemon
144
 
        needs to authorize a connection/service request.
145
 
        '''
146
 
        dprint("Authorize (%s, %s)" % (device, uuid))
147
 
    # Authorize
 
76
        dprint('Authorize (%s, %s)' % (device, uuid))
148
77
 
149
78
    @AgentMethod
150
 
    def ConfirmModeChange(self, mode):
151
 
        '''
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.
155
 
        '''
156
 
        dprint("ConfirmModeChange (%s)" % (mode))
157
 
    # ConfirmModeChange
 
79
    def AuthorizeService(self, device, uuid):
 
80
        dprint('AuthorizeService (%s, %s)' % (device, uuid))
158
81
 
159
82
    @AgentMethod
160
83
    def Cancel(self):
161
 
        '''
162
 
        This method gets called to indicate that the agent
163
 
        request failed before a reply was returned.
164
 
        '''
165
 
        dprint("Cancel")
166
 
    # Cancel
167
 
# Agent
 
84
        dprint('Cancel')