mirror of
https://git.disroot.org/pranav/pybatmesh.git
synced 2024-12-28 02:50:20 +05:30
Pranav Jerry
2e4c3a70a4
This was previously done by the systemd service. But since we allowed changing the name of bat0 and bridge0, we can't expect systemd to still do that job. Commented out some lines in the systemd service and made it send SIGINT instead of the default SIGTERM to kill naxalnet. I accidentally used to increment a2, a3, a4, ... in the __version__ instead of dev1, dev2, &c. a few commits back. Removed some print() lines lurking somewhere in the code. The cleanup is still not completed. We still have to delete the interfaces bridge0 and bat0, or whatever name the user gives it. Just out of boredom, I added some description to some network configuration, though so I doubt if anyone will understand it more because of that.
71 lines
2.1 KiB
Python
71 lines
2.1 KiB
Python
# This file is part of naxalnet.
|
|
# Copyright (C) 2021 The naxalnet Authors
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
"""
|
|
daemon.py
|
|
---------
|
|
|
|
The daemon part. This is currently under construction.
|
|
"""
|
|
|
|
from dasbus.loop import EventLoop
|
|
from naxalnet.iwd import IWD, IWD_DEVICE_INTERFACE
|
|
from naxalnet.log import logger
|
|
|
|
|
|
class Daemon:
|
|
"""implements the daemon part"""
|
|
|
|
def __init__(self):
|
|
self.loop = EventLoop()
|
|
self.iwd = IWD()
|
|
self.callback = None
|
|
|
|
def on_device_add(self, path, data):
|
|
"""
|
|
this function will be run every time a device is added
|
|
"""
|
|
if IWD_DEVICE_INTERFACE in data:
|
|
logger.debug("New device %s found", str(data[IWD_DEVICE_INTERFACE]["Name"]))
|
|
logger.info("Reloading")
|
|
self.callback()
|
|
|
|
def on_device_remove(self, path, data):
|
|
"""
|
|
this function will be run every time a device is removed
|
|
"""
|
|
if IWD_DEVICE_INTERFACE in data:
|
|
logger.debug("A device was removed")
|
|
logger.info("Reloading")
|
|
self.callback()
|
|
|
|
def add_callback(self, callback):
|
|
"""
|
|
register the callback with D-Bus so that callback is
|
|
run every time a device is added or removed
|
|
"""
|
|
self.callback = callback
|
|
proxy = self.iwd._proxy
|
|
proxy.InterfacesAdded.connect(self.on_device_add)
|
|
proxy.InterfacesRemoved.connect(self.on_device_remove)
|
|
|
|
def start(self):
|
|
"""
|
|
start the daemon
|
|
"""
|
|
logger.debug("Starting daemon")
|
|
self.loop.run()
|