implement device shutdown on deletion or lack of profiles
This commit is contained in:
		| @@ -230,6 +230,11 @@ class OpenWebRxReceiverClient(OpenWebRxClient, SdrSourceEventClient): | |||||||
|         self.write_log_message('SDR device "{0}" was disabled, selecting new device'.format(self.sdr.getName())) |         self.write_log_message('SDR device "{0}" was disabled, selecting new device'.format(self.sdr.getName())) | ||||||
|         self.setSdr() |         self.setSdr() | ||||||
|  |  | ||||||
|  |     def onShutdown(self): | ||||||
|  |         logger.warning('SDR device "%s" is shutting down, selecting new device', self.sdr.getName()) | ||||||
|  |         self.write_log_message('SDR device "{0}" is shutting down, selecting new device'.format(self.sdr.getName())) | ||||||
|  |         self.setSdr() | ||||||
|  |  | ||||||
|     def getClientClass(self) -> SdrClientClass: |     def getClientClass(self) -> SdrClientClass: | ||||||
|         return SdrClientClass.USER |         return SdrClientClass.USER | ||||||
|  |  | ||||||
|   | |||||||
| @@ -214,3 +214,6 @@ class DspManager(csdr.output, SdrSourceEventClient): | |||||||
|     def onFail(self): |     def onFail(self): | ||||||
|         logger.debug("received onFail(), shutting down DspSource") |         logger.debug("received onFail(), shutting down DspSource") | ||||||
|         self.dsp.stop() |         self.dsp.stop() | ||||||
|  |  | ||||||
|  |     def onShutdown(self): | ||||||
|  |         self.dsp.stop() | ||||||
|   | |||||||
| @@ -84,3 +84,6 @@ class SpectrumThread(csdr.output, SdrSourceEventClient): | |||||||
|  |  | ||||||
|     def onFail(self): |     def onFail(self): | ||||||
|         self.dsp.stop() |         self.dsp.stop() | ||||||
|  |  | ||||||
|  |     def onShutdown(self): | ||||||
|  |         self.dsp.stop() | ||||||
|   | |||||||
							
								
								
									
										25
									
								
								owrx/sdr.py
									
									
									
									
									
								
							
							
						
						
									
										25
									
								
								owrx/sdr.py
									
									
									
									
									
								
							| @@ -27,7 +27,7 @@ class MappedSdrSources(PropertyDelegator): | |||||||
|         if self.isDeviceValid(value) and key not in self: |         if self.isDeviceValid(value) and key not in self: | ||||||
|             self._addSource(key, value) |             self._addSource(key, value) | ||||||
|         elif not self.isDeviceValid(value) and key in self: |         elif not self.isDeviceValid(value) and key in self: | ||||||
|             self._removeSource(key) |             del self[key] | ||||||
|  |  | ||||||
|     def _addSource(self, key, value): |     def _addSource(self, key, value): | ||||||
|         if self.isDeviceValid(value): |         if self.isDeviceValid(value): | ||||||
| @@ -38,13 +38,6 @@ class MappedSdrSources(PropertyDelegator): | |||||||
|             value["profiles"].wire(updateMethod) |             value["profiles"].wire(updateMethod) | ||||||
|         ] |         ] | ||||||
|  |  | ||||||
|     def _removeSource(self, key): |  | ||||||
|         if key in self: |  | ||||||
|             self[key].stop() |  | ||||||
|         for sub in self.subscriptions[key]: |  | ||||||
|             sub.cancel() |  | ||||||
|         del self.subscriptions[key] |  | ||||||
|  |  | ||||||
|     def isDeviceValid(self, device): |     def isDeviceValid(self, device): | ||||||
|         return self._hasProfiles(device) and self._sdrTypeAvailable(device) |         return self._hasProfiles(device) and self._sdrTypeAvailable(device) | ||||||
|  |  | ||||||
| @@ -75,15 +68,23 @@ class MappedSdrSources(PropertyDelegator): | |||||||
|         cls = getattr(module, className) |         cls = getattr(module, className) | ||||||
|         return cls(id, props) |         return cls(id, props) | ||||||
|  |  | ||||||
|  |     def _removeSource(self, key, source): | ||||||
|  |         source.shutdown() | ||||||
|  |         for sub in self.subscriptions[key]: | ||||||
|  |             sub.cancel() | ||||||
|  |         del self.subscriptions[key] | ||||||
|  |  | ||||||
|     def __setitem__(self, key, value): |     def __setitem__(self, key, value): | ||||||
|         if key in self: |         source = self[key] if key in self else None | ||||||
|             self._removeSource(key) |  | ||||||
|         super().__setitem__(key, value) |         super().__setitem__(key, value) | ||||||
|  |         if source is not None: | ||||||
|  |             self._removeSource(key, source) | ||||||
|  |  | ||||||
|     def __delitem__(self, key): |     def __delitem__(self, key): | ||||||
|         if key in self: |         source = self[key] if key in self else None | ||||||
|             self._removeSource(key) |  | ||||||
|         super().__delitem__(key) |         super().__delitem__(key) | ||||||
|  |         if source is not None: | ||||||
|  |             self._removeSource(key, source) | ||||||
|  |  | ||||||
|  |  | ||||||
| class SdrService(object): | class SdrService(object): | ||||||
|   | |||||||
| @@ -122,6 +122,10 @@ class ServiceHandler(SdrSourceEventClient): | |||||||
|         logger.debug("sdr source failed; stopping services.") |         logger.debug("sdr source failed; stopping services.") | ||||||
|         self.stopServices() |         self.stopServices() | ||||||
|  |  | ||||||
|  |     def onShutdown(self): | ||||||
|  |         logger.debug("sdr source is shutting down; shutting down service handler, too.") | ||||||
|  |         self.shutdown() | ||||||
|  |  | ||||||
|     def onEnable(self): |     def onEnable(self): | ||||||
|         self._scheduleServiceStartup() |         self._scheduleServiceStartup() | ||||||
|  |  | ||||||
|   | |||||||
| @@ -258,6 +258,9 @@ class ServiceScheduler(SdrSourceEventClient): | |||||||
|     def onFail(self): |     def onFail(self): | ||||||
|         self.shutdown() |         self.shutdown() | ||||||
|  |  | ||||||
|  |     def onShutdown(self): | ||||||
|  |         self.shutdown() | ||||||
|  |  | ||||||
|     def onDisable(self): |     def onDisable(self): | ||||||
|         self.cancelTimer() |         self.cancelTimer() | ||||||
|  |  | ||||||
|   | |||||||
| @@ -56,6 +56,9 @@ class SdrSourceEventClient(object): | |||||||
|     def onFail(self): |     def onFail(self): | ||||||
|         pass |         pass | ||||||
|  |  | ||||||
|  |     def onShutdown(self): | ||||||
|  |         pass | ||||||
|  |  | ||||||
|     def onDisable(self): |     def onDisable(self): | ||||||
|         pass |         pass | ||||||
|  |  | ||||||
| @@ -349,6 +352,11 @@ class SdrSource(ABC): | |||||||
|             if self.monitor: |             if self.monitor: | ||||||
|                 self.monitor.join() |                 self.monitor.join() | ||||||
|  |  | ||||||
|  |     def shutdown(self): | ||||||
|  |         self.stop() | ||||||
|  |         for c in self.clients.copy(): | ||||||
|  |             c.onShutdown() | ||||||
|  |  | ||||||
|     def getClients(self, *args): |     def getClients(self, *args): | ||||||
|         if not args: |         if not args: | ||||||
|             return self.clients |             return self.clients | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Jakob Ketterl
					Jakob Ketterl