Commit a7c3b020 authored by Cosimo Cecchi's avatar Cosimo Cecchi Committed by Ray Strode
parent 82fde2ab
......@@ -16,6 +16,7 @@ AM_CPPFLAGS = \
AM_CFLAGS = $(WARN_CFLAGS)
gnome_session_SOURCES = \
$(BUILT_SOURCES) \
gsm-app.h \
gsm-app.c \
gsm-autostart-app.h \
......@@ -125,8 +126,14 @@ test_process_helper_SOURCES = test-process-helper.c gsm-process-helper.c gsm-pro
test_process_helper_CFLAGS = $(AM_CFLAGS) $(GIO_CFLAGS)
test_process_helper_LDADD = $(GIO_LIBS)
gsm-manager-glue.h: org.gnome.SessionManager.xml Makefile.am
$(AM_V_GEN)dbus-binding-tool --prefix=gsm_manager --mode=glib-server --output=gsm-manager-glue.h $(srcdir)/org.gnome.SessionManager.xml
org.gnome.SessionManager.h: org.gnome.SessionManager.xml Makefile.am
$(AM_V_GEN) gdbus-codegen --interface-prefix org.gnome.SessionManager. \
--generate-c-code org.gnome.SessionManager \
--c-namespace Gsm \
--annotate "org.gnome.SessionManager" "org.gtk.GDBus.C.Name" ExportedManager \
$(srcdir)/org.gnome.SessionManager.xml
org.gnome.SessionManager.c: org.gnome.SessionManager.h
@: # generated as a side-effect
gsm-client-glue.h: org.gnome.SessionManager.Client.xml Makefile.am
$(AM_V_GEN)dbus-binding-tool --prefix=gsm_client --mode=glib-server --output=gsm-client-glue.h $(srcdir)/org.gnome.SessionManager.Client.xml
......@@ -141,7 +148,8 @@ gsm-presence-glue.h: org.gnome.SessionManager.Presence.xml Makefile.am
$(AM_V_GEN)dbus-binding-tool --prefix=gsm_presence --mode=glib-server --output=gsm-presence-glue.h $(srcdir)/org.gnome.SessionManager.Presence.xml
BUILT_SOURCES = \
gsm-manager-glue.h \
org.gnome.SessionManager.h \
org.gnome.SessionManager.c \
gsm-presence-glue.h \
gsm-inhibitor-glue.h \
gsm-client-glue.h \
......
This diff is collapsed.
......@@ -48,21 +48,8 @@ typedef struct
{
GObjectClass parent_class;
void (* session_running) (GsmManager *manager);
void (* session_over) (GsmManager *manager);
void (* session_over_notice) (GsmManager *manager);
void (* phase_changed) (GsmManager *manager,
const char *phase);
void (* client_added) (GsmManager *manager,
const char *id);
void (* client_removed) (GsmManager *manager,
const char *id);
void (* inhibitor_added) (GsmManager *manager,
const char *id);
void (* inhibitor_removed) (GsmManager *manager,
const char *id);
} GsmManagerClass;
typedef enum {
......@@ -103,11 +90,8 @@ typedef enum
} GsmManagerError;
#define GSM_MANAGER_ERROR gsm_manager_error_quark ()
GType gsm_manager_error_get_type (void);
#define GSM_MANAGER_TYPE_ERROR (gsm_manager_error_get_type ())
GQuark gsm_manager_error_quark (void);
GType gsm_manager_get_type (void);
GsmManager * gsm_manager_new (GsmStore *client_store,
......@@ -135,70 +119,12 @@ void _gsm_manager_set_active_session (GsmManager *
const char *session_name,
gboolean is_fallback);
/* exported methods */
gboolean gsm_manager_register_client (GsmManager *manager,
const char *app_id,
const char *client_startup_id,
DBusGMethodInvocation *context);
gboolean gsm_manager_unregister_client (GsmManager *manager,
const char *session_client_id,
DBusGMethodInvocation *context);
gboolean gsm_manager_inhibit (GsmManager *manager,
const char *app_id,
guint toplevel_xid,
const char *reason,
guint flags,
DBusGMethodInvocation *context);
gboolean gsm_manager_uninhibit (GsmManager *manager,
guint inhibit_cookie,
DBusGMethodInvocation *context);
gboolean gsm_manager_is_inhibited (GsmManager *manager,
guint flags,
gboolean *is_inhibited,
GError *error);
gboolean gsm_manager_shutdown (GsmManager *manager,
DBusGMethodInvocation *context);
gboolean gsm_manager_reboot (GsmManager *manager,
DBusGMethodInvocation *context);
gboolean gsm_manager_can_shutdown (GsmManager *manager,
gboolean *shutdown_available,
GError **error);
gboolean gsm_manager_logout (GsmManager *manager,
guint logout_mode,
GError **error);
gboolean gsm_manager_setenv (GsmManager *manager,
const char *variable,
const char *value,
GError **error);
gboolean gsm_manager_get_locale (GsmManager *manager,
int category,
const char **value,
GError **error);
gboolean gsm_manager_initialization_error (GsmManager *manager,
const char *message,
gboolean fatal,
GError **error);
gboolean gsm_manager_get_clients (GsmManager *manager,
GPtrArray **clients,
GError **error);
gboolean gsm_manager_get_inhibitors (GsmManager *manager,
GPtrArray **inhibitors,
GError **error);
gboolean gsm_manager_is_autostart_condition_handled (GsmManager *manager,
const char *condition,
gboolean *handled,
GError **error);
gboolean gsm_manager_set_phase (GsmManager *manager,
GsmManagerPhase phase);
gboolean gsm_manager_is_session_running (GsmManager *manager,
gboolean *running,
GError **error);
G_END_DECLS
......
......@@ -28,13 +28,8 @@
#include <glib/gi18n.h>
#include <glib.h>
#include <glib-unix.h>
#include <dbus/dbus.h>
#include <dbus/dbus-glib.h>
#include <dbus/dbus-glib-bindings.h>
#include <dbus/dbus-glib-lowlevel.h>
#include <gio/gio.h>
#include "gdm-log.h"
......@@ -56,13 +51,11 @@ static gboolean show_version = FALSE;
static gboolean debug = FALSE;
static gboolean please_fail = FALSE;
static gboolean disable_acceleration_check = FALSE;
static DBusGProxy *bus_proxy = NULL;
static const char *session_name = NULL;
static GsmManager *manager = NULL;
static GMainLoop *loop;
static void shutdown_cb (gpointer data);
void
gsm_quit (void)
{
......@@ -79,111 +72,28 @@ gsm_main (void)
}
static void
on_bus_name_lost (DBusGProxy *bus_proxy,
const char *name,
gpointer data)
{
g_warning ("Lost name on bus: %s, exiting", name);
exit (1);
}
static gboolean
acquire_name_on_proxy (DBusGProxy *bus_proxy,
const char *name)
{
GError *error;
guint result;
gboolean res;
gboolean ret;
ret = FALSE;
if (bus_proxy == NULL) {
goto out;
}
error = NULL;
res = dbus_g_proxy_call (bus_proxy,
"RequestName",
&error,
G_TYPE_STRING, name,
G_TYPE_UINT, 0,
G_TYPE_INVALID,
G_TYPE_UINT, &result,
G_TYPE_INVALID);
if (! res) {
if (error != NULL) {
g_warning ("Failed to acquire %s: %s", name, error->message);
g_error_free (error);
} else {
g_warning ("Failed to acquire %s", name);
}
goto out;
}
if (result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
if (error != NULL) {
g_warning ("Failed to acquire %s: %s", name, error->message);
g_error_free (error);
} else {
g_warning ("Failed to acquire %s", name);
}
goto out;
}
/* register for name lost */
dbus_g_proxy_add_signal (bus_proxy,
"NameLost",
G_TYPE_STRING,
G_TYPE_INVALID);
dbus_g_proxy_connect_signal (bus_proxy,
"NameLost",
G_CALLBACK (on_bus_name_lost),
NULL,
NULL);
ret = TRUE;
out:
return ret;
}
static gboolean
acquire_name (void)
on_name_lost (GDBusConnection *connection,
const char *name,
gpointer data)
{
GError *error;
DBusGConnection *connection;
GsmManager *manager = (GsmManager *)data;
error = NULL;
connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
if (connection == NULL) {
gsm_util_init_error (TRUE,
"Could not connect to session bus: %s",
error->message);
return FALSE;
}
g_warning ("Lost name on bus: %s", name);
gsm_fail_whale_dialog_we_failed (TRUE, TRUE, NULL);
} else {
g_debug ("Calling name lost callback function");
bus_proxy = dbus_g_proxy_new_for_name_owner (connection,
DBUS_SERVICE_DBUS,
DBUS_PATH_DBUS,
DBUS_INTERFACE_DBUS,
&error);
if (error != NULL) {
gsm_util_init_error (TRUE,
"Could not connect to session bus: %s",
error->message);
return FALSE;
}
/*
* When the signal handler gets a shutdown signal, it calls
* this function to inform GsmManager to not restart
* applications in the off chance a handler is already queued
* to dispatch following the below call to gtk_main_quit.
*/
gsm_manager_set_phase (manager, GSM_MANAGER_PHASE_EXIT);
if (! acquire_name_on_proxy (bus_proxy, GSM_DBUS_NAME) ) {
gsm_util_init_error (TRUE,
"%s",
"Could not acquire name on session bus");
return FALSE;
gsm_quit ();
}
return TRUE;
}
static gboolean
......@@ -214,20 +124,48 @@ sigusr1_cb (gpointer data)
}
static void
shutdown_cb (gpointer data)
create_manager (void)
{
GsmManager *manager = (GsmManager *)data;
g_debug ("Calling shutdown callback function");
GsmStore *client_store;
/*
* When the signal handler gets a shutdown signal, it calls
* this function to inform GsmManager to not restart
* applications in the off chance a handler is already queued
* to dispatch following the below call to gtk_main_quit.
*/
gsm_manager_set_phase (manager, GSM_MANAGER_PHASE_EXIT);
client_store = gsm_store_new ();
manager = gsm_manager_new (client_store, failsafe);
g_object_unref (client_store);
g_unix_signal_add (SIGTERM, term_or_int_signal_cb, manager);
g_unix_signal_add (SIGINT, term_or_int_signal_cb, manager);
g_unix_signal_add (SIGUSR1, sigusr1_cb, manager);
g_unix_signal_add (SIGUSR2, sigusr2_cb, manager);
if (IS_STRING_EMPTY (session_name)) {
session_name = _gsm_manager_get_default_session (manager);
}
if (!gsm_session_fill (manager, session_name)) {
gsm_fail_whale_dialog_we_failed (FALSE, TRUE, NULL);
}
gsm_quit ();
gsm_manager_start (manager);
}
static void
on_bus_acquired (GDBusConnection *connection,
const char *name,
gpointer data)
{
create_manager ();
}
static guint
acquire_name (void)
{
return g_bus_own_name (G_BUS_TYPE_SESSION,
GSM_DBUS_NAME,
G_BUS_NAME_OWNER_FLAGS_NONE,
on_bus_acquired,
NULL,
on_name_lost,
NULL, NULL);
}
static gboolean
......@@ -293,12 +231,10 @@ int
main (int argc, char **argv)
{
GError *error = NULL;
GsmManager *manager;
GsmStore *client_store;
static char **override_autostart_dirs = NULL;
static char *opt_session_name = NULL;
const char *session_name;
gboolean gl_failed = FALSE;
guint name_owner_id;
GOptionContext *options;
static GOptionEntry entries[] = {
{ "autostart", 'a', 0, G_OPTION_ARG_STRING_ARRAY, &override_autostart_dirs, N_("Override standard autostart directories"), N_("AUTOSTART_DIR") },
......@@ -407,7 +343,8 @@ main (int argc, char **argv)
*/
gsm_util_setenv ("XDG_MENU_PREFIX", "gnome-");
client_store = gsm_store_new ();
gsm_util_set_autostart_dirs (override_autostart_dirs);
session_name = opt_session_name;
/* Talk to logind before acquiring a name, since it does synchronous
* calls at initialization time that invoke a main loop and if we
......@@ -416,44 +353,13 @@ main (int argc, char **argv)
*/
g_object_unref (gsm_get_system ());
if (!acquire_name ()) {
gsm_fail_whale_dialog_we_failed (TRUE, TRUE, NULL);
gsm_main ();
exit (1);
}
manager = gsm_manager_new (client_store, failsafe);
g_signal_connect_object (bus_proxy,
"destroy",
G_CALLBACK (shutdown_cb),
manager,
G_CONNECT_SWAPPED);
g_unix_signal_add (SIGTERM, term_or_int_signal_cb, manager);
g_unix_signal_add (SIGINT, term_or_int_signal_cb, manager);
g_unix_signal_add (SIGUSR1, sigusr1_cb, manager);
g_unix_signal_add (SIGUSR2, sigusr2_cb, manager);
if (IS_STRING_EMPTY (opt_session_name))
session_name = _gsm_manager_get_default_session (manager);
else
session_name = opt_session_name;
gsm_util_set_autostart_dirs (override_autostart_dirs);
if (!gsm_session_fill (manager, session_name)) {
gsm_fail_whale_dialog_we_failed (FALSE, TRUE, NULL);
}
gsm_manager_start (manager);
name_owner_id = acquire_name ();
gsm_main ();
g_clear_object (&manager);
g_clear_object (&client_store);
g_clear_object (&bus_proxy);
g_bus_unown_name (name_owner_id);
gdm_log_shutdown ();
return 0;
......
......@@ -62,7 +62,6 @@
<!-- Running phase interfaces -->
<method name="RegisterClient">
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<arg type="s" name="app_id" direction="in">
<doc:doc>
<doc:summary>The application identifier</doc:summary>
......@@ -86,7 +85,6 @@
</method>
<method name="UnregisterClient">
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<arg type="o" name="client_id" direction="in">
<doc:doc>
<doc:summary>The object path of the client</doc:summary>
......@@ -100,7 +98,6 @@
</method>
<method name="Inhibit">
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<arg type="s" name="app_id" direction="in">
<doc:doc>
<doc:summary>The application identifier</doc:summary>
......@@ -181,7 +178,6 @@
</method>
<method name="Uninhibit">
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<arg type="u" name="inhibit_cookie" direction="in">
<doc:doc>
<doc:summary>The cookie</doc:summary>
......@@ -271,7 +267,6 @@
</method>
<method name="Shutdown">
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<doc:doc>
<doc:description>
<doc:para>Request a shutdown dialog.</doc:para>
......@@ -280,7 +275,6 @@
</method>
<method name="Reboot">
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<doc:doc>
<doc:description>
<doc:para>Request a reboot dialog.</doc:para>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment