Bonjour,

Je fais face à un problème depuis quelques jours avec l'API dbus-java. Je travaille sous GNU/Linux (Ubuntu en particulier). J'essaie d'empêcher l'ordinateur de se mettre en veille lors de lon traitement. Je suis arrivé à extraire l'interface Inhibit qui fait partie de PowerManagement. On arrive à un code de ce style.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import java.util.List;
 
import org.freedesktop.dbus.DBusInterface;
import org.freedesktop.dbus.DBusSignal;
import org.freedesktop.dbus.UInt32;
import org.freedesktop.dbus.exceptions.DBusException;
 
public interface Inhibit extends DBusInterface {
	public static class HasInhibitChanged extends DBusSignal {
		public final boolean hasInhibit;
 
		public HasInhibitChanged(String path, boolean hasInhibit) throws DBusException {
			super(path, hasInhibit);
			this.hasInhibit = hasInhibit;
		}
	}
 
	public List<String> GetRequests();
	public boolean HasInhibit();
	public void UnInhibit(UInt32 cookie);
	public UInt32 Inhibit(String application, String reason);
}
Le soucis se situe lorsque j'essaie d'utiliser cette interface.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
public static void inhibitHibernation() {
	DBusConnection bus = null;
	Inhibit inhibit    = null;
 
	try {
		// Get DBus connection
		bus     = DBusConnection.getConnection(DBusConnection.SESSION);
 
		// Get inhibit object
		inhibit = bus.getRemoteObject("org.freedesktop.PowerManagement", "/org/freedesktop/PowerManagement/Inhibit", Inhibit.class);
 
		// Inhibit hibernation and get inhibit cookie
		cookie  = inhibit.Inhibit("application", "reason");
	} catch (DBusException e) {
		e.printStackTrace();
	} finally {
		// Close connection
		if (bus != null)
			bus.disconnect();
	}
}
Une exception comme quoi la méthode "Inhibit" n'existe pas est générée.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
Exception in thread "Thread-2" org.freedesktop.DBus$Error$UnknownMethod: Method "Inhibit" with signature "ss" on interface "Inhibit" doesn't exist
Je crois que je dois faire une erreur quelque part. J'ai testé un code équivalent en Python et ça marche très bien, je suppose donc que je m'y prend pas mal en Java. (Doc du GNOME Power Management si besoin)

Merci d'avance pour votre aide.