dbus java bindings

pgodin pgodin at rheinmetall.ca
Fri Oct 30 07:05:43 PDT 2009


Good day,

I'm having some issues trying to add signal handlers to access the bluez
bus. My code executes and seems OK but I my signal handler is never
notified although d-feet indicates changes.

In this example, I'm trying to get notified of a PropertyChanged event
from the org.bluez.Adapter.PropertyChanged signal.

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));
 new Variant(true)));
        }
        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;
        }
    }
}

I'm using bluez-4.56, dbus-1.2.16, jdk-1.6.0_16 and dbus-java-2.6.

Can someone provide some help please? I don't think this problem is
related to bluez's dbus implementation. In my opinion my problem is
cause by a wrong utilisation of dbus...

TIA,
Phil




More information about the dbus mailing list