Skip to content

Commit f48ba51

Browse files
authored
Merge pull request #48 from Ultimaker/CES-2235-delay-dbus-publication
CES-2235 Delay DBus publication
2 parents 552e067 + 14b8df1 commit f48ba51

5 files changed

Lines changed: 31 additions & 8 deletions

File tree

Charon/Service/FileService.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,31 @@
1818
# Note: This class does not currently use type hinting since type hints,
1919
# dbus-python decorators and Python 3.4 do not mix well.
2020
class FileService(dbus.service.Object):
21+
2122
def __init__(self, dbus_bus: dbus.Bus) -> None:
23+
self.__dbus_bus = dbus_bus
2224
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,
2532
)
33+
self.__bus_name = None
2634

2735
log.debug("FileService initialized")
2836
self.__queue = RequestQueue.RequestQueue()
2937

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+
3046
## Start a request for data from a file.
3147
#
3248
# This function will start a request for data from a certain file.

Charon/Service/main.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,6 @@
3131
_bus = dbus.SystemBus(private=True, mainloop=dbus.mainloop.glib.DBusGMainLoop())
3232

3333
_service = Charon.Service.FileService(_bus)
34+
_service.publish()
3435

3536
_loop.run()

build.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/sh
1+
#!/bin/bash
22

33
ARCH="armhf"
44

@@ -42,7 +42,7 @@ usage()
4242
echo "NOTE: This script requires root permissions to run."
4343
}
4444

45-
while getopts ":hc" options; do
45+
while getopts ":hcs" options; do
4646
case "${options}" in
4747
c)
4848
cleanup
@@ -52,6 +52,9 @@ while getopts ":hc" options; do
5252
usage
5353
exit 0
5454
;;
55+
s)
56+
# Ignore for compatibility with other build scripts
57+
;;
5558
:)
5659
echo "Option -${OPTARG} requires an argument."
5760
exit 1

build_for_ultimaker.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/sh
1+
#!/bin/bash
22
#
33
# Copyright (C) 2019 Ultimaker B.V.
44
#
@@ -19,7 +19,7 @@ run_linters="yes"
1919
run_tests="yes"
2020

2121
# Run the make_docker.sh script here, within the context of the build_for_ultimaker.sh script
22-
. ./make_docker.sh
22+
. ./make_docker.sh ""
2323

2424
env_check()
2525
{
@@ -71,7 +71,7 @@ usage()
7171
echo " -t Skip tests"
7272
}
7373

74-
while getopts ":chlt" options; do
74+
while getopts ":chlst" options; do
7575
case "${options}" in
7676
c)
7777
run_env_check="no"
@@ -86,6 +86,9 @@ while getopts ":chlt" options; do
8686
t)
8787
run_tests="no"
8888
;;
89+
s)
90+
# Ignore for compatibility with other build scripts
91+
;;
8992
:)
9093
echo "Option -${OPTARG} requires an argument."
9194
exit 1

docker_env/buildenv_check.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/sh
1+
#!/bin/bash
22

33
set -eu
44

0 commit comments

Comments
 (0)