Esempio n. 1
0
    def __init__(self, bus: SystemMessageBus, loop: asyncio.AbstractEventLoop,
                 device_registry, object_path, is_host, control_socket_path,
                 interrupt_socket_path):
        self.device = bus.get_proxy(service_name="org.bluez",
                                    object_path=object_path,
                                    interface_name=DEVICE_INTERFACE)
        self.props = bus.get_proxy(service_name="org.bluez",
                                   object_path=object_path,
                                   interface_name=PROPERTIES_INTERFACE)
        self.props.PropertiesChanged.connect(
            self.device_connected_state_changed)

        self.bus = bus
        self.loop = loop
        self.device_registry = device_registry
        self.object_path = object_path
        self.is_host = is_host
        self.control_socket_path = control_socket_path
        self.control_socket = None
        self.interrupt_socket_path = interrupt_socket_path
        self.interrupt_socket = None
        self.sockets_connected = False

        print("BT Device ", object_path, " created")
        asyncio.run_coroutine_threadsafe(self.reconcile_connected_state(1),
                                         loop=self.loop)
Esempio n. 2
0
# Copyright (c) 2020 ruundii. All rights reserved.

import asyncio
import sys
from signal import SIGINT

import asyncio_glib
from dasbus.connection import SystemMessageBus

from adapter import BluetoothAdapter
from bluetooth_devices import *
from hid_devices import *
from web import Web

if __name__ == "__main__":
    asyncio.set_event_loop_policy(asyncio_glib.GLibEventLoopPolicy())
    loop = asyncio.get_event_loop()
    loop.add_signal_handler(SIGINT, sys.exit)
    bus = SystemMessageBus()
    bluetooth_devices = BluetoothDeviceRegistry(bus, loop)
    hid_devices = HIDDeviceRegistry(loop)
    hid_devices.set_bluetooth_devices(bluetooth_devices)
    bluetooth_devices.set_hid_devices(hid_devices)
    adapter = BluetoothAdapter(bus, loop, bluetooth_devices, hid_devices)
    web = Web(loop, adapter, bluetooth_devices, hid_devices)
    loop.run_forever()

#print(proxy)
Esempio n. 3
0
def SystemBus() -> MessageBus:
    return cast(MessageBus, SystemMessageBus(error_mapper=error_mapper))
Esempio n. 4
0
 def test_system_bus(self, getter):
     """Test the system bus."""
     message_bus = SystemMessageBus()
     self.assertIsNotNone(message_bus.connection)
     getter.assert_called_once_with(Gio.BusType.SYSTEM, None)
Esempio n. 5
0
#
# Show the current hostname.
#
from dasbus.connection import SystemMessageBus
from dasbus.identifier import DBusServiceIdentifier

# Define the message bus.
SYSTEM_BUS = SystemMessageBus()

# Define services and objects.
HOSTNAME = DBusServiceIdentifier(namespace=("org", "freedesktop", "hostname"),
                                 service_version=1,
                                 object_version=1,
                                 interface_version=1,
                                 message_bus=SYSTEM_BUS)

if __name__ == "__main__":
    # Create a proxy of the object /org/freedesktop/hostname1
    # provided by the service org.freedesktop.hostname1.
    proxy = HOSTNAME.get_proxy()

    # Print a value of the DBus property Hostname.
    print(proxy.Hostname)
Esempio n. 6
0
class DefaultMessageBus(AnacondaMessageBus):
    """Representation of a default bus connection."""
    def _find_bus_address(self):
        """Get the address of the default bus.

        Connect to the bus specified by the environmental variable
        DBUS_STARTER_ADDRESS. If it is not specified, connect to
        the Anaconda bus.
        """
        if DBUS_STARTER_ADDRESS in os.environ:
            return os.environ.get(DBUS_STARTER_ADDRESS)

        return super()._find_bus_address()


# The mapper of DBus errors.
error_mapper = ErrorMapper()

# Default bus. Anaconda uses this connection.
DBus = DefaultMessageBus(error_mapper=error_mapper)

# System bus.
SystemBus = SystemMessageBus(error_mapper=error_mapper)

# The decorator for DBus errors.
dbus_error = get_error_decorator(error_mapper)

# Register all DBus errors.
register_errors()
Esempio n. 7
0
import asyncio, gbulb
gbulb.install()
#import asyncio_glib
#asyncio.set_event_loop_policy(asyncio_glib.GLibEventLoopPolicy())

# UUID for HID service (1124)
# https://www.bluetooth.com/specifications/assigned-numbers/service-discovery
UUID = '00001124-0000-1000-8000-00805f9b34fb'
ADAPTER_OBJECT = '/org/bluez/hci0'
DEVICE_INTERFACE = 'org.bluez.Device1'
INPUT_DEVICE_INTERFACE = 'org.bluez.Input1'
INPUT_HOST_INTERFACE = 'org.bluez.InputHost1'
DEVICE_NAME = 'Bluetooth HID Hub - Ubuntu'

bus = SystemMessageBus()
loop = asyncio.get_event_loop()


class BluetoothAdapter:
    def __init__(self):
        self.om = bus.get_proxy(
            service_name="org.bluez",
            object_path="/",
            interface_name="org.freedesktop.DBus.ObjectManager")
        self.om.InterfacesAdded.connect(self.interfaces_added)
        self.om.InterfacesRemoved.connect(self.interfaces_removed)
        objs = self.om.GetManagedObjects()
        self.host_sockets = {}
        self.device_sockets = {}
        if ADAPTER_OBJECT in objs: