Package com.lucimber.dbus.proxy
Class ServiceProxy
java.lang.Object
com.lucimber.dbus.proxy.ServiceProxy
Factory for creating dynamic proxies for D-Bus service clients.
This class simplifies D-Bus method calls by allowing you to define a Java interface with annotations and automatically handling the underlying D-Bus communication.
Note: ServiceProxy is designed for simple client-side request/response scenarios only. It does not support:
- Receiving D-Bus signals
- Implementing D-Bus services (use
StandardInterfaceHandler
instead) - Complex argument marshalling (currently limited to methods without arguments)
Relationship to StandardInterfaceHandler:
ServiceProxy
- Client-side proxy for calling remote D-Bus servicesStandardInterfaceHandler
- Server-side handler for implementing D-Bus services
Example usage:
@DBusInterface("org.freedesktop.DBus")
public interface DBusService {
@DBusMethod("ListNames")
CompletableFuture<String[]> listNames();
@DBusMethod("GetId")
String getId();
}
// Create proxy
DBusService service = ServiceProxy.create(
connection,
"org.freedesktop.DBus",
"/org/freedesktop/DBus",
DBusService.class
);
// Use it - synchronous
String id = service.getId();
// Or asynchronous
service.listNames().thenAccept(names -> {
for (String name : names) {
System.out.println(name);
}
});
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Exception thrown when D-Bus operations fail. -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> T
create
(Connection connection, String objectPath, Class<T> interfaceClass) Creates a proxy with automatic interface name detection.static <T> T
create
(Connection connection, String destination, String objectPath, Class<T> interfaceClass) Creates a proxy instance for the specified D-Bus service interface.
-
Method Details
-
create
public static <T> T create(Connection connection, String destination, String objectPath, Class<T> interfaceClass) Creates a proxy instance for the specified D-Bus service interface.- Type Parameters:
T
- the interface type- Parameters:
connection
- the D-Bus connectiondestination
- the D-Bus service name (e.g., "org.freedesktop.DBus")objectPath
- the object path (e.g., "/org/freedesktop/DBus")interfaceClass
- the Java interface class with D-Bus annotations- Returns:
- a proxy instance implementing the interface
-
create
Creates a proxy with automatic interface name detection. Uses the @DBusInterface annotation value as the destination.- Type Parameters:
T
- the interface type- Parameters:
connection
- the D-Bus connectionobjectPath
- the object pathinterfaceClass
- the Java interface class with D-Bus annotations- Returns:
- a proxy instance implementing the interface
-