Class GDBus
java.lang.Object
org.eclipse.swt.internal.GDBus
General purpose DBus interface for SWT to interact with the operating system and vice versa.
(See also WebkitGDBus for the webkit specific gdbus interface).
This implementation uses GDBus (Gnome DBus) to implement the DBus interface.
It can be reached via:
gdbus call --session --dest org.eclipse.swt --object-path /org/eclipse/swt --method org.eclipse.swt.YOUR_METHOD YOUR_ARGS
where YOUR_ARGS can be something like "MyString" or "['/tmp/myFile', '/tmp/myFile2']" etc..
For hygiene purposes, GVariant/GDBus native types/values should *never* leave this class. Convert on the way in/out.
Technical notes:
- Concurrent gdbus names can co-exist. (i.e, multiple session names in single proc).
Meaning if you don't like org.eclipse.swt, you can add more session names.
- This implementation is only a small subset of GDBus.
E.g not all types are translated and not functionality implemented. Add them as you need them.
- At time of writing (v 1.4), only handles incoming gdbus calls. But could be easily extended to
handle outgoing gdbus calls.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Stringprivate static final Stringprivate static List<GDBus.GDBusMethod> private static Callbackprivate static booleanprivate static final Stringprivate static Callbackprivate static Callbackprivate static Callback(package private) static final String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Object[]convertGVariantToJava(long gVariant) Converts the given GVariant(s) to Java Object(s).private static ObjectconvertGVariantToJavaHelper(long gVariant) static longconvertJavaToGVariant(Object javaObject) Converts the given Java Object to a GVariant * representation.private static longhandleMethod(long connection, long sender, long object_path, long interface_name, long method_name, long gvar_parameters, long invocation, long user_data) This is called when a client calls one of the GDBus methods.static voidinit(GDBus.GDBusMethod[] methods, String appName) Instantiate GDBus for use by SWT.private static longonBusAcquired(long gDBusConnection, long const_gchar_name, long user_data) private static longonNameAcquired(long connection, long name, long user_data) private static longonNameLost(long connection, long name, long user_data) (package private) static void
-
Field Details
-
SWT_GDBUS_VERSION_INFO
- See Also:
-
initialized
private static boolean initialized -
gdbusMethods
-
DBUS_SERVICE_NAME
- See Also:
-
DBUS_OBJECT_NAME
- See Also:
-
INTERFACE_NAME
- See Also:
-
onBusAcquired
-
onNameAcquired
-
onNameLost
-
handleMethod
-
-
Constructor Details
-
GDBus
public GDBus()
-
-
Method Details
-
init
Instantiate GDBus for use by SWT. Note, a new SWT instance that runs this "Steals" the session bus, but upon termination it returns the session back to the previous owner. To make this more flexible we append appName (derived from the application executable but can be set with the command-line argument -name) to the session name.- Parameters:
methods- GDBus methods that we should handle.appName- appName to append to GDBus object name if not null
-
teardown_gdbus
static void teardown_gdbus() -
onBusAcquired
private static long onBusAcquired(long gDBusConnection, long const_gchar_name, long user_data) - Returns:
- void. (No return value actually returned to OS. Just SWT mechanism dicates 'long' is returned.
-
onNameAcquired
private static long onNameAcquired(long connection, long name, long user_data) -
onNameLost
private static long onNameLost(long connection, long name, long user_data) -
handleMethod
private static long handleMethod(long connection, long sender, long object_path, long interface_name, long method_name, long gvar_parameters, long invocation, long user_data) This is called when a client calls one of the GDBus methods. Developer note: This method can be reached directly from GDBus cmd utility: gdbus call --session --dest org.eclipse.swt --object-path /org/eclipse/swt --method org.eclipse.swt.Tip: Use tab-completion. - Parameters:
connection- GDBusConnectionsender- const gcharobject_path- const gcharinterface_name- const gcharmethod_name- const gchargvar_parameters- GVariantinvocation- GDBusMethodInvocationuser_data- gpointer
-
convertGVariantToJava
Converts the given GVariant(s) to Java Object(s). If GVariant is not an array, this returns an Object[] array with one element. Only subset of types is currently supported, add type(s) as/when you need them. For inspiration, see WebkitGDBus.java:convert..()- Parameters:
gVariant- a pointer to the native GVariant
-
convertGVariantToJavaHelper
-
convertJavaToGVariant
Converts the given Java Object to a GVariant * representation. (Only subset of types is currently supported). We assume that input Object may contain invalid types.- Returns:
- pointer GVariant *
- Throws:
SWTException
-