explicit typing of the source event interface
This commit is contained in:
		| @@ -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 | ||||
|   | ||||
| @@ -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__() | ||||
|   | ||||
| @@ -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 = [] | ||||
|   | ||||
| @@ -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 | ||||
|   | ||||
| @@ -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: | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Jakob Ketterl
					Jakob Ketterl