refactor state handling: uncouple failed and enabled flags

This commit is contained in:
Jakob Ketterl
2021-03-18 19:34:53 +01:00
parent 916f19ac60
commit b25a673829
7 changed files with 66 additions and 43 deletions

View File

@ -1,5 +1,5 @@
import threading
from owrx.source import SdrSourceEventClient, SdrSourceState, SdrBusyState, SdrClientClass
from owrx.source import SdrSourceEventClient, SdrSourceState, SdrClientClass
from owrx.sdr import SdrService
from owrx.bands import Bandplan
from csdr.csdr import dsp, output
@ -117,12 +117,10 @@ class ServiceHandler(SdrSourceEventClient):
elif state is SdrSourceState.STOPPING:
logger.debug("sdr source becoming unavailable; stopping services.")
self.stopServices()
elif state is SdrSourceState.FAILED:
logger.debug("sdr source failed; stopping services.")
self.stopServices()
def onBusyStateChange(self, state: SdrBusyState):
pass
def onFail(self):
logger.debug("sdr source failed; stopping services.")
self.stopServices()
def isSupported(self, mode):
configured = Config.get()["services_decoders"]

View File

@ -231,7 +231,7 @@ class ServiceScheduler(SdrSourceEventClient):
self.source.removeClient(self)
def scheduleSelection(self, time=None):
if self.source.getState() is SdrSourceState.FAILED:
if self.source.isFailed():
return
seconds = 10
if time is not None:
@ -254,8 +254,9 @@ class ServiceScheduler(SdrSourceEventClient):
def onStateChange(self, state: SdrSourceState):
if state is SdrSourceState.STOPPING:
self.scheduleSelection()
elif state is SdrSourceState.FAILED:
self.shutdown()
def onFail(self):
self.shutdown()
def onBusyStateChange(self, state: SdrBusyState):
if state is SdrBusyState.IDLE: