mirror of
https://git.disroot.org/pranav/pybatmesh.git
synced 2024-11-30 02:32:24 +05:30
Updated HACKING.md and naxalnet/iwd.py
Added Device.reload() to reload the proxy every time the device mode is changed. Added Device.set_mode() and partial implementation of Device.start_adhoc_open(). Added link to meaning of hack in HACKING.md
This commit is contained in:
parent
d4e6b929d2
commit
0e7a69be53
@ -1,6 +1,9 @@
|
||||
# Hacking
|
||||
|
||||
## Reporting issues and ideas
|
||||
Everyone is welcome to [hack][] naxalnet.
|
||||
See below for how to hack.
|
||||
|
||||
## Reporting issues and suggesting ideas
|
||||
|
||||
To report a bug or suggest an idea, create a new issue at
|
||||
<https://git.disroot.org/pranav/naxalnet/issues> with a
|
||||
@ -21,3 +24,5 @@ your username to:
|
||||
naxalnet needs distro packages in Debian, Fedora, openSUSE,
|
||||
and nixos. If you know/like to package it to your distro,
|
||||
post to issue #6.
|
||||
|
||||
[hack]: https://catb.org/jargon/html/H/hack.html
|
||||
|
@ -17,7 +17,12 @@ class IWD:
|
||||
"""Manage iwd via dbus"""
|
||||
|
||||
def __init__(self, bus=SystemMessageBus()):
|
||||
# self._bus and self._proxy are meant for use only in this file
|
||||
self._bus = bus
|
||||
self.reload()
|
||||
|
||||
def reload(self):
|
||||
"""reload the proxy"""
|
||||
self._proxy = self._bus.get_proxy(IWD_BUS, IWD_ROOT_PATH)
|
||||
|
||||
def get_name_from_path(self, path: str) -> str:
|
||||
@ -32,6 +37,7 @@ class IWD:
|
||||
proxy = self._bus.get_proxy(IWD_BUS, i)
|
||||
if proxy.Name == name:
|
||||
return i
|
||||
# If no devices were found, return None
|
||||
return None
|
||||
|
||||
def get_adapter_path_from_name(self, name: str) -> str:
|
||||
@ -41,6 +47,7 @@ class IWD:
|
||||
proxy = self._bus.get_proxy(IWD_BUS, i)
|
||||
if proxy.Name == name:
|
||||
return i
|
||||
# If no adapters were found
|
||||
return None
|
||||
|
||||
def get_all_device_paths(self) -> list:
|
||||
@ -92,20 +99,38 @@ class IWD:
|
||||
|
||||
|
||||
class Device:
|
||||
"""control devices with iwd"""
|
||||
"""
|
||||
control devices with iwd
|
||||
name: name of device
|
||||
adapter: name of adapter (str)
|
||||
"""
|
||||
|
||||
def __init__(self, name: str, bus=SystemMessageBus()):
|
||||
self._iwd = IWD(bus)
|
||||
self._bus = self._iwd._bus
|
||||
self._path = self._iwd.get_device_path_from_name(name)
|
||||
self._proxy = self._bus.get_proxy(IWD_BUS, self._path)
|
||||
self.reload()
|
||||
self.name = self._proxy.Name
|
||||
adapter_path = self._proxy.Adapter
|
||||
self.adapter = self._iwd.get_name_from_path(adapter_path)
|
||||
|
||||
def reload(self):
|
||||
"""reload the proxy after changing mode"""
|
||||
self._proxy = self._bus.get_proxy(IWD_BUS, self._path)
|
||||
|
||||
def get_mode(self) -> str:
|
||||
"""
|
||||
returns the mode in which the device is in
|
||||
example: "ap"
|
||||
"""
|
||||
return self._proxy.Mode
|
||||
|
||||
def set_mode(self, mode: str):
|
||||
"""change the device mode to mode"""
|
||||
self._proxy.Mode = mode
|
||||
self.reload()
|
||||
|
||||
def start_adhoc_open(self, name):
|
||||
if self.get_mode() != "ad-hoc":
|
||||
self.set_mode("ad-hoc")
|
||||
# TODO: connect to network
|
||||
|
Loading…
Reference in New Issue
Block a user