diff options
author | Eric Koegel <eric.koegel@gmail.com> | 2017-05-21 02:41:21 +0300 |
---|---|---|
committer | Eric Koegel <eric.koegel@gmail.com> | 2017-05-21 02:42:45 +0300 |
commit | c18d666f4f44abb9cb585a5ef59cf91b2f14b29f (patch) | |
tree | 9f27dd892fc149ffa5b431e8229f3c707de6fc55 | |
parent | 6820798cadc326f2664bdb452353889524624fdc (diff) | |
download | ConsoleKit2-c18d666f4f44abb9cb585a5ef59cf91b2f14b29f.tar.gz |
feat: Add session-class dbus property and get method
This adds a session-class property to the CK2 Session. It maps
to the class property of logind.
-rw-r--r-- | data/ConsoleKit.conf | 3 | ||||
-rw-r--r-- | doc/libconsolekit/libconsolekit-sections.txt | 3 | ||||
-rw-r--r-- | libconsolekit/libconsolekit.c | 92 | ||||
-rw-r--r-- | libconsolekit/libconsolekit.h | 5 | ||||
-rw-r--r-- | libconsolekit/test-libconsolekit.c | 20 | ||||
-rw-r--r-- | src/ck-session.c | 29 | ||||
-rw-r--r-- | src/org.freedesktop.ConsoleKit.Session.xml | 28 |
7 files changed, 176 insertions, 4 deletions
diff --git a/data/ConsoleKit.conf b/data/ConsoleKit.conf index ae67779..54f2ac2 100644 --- a/data/ConsoleKit.conf +++ b/data/ConsoleKit.conf @@ -154,6 +154,9 @@ send_member="GetSessionType"/> <allow send_destination="org.freedesktop.ConsoleKit" send_interface="org.freedesktop.ConsoleKit.Session" + send_member="GetSessionClass"/> + <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 e5ad3a0..dba061d 100644 --- a/doc/libconsolekit/libconsolekit-sections.txt +++ b/doc/libconsolekit/libconsolekit-sections.txt @@ -8,11 +8,13 @@ lib_consolekit_seat_get_sessions lib_consolekit_seat_can_multi_session lib_consolekit_session_is_active lib_consolekit_session_is_remote +lib_consolekit_session_get_class lib_consolekit_session_get_uid lib_consolekit_session_get_seat lib_consolekit_session_get_display lib_consolekit_session_get_remote_host lib_consolekit_session_get_tty +lib_consolekit_session_get_type lib_consolekit_session_get_vt lib_consolekit_pid_get_session <SUBSECTION Standard> @@ -24,5 +26,4 @@ LIB_IS_CONSOLEKIT_CLASS LIB_TYPE_CONSOLEKIT LibConsoleKit lib_consolekit_get_type -lib_consolekit_session_get_type </SECTION> diff --git a/libconsolekit/libconsolekit.c b/libconsolekit/libconsolekit.c index 2fd1b21..b67a711 100644 --- a/libconsolekit/libconsolekit.c +++ b/libconsolekit/libconsolekit.c @@ -840,6 +840,98 @@ lib_consolekit_session_get_type (LibConsoleKit *ck, } /** + * lib_consolekit_session_get_class: + * @ck : A #LibConsoleKit + * @session : The session to query + * @session_class : (out) (transfer full): The session's class + * @error : (out) (allow-none) (transfer full): The error message if something failed + * + * Returns the class of the provided session. The following classes + * may be returned: + * "user" - A normal user session, the default + * "greeter" - Display Manager pseudo session + * "lock-screen" - Screensaver based session + * "background" - A long running background process that requires its own session + * + * Note: Additional classes may be added in the future. Free the session_class + * string with g_free. + * + * Return value: TRUE on Success. + * + * Since: 1.0 + **/ +gboolean +lib_consolekit_session_get_class (LibConsoleKit *ck, + const gchar *session, + gchar **session_class, + 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 (session_class == NULL) { + g_set_error (error, + CONSOLEKIT_ERROR, + CONSOLEKIT_ERROR_INVALID_INPUT, + "session_class 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, + "GetSessionClass", + 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", session_class); + + g_variant_unref (variant); + variant = NULL; + + return TRUE; +} + +/** * lib_consolekit_session_get_display: * @ck : A #LibConsoleKit * @session : The session to query diff --git a/libconsolekit/libconsolekit.h b/libconsolekit/libconsolekit.h index a11d76f..234ac73 100644 --- a/libconsolekit/libconsolekit.h +++ b/libconsolekit/libconsolekit.h @@ -106,6 +106,11 @@ gboolean lib_consolekit_session_get_type (LibConsoleKit *ck, gchar **type, GError **error); +gboolean lib_consolekit_session_get_class (LibConsoleKit *ck, + const gchar *session, + gchar **session_class, + 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 75ad77e..3b77040 100644 --- a/libconsolekit/test-libconsolekit.c +++ b/libconsolekit/test-libconsolekit.c @@ -232,6 +232,24 @@ test_session_get_type (LibConsoleKit *ck, } static void +test_session_get_class (LibConsoleKit *ck, + const gchar *session) +{ + gchar *session_class = NULL; + GError *error = NULL; + + lib_consolekit_session_get_class (ck, session, &session_class, &error); + if (!error) { + g_print ("lib_consolekit_session_get_class (session %s) : session class %s\n", session, session_class); + } else { + g_print ("lib_consolekit_session_get_class (session %s) : error %s\n", session, error->message); + g_clear_error (&error); + } + + g_free (session_class); +} + +static void test_session_get_tty (LibConsoleKit *ck, const gchar *session) { @@ -352,6 +370,8 @@ main (int argc, test_session_get_type (ck, opt_session); + test_session_get_class (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 e2e7176..5c6eaaa 100644 --- a/src/ck-session.c +++ b/src/ck-session.c @@ -197,7 +197,7 @@ throw_error (GDBusMethodInvocation *context, static gboolean register_session (CkSession *session, GDBusConnection *connection) { - GError *error = NULL; + GError *error = NULL; g_debug ("register session"); @@ -249,7 +249,14 @@ register_session (CkSession *session, GDBusConnection *connection) } /* default to unspecified for the session type on startup */ - console_kit_session_set_session_type (CONSOLE_KIT_SESSION (session), "unspecified"); + if (console_kit_session_get_session_type (CONSOLE_KIT_SESSION (session)) == NULL) { + console_kit_session_set_session_type (CONSOLE_KIT_SESSION (session), "unspecified"); + } + + /* default to user for the session class on startup */ + if (console_kit_session_get_session_class (CONSOLE_KIT_SESSION (session)) == NULL) { + console_kit_session_set_session_class (CONSOLE_KIT_SESSION (session), "user"); + } return TRUE; } @@ -535,6 +542,23 @@ dbus_get_session_type (ConsoleKitSession *cksession, return TRUE; } +static gboolean +dbus_get_session_class (ConsoleKitSession *cksession, + GDBusMethodInvocation *context) +{ + const gchar *session_class = console_kit_session_get_session_class (cksession); + + TRACE (); + + if (session_class == NULL) { + /* default to user */ + session_class = "user"; + } + + console_kit_session_complete_get_session_class (cksession, context, session_class); + return TRUE; +} + static void ck_session_print_list_size (CkSession *session) { @@ -1988,6 +2012,7 @@ ck_session_iface_init (ConsoleKitSessionIface *iface) iface->handle_get_login_session_id = dbus_get_login_session_id; 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_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 a94e771..c698023 100644 --- a/src/org.freedesktop.ConsoleKit.Session.xml +++ b/src/org.freedesktop.ConsoleKit.Session.xml @@ -50,12 +50,31 @@ <doc:para>"wayland" - A Wayland based session</doc:para> <doc:para>"tty" - A text console based session</doc:para> <doc:para>"mir" - A session using the Mir display server</doc:para> - <doc:para>"unspecified" - Unknown session type.</doc:para> + <doc:para>"unspecified" - Unknown session type, the default.</doc:para> <doc:para>Note: Additional types may be added in the future.</doc:para> </doc:description> <doc:seealso><doc:ref type="property" to="Session:session-type">session-type</doc:ref></doc:seealso> </doc:doc> </method> + <method name="GetSessionClass"> + <arg name="type" direction="out" type="s"> + <doc:doc> + <doc:summary>Session class</doc:summary> + </doc:doc> + </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>"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> + <doc:para>"background" - A long running background process that requires its own session</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-class">session-class</doc:ref></doc:seealso> + </doc:doc> + </method> <method name="GetUser"> <arg name="uid" direction="out" type="u"> <doc:doc> @@ -598,6 +617,13 @@ </doc:description> </doc:doc> </property> + <property name="session-class" type="s" access="readwrite"> + <doc:doc> + <doc:description> + <doc:para>The class of the session.</doc:para> + </doc:description> + </doc:doc> + </property> <property name="remote-host-name" type="s" access="read"> <doc:doc> <doc:description> |