mirror of
https://git.kernel.org/pub/scm/network/wireless/iwd.git
synced 2024-12-26 01:02:35 +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:
parent
4657bd55f5
commit
1a01486170
@ -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(
|
||||
|
Loading…
Reference in New Issue
Block a user