explicit typing of the source event interface

This commit is contained in:
Jakob Ketterl 2020-08-30 23:47:04 +02:00
parent 805039ec02
commit 9be0664e14
5 changed files with 23 additions and 10 deletions

View File

@ -3,7 +3,7 @@ from owrx.wsjt import WsjtParser
from owrx.js8 import Js8Parser from owrx.js8 import Js8Parser
from owrx.aprs import AprsParser from owrx.aprs import AprsParser
from owrx.pocsag import PocsagParser from owrx.pocsag import PocsagParser
from owrx.source import SdrSource from owrx.source import SdrSource, SdrSourceEventClient
from owrx.property import PropertyStack, PropertyLayer from owrx.property import PropertyStack, PropertyLayer
from owrx.modes import Modes from owrx.modes import Modes
from csdr import csdr from csdr import csdr
@ -14,7 +14,7 @@ import logging
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
class DspManager(csdr.output): class DspManager(csdr.output, SdrSourceEventClient):
def __init__(self, handler, sdrSource): def __init__(self, handler, sdrSource):
self.handler = handler self.handler = handler
self.sdrSource = sdrSource self.sdrSource = sdrSource

View File

@ -1,7 +1,7 @@
from owrx.config import Config from owrx.config import Config
from csdr import csdr from csdr import csdr
import threading import threading
from owrx.source import SdrSource from owrx.source import SdrSource, SdrSourceEventClient
from owrx.property import PropertyStack from owrx.property import PropertyStack
import logging import logging
@ -9,7 +9,7 @@ import logging
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
class SpectrumThread(csdr.output): class SpectrumThread(csdr.output, SdrSourceEventClient):
def __init__(self, sdrSource): def __init__(self, sdrSource):
self.sdrSource = sdrSource self.sdrSource = sdrSource
super().__init__() super().__init__()

View File

@ -1,5 +1,5 @@
import threading import threading
from owrx.source import SdrSource from owrx.source import SdrSource, SdrSourceEventClient
from owrx.sdr import SdrService from owrx.sdr import SdrService
from owrx.bands import Bandplan from owrx.bands import Bandplan
from csdr.csdr import dsp, output from csdr.csdr import dsp, output
@ -59,7 +59,7 @@ class Js8ServiceOutput(ServiceOutput):
return t == "js8_demod" return t == "js8_demod"
class ServiceHandler(object): class ServiceHandler(SdrSourceEventClient):
def __init__(self, source): def __init__(self, source):
self.lock = threading.RLock() self.lock = threading.RLock()
self.services = [] self.services = []

View File

@ -1,5 +1,5 @@
from datetime import datetime, timezone, timedelta from datetime import datetime, timezone, timedelta
from owrx.source import SdrSource from owrx.source import SdrSource, SdrSourceEventClient
from owrx.config import Config from owrx.config import Config
import threading import threading
import math import math
@ -204,7 +204,7 @@ class DaylightSchedule(TimerangeSchedule):
return entries return entries
class ServiceScheduler(object): class ServiceScheduler(SdrSourceEventClient):
def __init__(self, source): def __init__(self, source):
self.source = source self.source = source
self.selectionTimer = None self.selectionTimer = None

View File

@ -16,6 +16,19 @@ import logging
logger = logging.getLogger(__name__) 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): class SdrSource(ABC):
STATE_STOPPED = 0 STATE_STOPPED = 0
STATE_STARTING = 1 STATE_STARTING = 1
@ -238,7 +251,7 @@ class SdrSource(ABC):
clients = [c for c in self.clients if c.getClientClass() in args] clients = [c for c in self.clients if c.getClientClass() in args]
return len(clients) > 0 return len(clients) > 0
def addClient(self, c): def addClient(self, c: SdrSourceEventClient):
self.clients.append(c) self.clients.append(c)
hasUsers = self.hasClients(SdrSource.CLIENT_USER) hasUsers = self.hasClients(SdrSource.CLIENT_USER)
hasBackgroundTasks = self.hasClients(SdrSource.CLIENT_BACKGROUND) hasBackgroundTasks = self.hasClients(SdrSource.CLIENT_BACKGROUND)
@ -246,7 +259,7 @@ class SdrSource(ABC):
self.start() self.start()
self.setBusyState(SdrSource.BUSYSTATE_BUSY if hasUsers else SdrSource.BUSYSTATE_IDLE) self.setBusyState(SdrSource.BUSYSTATE_BUSY if hasUsers else SdrSource.BUSYSTATE_IDLE)
def removeClient(self, c): def removeClient(self, c: SdrSourceEventClient):
try: try:
self.clients.remove(c) self.clients.remove(c)
except ValueError: except ValueError: