summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore2
-rw-r--r--data/ConsoleKit.conf3
-rw-r--r--doc/libconsolekit/libconsolekit-sections.txt1
-rw-r--r--libconsolekit/libconsolekit.c93
-rw-r--r--libconsolekit/libconsolekit.h5
-rw-r--r--libconsolekit/test-libconsolekit.c20
-rw-r--r--src/ck-session.c27
-rw-r--r--src/org.freedesktop.ConsoleKit.Session.xml31
8 files changed, 178 insertions, 4 deletions
diff --git a/.gitignore b/.gitignore
index 45686a9..dafebac 100644
--- a/.gitignore
+++ b/.gitignore
@@ -84,6 +84,8 @@ doc/libconsolekit/setup-build.stamp
doc/libconsolekit/libconsolekit-scan.c
doc/libconsolekit/libconsolekit-decl.txt
doc/libconsolekit/libconsolekit-decl-list.txt
+doc/libconsolekit/libconsolekit-decl-list.txt.bak
+doc/libconsolekit/libconsolekit-decl.txt.bak
doc/libconsolekit/.libs/
doc/libconsolekit/gtkdoc-check.log
doc/libconsolekit/gtkdoc-check.test
diff --git a/data/ConsoleKit.conf b/data/ConsoleKit.conf
index 54f2ac2..9c564ce 100644
--- a/data/ConsoleKit.conf
+++ b/data/ConsoleKit.conf
@@ -157,6 +157,9 @@
send_member="GetSessionClass"/>
<allow send_destination="org.freedesktop.ConsoleKit"
send_interface="org.freedesktop.ConsoleKit.Session"
+ send_member="GetSessionState"/>
+ <allow send_destination="org.freedesktop.ConsoleKit"
+ send_interface="org.freedesktop.ConsoleKit.Session"
send_member="GetUser"/>
<allow send_destination="org.freedesktop.ConsoleKit"
send_interface="org.freedesktop.ConsoleKit.Session"
diff --git a/doc/libconsolekit/libconsolekit-sections.txt b/doc/libconsolekit/libconsolekit-sections.txt
index dba061d..3c34527 100644
--- a/doc/libconsolekit/libconsolekit-sections.txt
+++ b/doc/libconsolekit/libconsolekit-sections.txt
@@ -11,6 +11,7 @@ lib_consolekit_session_is_remote
lib_consolekit_session_get_class
lib_consolekit_session_get_uid
lib_consolekit_session_get_seat
+lib_consolekit_session_get_state
lib_consolekit_session_get_display
lib_consolekit_session_get_remote_host
lib_consolekit_session_get_tty
diff --git a/libconsolekit/libconsolekit.c b/libconsolekit/libconsolekit.c
index b67a711..0b77e63 100644
--- a/libconsolekit/libconsolekit.c
+++ b/libconsolekit/libconsolekit.c
@@ -932,6 +932,97 @@ lib_consolekit_session_get_class (LibConsoleKit *ck,
}
/**
+ * lib_consolekit_session_get_state:
+ * @ck : A #LibConsoleKit
+ * @session : The session to query
+ * @state : (out) (transfer full): The session's state
+ * @error : (out) (allow-none) (transfer full): The error message if something failed
+ *
+ * Returns the current state of the provided session. The following states
+ * may be returned:
+ * "online" - Session is logged in but not active
+ * "active" - Session is logged in and active
+ * "closing" - Session is in the process of shutting down
+ *
+ * Note: Additional states may be added in the future. Free the state
+ * string with g_free.
+ *
+ * Return value: TRUE on Success.
+ *
+ * Since: 1.0
+ **/
+gboolean
+lib_consolekit_session_get_state (LibConsoleKit *ck,
+ const gchar *session,
+ gchar **state,
+ GError **error)
+{
+ GDBusProxy *session_proxy = NULL;
+ GVariant *variant = NULL;
+
+ if (ck == NULL) {
+ g_set_error (error,
+ CONSOLEKIT_ERROR,
+ CONSOLEKIT_ERROR_INVALID_INPUT,
+ "Invalid LibConsoleKit");
+ return FALSE;
+ }
+
+ if (session == NULL) {
+ g_set_error (error,
+ CONSOLEKIT_ERROR,
+ CONSOLEKIT_ERROR_INVALID_INPUT,
+ "Session must not be NULL");
+ return FALSE;
+ }
+
+ if (state == NULL) {
+ g_set_error (error,
+ CONSOLEKIT_ERROR,
+ CONSOLEKIT_ERROR_INVALID_INPUT,
+ "state must not be NULL");
+ return FALSE;
+ }
+
+ /* connect to the ConsoleKit session */
+ session_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
+ G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES | G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS,
+ NULL,
+ CK_NAME,
+ session,
+ CK_SESSION_NAME,
+ NULL,
+ error);
+
+ /* failed to connect */
+ if (session_proxy == NULL) {
+ return FALSE;
+ }
+
+ variant = g_dbus_proxy_call_sync (session_proxy,
+ "GetSessionState",
+ g_variant_new ("()"),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ error);
+
+ /* We're done with the session proxy */
+ g_clear_object(&session_proxy);
+
+ if (variant == NULL) {
+ return FALSE;
+ }
+
+ g_variant_get_child (variant, 0, "s", state);
+
+ g_variant_unref (variant);
+ variant = NULL;
+
+ return TRUE;
+}
+
+/**
* lib_consolekit_session_get_display:
* @ck : A #LibConsoleKit
* @session : The session to query
@@ -1183,7 +1274,7 @@ lib_consolekit_session_get_tty (LibConsoleKit *ck,
/* We're not running X11, try for just the display device */
if (strlen (*tty) == 0) {
- g_free (tty);
+ g_free (*tty);
variant = g_dbus_proxy_call_sync (session_proxy,
"GetDisplayDevice",
diff --git a/libconsolekit/libconsolekit.h b/libconsolekit/libconsolekit.h
index 234ac73..fd75362 100644
--- a/libconsolekit/libconsolekit.h
+++ b/libconsolekit/libconsolekit.h
@@ -111,6 +111,11 @@ gboolean lib_consolekit_session_get_class (LibConsoleKit *ck,
gchar **session_class,
GError **error);
+gboolean lib_consolekit_session_get_state (LibConsoleKit *ck,
+ const gchar *session,
+ gchar **state,
+ GError **error);
+
gboolean lib_consolekit_session_get_display (LibConsoleKit *ck,
const gchar *session,
gchar **display,
diff --git a/libconsolekit/test-libconsolekit.c b/libconsolekit/test-libconsolekit.c
index 3b77040..449a6d3 100644
--- a/libconsolekit/test-libconsolekit.c
+++ b/libconsolekit/test-libconsolekit.c
@@ -250,6 +250,24 @@ test_session_get_class (LibConsoleKit *ck,
}
static void
+test_session_get_state (LibConsoleKit *ck,
+ const gchar *session)
+{
+ gchar *state = NULL;
+ GError *error = NULL;
+
+ lib_consolekit_session_get_state (ck, session, &state, &error);
+ if (!error) {
+ g_print ("lib_consolekit_session_get_state (session %s) : session state %s\n", session, state);
+ } else {
+ g_print ("lib_consolekit_session_get_state (session %s) : error %s\n", session, error->message);
+ g_clear_error (&error);
+ }
+
+ g_free (state);
+}
+
+static void
test_session_get_tty (LibConsoleKit *ck,
const gchar *session)
{
@@ -372,6 +390,8 @@ main (int argc,
test_session_get_class (ck, opt_session);
+ test_session_get_state (ck, opt_session);
+
test_session_get_tty (ck, opt_session);
test_session_get_vt (ck, opt_session);
diff --git a/src/ck-session.c b/src/ck-session.c
index 5c6eaaa..a994c69 100644
--- a/src/ck-session.c
+++ b/src/ck-session.c
@@ -258,6 +258,11 @@ register_session (CkSession *session, GDBusConnection *connection)
console_kit_session_set_session_class (CONSOLE_KIT_SESSION (session), "user");
}
+ /* default to online for the session state on startup */
+ if (console_kit_session_get_session_class (CONSOLE_KIT_SESSION (session)) == NULL) {
+ console_kit_session_set_session_class (CONSOLE_KIT_SESSION (session), "online");
+ }
+
return TRUE;
}
@@ -559,6 +564,23 @@ dbus_get_session_class (ConsoleKitSession *cksession,
return TRUE;
}
+static gboolean
+dbus_get_session_state (ConsoleKitSession *cksession,
+ GDBusMethodInvocation *context)
+{
+ const gchar *state = console_kit_session_get_session_state (cksession);
+
+ TRACE ();
+
+ if (state == NULL) {
+ /* default to online, but this shouldn't really happen */
+ state = "online";
+ }
+
+ console_kit_session_complete_get_session_state (cksession, context, state);
+ return TRUE;
+}
+
static void
ck_session_print_list_size (CkSession *session)
{
@@ -593,6 +615,7 @@ ck_session_check_paused_devices (CkSession *session)
console_kit_session_set_active (cksession, FALSE);
console_kit_session_emit_active_changed (cksession, FALSE);
+ console_kit_session_set_session_state (cksession, "online");
}
if (session->priv->pause_devices_timer != 0) {
@@ -663,6 +686,7 @@ ck_session_pause_all_devices (CkSession *session,
console_kit_session_set_active (cksession, FALSE);
console_kit_session_emit_active_changed (cksession, FALSE);
+ console_kit_session_set_session_state (cksession, "online");
} else {
session->priv->pause_devices_timer = g_timeout_add_seconds (3, (GSourceFunc)force_pause_devices, session);
}
@@ -728,6 +752,7 @@ ck_session_resume_all_devices (CkSession *session)
g_debug ("no session controller: marking session active");
console_kit_session_set_active (cksession, TRUE);
console_kit_session_emit_active_changed (cksession, TRUE);
+ console_kit_session_set_session_state (cksession, "active");
return;
}
@@ -789,6 +814,7 @@ ck_session_resume_all_devices (CkSession *session)
g_debug ("marking session active");
console_kit_session_set_active (cksession, TRUE);
console_kit_session_emit_active_changed (cksession, TRUE);
+ console_kit_session_set_session_state (cksession, "active");
}
gboolean
@@ -2013,6 +2039,7 @@ ck_session_iface_init (ConsoleKitSessionIface *iface)
iface->handle_get_vtnr = dbus_get_vtnr;
iface->handle_get_session_type = dbus_get_session_type;
iface->handle_get_session_class = dbus_get_session_class;
+ iface->handle_get_session_state = dbus_get_session_state;
iface->handle_get_x11_display_device = dbus_get_x11_display_device;
iface->handle_get_display_device = dbus_get_display_device;
iface->handle_get_x11_display = dbus_get_x11_display;
diff --git a/src/org.freedesktop.ConsoleKit.Session.xml b/src/org.freedesktop.ConsoleKit.Session.xml
index c698023..f899103 100644
--- a/src/org.freedesktop.ConsoleKit.Session.xml
+++ b/src/org.freedesktop.ConsoleKit.Session.xml
@@ -64,7 +64,7 @@
</arg>
<doc:doc>
<doc:description>
- <doc:para>Returns the display type of the provided session. The following type may be returned:</doc:para>
+ <doc:para>Returns the display type of the provided session. The following classes may be returned:</doc:para>
<doc:para>"user" - A normal user session, the default</doc:para>
<doc:para>"greeter" - Display Manager pseudo session</doc:para>
<doc:para>"lock-screen" - Screensaver based session</doc:para>
@@ -75,6 +75,24 @@
<doc:seealso><doc:ref type="property" to="Session:session-class">session-class</doc:ref></doc:seealso>
</doc:doc>
</method>
+ <method name="GetSessionState">
+ <arg name="type" direction="out" type="s">
+ <doc:doc>
+ <doc:summary>Session state</doc:summary>
+ </doc:doc>
+ </arg>
+ <doc:doc>
+ <doc:description>
+ <doc:para>Returns the current state of the session. The following states may be returned:</doc:para>
+ <doc:para>"online" - Session is logged in but not active</doc:para>
+ <doc:para>"active" - Session is logged in and active</doc:para>
+ <doc:para>"closing" - Session is in the process of shutting down</doc:para>
+ <doc:para>Note: Additional classes may be added in the future.</doc:para>
+ <doc:para>Since 1.1.2</doc:para>
+ </doc:description>
+ <doc:seealso><doc:ref type="property" to="Session:session-state">session-state</doc:ref></doc:seealso>
+ </doc:doc>
+ </method>
<method name="GetUser">
<arg name="uid" direction="out" type="u">
<doc:doc>
@@ -610,20 +628,27 @@
</doc:description>
</doc:doc>
</property>
- <property name="session-type" type="s" access="readwrite">
+ <property name="session-type" type="s" access="read">
<doc:doc>
<doc:description>
<doc:para>The type of the session.</doc:para>
</doc:description>
</doc:doc>
</property>
- <property name="session-class" type="s" access="readwrite">
+ <property name="session-class" type="s" access="read">
<doc:doc>
<doc:description>
<doc:para>The class of the session.</doc:para>
</doc:description>
</doc:doc>
</property>
+ <property name="session-state" type="s" access="read">
+ <doc:doc>
+ <doc:description>
+ <doc:para>The state of the session.</doc:para>
+ </doc:description>
+ </doc:doc>
+ </property>
<property name="remote-host-name" type="s" access="read">
<doc:doc>
<doc:description>