3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-11-25 09:39:25 +01:00

auto-t: hostapd.py: properly implement singleton (per-config)

This shouldn't change any functionality but it is much more convenient
in the cleanup path i.e. nothing special needs to be done.
This commit is contained in:
James Prestwood 2021-08-26 13:33:32 -07:00 committed by Denis Kenzior
parent 1a01486170
commit cb7e9b5885
2 changed files with 6 additions and 17 deletions

View File

@ -5,6 +5,7 @@ import socket
import select
import time
from gi.repository import GLib
from weakref import WeakValueDictionary
from config import ctx
chan_freq_map = [
@ -29,7 +30,7 @@ ctrl_count = 0
mainloop = GLib.MainLoop()
class HostapdCLI(object):
_instances = {}
_instances = WeakValueDictionary()
def __new__(cls, config=None, *args, **kwargs):
hapd = ctx.hostapd[config]
@ -38,8 +39,10 @@ class HostapdCLI(object):
config = hapd.config
if not config in cls._instances.keys():
cls._instances[config] = object.__new__(cls, *args, **kwargs)
cls._instances[config]._initialized = False
obj = object.__new__(cls, *args, **kwargs)
obj._initialized = False
cls._instances[config] = obj
return cls._instances[config]
@ -123,13 +126,6 @@ class HostapdCLI(object):
except:
pass
HostapdCLI._instances[self.config] = None
# Check if this is the final instance
destroy = len([hapd for hapd in HostapdCLI._instances.values() if hapd is not None]) == 0
if destroy:
HostapdCLI._instances = {}
def set_value(self, key, value):
cmd = self.cmdline + ['set', key, value]
ctx.start_process(cmd).wait()

View File

@ -541,13 +541,6 @@ class Hostapd:
except:
print("Failed to remove %s" % self.global_ctrl_iface)
for hapd in self.instances:
if not hapd.cli:
continue
hapd.cli._instances[hapd.config] = None
hapd.cli = None
self.instances = None
# Hostapd may have already been stopped