- private int handleCommand(Command command, Signal ts, DBusConnection dBusConn) {
- if (command instanceof ExtendedDbusCommand) {
- return ((ExtendedDbusCommand) command).handleCommand(ns, ts, dBusConn);
- } else if (command instanceof DbusCommand) {
- return ((DbusCommand) command).handleCommand(ns, ts);
- } else {
- System.err.println("Command is not yet implemented via dbus");
- return 1;
+ private void initDbusClient(
+ final Command command, final String account, final boolean systemBus, final CommandHandler commandHandler
+ ) throws CommandException {
+ try {
+ final var busType = systemBus ? DBusConnection.DBusBusType.SYSTEM : DBusConnection.DBusBusType.SESSION;
+ try (var dBusConn = DBusConnectionBuilder.forType(busType).build()) {
+ DbusCommandHandler.handleCommand(command, account, dBusConn, commandHandler);
+ }
+ } catch (ServiceUnknown e) {
+ throw new UserErrorException("signal-cli DBus daemon not running on "
+ + (systemBus ? "system" : "session")
+ + " bus: "
+ + e.getMessage(), e);
+ } catch (DBusExecutionException | DBusException | IOException e) {
+ throw new UnexpectedErrorException("Dbus client failed: " + e.getMessage(), e);