+ protected Thread exportDbusObject(final DBusConnection conn, final String objectPath, final Manager m) {
+ final var signal = new DbusSignalImpl(m, conn, objectPath, receiveMode != ReceiveMode.ON_START);
+
+ return Thread.ofPlatform().name("dbus-init-" + m.getSelfNumber()).start(signal::initObjects);
+ }
+
+ protected void runDbus(
+ final boolean isDbusSystem, MultiAccountDaemonHandler.DbusRunner dbusRunner
+ ) throws CommandException {
+ DBusConnection.DBusBusType busType;
+ if (isDbusSystem) {
+ busType = DBusConnection.DBusBusType.SYSTEM;
+ } else {
+ busType = DBusConnection.DBusBusType.SESSION;
+ }
+ DBusConnection conn;
+ try {
+ conn = DBusConnectionBuilder.forType(busType).build();
+ dbusRunner.run(conn, DbusConfig.getObjectPath());
+ } catch (DBusException e) {
+ throw new UnexpectedErrorException("Dbus command failed: " + e.getMessage(), e);
+ } catch (UnsupportedOperationException e) {
+ throw new UserErrorException("Failed to connect to Dbus: " + e.getMessage(), e);
+ }
+
+ try {
+ conn.requestBusName(DbusConfig.getBusname());
+ } catch (DBusException e) {
+ throw new UnexpectedErrorException(
+ "Dbus command failed, maybe signal-cli dbus daemon is already running: " + e.getMessage(),
+ e);
+ }
+
+ logger.info("DBus daemon running on {} bus: {}", busType, DbusConfig.getBusname());
+ }
+
+ @Override
+ public void close() {
+ // TODO
+ }
+ }
+
+ private static final class SingleAccountDaemonHandler extends DaemonHandler {
+
+ private final Manager m;
+
+ private SingleAccountDaemonHandler(final Manager m, final ReceiveMode receiveMode) {
+ super(receiveMode);
+ this.m = m;
+ }
+
+ @Override
+ public void runSocket(final ServerSocketChannel serverChannel) {
+ runSocket(serverChannel, channel -> {
+ final var handler = getSignalJsonRpcDispatcherHandler(channel);
+ handler.handleConnection(m);
+ });
+ }
+
+ @Override
+ public void runDbus(final boolean isDbusSystem) throws CommandException {
+ runDbus(isDbusSystem, (conn, objectPath) -> {