Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(feat): Add BusName and ObjectPath annotation support for core #272

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.freedesktop.dbus.annotations;


import java.lang.annotation.*;

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Inherited
public @interface BusName {
String value();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.freedesktop.dbus.annotations;

import java.lang.annotation.*;

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Inherited
public @interface ObjectPath {
String value();
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import org.freedesktop.dbus.DBusMatchRule;
import org.freedesktop.dbus.RemoteInvocationHandler;
import org.freedesktop.dbus.RemoteObject;
import org.freedesktop.dbus.annotations.BusName;
import org.freedesktop.dbus.annotations.DBusInterfaceName;
import org.freedesktop.dbus.annotations.ObjectPath;
import org.freedesktop.dbus.connections.AbstractConnection;
import org.freedesktop.dbus.connections.IDisconnectAction;
import org.freedesktop.dbus.connections.config.ReceivingServiceConfig;
Expand Down Expand Up @@ -455,6 +458,27 @@ public <I extends DBusInterface> I getRemoteObject(String _busname, String _obje
return getRemoteObject(_busname, _objectpath, _type, true);
}

public <I extends DBusInterface> I getRemoteObject(Class<I> type) throws DBusException{
BusName[] busNameTypes
= type.getAnnotationsByType(BusName.class);
if(busNameTypes.length == 0){
throw new DBusException("No BusName annotation found on class " + type.getName());
}
if(busNameTypes.length > 1){
throw new DBusException("Multiple BusName annotations found on class " + type.getName());
}
String busName= busNameTypes[0].value();
ObjectPath[] objectPathTypes = type.getAnnotationsByType(ObjectPath.class);
if(objectPathTypes.length == 0){
throw new DBusException("No DBusInterfaceName annotation found on class " + type.getName());
}
if(objectPathTypes.length > 1){
throw new DBusException("Multiple DBusInterfaceName annotations found on class " + type.getName());
}
String interfaceName = objectPathTypes[0].value();
return getRemoteObject(busName, interfaceName, type);
}

/**
* Return a reference to a remote object. This method will always refer to the well known name (if given) rather
* than resolving it to a unique bus name. In particular this means that if a process providing the well known name
Expand Down