Add exportObject helper method

This commit is contained in:
AsamK 2021-11-07 11:04:41 +01:00
parent 8a216e3245
commit 82bb4f22f0
2 changed files with 16 additions and 21 deletions

View file

@ -97,7 +97,7 @@ public class StorageHelper {
(contact == null || !contact.isBlocked()) && contactRecord.isBlocked() (contact == null || !contact.isBlocked()) && contactRecord.isBlocked()
)) { )) {
final var newContact = (contact == null ? Contact.newBuilder() : Contact.newBuilder(contact)).withBlocked( final var newContact = (contact == null ? Contact.newBuilder() : Contact.newBuilder(contact)).withBlocked(
contactRecord.isBlocked()) contactRecord.isBlocked())
.withName((contactRecord.getGivenName().or("") + " " + contactRecord.getFamilyName().or("")).trim()) .withName((contactRecord.getGivenName().or("") + " " + contactRecord.getFamilyName().or("")).trim())
.build(); .build();
account.getContactStore().storeContact(recipientId, newContact); account.getContactStore().storeContact(recipientId, newContact);

View file

@ -32,6 +32,7 @@ import org.freedesktop.dbus.DBusPath;
import org.freedesktop.dbus.connections.impl.DBusConnection; import org.freedesktop.dbus.connections.impl.DBusConnection;
import org.freedesktop.dbus.exceptions.DBusException; import org.freedesktop.dbus.exceptions.DBusException;
import org.freedesktop.dbus.exceptions.DBusExecutionException; import org.freedesktop.dbus.exceptions.DBusExecutionException;
import org.freedesktop.dbus.interfaces.DBusInterface;
import org.freedesktop.dbus.types.Variant; import org.freedesktop.dbus.types.Variant;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -839,12 +840,7 @@ public class DbusSignalImpl implements Signal {
linkedDevices.forEach(d -> { linkedDevices.forEach(d -> {
final var object = new DbusSignalDeviceImpl(d); final var object = new DbusSignalDeviceImpl(d);
final var deviceObjectPath = object.getObjectPath(); final var deviceObjectPath = object.getObjectPath();
try { exportObject(object);
connection.exportObject(object);
logger.debug("Exported dbus object: " + deviceObjectPath);
} catch (DBusException e) {
e.printStackTrace();
}
if (d.isThisDevice()) { if (d.isThisDevice()) {
thisDevice = new DBusPath(deviceObjectPath); thisDevice = new DBusPath(deviceObjectPath);
} }
@ -876,12 +872,7 @@ public class DbusSignalImpl implements Signal {
groups.forEach(g -> { groups.forEach(g -> {
final var object = new DbusSignalGroupImpl(g.groupId()); final var object = new DbusSignalGroupImpl(g.groupId());
try { exportObject(object);
connection.exportObject(object);
logger.debug("Exported dbus object: " + object.getObjectPath());
} catch (DBusException e) {
e.printStackTrace();
}
this.groups.add(new StructGroup(new DBusPath(object.getObjectPath()), this.groups.add(new StructGroup(new DBusPath(object.getObjectPath()),
g.groupId().serialize(), g.groupId().serialize(),
emptyIfNull(g.title()))); emptyIfNull(g.title())));
@ -898,14 +889,9 @@ public class DbusSignalImpl implements Signal {
} }
private void updateConfiguration() { private void updateConfiguration() {
try { unExportConfiguration();
unExportConfiguration(); final var object = new DbusSignalConfigurationImpl();
final var object = new DbusSignalConfigurationImpl(); exportObject(object);
connection.exportObject(object);
logger.debug("Exported dbus object: " + objectPath + "/Configuration");
} catch (DBusException e) {
e.printStackTrace();
}
} }
private void unExportConfiguration() { private void unExportConfiguration() {
@ -913,6 +899,15 @@ public class DbusSignalImpl implements Signal {
connection.unExportObject(objectPath); connection.unExportObject(objectPath);
} }
private void exportObject(final DBusInterface object) {
try {
connection.exportObject(object);
logger.debug("Exported dbus object: " + object.getObjectPath());
} catch (DBusException e) {
e.printStackTrace();
}
}
public class DbusSignalDeviceImpl extends DbusProperties implements Signal.Device { public class DbusSignalDeviceImpl extends DbusProperties implements Signal.Device {
private final org.asamk.signal.manager.api.Device device; private final org.asamk.signal.manager.api.Device device;