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: hwsim.py: turn Hwsim into singleton (per-namespace)

This prevents reallocation of new Hwsim classes on each call if one
already exists. This is a bit more efficient on memory.
This commit is contained in:
James Prestwood 2021-08-26 13:33:31 -07:00 committed by Denis Kenzior
parent 4657bd55f5
commit 1a01486170

View File

@ -3,6 +3,7 @@ import dbus
import sys
import collections
from weakref import WeakValueDictionary
from abc import ABCMeta, abstractmethod
from enum import Enum
@ -297,7 +298,25 @@ class RadioList(collections.Mapping):
return obj
class Hwsim(iwd.AsyncOpAbstract):
_instances = WeakValueDictionary()
def __new__(cls, namespace=ctx):
name = namespace.name
if name not in cls._instances.keys():
obj = object.__new__(cls)
obj._initialized = False
cls._instances[name] = obj
return cls._instances[name]
def __init__(self, namespace=ctx):
if self._initialized:
return
self._initialized = True
self._bus = namespace.get_bus()
self._rule_manager_if = dbus.Interface(