introduce enums for state management
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
import threading
|
||||
from owrx.source import SdrSource, SdrSourceEventClient
|
||||
from owrx.source import SdrSourceEventClient, SdrSourceState, SdrBusyState, SdrClientClass
|
||||
from owrx.sdr import SdrService
|
||||
from owrx.bands import Bandplan
|
||||
from csdr.csdr import dsp, output
|
||||
@ -75,22 +75,22 @@ class ServiceHandler(SdrSourceEventClient):
|
||||
if "schedule" in props or "scheduler" in props:
|
||||
self.scheduler = ServiceScheduler(self.source)
|
||||
|
||||
def getClientClass(self):
|
||||
return SdrSource.CLIENT_INACTIVE
|
||||
def getClientClass(self) -> SdrClientClass:
|
||||
return SdrClientClass.INACTIVE
|
||||
|
||||
def onStateChange(self, state):
|
||||
if state == SdrSource.STATE_RUNNING:
|
||||
def onStateChange(self, state: SdrSourceState):
|
||||
if state is SdrSourceState.RUNNING:
|
||||
self.scheduleServiceStartup()
|
||||
elif state == SdrSource.STATE_STOPPING:
|
||||
elif state is SdrSourceState.STOPPING:
|
||||
logger.debug("sdr source becoming unavailable; stopping services.")
|
||||
self.stopServices()
|
||||
elif state == SdrSource.STATE_FAILED:
|
||||
elif state is SdrSourceState.FAILED:
|
||||
logger.debug("sdr source failed; stopping services.")
|
||||
self.stopServices()
|
||||
if self.scheduler:
|
||||
self.scheduler.shutdown()
|
||||
|
||||
def onBusyStateChange(self, state):
|
||||
def onBusyStateChange(self, state: SdrBusyState):
|
||||
pass
|
||||
|
||||
def isSupported(self, mode):
|
||||
@ -164,7 +164,8 @@ class ServiceHandler(SdrSourceEventClient):
|
||||
for dial in group:
|
||||
self.services.append(self.setupService(dial["mode"], dial["frequency"], resampler))
|
||||
|
||||
# resampler goes in after the services since it must not be shutdown as long as the services are still running
|
||||
# resampler goes in after the services since it must not be shutdown as long as the services are
|
||||
# still running
|
||||
self.services.append(resampler)
|
||||
|
||||
def get_min_max(self, group):
|
||||
|
@ -1,5 +1,5 @@
|
||||
from datetime import datetime, timezone, timedelta
|
||||
from owrx.source import SdrSource, SdrSourceEventClient
|
||||
from owrx.source import SdrSourceEventClient, SdrSourceState, SdrClientClass, SdrBusyState
|
||||
from owrx.config import Config
|
||||
import threading
|
||||
import math
|
||||
@ -220,7 +220,7 @@ class ServiceScheduler(SdrSourceEventClient):
|
||||
self.source.removeClient(self)
|
||||
|
||||
def scheduleSelection(self, time=None):
|
||||
if self.source.getState() == SdrSource.STATE_FAILED:
|
||||
if self.source.getState() is SdrSourceState.FAILED:
|
||||
return
|
||||
seconds = 10
|
||||
if time is not None:
|
||||
@ -234,24 +234,24 @@ class ServiceScheduler(SdrSourceEventClient):
|
||||
if self.selectionTimer:
|
||||
self.selectionTimer.cancel()
|
||||
|
||||
def getClientClass(self):
|
||||
return SdrSource.CLIENT_BACKGROUND
|
||||
def getClientClass(self) -> SdrClientClass:
|
||||
return SdrClientClass.BACKGROUND
|
||||
|
||||
def onStateChange(self, state):
|
||||
if state == SdrSource.STATE_STOPPING:
|
||||
def onStateChange(self, state: SdrSourceState):
|
||||
if state is SdrSourceState.STOPPING:
|
||||
self.scheduleSelection()
|
||||
elif state == SdrSource.STATE_FAILED:
|
||||
elif state is SdrSourceState.FAILED:
|
||||
self.cancelTimer()
|
||||
|
||||
def onBusyStateChange(self, state):
|
||||
if state == SdrSource.BUSYSTATE_IDLE:
|
||||
def onBusyStateChange(self, state: SdrBusyState):
|
||||
if state is SdrBusyState.IDLE:
|
||||
self.scheduleSelection()
|
||||
|
||||
def onFrequencyChange(self, changes):
|
||||
self.scheduleSelection()
|
||||
|
||||
def selectProfile(self):
|
||||
if self.source.hasClients(SdrSource.CLIENT_USER):
|
||||
if self.source.hasClients(SdrClientClass.USER):
|
||||
logger.debug("source has active users; not touching")
|
||||
return
|
||||
logger.debug("source seems to be idle, selecting profile for background services")
|
||||
|
Reference in New Issue
Block a user