mirror of
https://github.com/jketterl/openwebrx.git
synced 2025-12-06 07:12:09 +01:00
implement enabled & failed filters
This commit is contained in:
parent
1f7673e328
commit
3a8caedc67
55
owrx/sdr.py
55
owrx/sdr.py
|
|
@ -1,5 +1,5 @@
|
|||
from owrx.config import Config
|
||||
from owrx.source import SdrSource
|
||||
from owrx.source import SdrSourceEventClient
|
||||
from owrx.feature import FeatureDetector, UnknownFeatureException
|
||||
from owrx.active.list import ActiveListTransformation, ActiveListFilter, ActiveListListener, ActiveList, ActiveListChange
|
||||
|
||||
|
|
@ -61,6 +61,55 @@ class HasProfilesFilter(ActiveListFilter):
|
|||
device["profiles"].removeListener(self.monitors[id(device)])
|
||||
|
||||
|
||||
class SourceIsEnabledListener(SdrSourceEventClient):
|
||||
def __init__(self, callback: callable):
|
||||
self.callback = callback
|
||||
|
||||
def onEnable(self):
|
||||
self.callback()
|
||||
|
||||
def onDisable(self):
|
||||
self.callback()
|
||||
|
||||
|
||||
class SourceIsEnabledFilter(ActiveListFilter):
|
||||
def __init__(self):
|
||||
self.monitors = {}
|
||||
|
||||
def predicate(self, source) -> bool:
|
||||
return source.isEnabled()
|
||||
|
||||
def monitor(self, source, callback: callable):
|
||||
self.monitors[id(source)] = monitor = SourceIsEnabledListener(callback)
|
||||
source.addClient(monitor)
|
||||
|
||||
def unmonitor(self, source):
|
||||
source.removeClient(self.monitors[id(source)])
|
||||
|
||||
|
||||
class SourceIsNotFailedListener(SdrSourceEventClient):
|
||||
def __init__(self, callback: callable):
|
||||
self.callback = callback
|
||||
|
||||
def onFail(self):
|
||||
self.callback()
|
||||
|
||||
|
||||
class SourceIsNotFailedFilter(ActiveListFilter):
|
||||
def __init__(self):
|
||||
self.monitors = {}
|
||||
|
||||
def predicate(self, source) -> bool:
|
||||
return not source.isFailed()
|
||||
|
||||
def monitor(self, source, callback: callable):
|
||||
self.monitors[id(source)] = monitor = SourceIsNotFailedListener(callback)
|
||||
source.addClient(monitor)
|
||||
|
||||
def unmonitor(self, source):
|
||||
source.removeClient(self.monitors[id(source)])
|
||||
|
||||
|
||||
class SdrService(object):
|
||||
sources = None
|
||||
activeSources = None
|
||||
|
|
@ -128,8 +177,8 @@ class SdrService(object):
|
|||
def getActiveSources():
|
||||
if SdrService.activeSources is None:
|
||||
SdrService.activeSources = SdrService.getAllSources() \
|
||||
.filter(lambda source: source.isEnabled()) \
|
||||
.filter(lambda source: not source.isFailed())
|
||||
.filter(SourceIsEnabledFilter()) \
|
||||
.filter(SourceIsNotFailedFilter())
|
||||
return SdrService.activeSources
|
||||
|
||||
@staticmethod
|
||||
|
|
|
|||
Loading…
Reference in a new issue