diff options
Diffstat (limited to 'service.py')
-rwxr-xr-x | service.py | 75 |
1 files changed, 68 insertions, 7 deletions
@@ -20,6 +20,16 @@ ALLOW_ONLY_ONE_SESSION = True class RWAService(dbus.service.Object): + """D-Bus Session Service for RWA. + + D-Bus namespace: ``org.ArcticaProject.RWA`` + + D-Bus object name: ``/RWA`` + + :param loop: GLib main loop running the service + :param mockup_mode: Starts the service in mock up mode + """ + def __init__(self, loop, mockup_mode: bool = False): self.loop = loop self.mockup_mode = mockup_mode @@ -34,11 +44,26 @@ class RWAService(dbus.service.Object): self.sessions = {} super().__init__(name, "/RWA") - logging.info("DBus service has been started.") + logging.info("D-Bus service has been started.") @dbus.service.method("org.ArcticaProject.RWA", out_signature="s") - def start(self): - """Start a new remote session.""" + def start(self) -> str: + """Start a new remote session and register it in RWA. + + :return: Result as JSON (D-Bus string) + + **Structure of returned JSON (success):** + + :: + + {"status": "success", "id": <pid>, "url": "<url>", "pin": <pin>} + + **Structure of returned JSON (error):** + + :: + + {"status": "error"} + """ if ALLOW_ONLY_ONE_SESSION and len(self.sessions.values()) > 0: logging.warning( "There is already one session running and the service is configured to allow only one " @@ -64,18 +89,52 @@ class RWAService(dbus.service.Object): @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 the status of a session. + + .. note:: + + This uses the last status version got by the update service in the background. + + :param pid: (Process) ID of session (D-Bus integer) + :return: Session status as JSON (D-Bus string) + + **Structure of returned JSON:** + + :: + + {"id": <pid>, "status": <status>} + + **Possible status options:** + + ============ ====================== + ``running`` The session is running and ready for connecting. + ``active`` The session is running and a the remote connected to the session. + ``stopped`` The session was stopped. + ``dead`` There was a problem, so that the session is dead. + ============ ====================== + """ 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.""" + """Same as :meth:`status`, but updates status from RWA before returning it here. + """ self._update_session(pid) return self._get_status(pid) @dbus.service.method("org.ArcticaProject.RWA", in_signature="i", out_signature="s") def stop(self, pid: int): - """Stop a remote session.""" + """Stop a remote session. + + :param pid: (Process) ID of session (D-Bus integer) + :return: Session status as JSON (D-Bus string) + + **Structure of returned JSON:** + + :: + + {"id": <pid>, "status": "stopped"} + """ try: session = self.sessions[pid] except KeyError: @@ -171,7 +230,9 @@ def str2bool(v: Union[str, bool, int]) -> bool: if __name__ == "__main__": parser = argparse.ArgumentParser( - description="DBus session service for " + "ArcticaProject's " + "Remote Web App" + description="D-Bus session service for " + + "ArcticaProject's " + + "Remote Web App" ) parser.add_argument( "-m", |