Refactor dbus linked devices interface

Export a separate dbus object for each device
This commit is contained in:
AsamK 2021-10-02 18:04:30 +02:00
parent 1548ce9c79
commit 778adacb80
8 changed files with 157 additions and 38 deletions

View file

@ -120,7 +120,10 @@ public class DaemonCommand implements MultiLocalCommand {
private Thread run(
DBusConnection conn, String objectPath, Manager m, OutputWriter outputWriter, boolean ignoreAttachments
) throws DBusException {
conn.exportObject(new DbusSignalImpl(m, objectPath));
final var signal = new DbusSignalImpl(m, conn, objectPath);
conn.exportObject(signal);
final var initThread = new Thread(signal::initObjects);
initThread.start();
logger.info("Exported dbus object: " + objectPath);
@ -136,6 +139,11 @@ public class DaemonCommand implements MultiLocalCommand {
logger.warn("Receiving messages failed, retrying", e);
}
}
try {
initThread.join();
} catch (InterruptedException ignored) {
}
signal.close();
});
thread.start();

View file

@ -21,7 +21,7 @@ public class RemoveDeviceCommand implements JsonRpcLocalCommand {
public void attachToSubparser(final Subparser subparser) {
subparser.help("Remove a linked device.");
subparser.addArgument("-d", "--device-id", "--deviceId")
.type(int.class)
.type(long.class)
.required(true)
.help("Specify the device you want to remove. Use listDevices to see the deviceIds.");
}
@ -31,7 +31,7 @@ public class RemoveDeviceCommand implements JsonRpcLocalCommand {
final Namespace ns, final Manager m, final OutputWriter outputWriter
) throws CommandException {
try {
int deviceId = ns.getInt("device-id");
final var deviceId = ns.getLong("device-id");
m.removeLinkedDevices(deviceId);
} catch (IOException e) {
throw new IOErrorException("Error while removing device: " + e.getMessage(), e);