|
View:
New views
5 Messages
—
Rating Filter:
Alert me
|
|
|
dbus-java-2.6 No signal notificationUsing 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(); } _______________________________________________ dbus mailing list dbus@... http://lists.freedesktop.org/mailman/listinfo/dbus |
|
|
Re: dbus-java-2.6 No signal notificationHi,
On Mon, Nov 2, 2009 at 7:34 PM, pgodin <pgodin@...> wrote: > 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. I am pretty new to all this but I think you are indeed doing it the wrong way. > public class DBusConn > { > public DBusConn() > { > DBusConnection connection = null; > try > { > connection = > DBusConnection.getConnection(DBusConnection.SYSTEM); > > final Manager manager = > connection.getRemoteObject("org.bluez", "/", Manager.class); Getting a reference to a remote object > > final Path defaultAdapterPath = manager.DefaultAdapter(); > > final Adapter adapter = > connection.getRemoteObject("org.bluez", defaultAdapterPath.getPath(), > Adapter.class); Idem > connection.addSigHandler(org.bluez.Adapter.PropertyChanged.class, Registering to receive Signal but this is totally unrelated to the previous code (getting hold of remote objects). I aksed the same kind of question yesterday signals are sent "to" object and not from so I threory you need to implement the Object before you can listen to changed. However apparently the Java implementation makes it possible to listen to those signals but in that case you don't need to get hold of the remote objects a all. Here is an example that works for me /** http://github.com/keesj/dbus_glib_pthread/blob/master/java/src/com/test/RunNotification.java **/ package com.test; import org.freedesktop.dbus.DBusConnection; import org.freedesktop.dbus.DBusSigHandler; import org.freedesktop.dbus.exceptions.DBusException; /** * dbus-send \ --system \ /com/test/Notification \ com.test.Notification.Notify * */ public class RunNotification implements DBusSigHandler<Notification.Notify> { public static void main(String[] args) throws DBusException { RunNotification instance = new RunNotification(); DBusConnection conn = DBusConnection.getConnection(DBusConnection.SYSTEM); conn.addSigHandler(Notification.Notify.class, instance); } public void handle(Notification.Notify arg0) { System.err.println("Notified"); } } _______________________________________________ dbus mailing list dbus@... http://lists.freedesktop.org/mailman/listinfo/dbus |
|
|
Re: dbus-java-2.6 No signal notificationHi Kees,
Thanks for your answer. I think you were mislead by the remote object invocations. In my proof of concept, getting a hold of these remote objects only allows me to call bluez/dbus methods and change some properties. This works fine. I am able to change the adapter visibility without any glitch. Removing these statements only leaves the dbus connection and signal handler. This does not work. I am never notified when a property is changed in the adapter interface (at least in java since dbus-monitor does output the signal that a property have been changed). So here's my issue, it's only in java in these ~10 lines of code. Any other hints or ideas would be greatly appreciated. Phil On Mon, 2009-11-02 at 18:03 -0500, Kees Jongenburger wrote: > Hi, > > On Mon, Nov 2, 2009 at 7:34 PM, pgodin <pgodin@...> wrote: > > 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. > > I am pretty new to all this but I think you are indeed doing it the wrong way. > > > public class DBusConn > > { > > public DBusConn() > > { > > DBusConnection connection = null; > > try > > { > > connection = > > DBusConnection.getConnection(DBusConnection.SYSTEM); > > > > final Manager manager = > > connection.getRemoteObject("org.bluez", "/", Manager.class); > > Getting a reference to a remote object > > > > > final Path defaultAdapterPath = manager.DefaultAdapter(); > > > > final Adapter adapter = > > connection.getRemoteObject("org.bluez", defaultAdapterPath.getPath(), > > Adapter.class); > > Idem > > > > connection.addSigHandler(org.bluez.Adapter.PropertyChanged.class, > > Registering to receive Signal but this is totally unrelated to the > previous code (getting hold of > remote objects). I aksed the same kind of question yesterday signals > are sent "to" object and not from so I threory > you need to implement the Object before you can listen to changed. > > However apparently the Java implementation makes it possible to listen > to those signals but in that case you don't need to > get hold of the remote objects a all. > > Here is an example that works for me > > /** > http://github.com/keesj/dbus_glib_pthread/blob/master/java/src/com/test/RunNotification.java > **/ > package com.test; > > import org.freedesktop.dbus.DBusConnection; > import org.freedesktop.dbus.DBusSigHandler; > import org.freedesktop.dbus.exceptions.DBusException; > > /** > * dbus-send \ > --system \ > /com/test/Notification \ > com.test.Notification.Notify > > * > */ > public class RunNotification implements DBusSigHandler<Notification.Notify> { > > public static void main(String[] args) throws DBusException { > RunNotification instance = new RunNotification(); > DBusConnection conn = > DBusConnection.getConnection(DBusConnection.SYSTEM); > conn.addSigHandler(Notification.Notify.class, instance); > } > > public void handle(Notification.Notify arg0) { > System.err.println("Notified"); > } > } _______________________________________________ dbus mailing list dbus@... http://lists.freedesktop.org/mailman/listinfo/dbus |
|
|
Re: dbus-java-2.6 No signal notificationThanks to everyone (in fact only Kees offered some kind of support but
hey, I'm forgiving) my problem is now solved. The public static class defined in the object implementing the DbusInterface must define the signal using an undocumented, additional parameter. Example if the API defines a signal like this one: PropertyChanged(String propertyName, Variant newValue) The class definition in java should be done as this: PropertyChanged(String path, String propertyName, Variant newValue) That's it. Now looking at examples my error seems so obvious. Maybe the binding documentation should emphasize the use of the automatic interface creation supplied with the bindings in order to minimize the risk of such stupid errors. Phil On Tue, 2009-11-03 at 14:27 -0500, pgodin wrote: > Hi Kees, > > Thanks for your answer. I think you were mislead by the remote object > invocations. In my proof of concept, getting a hold of these remote > objects only allows me to call bluez/dbus methods and change some > properties. This works fine. I am able to change the adapter visibility > without any glitch. > > Removing these statements only leaves the dbus connection and signal > handler. This does not work. I am never notified when a property is > changed in the adapter interface (at least in java since dbus-monitor > does output the signal that a property have been changed). So here's my > issue, it's only in java in these ~10 lines of code. > > Any other hints or ideas would be greatly appreciated. > Phil > > On Mon, 2009-11-02 at 18:03 -0500, Kees Jongenburger wrote: > > Hi, > > > > On Mon, Nov 2, 2009 at 7:34 PM, pgodin <pgodin@...> wrote: > > > 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. > > > > I am pretty new to all this but I think you are indeed doing it the wrong way. > > > > > public class DBusConn > > > { > > > public DBusConn() > > > { > > > DBusConnection connection = null; > > > try > > > { > > > connection = > > > DBusConnection.getConnection(DBusConnection.SYSTEM); > > > > > > final Manager manager = > > > connection.getRemoteObject("org.bluez", "/", Manager.class); > > > > Getting a reference to a remote object > > > > > > > > final Path defaultAdapterPath = manager.DefaultAdapter(); > > > > > > final Adapter adapter = > > > connection.getRemoteObject("org.bluez", defaultAdapterPath.getPath(), > > > Adapter.class); > > > > Idem > > > > > > > connection.addSigHandler(org.bluez.Adapter.PropertyChanged.class, > > > > Registering to receive Signal but this is totally unrelated to the > > previous code (getting hold of > > remote objects). I aksed the same kind of question yesterday signals > > are sent "to" object and not from so I threory > > you need to implement the Object before you can listen to changed. > > > > However apparently the Java implementation makes it possible to listen > > to those signals but in that case you don't need to > > get hold of the remote objects a all. > > > > Here is an example that works for me > > > > /** > > http://github.com/keesj/dbus_glib_pthread/blob/master/java/src/com/test/RunNotification.java > > **/ > > package com.test; > > > > import org.freedesktop.dbus.DBusConnection; > > import org.freedesktop.dbus.DBusSigHandler; > > import org.freedesktop.dbus.exceptions.DBusException; > > > > /** > > * dbus-send \ > > --system \ > > /com/test/Notification \ > > com.test.Notification.Notify > > > > * > > */ > > public class RunNotification implements DBusSigHandler<Notification.Notify> { > > > > public static void main(String[] args) throws DBusException { > > RunNotification instance = new RunNotification(); > > DBusConnection conn = > > DBusConnection.getConnection(DBusConnection.SYSTEM); > > conn.addSigHandler(Notification.Notify.class, instance); > > } > > > > public void handle(Notification.Notify arg0) { > > System.err.println("Notified"); > > } > > } > > _______________________________________________ > dbus mailing list > dbus@... > http://lists.freedesktop.org/mailman/listinfo/dbus _______________________________________________ dbus mailing list dbus@... http://lists.freedesktop.org/mailman/listinfo/dbus |
|
|
Re: dbus-java-2.6 No signal notificationOn Tue Nov 03 15:50, pgodin wrote:
> Thanks to everyone (in fact only Kees offered some kind of support but > hey, I'm forgiving) my problem is now solved. > > The public static class defined in the object implementing the > DbusInterface must define the signal using an undocumented, additional > parameter. Ah, yes, sorry I've been a bit busy to look over this. It's mentioned in the docs [0]: "For the reflection to work, a Signal declare a single constructor of the correct type. The constructor must take the object path they are being emitted from as their first (String) argument, followed by the other parameters in order. They must also call the superclass constructor with the same parameters. A full definition of a signal can be seen in figure 5." Matt 0. http://dbus.freedesktop.org/doc/dbus-java/dbus-java/dbus-javase4.html#x17-170004 -- www.matthew.ath.cx D-Bus Java _______________________________________________ dbus mailing list dbus@... http://lists.freedesktop.org/mailman/listinfo/dbus |
| Free embeddable forum powered by Nabble | Forum Help |