|
18 | 18 | # Note: This class does not currently use type hinting since type hints, |
19 | 19 | # dbus-python decorators and Python 3.4 do not mix well. |
20 | 20 | class FileService(dbus.service.Object): |
| 21 | + |
21 | 22 | def __init__(self, dbus_bus: dbus.Bus) -> None: |
| 23 | + self.__dbus_bus = dbus_bus |
22 | 24 | super().__init__( |
23 | | - bus_name = dbus.service.BusName("nl.ultimaker.charon", dbus_bus), |
24 | | - object_path = "/nl/ultimaker/charon" |
| 25 | + conn=self.__dbus_bus, |
| 26 | + object_path="/nl/ultimaker/charon", |
| 27 | + # Postpone claiming a well-known name until the class is fully initialized. |
| 28 | + # If we do this right now, the DBus service will be published to the |
| 29 | + # bus in an incomplete state, and clients connecting early on may |
| 30 | + # encounter, for instance, emptry introspection data on this service. |
| 31 | + bus_name=None, |
25 | 32 | ) |
| 33 | + self.__bus_name = None |
26 | 34 |
|
27 | 35 | log.debug("FileService initialized") |
28 | 36 | self.__queue = RequestQueue.RequestQueue() |
29 | 37 |
|
| 38 | + ## Publish the fully initialized DBus service to the bus |
| 39 | + def publish(self) -> None: |
| 40 | + # Store a reference to the BusName for as long as the DBus service is alive; |
| 41 | + # otherwise it gets GC'd, and the well-known name gets released again. |
| 42 | + # Taking ownership of this well-known name is also the trigger for other services |
| 43 | + # to notice that we are alive & available. |
| 44 | + self.__bus_name = dbus.service.BusName("nl.ultimaker.charon", self.__dbus_bus) |
| 45 | + |
30 | 46 | ## Start a request for data from a file. |
31 | 47 | # |
32 | 48 | # This function will start a request for data from a certain file. |
|
0 commit comments