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

public Class SessionManagerDBus

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

Communicates with session manager to receive logoff/shutdown events. GTK also has an implementation (see gtk_application_impl_dbus_startup) However, it requires GtkApplication, and SWT doesn't use that. Current session manager clients can be seen in: Gnome: dbus-send --print-reply --dest=org.gnome.SessionManager /org/gnome/SessionManager org.gnome.SessionManager.GetClients XFCE: dbus-send --print-reply --dest=org.xfce.SessionManager /org/xfce/SessionManager org.xfce.Session.Manager.ListClients If you know clientObjectPath, you can send Stop signal with: dbus-send --print-reply --dest=org.gnome.SessionManager /org/gnome/SessionManager/ClientXX org.gnome.SessionManager.Client.Stop

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
private static class

Field Summary

Modifier and TypeField and Description
private String
private long
private static int
private long
endSessionResponseCounter

1) Prevents old answers to new signals.

private long
private Callback
private long
private boolean
private List<SessionManagerDBus.IListener>
private long
private SessionManagerDBus.ShutdownHook

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
addListener(SessionManagerDBus.IListener listener)

Subscribes display for session manager events.

private String
claimDesktopAutostartID()

Gets the value of 'DESKTOP_AUTOSTART_ID'.

private boolean
private long

Returns:

Pointer to dbus proxy, 0 if failed.
connectSessionManager
(String dbusName, String objectPath, String interfaceName)

Creates a connection to the session manager.

private boolean
public void
private static String
extractFreeGError(long errorPtr)

private static String
extractVariantTupleS(long variant)

private long

Returns:

Error string in case of error, null if successful.
g_signal_handler
(long proxy, long sender_name, long signal_name, long parameters, long user_data)

Receives events from session manager.

private void
private void
private void
private boolean
private String

Returns:

Error string in case of error, null if successful.
registerClient
(String appID, String clientStartupID)

Issues 'RegisterClient' dbus request to register with session manager.

private boolean
public void
private void
sendEndSessionResponse(boolean is_ok, String reason, long responseID)

private boolean
private synchronized void
stop()

Un-subscribes from session manager events.

private long
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

clientObjectPathback to summary
private String clientObjectPath
clientProxyback to summary
private long clientProxy
dbusTimeoutMsecback to summary
private static int dbusTimeoutMsec
endSessionResponseCounterback to summary
private long endSessionResponseCounter

1) Prevents old answers to new signals. For example, if signal's handler asks user, it can stay for a while and when it's closed it could be the other signal already. 2) Makes sure answer is given on System.exit()

endSessionResponseWantedback to summary
private long endSessionResponseWanted
g_signal_callbackback to summary
private Callback g_signal_callback
g_signal_callbackidback to summary
private long g_signal_callbackid
isGnomeback to summary
private boolean isGnome
listenersback to summary
private List<SessionManagerDBus.IListener> listeners
sessionManagerProxyback to summary
private long sessionManagerProxy
shutdownHookback to summary
private SessionManagerDBus.ShutdownHook shutdownHook

Constructor Detail

SessionManagerDBusback to summary
public SessionManagerDBus()

Method Detail

addListenerback to summary
public void addListener(SessionManagerDBus.IListener listener)

Subscribes display for session manager events. Display will receive SWT.Close and will be able to hint that the session should not end. Please note that time limit imposed by session manager is 1 second. Final cleanup should happen at Display.dispose(). Display will be disposed before session ends, allowing final cleanup to happen. Please note that time limit imposed by session manager is 10 seconds.

claimDesktopAutostartIDback to summary
private String claimDesktopAutostartID()

Gets the value of 'DESKTOP_AUTOSTART_ID'. This environment variable is set by session manager if the application was auto started (because it is configured to run automatically for every session). The variable helps session manager to match autostart settings with actual applications. For applications that were not started automatically, the variable is expected to be absent. Once used, 'DESKTOP_AUTOSTART_ID' must not leak into child processes, or they will fail to 'RegisterClient'.

Note

calling this function twice will give empty ID on second call. I think this is reasonable. If second object is created for whatever reason, it's OK to consider it to be a separate client.

connectClientSignalback to summary
private boolean connectClientSignal()
connectSessionManagerback to summary
private long connectSessionManager(String dbusName, String objectPath, String interfaceName)

Creates a connection to the session manager.

Returns:long

Pointer to dbus proxy, 0 if failed.

