LCOV - code coverage report
Current view: top level - src/plugins/xdp - valent-xdp-session.c (source / functions) Coverage Total Hit
Test: Code Coverage Lines: 0.0 % 61 0
Test Date: 2024-04-23 06:02:46 Functions: 0.0 % 11 0
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : // SPDX-License-Identifier: GPL-3.0-or-later
       2                 :             : // SPDX-FileCopyrightText: Andy Holmes <andrew.g.r.holmes@gmail.com>
       3                 :             : 
       4                 :             : #define G_LOG_DOMAIN "valent-xdp-session"
       5                 :             : 
       6                 :             : #include "config.h"
       7                 :             : 
       8                 :             : #include <libportal/portal.h>
       9                 :             : #include <valent.h>
      10                 :             : 
      11                 :             : #include "valent-xdp-session.h"
      12                 :             : #include "valent-xdp-utils.h"
      13                 :             : 
      14                 :             : 
      15                 :             : struct _ValentXdpSession
      16                 :             : {
      17                 :             :   ValentSessionAdapter  parent_instance;
      18                 :             : 
      19                 :             :   unsigned int          active : 1;
      20                 :             :   unsigned int          locked : 1;
      21                 :             : };
      22                 :             : 
      23                 :             : static void   g_async_initable_iface_init (GAsyncInitableIface *iface);
      24                 :             : 
      25                 :           0 : G_DEFINE_FINAL_TYPE_WITH_CODE (ValentXdpSession, valent_xdp_session, VALENT_TYPE_SESSION_ADAPTER,
      26                 :             :                                G_IMPLEMENT_INTERFACE (G_TYPE_ASYNC_INITABLE, g_async_initable_iface_init))
      27                 :             : 
      28                 :             : 
      29                 :             : static void
      30                 :           0 : on_session_state_changed (XdpPortal            *portal,
      31                 :             :                           gboolean              screensaver_active,
      32                 :             :                           XdpLoginSessionState  state,
      33                 :             :                           ValentXdpSession     *self)
      34                 :             : {
      35                 :           0 :   g_assert (VALENT_IS_XDP_SESSION (self));
      36                 :             : 
      37                 :           0 :   if (self->active != (state == XDP_LOGIN_SESSION_RUNNING))
      38                 :             :     {
      39                 :           0 :       self->active = (state == XDP_LOGIN_SESSION_RUNNING);
      40                 :           0 :       g_object_notify (G_OBJECT (self), "active");
      41                 :             :     }
      42                 :             : 
      43                 :           0 :   if (self->locked != screensaver_active)
      44                 :             :     {
      45                 :           0 :       self->locked = screensaver_active;
      46                 :           0 :       g_object_notify (G_OBJECT (self), "locked");
      47                 :             :     }
      48                 :             : 
      49                 :           0 :   xdp_portal_session_monitor_query_end_response (portal);
      50                 :           0 : }
      51                 :             : 
      52                 :             : /*
      53                 :             :  * ValentSessionAdapter
      54                 :             :  */
      55                 :             : static gboolean
      56                 :           0 : valent_xdp_session_get_active (ValentSessionAdapter *adapter)
      57                 :             : {
      58                 :           0 :   ValentXdpSession *self = VALENT_XDP_SESSION (adapter);
      59                 :             : 
      60                 :           0 :   return self->active;
      61                 :             : }
      62                 :             : 
      63                 :             : static gboolean
      64                 :           0 : valent_xdp_session_get_locked (ValentSessionAdapter *adapter)
      65                 :             : {
      66                 :           0 :   ValentXdpSession *self = VALENT_XDP_SESSION (adapter);
      67                 :             : 
      68                 :           0 :   return self->locked;
      69                 :             : }
      70                 :             : 
      71                 :             : /*
      72                 :             :  * GAsyncInitable
      73                 :             :  */
      74                 :             : static void
      75                 :           0 : xdp_portal_session_monitor_start_cb (GObject      *object,
      76                 :             :                                      GAsyncResult *result,
      77                 :             :                                      gpointer      user_data)
      78                 :             : {
      79                 :           0 :   XdpPortal *portal = XDP_PORTAL (object);
      80                 :           0 :   g_autoptr (GTask) task = G_TASK (user_data);
      81                 :           0 :   ValentXdpSession *self = g_task_get_source_object (task);
      82                 :           0 :   g_autoptr (GError) error = NULL;
      83                 :             : 
      84                 :           0 :   g_assert (G_IS_TASK (task));
      85                 :           0 :   g_assert (VALENT_IS_XDP_SESSION (self));
      86                 :             : 
      87                 :           0 :   if (!xdp_portal_session_monitor_start_finish (portal, result, &error))
      88                 :             :     {
      89                 :           0 :       valent_extension_plugin_state_changed (VALENT_EXTENSION (self),
      90                 :             :                                              VALENT_PLUGIN_STATE_ERROR,
      91                 :             :                                              error);
      92                 :           0 :       return g_task_return_error (task, g_steal_pointer (&error));
      93                 :             :     }
      94                 :             : 
      95                 :           0 :   g_signal_connect_object (portal,
      96                 :             :                            "session-state-changed",
      97                 :             :                            G_CALLBACK (on_session_state_changed),
      98                 :             :                            self, 0);
      99                 :             : 
     100                 :             :   /* Report the adapter as active */
     101                 :           0 :   valent_extension_plugin_state_changed (VALENT_EXTENSION (self),
     102                 :             :                                          VALENT_PLUGIN_STATE_ACTIVE,
     103                 :             :                                          NULL);
     104                 :           0 :   g_task_return_boolean (task, TRUE);
     105                 :             : }
     106                 :             : 
     107                 :             : static void
     108                 :           0 : valent_xdp_session_init_async (GAsyncInitable      *initable,
     109                 :             :                                int                  io_priority,
     110                 :             :                                GCancellable        *cancellable,
     111                 :             :                                GAsyncReadyCallback  callback,
     112                 :             :                                gpointer             user_data)
     113                 :             : {
     114                 :           0 :   g_autoptr (GTask) task = NULL;
     115                 :           0 :   g_autoptr (GCancellable) destroy = NULL;
     116                 :           0 :   g_autoptr (XdpParent) parent = NULL;
     117                 :             : 
     118                 :           0 :   g_assert (VALENT_IS_XDP_SESSION (initable));
     119                 :             : 
     120                 :             :   /* Cede the primary position until complete */
     121                 :           0 :   valent_extension_plugin_state_changed (VALENT_EXTENSION (initable),
     122                 :             :                                          VALENT_PLUGIN_STATE_INACTIVE,
     123                 :             :                                          NULL);
     124                 :             : 
     125                 :             :   /* Cancel initialization if the object is destroyed */
     126                 :           0 :   destroy = valent_object_chain_cancellable (VALENT_OBJECT (initable),
     127                 :             :                                              cancellable);
     128                 :             : 
     129                 :           0 :   task = g_task_new (initable, destroy, callback, user_data);
     130                 :           0 :   g_task_set_priority (task, io_priority);
     131                 :           0 :   g_task_set_source_tag (task, valent_xdp_session_init_async);
     132                 :             : 
     133                 :           0 :   parent = valent_xdp_get_parent ();
     134                 :           0 :   xdp_portal_session_monitor_start (valent_xdp_get_default (),
     135                 :             :                                     parent,
     136                 :             :                                     XDP_SESSION_MONITOR_FLAG_NONE,
     137                 :             :                                     destroy,
     138                 :             :                                     xdp_portal_session_monitor_start_cb,
     139                 :             :                                     g_steal_pointer (&task));
     140                 :           0 : }
     141                 :             : 
     142                 :             : static void
     143                 :           0 : g_async_initable_iface_init (GAsyncInitableIface *iface)
     144                 :             : {
     145                 :           0 :   iface->init_async = valent_xdp_session_init_async;
     146                 :           0 : }
     147                 :             : 
     148                 :             : /*
     149                 :             :  * ValentObject
     150                 :             :  */
     151                 :             : static void
     152                 :           0 : valent_xdp_session_destroy (ValentObject *object)
     153                 :             : {
     154                 :           0 :   ValentXdpSession *self = VALENT_XDP_SESSION (object);
     155                 :           0 :   XdpPortal *portal = valent_xdp_get_default ();
     156                 :             : 
     157                 :           0 :   g_signal_handlers_disconnect_by_data (portal, self);
     158                 :           0 :   xdp_portal_session_monitor_stop (portal);
     159                 :             : 
     160                 :           0 :   VALENT_OBJECT_CLASS (valent_xdp_session_parent_class)->destroy (object);
     161                 :           0 : }
     162                 :             : 
     163                 :             : /*
     164                 :             :  * GObject
     165                 :             :  */
     166                 :             : static void
     167                 :           0 : valent_xdp_session_class_init (ValentXdpSessionClass *klass)
     168                 :             : {
     169                 :           0 :   ValentObjectClass *vobject_class = VALENT_OBJECT_CLASS (klass);
     170                 :           0 :   ValentSessionAdapterClass *session_class = VALENT_SESSION_ADAPTER_CLASS (klass);
     171                 :             : 
     172                 :           0 :   vobject_class->destroy = valent_xdp_session_destroy;
     173                 :             : 
     174                 :           0 :   session_class->get_active = valent_xdp_session_get_active;
     175                 :           0 :   session_class->get_locked = valent_xdp_session_get_locked;
     176                 :             : }
     177                 :             : 
     178                 :             : static void
     179                 :           0 : valent_xdp_session_init (ValentXdpSession *self)
     180                 :             : {
     181                 :           0 : }
     182                 :             : 
        

Generated by: LCOV version 2.0-1