Class GDBus

java.lang.Object
org.eclipse.swt.internal.GDBus

public class GDBus extends Object
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.
  • Field Details

  • Constructor Details

    • GDBus

      public GDBus()
  • Method Details

    • init

      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 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 - GDBusConnection
      sender - const gchar
      object_path - const gchar
      interface_name - const gchar
      method_name - const gchar
      gvar_parameters - GVariant
      invocation - GDBusMethodInvocation
      user_data - gpointer
    • convertGVariantToJava

      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 - a pointer to the native GVariant
    • convertGVariantToJavaHelper

      private static Object convertGVariantToJavaHelper(long gVariant)
    • convertJavaToGVariant

      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:
      pointer GVariant *
      Throws:
      SWTException