LCOV - code coverage report
Current view: top level - libmalcontent - session-limits.h (source / functions) Coverage Total Hit
Test: 2 coverage DB files Lines: 100.0 % 3 3
Test Date: 2025-11-28 11:32:13 Functions: 100.0 % 5 5
Branches: 100.0 % 4 4

             Branch data     Line data    Source code
       1                 :             : /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
       2                 :             :  *
       3                 :             :  * Copyright © 2019 Endless Mobile, Inc.
       4                 :             :  * Copyright 2025 GNOME Foundation, Inc.
       5                 :             :  *
       6                 :             :  * SPDX-License-Identifier: LGPL-2.1-or-later
       7                 :             :  *
       8                 :             :  * This library is free software; you can redistribute it and/or
       9                 :             :  * modify it under the terms of the GNU Lesser General Public
      10                 :             :  * License as published by the Free Software Foundation; either
      11                 :             :  * version 2.1 of the License, or (at your option) any later version.
      12                 :             :  *
      13                 :             :  * This library is distributed in the hope that it will be useful,
      14                 :             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      15                 :             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      16                 :             :  * Lesser General Public License for more details.
      17                 :             :  *
      18                 :             :  * You should have received a copy of the GNU Lesser General Public
      19                 :             :  * License along with this library; if not, write to the Free Software
      20                 :             :  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
      21                 :             :  *
      22                 :             :  * Authors:
      23                 :             :  *  - Philip Withnall <withnall@endlessm.com>
      24                 :             :  */
      25                 :             : 
      26                 :             : #pragma once
      27                 :             : 
      28                 :             : #include <gio/gio.h>
      29                 :             : #include <glib.h>
      30                 :             : #include <glib-object.h>
      31                 :             : #include <stdint.h>
      32                 :             : 
      33                 :             : G_BEGIN_DECLS
      34                 :             : 
      35                 :             : /**
      36                 :             :  * MctSessionLimits:
      37                 :             :  *
      38                 :             :  * An opaque, immutable structure which contains a snapshot
      39                 :             :  * of the session limits settings for a user at a given time.
      40                 :             :  *
      41                 :             :  * This includes whether session limits are being enforced, and the limit
      42                 :             :  * policy — for example, the times of day when a user is allowed to use the
      43                 :             :  * computer.
      44                 :             :  *
      45                 :             :  * Typically, session limits settings can only be changed by the administrator,
      46                 :             :  * and are read-only for non-administrative users. The precise policy is set
      47                 :             :  * using polkit.
      48                 :             :  *
      49                 :             :  * Since: 0.5.0
      50                 :             :  */
      51                 :             : typedef struct _MctSessionLimits MctSessionLimits;
      52                 :             : GType mct_session_limits_get_type (void);
      53                 :             : #define MCT_TYPE_SESSION_LIMITS mct_session_limits_get_type ()
      54                 :             : 
      55                 :             : MctSessionLimits *mct_session_limits_ref   (MctSessionLimits *limits);
      56                 :             : void              mct_session_limits_unref (MctSessionLimits *limits);
      57                 :             : 
      58         [ +  + ]:         346 : G_DEFINE_AUTOPTR_CLEANUP_FUNC (MctSessionLimits, mct_session_limits_unref)
      59                 :             : 
      60                 :             : uid_t    mct_session_limits_get_user_id          (MctSessionLimits *limits);
      61                 :             : 
      62                 :             : gboolean mct_session_limits_is_enabled           (MctSessionLimits *limits);
      63                 :             : 
      64                 :             : gboolean mct_session_limits_get_daily_schedule (MctSessionLimits *limits,
      65                 :             :                                                 unsigned int     *out_start_time_secs,
      66                 :             :                                                 unsigned int     *out_end_time_secs);
      67                 :             : gboolean mct_session_limits_get_daily_limit (MctSessionLimits *limits,
      68                 :             :                                              unsigned int     *out_daily_limit_secs);
      69                 :             : 
      70                 :             : gboolean mct_session_limits_check_time_remaining (MctSessionLimits *limits,
      71                 :             :                                                   GDateTime        *now_dt,
      72                 :             :                                                   uint64_t          active_session_time_today_secs,
      73                 :             :                                                   guint64          *time_remaining_secs_out,
      74                 :             :                                                   gboolean         *time_limit_enabled_out);
      75                 :             : 
      76                 :             : GVariant         *mct_session_limits_serialize   (MctSessionLimits  *limits);
      77                 :             : MctSessionLimits *mct_session_limits_deserialize (GVariant          *variant,
      78                 :             :                                                   uid_t              user_id,
      79                 :             :                                                   GError           **error);
      80                 :             : 
      81                 :             : gboolean mct_session_limits_equal (MctSessionLimits *a,
      82                 :             :                                    MctSessionLimits *b);
      83                 :             : 
      84                 :             : /**
      85                 :             :  * MctSessionLimitsBuilder:
      86                 :             :  *
      87                 :             :  * A stack-allocated mutable structure used to build an
      88                 :             :  * [struct@Malcontent.SessionLimits] instance. Use
      89                 :             :  * [method@Malcontent.SessionLimitsBuilder.init], various method calls to set
      90                 :             :  * properties of the session limits, and then
      91                 :             :  * [method@Malcontent.SessionLimitsBuilder.end], to construct an
      92                 :             :  * [struct@Malcontent.SessionLimits].
      93                 :             :  *
      94                 :             :  * Since: 0.14.0
      95                 :             :  */
      96                 :             : typedef struct
      97                 :             : {
      98                 :             :   /*< private >*/
      99                 :             :   guint u0;
     100                 :             :   guint u1;
     101                 :             :   guint u2;
     102                 :             :   guint u3;
     103                 :             :   unsigned int u4;
     104                 :             :   gpointer p0[9];
     105                 :             : } MctSessionLimitsBuilder;
     106                 :             : 
     107                 :             : GType mct_session_limits_builder_get_type (void);
     108                 :             : 
     109                 :             : /**
     110                 :             :  * MCT_SESSION_LIMITS_BUILDER_INIT:
     111                 :             :  *
     112                 :             :  * Initialise a stack-allocated [struct@Malcontent.SessionLimitsBuilder]
     113                 :             :  * instance at declaration time.
     114                 :             :  *
     115                 :             :  * This is typically used with `g_auto()`:
     116                 :             :  * ```c
     117                 :             :  * g_auto(MctSessionLimitsBuilder) builder = MCT_SESSION_LIMITS_BUILDER_INIT ();
     118                 :             :  * ```
     119                 :             :  *
     120                 :             :  * Since: 0.14.0
     121                 :             :  */
     122                 :             : #define MCT_SESSION_LIMITS_BUILDER_INIT() \
     123                 :             :   { \
     124                 :             :     0,  /* MCT_SESSION_LIMITS_TYPE_NONE */ \
     125                 :             :     0,  /* MCT_SESSION_LIMITS_TYPE_NONE */ \
     126                 :             :     0, \
     127                 :             :     0, \
     128                 :             :     0, \
     129                 :             :     /* padding: */ \
     130                 :             :     { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL } \
     131                 :             :   }
     132                 :             : 
     133                 :             : void mct_session_limits_builder_init  (MctSessionLimitsBuilder *builder);
     134                 :             : void mct_session_limits_builder_clear (MctSessionLimitsBuilder *builder);
     135                 :             : 
     136                 :          22 : G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC (MctSessionLimitsBuilder,
     137                 :             :                                   mct_session_limits_builder_clear)
     138                 :             : 
     139                 :             : MctSessionLimitsBuilder *mct_session_limits_builder_new  (void);
     140                 :             : MctSessionLimitsBuilder *mct_session_limits_builder_copy (MctSessionLimitsBuilder *builder);
     141                 :             : void                     mct_session_limits_builder_free (MctSessionLimitsBuilder *builder);
     142                 :             : 
     143         [ +  + ]:          72 : G_DEFINE_AUTOPTR_CLEANUP_FUNC (MctSessionLimitsBuilder, mct_session_limits_builder_free)
     144                 :             : 
     145                 :             : MctSessionLimits *mct_session_limits_builder_end (MctSessionLimitsBuilder *builder);
     146                 :             : 
     147                 :             : void mct_session_limits_builder_set_none (MctSessionLimitsBuilder *builder);
     148                 :             : 
     149                 :             : void mct_session_limits_builder_set_daily_schedule (MctSessionLimitsBuilder *builder,
     150                 :             :                                                     gboolean                 enforced,
     151                 :             :                                                     guint                    start_time_secs,
     152                 :             :                                                     guint                    end_time_secs);
     153                 :             : void mct_session_limits_builder_set_daily_limit (MctSessionLimitsBuilder *builder,
     154                 :             :                                                  gboolean                 enforced,
     155                 :             :                                                  unsigned int             daily_limit_secs);
     156                 :             : 
     157                 :             : G_END_DECLS
        

Generated by: LCOV version 2.0-1