X-Git-Url: https://git.nmode.ca/signal-cli/blobdiff_plain/62687d103fab1ade650b920008060c220361d581..805f976d9e3de22e4842df1622941584c7f7c041:/src/main/java/org/asamk/signal/dbus/DbusSignalControlImpl.java diff --git a/src/main/java/org/asamk/signal/dbus/DbusSignalControlImpl.java b/src/main/java/org/asamk/signal/dbus/DbusSignalControlImpl.java index cfd17610..aa357444 100644 --- a/src/main/java/org/asamk/signal/dbus/DbusSignalControlImpl.java +++ b/src/main/java/org/asamk/signal/dbus/DbusSignalControlImpl.java @@ -15,6 +15,7 @@ import org.freedesktop.dbus.DBusPath; import java.io.IOException; import java.net.URI; +import java.net.URISyntaxException; import java.nio.channels.OverlappingFileLockException; import java.util.List; import java.util.concurrent.TimeoutException; @@ -88,9 +89,9 @@ public class DbusSignalControlImpl implements org.asamk.SignalControl { @Override public String link(final String newDeviceName) throws Error.Failure { try { - final ProvisioningManager provisioningManager = c.getNewProvisioningManager(); - final URI deviceLinkUri = provisioningManager.getDeviceLinkUri(); + final URI deviceLinkUri = c.getNewProvisioningDeviceLinkUri(); new Thread(() -> { + final ProvisioningManager provisioningManager = c.getProvisioningManagerFor(deviceLinkUri); try { provisioningManager.finishDeviceLink(newDeviceName); } catch (IOException | TimeoutException | UserAlreadyExists e) { @@ -103,6 +104,26 @@ public class DbusSignalControlImpl implements org.asamk.SignalControl { } } + @Override + public String startLink() throws Error.Failure { + try { + final URI deviceLinkUri = c.getNewProvisioningDeviceLinkUri(); + return deviceLinkUri.toString(); + } catch (TimeoutException | IOException e) { + throw new SignalControl.Error.Failure(e.getClass().getSimpleName() + " " + e.getMessage()); + } + } + + @Override + public String finishLink(String deviceLinkUri, final String newDeviceName) throws Error.Failure { + try { + final var provisioningManager = c.getProvisioningManagerFor(new URI(deviceLinkUri)); + return provisioningManager.finishDeviceLink(newDeviceName); + } catch (TimeoutException | IOException | UserAlreadyExists | URISyntaxException e) { + throw new SignalControl.Error.Failure(e.getClass().getSimpleName() + " " + e.getMessage()); + } + } + @Override public String version() { return BaseConfig.PROJECT_VERSION; @@ -112,4 +133,9 @@ public class DbusSignalControlImpl implements org.asamk.SignalControl { public List listAccounts() { return c.getAccountNumbers().stream().map(u -> new DBusPath(DbusConfig.getObjectPath(u))).toList(); } + + @Override + public DBusPath getAccount(final String number) { + return new DBusPath(DbusConfig.getObjectPath(number)); + } }