diff options
Diffstat (limited to 'service.py')
-rw-r--r-- | service.py | 49 |
1 files changed, 32 insertions, 17 deletions
@@ -31,38 +31,53 @@ class RWAService(dbus.service.Object): return json.dumps(session.client_meta) + @dbus.service.method("org.ArcticaProject.RWA", in_signature="i", out_signature="s") + def status(self, pid: int) -> str: + """Get status information about a service.""" + return self._get_status(pid) + + @dbus.service.method("org.ArcticaProject.RWA", in_signature="i", out_signature="s") + def refresh_status(self, pid: int) -> str: + """Get status information about a service and refresh status before.""" + self._update_session(pid) + return self._get_status(pid) + @dbus.service.method("org.ArcticaProject.RWA", in_signature="i") def stop(self, pid: int): """Stop a remote session.""" session = self.sessions[pid] session.stop() + def _get_status(self, pid: int) -> str: + session = self.sessions[pid] + return json.dumps(session.status) + def _ensure_update_service(self): """Start session update thread if it isn't already running.""" if not self.update_service_running: self.update_thread = Thread(target=self._update_sessions) self.update_thread.start() - def _update_sessions(self): - """Go through all running sessions and update their status. + def _update_session(self, pid: int): + """Update the status of a session.""" + session = self.sessions[pid] + print(f"Session #{session.pid}") - Things that this function will do: - - Check if VNC is still running - - Kill websockify if VNC process is dead - """ - while len(self.sessions.values()) > 0: - for session in list(self.sessions.values()): - print(f"Session #{session.pid}") + # Check if VNC process is still running + running = session.vnc_process_running + if running: + print("Session is running") + else: + print("Session is dead.") - # Check if VNC process is still running - running = session.vnc_process_running - if running: - print("Session is running") - else: - print("Session is dead.") + session.stop() + del self.sessions[session.pid] - session.stop() - del self.sessions[session.pid] + def _update_sessions(self): + """Go through all running sessions and update their status using ``_update_session``.""" + while len(self.sessions.values()) > 0: + for session in list(self.sessions.values()): + self._update_session(session.pid) time.sleep(2) |