connectSessionManagerback to summary
private boolean connectSessionManager()
disposeback to summary
public void dispose()
extractFreeGErrorback to summary
private static String extractFreeGError(long errorPtr)
extractVariantTupleSback to summary
private static String extractVariantTupleS(long variant)
g_signal_handlerback to summary
private long g_signal_handler(long proxy, long sender_name, long signal_name, long parameters, long user_data)

Receives events from session manager. Docs: https://developer.gnome.org/gio/stable/GDBusProxy.html#GDBusProxy-g-signal NOTE: Will be called through native callback.

Returns:long

Error string in case of error, null if successful.

Annotations
@SuppressWarnings:unused
See Also
this.g_signal_callback
handleEndSessionback to summary
private void handleEndSession()
handleQueryEndSessionback to summary
private void handleQueryEndSession()
handleStopback to summary
private void handleStop()
queryReadyToExitback to summary
private boolean queryReadyToExit()
registerClientback to summary
private String registerClient(String appID, String clientStartupID)

Issues 'RegisterClient' dbus request to register with session manager. Saves result to member variable when successful.

Returns:String

Error string in case of error, null if successful.

registerClientback to summary
private boolean registerClient()
removeListenerback to summary
public void removeListener(SessionManagerDBus.IListener listener)
sendEndSessionResponseback to summary
private void sendEndSessionResponse(boolean is_ok, String reason, long responseID)
startback to summary
private boolean start()
stopback to summary
private synchronized void stop()

Un-subscribes from session manager events.

Note

Both Gnome and XFCE will automatically remove client record when client's process ends, so it's not a big deal if this is not called at all. See comments for this class to find 'dbus-send' commands to verify that. 'synchronized' guards against the rare possible case where some thread calls System.exit() while main thread is in Display.dispose() and both main thread and my 'ShutdownHook' try to run .stop().

wantEndSessionResponseback to summary
private long wantEndSessionResponse()
org.eclipse.swt.internal back to summary

public Interface SessionManagerDBus.IListener

Known Direct Implementers
org.eclipse.swt.widgets.Display.SessionManagerListener

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

false to hint that you're not ready. Session manager can ignore the hint.
isReadyToExit
()

Are you ready to exit?

public void
stop()

Perform final cleanup here.

Method Detail

isReadyToExitback to summary
public boolean isReadyToExit()

Are you ready to exit? Time limit imposed by session manager is 1 second. Final cleanup should happen in stop().

Returns:boolean

false to hint that you're not ready. Session manager can ignore the hint.

stopback to summary
public void stop()

Perform final cleanup here. Please note that time limit imposed by session manager is 10 seconds.

org.eclipse.swt.internal back to summary

private Class SessionManagerDBus.ShutdownHook

extends Thread
Class Inheritance

Field Summary

Modifier and TypeField and Description
private SessionManagerDBus
Inherited from java.lang.Thread:
MAX_PRIORITYMIN_PRIORITYNORM_PRIORITY

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
public void
public void
run()

Overrides java.lang.Thread.run.

Implements java.lang.Runnable.run.

This method is run by the thread when it executes.
Inherited from java.lang.Thread:
activeCountcheckAccessclonecurrentThreaddumpStackenumerategetAllStackTracesgetContextClassLoadergetDefaultUncaughtExceptionHandlergetIdgetNamegetPrioritygetStackTracegetStategetThreadGroupgetUncaughtExceptionHandlerholdsLockinterruptinterruptedisAliveisDaemonisInterruptedisVirtualjoinjoinjoinjoinofPlatformofVirtualonSpinWaitresumesetContextClassLoadersetDaemonsetDefaultUncaughtExceptionHandlersetNamesetPrioritysetUncaughtExceptionHandlersleepsleepsleepstartstartVirtualThreadstopsuspendthreadIdtoStringyield

Field Detail

parentback to summary
private SessionManagerDBus parent

Constructor Detail

ShutdownHookback to summary
public ShutdownHook(SessionManagerDBus parent)

Method Detail

installback to summary
public void install()
removeback to summary
public void remove()
runback to summary
public void run()

Overrides java.lang.Thread.run.

Implements java.lang.Runnable.run.

Doc from java.lang.Thread.run.

This method is run by the thread when it executes. Subclasses of Thread may override this method.

This method is not intended to be invoked directly. If this thread is a platform thread created with a Runnable task then invoking this method will invoke the task's run method. If this thread is a virtual thread then invoking this method directly does nothing.

Annotations
@Override