diff --git a/owrx/dsp.py b/owrx/dsp.py index eabe244..b268c6a 100644 --- a/owrx/dsp.py +++ b/owrx/dsp.py @@ -3,7 +3,7 @@ from owrx.wsjt import WsjtParser from owrx.js8 import Js8Parser from owrx.aprs import AprsParser from owrx.pocsag import PocsagParser -from owrx.source import SdrSource +from owrx.source import SdrSource, SdrSourceEventClient from owrx.property import PropertyStack, PropertyLayer from owrx.modes import Modes from csdr import csdr @@ -14,7 +14,7 @@ import logging logger = logging.getLogger(__name__) -class DspManager(csdr.output): +class DspManager(csdr.output, SdrSourceEventClient): def __init__(self, handler, sdrSource): self.handler = handler self.sdrSource = sdrSource diff --git a/owrx/fft.py b/owrx/fft.py index cbb98a6..717c086 100644 --- a/owrx/fft.py +++ b/owrx/fft.py @@ -1,7 +1,7 @@ from owrx.config import Config from csdr import csdr import threading -from owrx.source import SdrSource +from owrx.source import SdrSource, SdrSourceEventClient from owrx.property import PropertyStack import logging @@ -9,7 +9,7 @@ import logging logger = logging.getLogger(__name__) -class SpectrumThread(csdr.output): +class SpectrumThread(csdr.output, SdrSourceEventClient): def __init__(self, sdrSource): self.sdrSource = sdrSource super().__init__() diff --git a/owrx/service/__init__.py b/owrx/service/__init__.py index a8e60d8..98cf557 100644 --- a/owrx/service/__init__.py +++ b/owrx/service/__init__.py @@ -1,5 +1,5 @@ import threading -from owrx.source import SdrSource +from owrx.source import SdrSource, SdrSourceEventClient from owrx.sdr import SdrService from owrx.bands import Bandplan from csdr.csdr import dsp, output @@ -59,7 +59,7 @@ class Js8ServiceOutput(ServiceOutput): return t == "js8_demod" -class ServiceHandler(object): +class ServiceHandler(SdrSourceEventClient): def __init__(self, source): self.lock = threading.RLock() self.services = [] diff --git a/owrx/service/schedule.py b/owrx/service/schedule.py index 992757e..8cf4261 100644 --- a/owrx/service/schedule.py +++ b/owrx/service/schedule.py @@ -1,5 +1,5 @@ from datetime import datetime, timezone, timedelta -from owrx.source import SdrSource +from owrx.source import SdrSource, SdrSourceEventClient from owrx.config import Config import threading import math @@ -204,7 +204,7 @@ class DaylightSchedule(TimerangeSchedule): return entries -class ServiceScheduler(object): +class ServiceScheduler(SdrSourceEventClient): def __init__(self, source): self.source = source self.selectionTimer = None diff --git a/owrx/source/__init__.py b/owrx/source/__init__.py index fcb176f..defda6a 100644 --- a/owrx/source/__init__.py +++ b/owrx/source/__init__.py @@ -16,6 +16,19 @@ import logging logger = logging.getLogger(__name__) +class SdrSourceEventClient(ABC): + @abstractmethod + def onStateChange(self, state): + pass + + @abstractmethod + def onBusyStateChange(self, state): + pass + + def getClientClass(self): + return SdrSource.CLIENT_INACTIVE + + class SdrSource(ABC): STATE_STOPPED = 0 STATE_STARTING = 1 @@ -238,7 +251,7 @@ class SdrSource(ABC): clients = [c for c in self.clients if c.getClientClass() in args] return len(clients) > 0 - def addClient(self, c): + def addClient(self, c: SdrSourceEventClient): self.clients.append(c) hasUsers = self.hasClients(SdrSource.CLIENT_USER) hasBackgroundTasks = self.hasClients(SdrSource.CLIENT_BACKGROUND) @@ -246,7 +259,7 @@ class SdrSource(ABC): self.start() self.setBusyState(SdrSource.BUSYSTATE_BUSY if hasUsers else SdrSource.BUSYSTATE_IDLE) - def removeClient(self, c): + def removeClient(self, c: SdrSourceEventClient): try: self.clients.remove(c) except ValueError: