Recieving DBUS messages in Java
Matthew Johnson
dbus at matthew.ath.cx
Fri Feb 20 00:48:19 PST 2009
On Fri Feb 20 11:08, Paul Sztajer wrote:
> Hi all,
>
> I'm currently building a compiz plugin that needs two-way
> communication with a java application, and thus I'm trying to use dbus
> to do so. I've gotten sending from Java and recieving in compiz
> working, but I'm having issues going the other way.
What messages are you trying to send in each direction? AFAICT, you have
glib trying to call the method "test" on the Java, and Java listening
for the YellowSignal.connect/disconnect signals, but not exporting any
methods.
A couple of comments:
> 15 public static void main(String[] args){
> 16 /**
> 17 * First, send to compiz (this works, so I won't put the code in here)
> 18 */
> ...
> 27
> 28 /**
> 29 * Now wait to recieve
> 30 */
> 31 DBusConnection conn = null;
> 32 try {
> 33 conn = DBusConnection
> 34 .getConnection(DBusConnection.SYSTEM);
> 41 conn.addSigHandler(YellowSignal.Connect.class,
> 42 new Yellower());
The normal pattern for this would be to add all the listeners and export
objects straight away. Also, presumably you don't have a separate
connection for sending and receiving? (although, actually it does give
you back the same object if you call it twice anyway).
> 54 public void handle(DBusSignal s) {
> 55 if (s instanceof YellowSignal.Connect)
> 56 System.out.println("Got a connect for "
> 57 +((YellowSignal.Connect) s).address);
This all looks like it should work for receiving signals. You should be
able to test it with:
dbus-send --system --type=signal /foo nicta.yellower.compizfusion.dbus.YellowSignal.Connect string:"29 Acacia Road"
> Now I realise that I haven't actually got a "test" method in the java
> code to call, but I'm not all that sure where to place it etc. I get
> the distinct impression that I'm missing something, or that I've
> gotten confused somewhere. Any help I could get would be much
> appreciated.
You need to declare in in an interface which extends DBusInterface and
then implement that on an object which you create and pass to
conn.exportObject. It's all in the docs, if a little terse.
So for your test method, it might be something like:
package nicta.yellower.compizfusion.dbus;
public interface TestInterface extends DBusInterface
{
public void test();
}
...
public class TestImpl implements TestInterface
{
public void test() { /* do someting */ }
}
...
conn = DBusConnection.getConnection(DBusConnection.SYSTEM);
conn.exportObject("/test", new TestImpl);
This would then allow someone to call:
dbus-send --type=method_call --dest=<your address> /test nicta.yellower.compizfusion.dbus.TestInterface.test
Lemme know if you have further problems.
Thanks,
Matt
--
www.matthew.ath.cx
D-Bus Java
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://lists.freedesktop.org/archives/dbus/attachments/20090220/8d0f377f/attachment.pgp
More information about the dbus
mailing list