def connect(self, reply_handler=None, error_handler=None): channel = get_rfcomm_channel(self.short_uuid, self.device['Address']) if channel == 0: error = RFCOMMError("Failed to get rfcomm channel") if error_handler: error_handler(error) return True else: raise error try: port_id = create_rfcomm_device(Adapter(self.device["Adapter"])['Address'], self.device["Address"], channel) filename = '/dev/rfcomm%d' % port_id logging.info('Starting rfcomm watcher as root') Mechanism().open_rfcomm('(d)', port_id) mon = Gio.File.new_for_path(filename).monitor_file(Gio.FileMonitorFlags.NONE) self.file_changed_handler = mon.connect('changed', self.on_file_changed, port_id) self.try_replace_root_watcher(mon, filename, port_id) if reply_handler: reply_handler(filename) except RFCOMMError as e: if error_handler: error_handler(e) else: raise e return True
def connect(self, reply_handler=None, error_handler=None): channel = get_rfcomm_channel(self.short_uuid, self.device['Address']) if channel == 0: error = RFCOMMError("Failed to get rfcomm channel") if error_handler: error_handler(error) return True else: raise error try: port_id = create_rfcomm_device( Adapter(self.device["Adapter"])['Address'], self.device["Address"], channel) filename = '/dev/rfcomm%d' % port_id logging.info('Starting rfcomm watcher as root') Mechanism().open_rfcomm('(d)', port_id) mon = Gio.File.new_for_path(filename).monitor_file( Gio.FileMonitorFlags.NONE) self.file_changed_handler = mon.connect('changed', self.on_file_changed, port_id) self.try_replace_root_watcher(mon, filename, port_id) if reply_handler: reply_handler(filename) except RFCOMMError as e: if error_handler: error_handler(e) else: raise e return True
def connect( self, reply_handler: Optional[Callable[[int], None]] = None, error_handler: Optional[Callable[[RFCOMMError], None]] = None ) -> bool: # We expect this service to have a reserved UUID uuid = self.short_uuid assert uuid channel = get_rfcomm_channel(uuid, self.device['Address']) if channel is None or channel == 0: error = RFCOMMError("Failed to get rfcomm channel") if error_handler: error_handler(error) return True else: raise error try: port_id = create_rfcomm_device(Adapter(obj_path=self.device["Adapter"])['Address'], self.device["Address"], channel) filename = '/dev/rfcomm%d' % port_id logging.info('Starting rfcomm watcher as root') Mechanism().OpenRFCOMM('(d)', port_id) mon = Gio.File.new_for_path(filename).monitor_file(Gio.FileMonitorFlags.NONE) self._handlerids[port_id] = mon.connect('changed', self.on_file_changed, port_id) self.try_replace_root_watcher(mon, filename, port_id) if reply_handler: reply_handler(port_id) except RFCOMMError as e: if error_handler: error_handler(e) else: raise e return True
def connect(self, reply_handler=None, error_handler=None): props = self.device.get_properties() try: # TODO: Channel? port_id = create_rfcomm_device(Adapter(props['Adapter']).get_properties()['Address'], props['Address'], 1) Mechanism().open_rfcomm(port_id) if reply_handler: reply_handler('/dev/rfcomm%d' % port_id) except Exception as e: if error_handler: error_handler(e) else: raise e return True
def connect(self, reply_handler=None, error_handler=None): try: # TODO: Channel? port_id = create_rfcomm_device( Adapter(self.device["Adapter"])['Address'], self.device["Address"], 1) Mechanism().open_rfcomm(str('(d)'), port_id) if reply_handler: reply_handler('/dev/rfcomm%d' % port_id) except Exception as e: if error_handler: error_handler(e) else: raise e return True
def connect(self, reply_handler=None, error_handler=None): try: # TODO: Channel? port_id = create_rfcomm_device(Adapter(self.device["Adapter"])['Address'], self.device["Address"], 1) filename = '/dev/rfcomm%d' % port_id logging.info('Starting rfcomm watcher as root') Mechanism().open_rfcomm('(d)', port_id) mon = Gio.File.new_for_path(filename).monitor_file(Gio.FileMonitorFlags.NONE) self.file_changed_handler = mon.connect('changed', self.on_file_changed, port_id) self.try_replace_root_watcher(mon, filename, port_id) if reply_handler: reply_handler(filename) except Exception as e: if error_handler: error_handler(e) else: raise e return True
def connect(self, reply_handler=None, error_handler=None): props = self.device.get_properties() short_uuid = uuid128_to_uuid16(self.uuid) channel = get_rfcomm_channel(short_uuid, props['Address']) if channel == 0: error = RFCOMMError("Failed to get rfcomm channel") if error_handler: error_handler(error) return True else: raise error try: port_id = create_rfcomm_device(Adapter(props['Adapter']).get_properties()['Address'], props['Address'], channel) Mechanism().open_rfcomm(port_id) if reply_handler: reply_handler('/dev/rfcomm%d' % port_id) except RFCOMMError as e: if error_handler: error_handler(e) else: raise e return True