diff options
Diffstat (limited to 'bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/internal/GDBus.java')
-rw-r--r-- | bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/internal/GDBus.java | 38 |
1 files changed, 23 insertions, 15 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/internal/GDBus.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/internal/GDBus.java index 6c118f8d35..78def99d4a 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/internal/GDBus.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/internal/GDBus.java @@ -67,7 +67,7 @@ public class GDBus { * // From command line, it can be called like this: * // gdbus call --session --dest org.eclipse.swt --object-path /org/eclipse/swt --method org.eclipse.swt.typeTest true "world" 1234 * // The call will return a tuple (struct) like: (true, 'world', 5678) - * GDBusMethod typeTest = new GDBusMethod( + * GDBusMethod typeTest = new GDBusMethod( * "typeTest", * new String [][] {{OS.DBUS_TYPE_BOOLEAN, "boolean Test Val"}, {OS.DBUS_TYPE_STRING, "string Test Val"}, {OS.DBUS_TYPE_INT32, "int Test Val"}}, * new String [][] {{OS.DBUS_TYPE_BOOLEAN, "boolean Response"}, {OS.DBUS_TYPE_STRING, "string Test Response"}, {OS.DBUS_TYPE_INT32, "int Test Response"}}, @@ -129,12 +129,19 @@ public class GDBus { /** * Instantiate GDBus for use by SWT. - * Note, a new SWT instance that runs this "Steals" org.eclipse.swt session bus, + * 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. + * * @param methods GDBus methods that we should handle. + * @param appName appName to append to GDBus object name if not null */ - public static void init (GDBusMethod[] methods) { + public static void init (GDBusMethod[] methods, String appName) { + String serviceName = DBUS_SERVICE_NAME; + if (!initialized) initialized = true; else @@ -145,10 +152,18 @@ public class GDBus { return; } + if (appName != null) { + // GDBus allows alphanumeric characters, underscores and hyphens. + // https://gitlab.gnome.org/GNOME/glib/blob/master/gio/gdbusutils.c + // Replace invalid GDBus characters with hyphens. + appName = appName.replaceAll("[^0-9A-Za-z_.\\-]", "-"); + serviceName += "." + appName; + } + gdbusMethods = Arrays.asList(methods); int owner_id = OS.g_bus_own_name(OS.G_BUS_TYPE_SESSION, - Converter.javaStringToCString(DBUS_SERVICE_NAME), + Converter.javaStringToCString(serviceName), OS.G_BUS_NAME_OWNER_FLAGS_REPLACE | OS.G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT, // Allow name to be used by other eclipse instances. onBusAcquired.getAddress(), onNameAcquired.getAddress(), // name_acquired_handler @@ -157,7 +172,7 @@ public class GDBus { 0); // user_data_free_func if (owner_id == 0) { - System.err.println("SWT GDBus: Failed to aquire bus name: " + DBUS_SERVICE_NAME); + System.err.println("SWT GDBus: Failed to aquire bus name: " + serviceName); } } @@ -175,16 +190,9 @@ public class GDBus { static { onBusAcquired = new Callback (GDBus.class, "onBusAcquired", 3); //$NON-NLS-1$ - if (onBusAcquired.getAddress () == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS); - onNameAcquired = new Callback (GDBus.class, "onNameAcquired", 3); //$NON-NLS-1$ - if (onNameAcquired.getAddress () == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS); - onNameLost = new Callback (GDBus.class, "onNameLost", 3); //$NON-NLS-1$ - if (onNameLost.getAddress () == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS); - handleMethod = new Callback (GDBus.class, "handleMethod", 8); //$NON-NLS-1$ - if (handleMethod.getAddress () == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS); String swt_lib_versions = OS.getEnvironmentalVariable (OS.SWT_LIB_VERSIONS); // Note, this is read in multiple places. if (swt_lib_versions != null && swt_lib_versions.equals("1")) { @@ -327,7 +335,7 @@ public class GDBus { * * @param gVariant a pointer to the native GVariant */ - private static Object[] convertGVariantToJava(long gVariant) { + public static Object[] convertGVariantToJava(long gVariant) { Object retVal = convertGVariantToJavaHelper(gVariant); if (retVal instanceof Object[]) { return (Object[]) retVal; @@ -355,7 +363,7 @@ public class GDBus { return Boolean.valueOf(OS.g_variant_get_boolean(gVariant)); } - if (OS._g_variant_is_of_type(gVariant, OS.G_VARIANT_TYPE_IN32)) { + if (OS.g_variant_is_of_type(gVariant, OS.G_VARIANT_TYPE_IN32)) { return Integer.valueOf(OS.g_variant_get_int32(gVariant)); } @@ -397,7 +405,7 @@ public class GDBus { * * @return pointer GVariant * */ - private static long convertJavaToGVariant(Object javaObject) throws SWTException { + public static long convertJavaToGVariant(Object javaObject) throws SWTException { if (javaObject == null) { return 0; } |