make scheduler respond to config changes

This commit is contained in:
Jakob Ketterl 2021-02-25 22:19:05 +01:00
parent d8b3974728
commit 91c4d6f568
3 changed files with 19 additions and 9 deletions

View File

@ -72,8 +72,7 @@ class ServiceHandler(SdrSourceEventClient):
props.filter("center_freq", "samp_rate").wire(self.onFrequencyChange) props.filter("center_freq", "samp_rate").wire(self.onFrequencyChange)
if self.source.isAvailable(): if self.source.isAvailable():
self.scheduleServiceStartup() self.scheduleServiceStartup()
if "schedule" in props or "scheduler" in props: self.scheduler = ServiceScheduler(self.source)
self.scheduler = ServiceScheduler(self.source)
def getClientClass(self) -> SdrClientClass: def getClientClass(self) -> SdrClientClass:
return SdrClientClass.INACTIVE return SdrClientClass.INACTIVE

View File

@ -72,10 +72,7 @@ class DatetimeScheduleEntry(ScheduleEntry):
class Schedule(ABC): class Schedule(ABC):
@staticmethod @staticmethod
def parse(props): def parse(props):
# downwards compatibility if "scheduler" in props:
if "schedule" in props:
return StaticSchedule(props["schedule"])
elif "scheduler" in props:
sc = props["scheduler"] sc = props["scheduler"]
t = sc["type"] if "type" in sc else "static" t = sc["type"] if "type" in sc else "static"
if t == "static": if t == "static":
@ -84,6 +81,9 @@ class Schedule(ABC):
return DaylightSchedule(sc["schedule"]) return DaylightSchedule(sc["schedule"])
else: else:
logger.warning("Invalid scheduler type: %s", t) logger.warning("Invalid scheduler type: %s", t)
# downwards compatibility
elif "schedule" in props:
return StaticSchedule(props["schedule"])
@abstractmethod @abstractmethod
def getCurrentEntry(self): def getCurrentEntry(self):
@ -209,10 +209,15 @@ class ServiceScheduler(SdrSourceEventClient):
def __init__(self, source): def __init__(self, source):
self.source = source self.source = source
self.selectionTimer = None self.selectionTimer = None
self.source.addClient(self) self.schedule = None
props = self.source.getProps()
props.filter("center_freq", "samp_rate").wire(self.onFrequencyChange)
props.wireProperty("scheduler", self.parseSchedule)
self.parseSchedule()
def parseSchedule(self, *args):
props = self.source.getProps() props = self.source.getProps()
self.schedule = Schedule.parse(props) self.schedule = Schedule.parse(props)
props.filter("center_freq", "samp_rate").wire(self.onFrequencyChange)
self.scheduleSelection() self.scheduleSelection()
def shutdown(self): def shutdown(self):
@ -258,12 +263,16 @@ class ServiceScheduler(SdrSourceEventClient):
entry = self.schedule.getCurrentEntry() entry = self.schedule.getCurrentEntry()
if entry is None: if entry is None:
logger.debug("schedule did not return a profile. checking next entry...") logger.debug("schedule did not return a current profile. releasing source...")
self.source.removeClient(self)
logger.debug("checking next (future) entry...")
nextEntry = self.schedule.getNextEntry() nextEntry = self.schedule.getNextEntry()
if nextEntry is not None: if nextEntry is not None:
self.scheduleSelection(nextEntry.getNextActivation()) self.scheduleSelection(nextEntry.getNextActivation())
logger.debug("no next entry available, scheduler standing by for external events.")
return return
self.source.addClient(self)
logger.debug("selected profile %s until %s", entry.getProfile(), entry.getScheduledEnd()) logger.debug("selected profile %s until %s", entry.getProfile(), entry.getScheduledEnd())
self.scheduleSelection(entry.getScheduledEnd()) self.scheduleSelection(entry.getScheduledEnd())

View File

@ -303,6 +303,8 @@ class SdrSource(ABC):
return len(clients) > 0 return len(clients) > 0
def addClient(self, c: SdrSourceEventClient): def addClient(self, c: SdrSourceEventClient):
if c in self.clients:
return
self.clients.append(c) self.clients.append(c)
c.onStateChange(self.getState()) c.onStateChange(self.getState())
hasUsers = self.hasClients(SdrClientClass.USER) hasUsers = self.hasClients(SdrClientClass.USER)