eiwd

no dbus iwd with iwctl functionality
git clone https://git.daat.foo/repos/eiwd.git
Log | Files | Refs | Submodules | README | LICENSE

ead.py (3289B)


      1 #!/usr/bin/python3
      2 
      3 from gi.repository import GLib
      4 import dbus
      5 import time
      6 
      7 import iwd
      8 from collections.abc import Mapping
      9 from config import ctx
     10 
     11 EAD_SERVICE =                   'net.connman.ead'
     12 EAD_ADAPTER_INTERFACE =         'net.connman.ead.Adapter'
     13 DBUS_OBJECT_MANAGER =           'org.freedesktop.DBus.ObjectManager'
     14 DBUS_PROPERTIES =               'org.freedesktop.DBus.Properties'
     15 EAD_TOP_LEVEL_PATH =            '/'
     16 
     17 class Adapter(iwd.IWDDBusAbstract):
     18     _iface_name = "net.connman.ead.Adapter"
     19 
     20     @property
     21     def name(self):
     22         return self._properties['Name']
     23 
     24     @property
     25     def address(self):
     26         return self._properties['Address']
     27 
     28     @property
     29     def active(self):
     30         return self._properties['Active']
     31 
     32     @property
     33     def connected(self):
     34         return self._properties['Connected']
     35 
     36     @property
     37     def authenticated(self):
     38         return self._properties['Authenticated']
     39 
     40 
     41 class AdapterList(Mapping):
     42     def __init__(self, ead):
     43         self._dict = {}
     44 
     45         ead._object_manager.connect_to_signal("InterfacesAdded",
     46                                                self._interfaces_added_handler)
     47         ead._object_manager.connect_to_signal("InterfacesRemoved",
     48                                                self._interfaces_removed_handler)
     49 
     50         objects = ead._object_manager.GetManagedObjects()
     51 
     52         for path in objects:
     53             for interface in objects[path]:
     54                 if interface == EAD_ADAPTER_INTERFACE:
     55                     self._dict[path] = Adapter(path, objects[path][interface], service=EAD_SERVICE)
     56 
     57     def __getitem__(self, key):
     58         return self._dict.__getitem__(key)
     59 
     60     def __iter__(self):
     61         return self._dict.__iter__()
     62 
     63     def __len__(self):
     64         return self._dict.__len__()
     65 
     66     def __delitem__(self, key):
     67         self._dict.pop(key).remove()
     68 
     69     def _interfaces_added_handler(self, path, interfaces):
     70         if EAD_ADAPTER_INTERFACE in interfaces:
     71             self._dict[path] = Adapter(path, interfaces[EAD_ADAPTER_INTERFACE], service=EAD_SERVICE)
     72 
     73     def _interfaces_removed_handler(self, path, interfaces):
     74         if EAD_ADAPTER_INTERFACE in interfaces:
     75             del self._dict[path]
     76 
     77 class EAD(iwd.AsyncOpAbstract):
     78     _bus = ctx.get_bus()
     79 
     80     _object_manager_if = None
     81     _adapters = None
     82 
     83     def __init__(self):
     84         ctx.non_block_wait(self._bus.name_has_owner, 20, EAD_SERVICE,
     85                             exception=TimeoutError('EAD has failed to start'))
     86 
     87         self._adapters = AdapterList(self)
     88 
     89     @property
     90     def _object_manager(self):
     91         if self._object_manager_if is None:
     92             self._object_manager_if = \
     93                        dbus.Interface(self._bus.get_object(EAD_SERVICE,
     94                                                            EAD_TOP_LEVEL_PATH),
     95                                       DBUS_OBJECT_MANAGER)
     96         return self._object_manager_if
     97 
     98     def list_adapters(self, wait_to_appear = 0, max_wait = 50):
     99         if not wait_to_appear:
    100             return list(self._adapters.values())
    101 
    102         ctx.non_block_wait(lambda s, num : len(s._adapters) >= num, max_wait, self, wait_to_appear,
    103                             exception=TimeoutError('EAD has no associated devices'))
    104 
    105         return list(self._adapters.values())