adding signal handler in java

Henrik Petander henrik.petander at gmail.com
Tue Dec 12 19:13:13 PST 2006


Hi,

I am trying to add a signal handler using the java bindings v1.12 for
the TestSignal which is included in the test code of the binding. I am
using the dbus included in suse 10.2 (   dbus-1-1.0.0-7) and java 1.5
from Sun.

My code can create a connection to DBus session bus, but adding of the
signal handler  fails with the following message from the dbus
exception:

"Interface name 'TestSignalInterface' is invalid".

I am not sure, if I am missing something obvious here and would
appreciate any advice on this.

Thanks,
Henrik Petander

Below is a dump of DBUS_JAVA_DEBUG messages:

  <connected: unix:abstract=/tmp/dbus-lN1GKwYJVr,guid=1e4c80458edfbc414d087a89311c3900
><= CALL: org.freedesktop.DBus/org/freedesktop/DBus[org.freedesktop.DBus.Hello]()
{1}
=> REPLY: (org.freedesktop.DBus)(null)[(null).(null)](s) {1,1}
=> SIG: org.freedesktop.DBus/org/freedesktop/DBus[org.freedesktop.DBus.NameAcquired](s)
{2}
<= CALL: org.freedesktop.DBus/org/freedesktop/DBus[org.freedesktop.DBus.AddMatch](s)
{2}
=> REPLY: (org.freedesktop.DBus)(null)[(null).(null)]() {3,2}
Adding signal handlers
<= CALL: org.freedesktop.DBus/org/freedesktop/DBus[org.freedesktop.DBus.AddMatch](s)
{3}
=> ERROR: (org.freedesktop.DBus => :1.5)
org.freedesktop.DBus.Error.MatchRuleInvalid {4,3}

<disconnect>

My code (Client.java):


import org.freedesktop.dbus.DBusInterface;
import org.freedesktop.dbus.DBusSignal;
import org.freedesktop.dbus.DBusSigHandler;
import org.freedesktop.dbus.DBusException;
import org.freedesktop.dbus.DBusConnection;

public class Client implements DBusSigHandler
{
    public void handle(DBusSignal t)
    {
	System.out.println("Hello, event!");
    }


    public static void main(String[] args)
	{
	    System.out.println("Creating DBUS connection");
	    DBusConnection conn = null;
	    try {
		 conn = DBusConnection.getConnection(DBusConnection.SESSION);

		 try {
		     System.out.println("Adding signal handlers");
		     conn.addSigHandler(TestSignalInterface.TestSignal.class, new Client());

		 } catch (DBusException DBe) {
		     System.out.println("Failed to add handlers: "+DBe.getMessage());
		     conn.disconnect();
		     System.exit(1);
		 }
	    } catch (DBusException DBe) {
		System.out.println("Creating DBUS connection failed " +DBe.getMessage());
		System.exit(1);
	    }
	
	    while(true){}

	}
}

TestSignalInterface.java

/*
   D-Bus Java Bindings
   Copyright (c) 2005-2006 Matthew Johnson

   This program is free software; you can redistribute it and/or modify it
   under the terms of either the GNU General Public License Version 2 or the
   Academic Free Licence Version 2.1.

   Full licence texts are included in the COPYING file with this program.
*/

import org.freedesktop.dbus.DBusException;
import org.freedesktop.dbus.DBusInterface;
import org.freedesktop.dbus.DBusSignal;
import org.freedesktop.dbus.UInt32;
import org.freedesktop.dbus.Variant;
import org.freedesktop.DBus.Description;

import java.util.List;

/**
 * A sample signal with two parameters
 */
@Description("Test interface containing signals")
public interface TestSignalInterface extends DBusInterface
{
   @Description("Test basic signal")
   public class TestSignal extends DBusSignal
   {
      public final String value;
      public final UInt32 number;
      /**
       * Create a signal.
       */
      public TestSignal(String path, String value, UInt32 number)
throws DBusException
      {
         super(path, value, number);
         this.value = value;
         this.number = number;
      }
   }
}


More information about the dbus mailing list