refactor(dbus): Parameterize picontrol_device and config_rsc

Replaced hardcoded paths with configurable parameters `picontrol_device`
and `config_rsc` across multiple classes. This improves flexibility,
making the components adaptable to various environments or setups.
Updated corresponding initialization and method implementations to use
these parameters.
This commit is contained in:
2025-04-19 08:21:24 +02:00
parent 4c1dc1c9b5
commit a4ccb9081f
3 changed files with 17 additions and 9 deletions

View File

@@ -16,19 +16,26 @@ log = getLogger(__name__)
class BusProvider(Thread): class BusProvider(Thread):
def __init__(self): def __init__(
self,
picontrol_device="/dev/piControl0",
config_rsc="/etc/revpi/config.rsc",
):
log.debug("enter BusProvider.__init__") log.debug("enter BusProvider.__init__")
super().__init__() super().__init__()
self._bus = SystemBus() self._bus = SystemBus()
self._loop = GLib.MainLoop() self._loop = GLib.MainLoop()
self.picontrol_device = picontrol_device
self.config_rsc = config_rsc
def run(self): def run(self):
log.debug("enter BusProvider.run") log.debug("enter BusProvider.run")
self._bus.publish( self._bus.publish(
REVPI_DBUS_NAME, REVPI_DBUS_NAME,
InterfacePiControl(), InterfacePiControl(self.picontrol_device, self.config_rsc),
) )
self._loop.run() self._loop.run()

View File

@@ -27,10 +27,11 @@ class InterfacePiControl:
NotifyDriverReset = signal() NotifyDriverReset = signal()
def __init__(self): def __init__(self, picontrol_device: str, config_rsc: str):
self.pi_control = "/dev/piControl0" self.picontrol_device = picontrol_device
self.config_rsc = config_rsc
self.wd_reset_driver = ResetDriverWatchdog(self.pi_control) self.wd_reset_driver = ResetDriverWatchdog(self.picontrol_device)
self.wd_reset_driver.register_call(self.notify_reset_driver) self.wd_reset_driver.register_call(self.notify_reset_driver)
def notify_reset_driver(self): def notify_reset_driver(self):
@@ -40,9 +41,9 @@ class InterfacePiControl:
log.debug("enter InterfacePiControl.ResetDriver") log.debug("enter InterfacePiControl.ResetDriver")
try: try:
fd = os.open(self.pi_control, os.O_WRONLY) fd = os.open(self.picontrol_device, os.O_WRONLY)
except Exception as e: except Exception as e:
log.warning(f"could not open ${self.pi_control} to reset driver") log.warning(f"could not open ${self.picontrol_device} to reset driver")
raise e raise e
execption = None execption = None

View File

@@ -18,9 +18,9 @@ log = getLogger(__name__)
class ResetDriverWatchdog(Thread): class ResetDriverWatchdog(Thread):
"""Watchdog to catch the reset_driver action.""" """Watchdog to catch the reset_driver action."""
def __init__(self, pi_control_device="/dev/piControl0"): def __init__(self, picontrol_device: str):
super(ResetDriverWatchdog, self).__init__() super(ResetDriverWatchdog, self).__init__()
self.procimg = pi_control_device self.procimg = picontrol_device
self.daemon = True self.daemon = True
self._calls = [] self._calls = []
self._exit = False self._exit = False