hypfvieh / dbus-java

Improved version of java DBus library provided by freedesktop.org (https://dbus.freedesktop.org/doc/dbus-java/)
https://hypfvieh.github.io/dbus-java/
MIT License
185 stars 73 forks source link

NetworkManager -> Wireless interface unable to GetAllAccessPoints. #89

Closed yyvus closed 4 years ago

yyvus commented 4 years ago

Hi,

The following code does always retrieve an UnknownMethod exception for the call GetAllAccessPoints:

var wifiAdaptor = instance.getRemoteObject( "org.freedesktop.NetworkManager", "/org/freedesktop/NetworkManager/Devices/3", Wireless.class );
wifiAdaptor.GetAllAccessPoints();

All though I have a successful call in the terminal with:

dbus-send --system --print-reply --dest=org.freedesktop.NetworkManager /org/freedesktop/NetworkManager/Devices/3 org.freedesktop.NetworkManager.Device.Wireless.GetAllAccessPoints
method return time=1580485345.952203 sender=:1.16 -> destination=:1.991 serial=20193 reply_serial=2
   array [
      object path "/org/freedesktop/NetworkManager/AccessPoint/18"
   ]

Is there an error with the Wireless interface?

Below is my Wireless.java class:

package org.freedesktop.NetworkManager.Device;

import java.util.List;
import java.util.Map;
import org.freedesktop.dbus.DBusPath;
import org.freedesktop.dbus.ObjectPath;
import org.freedesktop.dbus.annotations.DBusInterfaceName;
import org.freedesktop.dbus.exceptions.DBusException;
import org.freedesktop.dbus.interfaces.DBusInterface;
import org.freedesktop.dbus.messages.DBusSignal;
import org.freedesktop.dbus.types.Variant;

/**
 * Auto-generated class.
 */
@DBusInterfaceName( "org.freedesktop.NetworkManager.Device" )
public interface Wireless extends DBusInterface {

    List<DBusPath> GetAccessPoints();

    List<DBusPath> GetAllAccessPoints();

    void RequestScan(Map<String,Variant<?>> options);

    class PropertiesChanged extends DBusSignal {

        private final Map<String,Variant<?>> properties;

        PropertiesChanged(String _path, String _interfaceName, Map<String,Variant<?>> _properties) throws DBusException {
            super( _path, _interfaceName );
            this.properties = _properties;
        }

        public Map<String,Variant<?>> getProperties() {
            return properties;
        }
    }

    class AccessPointAdded extends DBusSignal {

        private final DBusPath accessPoint;

        AccessPointAdded(String _path, String _interfaceName, DBusPath _accessPoint) throws DBusException {
            super( _path, _interfaceName );
            this.accessPoint = _accessPoint;
        }

        public DBusPath getAccessPoint() {
            return accessPoint;
        }
    }

    class AccessPointRemoved extends DBusSignal {

        private final DBusPath accessPoint;

        AccessPointRemoved(String _path, String _interfaceName, DBusPath _accessPoint) throws DBusException {
            super( _path, _interfaceName );
            this.accessPoint = _accessPoint;
        }

        public DBusPath getAccessPoint() {
            return accessPoint;
        }
    }
}
hypfvieh commented 4 years ago

The full DBus object class name is required in the @DBusInterfaceName annotation. It should be @DBusInterfaceName( "org.freedesktop.NetworkManager.Device.Wireless" ).

I fixed this in the interface creation util.

Another note: In Java package names are usually all lower case by convention, so I would suggest you follow that rule. The annotation mentioned above will take care that DBus will receive the String defined in it instead of the Java package name.

yyvus commented 4 years ago

Thanks for the careful reading. It did fix the last issue I had to have it work.