Top Description Inners Fields Constructors Methods
org.eclipse.swt.internal

public Class GDBus

extends Object
Class Inheritance
Imports
java.util.*, java.util.function.*, org.eclipse.swt.*, org.eclipse.swt.internal.gtk.*

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 and Inner Type Summary

Modifier and TypeClass and Description
public static class

Field Summary

Modifier and TypeField and Description
private static final String
private static final String
private static List<GDBus.GDBusMethod>
private static Callback
private static boolean
private static final String
private static Callback
private static Callback
private static Callback
pack-priv static final String

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static Object[]
convertGVariantToJava(long
a pointer to the native GVariant
gVariant
)

Converts the given GVariant(s) to Java Object(s).

private static Object
public static long

Returns:

pointer GVariant *
convertJavaToGVariant
(Object javaObject)

Converts the given Java Object to a GVariant * representation.

private static long
handleMethod(long
GDBusConnection
connection
,
long
const gchar
sender
,
long
const gchar
object_path
,
long
const gchar
interface_name
,
long
const gchar
method_name
,
long
GVariant
gvar_parameters
,
long
GDBusMethodInvocation
invocation
,
long
gpointer
user_data
)

This is called when a client calls one of the GDBus methods.

public static void
init(GDBus.GDBusMethod[]
GDBus methods that we should handle.
methods
,
String
appName to append to GDBus object name if not null
appName
)

Instantiate GDBus for use by SWT.

private static long

Returns:

