-
- try {
- manager.checkAccountState();
- } catch (IOException e) {
- try {
- manager.close();
- } catch (IOException ie) {
- logger.warn("Failed to close broken account", ie);
- }
- throw new IOErrorException("Error while checking account " + account + ": " + e.getMessage(), e);
- }
-
- return manager;
- }
-
- private void initDbusClient(
- final Command command, final String account, final boolean systemBus, final OutputWriter outputWriter
- ) throws CommandException {
- try {
- DBusConnection.DBusBusType busType;
- if (systemBus) {
- busType = DBusConnection.DBusBusType.SYSTEM;
- } else {
- busType = DBusConnection.DBusBusType.SESSION;
- }
- try (var dBusConn = DBusConnection.getConnection(busType)) {
- var ts = dBusConn.getRemoteObject(DbusConfig.getBusname(),
- DbusConfig.getObjectPath(account),
- Signal.class);
-
- handleCommand(command, ts, dBusConn, outputWriter);
- }
- } catch (DBusException | IOException e) {
- logger.error("Dbus client failed", e);
- throw new UnexpectedErrorException("Dbus client failed", e);
- }
- }
-
- private void handleCommand(
- Command command, Signal ts, DBusConnection dBusConn, OutputWriter outputWriter
- ) throws CommandException {
- if (command instanceof LocalCommand localCommand) {
- try (final var m = new DbusManagerImpl(ts, dBusConn)) {
- localCommand.handleCommand(ns, m, outputWriter);
- } catch (UnsupportedOperationException e) {
- throw new UserErrorException("Command is not yet implemented via dbus", e);
- } catch (IOException | DBusExecutionException e) {
- throw new UnexpectedErrorException(e.getMessage(), e);
- }
- } else {
- throw new UserErrorException("Command is not yet implemented via dbus");
- }