| 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 ( |
| 25 |
DbusInterfaceCommonAsync, |
| 26 |
SdBus, |
| 27 |
dbus_method_async, |
| 28 |
dbus_property_async, |
| 29 |
dbus_signal_async, |
| 30 |
) |
| 31 |
|
| 32 |
|
| 33 |
class FreedesktopDbus(DbusInterfaceCommonAsync, |
| 34 |
interface_name='org.freedesktop.DBus'): |
| 35 |
"""D-Bus daemon.""" |
| 36 |
|
| 37 |
def __init__(self, bus: Optional[SdBus] = None): |
| 38 |
"""This is the D-Bus daemon interface. Used for querying D-Bus state. |
| 39 |
|
| 40 |
D-Bus interface object path and service name is |
| 41 |
predetermined. |
| 42 |
(at ``'org.freedesktop.DBus'``, ``'/org/freedesktop/DBus'``) |
| 43 |
|
| 44 |
:param SdBus bus: |
| 45 |
Optional D-Bus connection. |
| 46 |
If not passed the default D-Bus will be used. |
| 47 |
""" |
| 48 |
super().__init__() |
| 49 |
self._proxify( |
| 50 |
'org.freedesktop.DBus', |
| 51 |
'/org/freedesktop/DBus', |
| 52 |
bus, |
| 53 |
) |
| 54 |
|
| 55 |
@dbus_method_async('s', method_name='GetConnectionUnixProcessID') |
| 56 |
async def get_connection_pid(self, service_name: str) -> int: |
| 57 |
"""Get process ID that owns a specified name. |
| 58 |
|
| 59 |
:param str service_name: Service name to query. |
| 60 |
:return: PID of name owner |
| 61 |
:raises DbusNameHasNoOwnerError: Nobody owns that name |
| 62 |
""" |
| 63 |
raise NotImplementedError |
| 64 |
|
| 65 |
@dbus_method_async('s', method_name='GetConnectionUnixUser') |
| 66 |
async def get_connection_uid(self, service_name: str) -> int: |
| 67 |
"""Get process user ID that owns a specified name. |
| 68 |
|
| 69 |
:param str service_name: Service name to query. |
| 70 |
:return: User ID of name owner |
| 71 |
:raises DbusNameHasNoOwnerError: Nobody owns that name |
| 72 |
""" |
| 73 |
raise NotImplementedError |
| 74 |
|
| 75 |
@dbus_method_async() |
| 76 |
async def get_id(self) -> str: |
| 77 |
"""Returns machine id where bus is run. (stored in ``/etc/machine-id``) |
| 78 |
|
| 79 |
:return: Machine id |
| 80 |
""" |
| 81 |
raise NotImplementedError |
| 82 |
|
| 83 |
@dbus_method_async('s') |
| 84 |
async def get_name_owner(self, service_name: str) -> str: |
| 85 |
"""Returns unique bus name (i.e. ``':1.94'``) for given service name. |
| 86 |
|
| 87 |
:param str service_name: Service name to query. |
| 88 |
:return: Unique bus name. |
| 89 |
:raises DbusNameHasNoOwnerError: Nobody owns that name |
| 90 |
""" |
| 91 |
raise NotImplementedError |
| 92 |
|
| 93 |
@dbus_method_async() |
| 94 |
async def list_activatable_names(self) -> list[str]: |
| 95 |
"""Lists all activatable services names. |
| 96 |
|
| 97 |
:return: List of all names. |
| 98 |
""" |
| 99 |
raise NotImplementedError |
| 100 |
|
| 101 |
@dbus_method_async() |
| 102 |
async def list_names(self) -> list[str]: |
| 103 |
"""List all services and connections currently of the bus. |
| 104 |
|
| 105 |
:return: List of all current names. |
| 106 |
""" |
| 107 |
raise NotImplementedError |
| 108 |
|
| 109 |
@dbus_method_async('s') |
| 110 |
async def name_has_owner(self, service_name: str) -> bool: |
| 111 |
""" |
| 112 |
Return True if someone already owns the name, |
| 113 |
False if nobody does. |
| 114 |
|
| 115 |
:param str service_name: Service name to query. |
| 116 |
:return: Is the name owned? |
| 117 |
""" |
| 118 |
raise NotImplementedError |
| 119 |
|
| 120 |
@dbus_method_async('su') |
| 121 |
async def start_service_by_name( |
| 122 |
self, |
| 123 |
service_name: str, |
| 124 |
flags: int = 0) -> int: |
| 125 |
"""Starts a specified service. |
| 126 |
|
| 127 |
Flags parameter is not used currently and should be |
| 128 |
omitted or set to 0. |
| 129 |
|
| 130 |
:param str service_name: Service name to start. |
| 131 |
:param int flags: Not used. Omit or pass 0. |
| 132 |
:return: 1 on success, 2 if already started. |
| 133 |
""" |
| 134 |
raise NotImplementedError |
| 135 |
|
| 136 |
@dbus_property_async('as') |
| 137 |
def features(self) -> list[str]: |
| 138 |
"""List of D-Bus daemon features. |
| 139 |
|
| 140 |
Features include: |
| 141 |
|
| 142 |
* 'AppArmor' - Messages filtered by AppArmor on this bus. |
| 143 |
* 'HeaderFiltering' - Messages are filtered if they have incorrect \ |
| 144 |
header fields. |
| 145 |
* 'SELinux' - Messages filtered by SELinux on this bus. |
| 146 |
* 'SystemdActivation' - services activated by systemd if their \ |
| 147 |
.service file specifies a D-Bus name. |
| 148 |
""" |
| 149 |
raise NotImplementedError |
| 150 |
|
| 151 |
@dbus_property_async('as') |
| 152 |
def interfaces(self) -> list[str]: |
| 153 |
"""Extra D-Bus daemon interfaces""" |
| 154 |
raise NotImplementedError |
| 155 |
|
| 156 |
@dbus_signal_async('s') |
| 157 |
def name_acquired(self) -> str: |
| 158 |
"""Signal when current process acquires a bus name.""" |
| 159 |
raise NotImplementedError |
| 160 |
|
| 161 |
@dbus_signal_async('s') |
| 162 |
def name_lost(self) -> str: |
| 163 |
"""Signal when current process loses a bus name.""" |
| 164 |
raise NotImplementedError |
| 165 |
|
| 166 |
@dbus_signal_async('sss') |
| 167 |
def name_owner_changed(self) -> tuple[str, str, str]: |
| 168 |
"""Signal when some name on a bus changes owner. |
| 169 |
|
| 170 |
Is a tuple of: |
| 171 |
|
| 172 |
* The name that acquired or lost |
| 173 |
* Old owner (by unique bus name) or empty string if no one owned it |
| 174 |
* New owner (by unique bus name) or empty string if no one owns it now |
| 175 |
""" |
| 176 |
raise NotImplementedError |