wire "services_enabled" setting

This commit is contained in:
Jakob Ketterl 2021-02-26 17:53:06 +01:00
parent 6822475674
commit 0231d98ab8

View File

@ -69,7 +69,7 @@ class ServiceHandler(SdrSourceEventClient):
self.scheduler = None self.scheduler = None
self.source.addClient(self) self.source.addClient(self)
props = self.source.getProps() props = self.source.getProps()
props.filter("center_freq", "samp_rate").wire(self.onFrequencyChange) self.subscriptions = [props.filter("center_freq", "samp_rate").wire(self.onFrequencyChange)]
if self.source.isAvailable(): if self.source.isAvailable():
self.scheduleServiceStartup() self.scheduleServiceStartup()
self.scheduler = ServiceScheduler(self.source) self.scheduler = ServiceScheduler(self.source)
@ -98,6 +98,8 @@ class ServiceHandler(SdrSourceEventClient):
return mode in configured and mode in available return mode in configured and mode in available
def shutdown(self): def shutdown(self):
while self.subscriptions:
self.subscriptions.pop().cancel()
self.stopServices() self.stopServices()
self.source.removeClient(self) self.source.removeClient(self)
if self.scheduler: if self.scheduler:
@ -282,15 +284,20 @@ class Services(object):
@staticmethod @staticmethod
def start(): def start():
if not Config.get()["services_enabled"]: config = Config.get()
return config.wireProperty("services_enabled", Services._receiveEvent)
for source in SdrService.getSources().values():
props = source.getProps() @staticmethod
if "services" not in props or props["services"] is not False: def _receiveEvent(state):
Services.handlers.append(ServiceHandler(source)) if state:
for source in SdrService.getSources().values():
props = source.getProps()
if "services" not in props or props["services"] is not False:
Services.handlers.append(ServiceHandler(source))
else:
Services.stop()
@staticmethod @staticmethod
def stop(): def stop():
for handler in Services.handlers: while Services.handlers:
handler.shutdown() Services.handlers.pop().shutdown()
Services.handlers = []