~ubuntu-branches/ubuntu/wily/blueman/wily

« back to all changes in this revision

Viewing changes to blueman/services/meta/SerialService.py

  • Committer: Package Import Robot
  • Author(s): Sean Davis
  • Date: 2015-09-07 12:48:18 UTC
  • mfrom: (2.3.11 sid)
  • Revision ID: package-import@ubuntu.com-20150907124818-evulc0mhjotz8q29
Tags: 2.0-1ubuntu1
* Merge from Debian unstable (LP: #1482626). Remaining changes:
  - debian/patches/03_filemanage_fix.patch:
    + Dropped, no longer needed.
  - debian/patches/dhcpclient_priority
  - debian/patches/01_dont_autostart_lxde.patch
    + Refreshed patches

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from __future__ import print_function
 
2
from __future__ import division
 
3
from __future__ import absolute_import
 
4
from __future__ import unicode_literals
 
5
 
 
6
from blueman.bluez.Adapter import Adapter
 
7
from _blueman import rfcomm_list, release_rfcomm_device, create_rfcomm_device
 
8
from blueman.Service import Service
 
9
from blueman.main.Mechanism import Mechanism
 
10
 
 
11
 
 
12
class SerialService(Service):
 
13
    def __init__(self, device, uuid):
 
14
        super(SerialService, self).__init__(device, uuid, False)
 
15
 
 
16
    def serial_port_id(self, channel):
 
17
        for dev in rfcomm_list():
 
18
            if dev["dst"] == self.device.Address and dev["state"] == "connected" and dev["channel"] == channel:
 
19
                return dev["id"]
 
20
 
 
21
    @property
 
22
    def connected(self):
 
23
        return False
 
24
 
 
25
    def connect(self, reply_handler=None, error_handler=None):
 
26
        props = self.device.get_properties()
 
27
        try:
 
28
            # TODO: Channel?
 
29
            port_id = create_rfcomm_device(Adapter(props['Adapter']).get_properties()['Address'], props['Address'], 1)
 
30
            Mechanism().open_rfcomm(port_id)
 
31
            if reply_handler:
 
32
                reply_handler('/dev/rfcomm%d' % port_id)
 
33
        except Exception as e:
 
34
            if error_handler:
 
35
                error_handler(e)
 
36
            else:
 
37
                raise e
 
38
        return True
 
39
 
 
40
    def disconnect(self, *args):
 
41
        Mechanism().close_rfcomm(args[0])
 
42
        release_rfcomm_device(args[0])