[gnome-session] Add a GsmSystem interface



commit 7082c67a6e31b19662bfe12a48710f408994a14b
Author: Matthias Clasen <mclasen redhat com>
Date:   Tue Jan 24 18:15:25 2012 -0500

    Add a GsmSystem interface
    
    https://bugzilla.gnome.org/show_bug.cgi?id=666891

 gnome-session/Makefile.am  |    2 +
 gnome-session/gsm-system.c |  118 ++++++++++++++++++++++++++++++++++++++++++++
 gnome-session/gsm-system.h |   88 ++++++++++++++++++++++++++++++++
 3 files changed, 208 insertions(+), 0 deletions(-)
---
diff --git a/gnome-session/Makefile.am b/gnome-session/Makefile.am
index c035aac..36a56ad 100644
--- a/gnome-session/Makefile.am
+++ b/gnome-session/Makefile.am
@@ -26,6 +26,8 @@ gnome_session_SOURCES =				\
 	gsm-fail-whale-dialog.c			\
 	gsm-marshal.h				\
 	gsm-marshal.c				\
+	gsm-system.h				\
+	gsm-system.c				\
 	gsm-consolekit.c			\
 	gsm-consolekit.h			\
 	gsm-logout-dialog.h			\
diff --git a/gnome-session/gsm-system.c b/gnome-session/gsm-system.c
new file mode 100644
index 0000000..da91d9f
--- /dev/null
+++ b/gnome-session/gsm-system.c
@@ -0,0 +1,118 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2012 Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+
+#include "config.h"
+
+#include <glib-object.h>
+#include <glib/gi18n.h>
+
+#include "gsm-system.h"
+#include "gsm-consolekit.h"
+
+enum {
+        REQUEST_COMPLETED = 0,
+        LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL] = { 0 };
+
+G_DEFINE_INTERFACE (GsmSystem, gsm_system, G_TYPE_INTERFACE);
+
+static void
+gsm_system_default_init (GsmSystemInterface *iface)
+{
+        signals [REQUEST_COMPLETED] =
+                g_signal_new ("request-completed",
+                              GSM_TYPE_SYSTEM,
+                              G_SIGNAL_RUN_LAST,
+                              G_STRUCT_OFFSET (GsmSystemInterface, request_completed),
+                              NULL,
+                              NULL,
+                              g_cclosure_marshal_VOID__POINTER,
+                              G_TYPE_NONE,
+                              1, G_TYPE_POINTER);
+}
+
+GQuark
+gsm_system_error_quark (void)
+{
+        static GQuark error_quark = 0;
+
+        if (error_quark == 0) {
+                error_quark = g_quark_from_static_string ("gsm-system-error");
+        }
+
+        return error_quark;
+}
+
+gboolean
+gsm_system_can_switch_user (GsmSystem *system)
+{
+        return GSM_SYSTEM_GET_IFACE (system)->can_switch_user (system);
+}
+
+gboolean
+gsm_system_can_stop (GsmSystem *system)
+{
+        return GSM_SYSTEM_GET_IFACE (system)->can_stop (system);
+}
+
+gboolean
+gsm_system_can_restart (GsmSystem *system)
+{
+        return GSM_SYSTEM_GET_IFACE (system)->can_restart (system);
+}
+
+void
+gsm_system_attempt_stop (GsmSystem *system)
+{
+        GSM_SYSTEM_GET_IFACE (system)->attempt_stop (system);
+}
+
+void
+gsm_system_attempt_restart (GsmSystem *system)
+{
+        GSM_SYSTEM_GET_IFACE (system)->attempt_restart (system);
+}
+
+void
+gsm_system_set_session_idle (GsmSystem *system,
+                             gboolean   is_idle)
+{
+        GSM_SYSTEM_GET_IFACE (system)->set_session_idle (system, is_idle);
+}
+
+gboolean
+gsm_system_is_login_session (GsmSystem *system)
+{
+        return GSM_SYSTEM_GET_IFACE (system)->is_login_session (system);
+}
+
+GsmSystem *
+gsm_get_system (void)
+{
+        static GsmSystem *system = NULL;
+
+        if (system == NULL) {
+                system = GSM_SYSTEM (gsm_consolekit_new ());
+        }
+
+        return g_object_ref (system);
+}
diff --git a/gnome-session/gsm-system.h b/gnome-session/gsm-system.h
new file mode 100644
index 0000000..c3975e7
--- /dev/null
+++ b/gnome-session/gsm-system.h
@@ -0,0 +1,88 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2008 Jon McCann <jmccann redhat com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * Authors:
+ *	Jon McCann <jmccann redhat com>
+ */
+
+#ifndef __GSM_SYSTEM_H__
+#define __GSM_SYSTEM_H__
+
+#include <glib.h>
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define GSM_TYPE_SYSTEM             (gsm_system_get_type ())
+#define GSM_SYSTEM(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), GSM_TYPE_SYSTEM, GsmSystem))
+#define GSM_SYSTEM_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), GSM_TYPE_SYSTEM, GsmSystemInterface))
+#define GSM_IS_SYSTEM(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GSM_TYPE_SYSTEM))
+#define GSM_SYSTEM_GET_IFACE(obj)   (G_TYPE_INSTANCE_GET_INTERFACE((obj), GSM_TYPE_SYSTEM, GsmSystemInterface))
+#define GSM_SYSTEM_ERROR            (gsm_system_error_quark ())
+
+typedef struct _GsmSystem          GsmSystem;
+typedef struct _GsmSystemInterface GsmSystemInterface;
+typedef enum   _GsmSystemError     GsmSystemError;
+
+struct _GsmSystemInterface
+{
+        GTypeInterface base_interface;
+
+        void (* request_completed)    (GsmSystem *system,
+                                       GError    *error);
+
+        gboolean (* can_switch_user)  (GsmSystem *system);
+        gboolean (* can_stop)         (GsmSystem *system);
+        gboolean (* can_restart)      (GsmSystem *system);
+        void     (* attempt_stop)     (GsmSystem *system);
+        void     (* attempt_restart)  (GsmSystem *system);
+        void     (* set_session_idle) (GsmSystem *system,
+                                       gboolean   is_idle);
+        gboolean (* is_login_session) (GsmSystem *system);
+};
+
+enum _GsmSystemError {
+        GSM_SYSTEM_ERROR_RESTARTING = 0,
+        GSM_SYSTEM_ERROR_STOPPING
+};
+
+GType      gsm_system_get_type         (void);
+
+GQuark     gsm_system_error_quark      (void);
+
+GsmSystem *gsm_get_system              (void);
+
+gboolean   gsm_system_can_switch_user  (GsmSystem *system);
+
+gboolean   gsm_system_can_stop         (GsmSystem *system);
+
+gboolean   gsm_system_can_restart      (GsmSystem *system);
+
+void       gsm_system_attempt_stop     (GsmSystem *system);
+
+void       gsm_system_attempt_restart  (GsmSystem *system);
+
+void       gsm_system_set_session_idle (GsmSystem *system,
+                                        gboolean   is_idle);
+
+gboolean   gsm_system_is_login_session (GsmSystem *system);
+
+G_END_DECLS
+
+#endif /* __GSM_SYSTEM_H__ */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]