Skip to content

Commit

Permalink
Issue #257: Updated PropRefRemoteHandler to deal with Structs properly
Browse files Browse the repository at this point in the history
  • Loading branch information
hypfvieh committed May 17, 2024
1 parent a59852f commit fc6506c
Showing 1 changed file with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package org.freedesktop.dbus.propertyref;

import org.freedesktop.dbus.Marshalling;
import org.freedesktop.dbus.RemoteInvocationHandler;
import org.freedesktop.dbus.RemoteObject;
import org.freedesktop.dbus.TypeRef;
import org.freedesktop.dbus.*;
import org.freedesktop.dbus.annotations.DBusBoundProperty;
import org.freedesktop.dbus.annotations.DBusProperty.Access;
import org.freedesktop.dbus.connections.AbstractConnection;
Expand All @@ -14,6 +11,7 @@
import org.freedesktop.dbus.utils.DBusNamingUtil;
import org.freedesktop.dbus.utils.Util;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.util.Optional;
Expand Down Expand Up @@ -79,7 +77,18 @@ public static Object handleDBusBoundProperty(AbstractConnection _conn, RemoteObj

// requested return type is not Variant but the result is -> unwrap Variant
if (_method.getReturnType() != Variant.class && typeClass != Variant.class && result instanceof Variant<?> v) {
return v.getValue();
result = v.getValue();
}

// if this is a Struct, convert it to the proper class
if (Struct.class.isAssignableFrom(typeClass)) {
Constructor<? extends Object> cons = typeClass.getConstructors()[0];
try {
result = cons.newInstance((Object[]) result);
} catch (Exception _ex) {
throw new DBusException(_ex.getMessage());
}

}

return result;
Expand Down

0 comments on commit fc6506c

Please sign in to comment.