void. (No return value actually returned to OS. Just SWT mechanism dicates 'long' is returned.
onBusAcquired
(long gDBusConnection, long const_gchar_name, long user_data)

private static long
onNameAcquired(long connection, long name, long user_data)

private static long
onNameLost(long connection, long name, long user_data)

pack-priv static void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DBUS_OBJECT_NAMEback to summary
private static final String DBUS_OBJECT_NAME
DBUS_SERVICE_NAMEback to summary
private static final String DBUS_SERVICE_NAME
gdbusMethodsback to summary
private static List<GDBus.GDBusMethod> gdbusMethods
handleMethodback to summary
private static Callback handleMethod
initializedback to summary
private static boolean initialized
INTERFACE_NAMEback to summary
private static final String INTERFACE_NAME
onBusAcquiredback to summary
private static Callback onBusAcquired
onNameAcquiredback to summary
private static Callback onNameAcquired
onNameLostback to summary
private static Callback onNameLost
SWT_GDBUS_VERSION_INFOback to summary
pack-priv static final String SWT_GDBUS_VERSION_INFO

Constructor Detail

GDBusback to summary
public GDBus()

Method Detail

convertGVariantToJavaback to summary
public static Object[] convertGVariantToJava(long gVariant)

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:long

a pointer to the native GVariant

convertGVariantToJavaHelperback to summary
private static Object convertGVariantToJavaHelper(long gVariant)
convertJavaToGVariantback to summary
public static long convertJavaToGVariant(Object javaObject) throws SWTException

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:long

pointer GVariant *

handleMethodback to summary
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:long

GDBusConnection

sender:long

const gchar

object_path:long

const gchar

interface_name:long

const gchar

method_name:long

const gchar

gvar_parameters:long

GVariant

invocation:long

GDBusMethodInvocation

user_data:long

gpointer

Annotations
@SuppressWarnings:unused
initback to summary
public static void init(GDBus.GDBusMethod[] methods, String appName)

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.GDBusMethod[]

GDBus methods that we should handle.

appName:String

appName to append to GDBus object name if not null

onBusAcquiredback to summary
private static long onBusAcquired(long gDBusConnection, long const_gchar_name, long user_data)
Returns:long

void. (No return value actually returned to OS. Just SWT mechanism dicates 'long' is returned.

Annotations
@SuppressWarnings:unused
onNameAcquiredback to summary
private static long onNameAcquired(long connection, long name, long user_data)
Annotations
@SuppressWarnings:unused
onNameLostback to summary
private static long onNameLost(long connection, long name, long user_data)
Annotations
@SuppressWarnings:unused
teardown_gdbusback to summary
pack-priv static void teardown_gdbus()
org.eclipse.swt.internal back to summary

public Class GDBus.GDBusMethod

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final String
private final String
private final Function<Object[], Object[]>

Constructor Summary

AccessConstructor and Description
public
GDBusMethod(String
of the method. It will be part of 'org.eclipse.swt.NAME'
name
,
String[][]
2D array pair of Strings in the format of: (DBUS_TYPE_*, argument_name). Where argument_name is only so that it's seen by command line by user.
inputArgs
,
String[][]
Same as inputArgs, but for returning values.
outputArgs
,
Function<Object[], Object[]>
A Function, that you would like to run when the user calls the method over gdbus. Note, input argument(s) are provided as an Object[] array. You need to cast items manually. Output must always be an Object[] array or null. (E.g Object[] with only 1 element in it). Here are examples that you can base your methods off of: // Multiple input types and multiple output types. // 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( "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"}}, (args) -> { System.out.println(args[0] + " " + args[1] + " " + args[2]); // A return new Object[] {Boolean.valueOf(true), "world", Integer.valueOf(5678)} ; }); // Single input and single output. Observe input is an array with one item. Output is an array with one item. // It can be called from cmd via: // gdbus call --session --dest org.eclipse.swt --object-path /org/eclipse/swt --method org.eclipse.swt.singleValueTest 123 // The return is a tuple with one element: (456,) GDBusMethod singleValTest = new GDBusMethod( "singleValueTest", new String[][] {{OS.DBUS_TYPE_INT32, "int val"}}, new String[][] {{OS.DBUS_TYPE_INT32, "int ret"}}, (arg) -> { System.out.println("Input int: " + arg[0]); return new Object[] {(Integer) 456}; }); // A simple method for clients to check if org.eclipse.swt is up and running. (getting/parsing interface xml is too tedious). // Reached via: gdbus call --session --dest org.eclipse.swt --object-path /org/eclipse/swt --method org.eclipse.swt.PingResponse // return is: (true,) #i.e (b) new GDBusMethod( "PingResponse", new String [0][0], // No input args. new String [][] {{OS.DBUS_TYPE_BOOLEAN, "Ping boolean response"}}, // Single boolean res (args) -> { return new Object[] {true}; // You should 'g_variant_unref(result)' on client side. })
userFunction
)

Create a method that GDBus will listen to.

Method Summary

Modifier and TypeMethod and Description
private String
private String
private Function<Object[], Object[]>
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

methodArgsXmlSignatureback to summary
private final String methodArgsXmlSignature
nameback to summary
private final String name
userFunctionback to summary
private final Function<Object[], Object[]> userFunction

Constructor Detail

GDBusMethodback to summary
public GDBusMethod(String name, String[][] inputArgs, String[][] outputArgs, Function<Object[], Object[]> userFunction)

Create a method that GDBus will listen to.

Parameters
name:String

of the method. It will be part of 'org.eclipse.swt.NAME'

inputArgs:String[][]

2D array pair of Strings in the format of: (DBUS_TYPE_*, argument_name). Where argument_name is only so that it's seen by command line by user.

outputArgs:String[][]

Same as inputArgs, but for returning values.

userFunction:Function<Object[], Object[]>

A Function, that you would like to run when the user calls the method over gdbus. Note, input argument(s) are provided as an Object[] array. You need to cast items manually. Output must always be an Object[] array or null. (E.g Object[] with only 1 element in it). Here are examples that you can base your methods off of: // Multiple input types and multiple output types. // 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( "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"}}, (args) -> { System.out.println(args[0] + " " + args[1] + " " + args[2]); // A return new Object[] {Boolean.valueOf(true), "world", Integer.valueOf(5678)} ; }); // Single input and single output. Observe input is an array with one item. Output is an array with one item. // It can be called from cmd via: // gdbus call --session --dest org.eclipse.swt --object-path /org/eclipse/swt --method org.eclipse.swt.singleValueTest 123 // The return is a tuple with one element: (456,) GDBusMethod singleValTest = new GDBusMethod( "singleValueTest", new String[][] {{OS.DBUS_TYPE_INT32, "int val"}}, new String[][] {{OS.DBUS_TYPE_INT32, "int ret"}}, (arg) -> { System.out.println("Input int: " + arg[0]); return new Object[] {(Integer) 456}; }); // A simple method for clients to check if org.eclipse.swt is up and running. (getting/parsing interface xml is too tedious). // Reached via: gdbus call --session --dest org.eclipse.swt --object-path /org/eclipse/swt --method org.eclipse.swt.PingResponse // return is: (true,) #i.e (b) new GDBusMethod( "PingResponse", new String [0][0], // No input args. new String [][] {{OS.DBUS_TYPE_BOOLEAN, "Ping boolean response"}}, // Single boolean res (args) -> { return new Object[] {true}; // You should 'g_variant_unref(result)' on client side. })

Method Detail

getMethodArgsXmlSignatureback to summary
private String getMethodArgsXmlSignature()
getNameback to summary
private String getName()
getUserFunctionback to summary
private Function<Object[], Object[]> getUserFunction()