in smart-mirror-full/extracted/device/script/src/agt/ble/adapter.py [0:0]
def __init__(self, protocol, gadget_name, on_connection_cb, on_disconnection_cb):
logger.debug('resetting Bluez...')
self.restart_bluez_deamon()
logger.debug('Initializing BLE service')
# protocol <-> Transport exchange packets for send/receive functionality
# Initialize protocol object
self._protocol = protocol
self._is_connected = False
self._gadget_name = gadget_name
self._on_connect_cb = on_connection_cb
self._on_disconnect_cb = on_disconnection_cb
global mainloop
DBusGMainLoop(set_as_default=True)
dbus_loop = DBusGMainLoop()
self._bus = dbus.SystemBus(dbus_loop)
super().__init__(self._bus, dbus)
self._adapter = find_adapter(self._bus)
if not self._adapter:
logger.debug('GattManager1 interface not found')
return
self._service_manager = dbus.Interface(
self._bus.get_object(BUS_NAME, self._adapter),
GATT_MANAGER_IFACE)
self._application = Application(self._bus, self._protocol)
self._loop = GObject.MainLoop()
logger.debug('Registering GATT application...')
self._service_manager.RegisterApplication(self._application.get_path(), {},
reply_handler=self.register_app_cb,
error_handler=self.register_app_error_cb)
self.listen_properties_changed(self._bus)
self.listen_interface_added(self._bus)