| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
from __future__ import annotations |
| 21 |
|
| 22 |
from typing import Optional |
| 23 |
|
| 24 |
from sdbus import DbusInterfaceCommon, SdBus, dbus_method, dbus_property |
| 25 |
|
| 26 |
|
| 27 |
class FreedesktopDbus(DbusInterfaceCommon, |
| 28 |
interface_name='org.freedesktop.DBus'): |
| 29 |
"""D-Bus daemon.""" |
| 30 |
|
| 31 |
def __init__(self, bus: Optional[SdBus] = None): |
| 32 |
"""This is the D-Bus daemon interface. Used for querying D-Bus state. |
| 33 |
|
| 34 |
D-Bus interface object path and service name is |
| 35 |
predetermined. |
| 36 |
(at ``'org.freedesktop.DBus'``, ``'/org/freedesktop/DBus'``) |
| 37 |
|
| 38 |
:param SdBus bus: |
| 39 |
Optional D-Bus connection. |
| 40 |
If not passed the default D-Bus will be used. |
| 41 |
""" |
| 42 |
super().__init__( |
| 43 |
'org.freedesktop.DBus', |
| 44 |
'/org/freedesktop/DBus', |
| 45 |
bus, |
| 46 |
) |
| 47 |
|
| 48 |
@dbus_method('s', method_name='GetConnectionUnixProcessID') |
| 49 |
def get_connection_pid(self, service_name: str) -> int: |
| 50 |
"""Get process ID that owns a specified name. |
| 51 |
|
| 52 |
:param str service_name: Service name to query. |
| 53 |
:return: PID of name owner |
| 54 |
:raises DbusNameHasNoOwnerError: Nobody owns that name |
| 55 |
""" |
| 56 |
raise NotImplementedError |
| 57 |
|
| 58 |
@dbus_method('s', method_name='GetConnectionUnixUser') |
| 59 |
def get_connection_uid(self, service_name: str) -> int: |
| 60 |
"""Get process user ID that owns a specified name. |
| 61 |
|
| 62 |
:param str service_name: Service name to query. |
| 63 |
:return: User ID of name owner |
| 64 |
:raises DbusNameHasNoOwnerError: Nobody owns that name |
| 65 |
""" |
| 66 |
raise NotImplementedError |
| 67 |
|
| 68 |
@dbus_method() |
| 69 |
def get_id(self) -> str: |
| 70 |
"""Returns machine id where bus is run. (stored in ``/etc/machine-id``) |
| 71 |
|
| 72 |
:return: Machine id |
| 73 |
""" |
| 74 |
raise NotImplementedError |
| 75 |
|
| 76 |
@dbus_method('s') |
| 77 |
def get_name_owner(self, service_name: str) -> str: |
| 78 |
"""Returns unique bus name (i.e. ``':1.94'``) for given service name. |
| 79 |
|
| 80 |
:param str service_name: Service name to query. |
| 81 |
:return: Unique bus name. |
| 82 |
:raises DbusNameHasNoOwnerError: Nobody owns that name |
| 83 |
""" |
| 84 |
raise NotImplementedError |
| 85 |
|
| 86 |
@dbus_method() |
| 87 |
def list_activatable_names(self) -> list[str]: |
| 88 |
"""Lists all activatable services names. |
| 89 |
|
| 90 |
:return: List of all names. |
| 91 |
""" |
| 92 |
raise NotImplementedError |
| 93 |
|
| 94 |
@dbus_method() |
| 95 |
def list_names(self) -> list[str]: |
| 96 |
"""List all services and connections currently of the bus. |
| 97 |
|
| 98 |
:return: List of all current names. |
| 99 |
""" |
| 100 |
raise NotImplementedError |
| 101 |
|
| 102 |
@dbus_method('s') |
| 103 |
def name_has_owner(self, service_name: str) -> bool: |
| 104 |
"""Return True if someone already owns the name, False if nobody does. |
| 105 |
|
| 106 |
:param str service_name: Service name to query. |
| 107 |
:return: Is the name owned? |
| 108 |
""" |
| 109 |
raise NotImplementedError |
| 110 |
|
| 111 |
@dbus_method('su') |
| 112 |
def start_service_by_name( |
| 113 |
self, |
| 114 |
service_name: str, |
| 115 |
flags: int = 0) -> int: |
| 116 |
"""Starts a specified service. |
| 117 |
|
| 118 |
Flags parameter is not used currently and should be |
| 119 |
omitted or set to 0. |
| 120 |
|
| 121 |
:param str service_name: Service name to start. |
| 122 |
:param int flags: Not used. Omit or pass 0. |
| 123 |
:return: 1 on success, 2 if already started. |
| 124 |
""" |
| 125 |
raise NotImplementedError |
| 126 |
|
| 127 |
@dbus_property('as') |
| 128 |
def features(self) -> list[str]: |
| 129 |
"""List of D-Bus daemon features. |
| 130 |
|
| 131 |
Features include: |
| 132 |
|
| 133 |
* 'AppArmor' - Messages filtered by AppArmor on this bus. |
| 134 |
* 'HeaderFiltering' - Messages are filtered if they have incorrect \ |
| 135 |
header fields. |
| 136 |
* 'SELinux' - Messages filtered by SELinux on this bus. |
| 137 |
* 'SystemdActivation' - services activated by systemd if their \ |
| 138 |
.service file specifies a D-Bus name. |
| 139 |
""" |
| 140 |
raise NotImplementedError |
| 141 |
|
| 142 |
@dbus_property('as') |
| 143 |
def interfaces(self) -> list[str]: |
| 144 |
"""Extra D-Bus daemon interfaces""" |
| 145 |
raise NotImplementedError |