dbus-java-2.6 No signal notification

pgodin pgodin at rheinmetall.ca
Mon Nov 2 10:34:18 PST 2009


Using dbus-1.2.14, dbus-java-2.6, jdk-1.6.0_16 and bluez-4.56,:

Java application isn't notified when a signal is sent on dbus. Using
dbus-monitor I can see signals being passed on the system bus. My proof
of concept application uses dbus to setup a bluetooth adapter
visibility. I would also like it to be notified of signals such as
device removal and addition although this example listens for
PopertyChanged signals. My gut feeling is that I am not using dbus as it
should be although I went through the documentation and several online
discussions. I you believe my problem better be posted on the bluez
list, please tell me so. 

Here's the proof of concept class:

import org.freedesktop.dbus.DBusConnection;
import org.freedesktop.dbus.Path;
import org.freedesktop.dbus.Variant;
import org.freedesktop.dbus.DBusSigHandler;
import org.freedesktop.dbus.exceptions.DBusException;
import org.bluez.Manager;
import org.bluez.Adapter;

public class DBusConn
{
    public DBusConn()
    {
        DBusConnection connection = null;
        try
        {
            connection =
DBusConnection.getConnection(DBusConnection.SYSTEM);

            final Manager manager =
connection.getRemoteObject("org.bluez", "/", Manager.class);

            final Path defaultAdapterPath = manager.DefaultAdapter();

            final Adapter adapter =
connection.getRemoteObject("org.bluez", defaultAdapterPath.getPath(),
Adapter.class);

            final DBusSigHandler<org.bluez.Adapter.PropertyChanged>
propertyChangedDBusSigHandler = new
DBusSigHandler<org.bluez.Adapter.PropertyChanged>()
            {
                public void handle(final
org.bluez.Adapter.PropertyChanged propertyChanged)
                {
                    System.out.println("Signal received from
Adapter.PropertyChanged handler");
                }
            };


connection.addSigHandler(org.bluez.Adapter.PropertyChanged.class,
propertyChangedDBusSigHandler);
            System.out.println("Waiting for signal...");

            adapter.SetProperty("Discoverable", new Variant(true));
            adapter.SetProperty("Discoverable", new Variant(false));
        }
        catch (final DBusException e)
        {
            e.printStackTrace();
        }
        finally
        {
//            connection.disconnect();
        }
    }

    public static void main(final String[] args)
    {
        new DBusConn();
    }
}

Here's the Adapter interface:

package org.bluez;

import org.freedesktop.dbus.DBusInterface;
import org.freedesktop.dbus.Variant;
import org.freedesktop.dbus.DBusSignal;
import org.freedesktop.dbus.exceptions.DBusException;

/**
 *
 */
public interface Adapter extends DBusInterface
{
    void SetProperty(String name, Variant value);

    public  class PropertyChanged extends DBusSignal
    {
        String _s;
        Variant _v;

        public PropertyChanged(final String s, final Variant v) throws
DBusException
        {
            super(s, v);
            _s = s;
            _v = v;
        }
    }
}

And finally here's the manager interface:

package org.bluez;

import org.freedesktop.dbus.DBusInterface;
import org.freedesktop.dbus.Path;

/**
 *
 */
public interface Manager extends DBusInterface
{
	/**
	 * Returns object path for the default adapter.
	 *
	 * @return returns Object in BlueZ 4
	 */
	Path DefaultAdapter();

    /**
	 * Returns list of adapter object paths under /org/bluez
	 *
	 * @return returns Object[] in BlueZ 4
	 */
	String[] ListAdapters();
}



More information about the dbus mailing list