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 : : * #MctSessionLimits is an opaque, immutable structure which contains a snapshot
39 : : * of the session limits settings for a user at a given time. This includes
40 : : * whether session limits are being enforced, and the limit policy — for
41 : : * example, the times of day when a user is allowed to use the computer.
42 : : *
43 : : * Typically, session limits settings can only be changed by the administrator,
44 : : * and are read-only for non-administrative users. The precise policy is set
45 : : * using polkit.
46 : : *
47 : : * Since: 0.5.0
48 : : */
49 : : typedef struct _MctSessionLimits MctSessionLimits;
50 : : GType mct_session_limits_get_type (void);
51 : : #define MCT_TYPE_SESSION_LIMITS mct_session_limits_get_type ()
52 : :
53 : : MctSessionLimits *mct_session_limits_ref (MctSessionLimits *limits);
54 : : void mct_session_limits_unref (MctSessionLimits *limits);
55 : :
56 [ + + ]: 338 : G_DEFINE_AUTOPTR_CLEANUP_FUNC (MctSessionLimits, mct_session_limits_unref)
57 : :
58 : : uid_t mct_session_limits_get_user_id (MctSessionLimits *limits);
59 : :
60 : : gboolean mct_session_limits_is_enabled (MctSessionLimits *limits);
61 : :
62 : : gboolean mct_session_limits_get_daily_schedule (MctSessionLimits *limits,
63 : : unsigned int *out_start_time_secs,
64 : : unsigned int *out_end_time_secs);
65 : : gboolean mct_session_limits_get_daily_limit (MctSessionLimits *limits,
66 : : unsigned int *out_daily_limit_secs);
67 : :
68 : : gboolean mct_session_limits_check_time_remaining (MctSessionLimits *limits,
69 : : GDateTime *now_dt,
70 : : uint64_t active_session_time_today_secs,
71 : : guint64 *time_remaining_secs_out,
72 : : gboolean *time_limit_enabled_out);
73 : :
74 : : GVariant *mct_session_limits_serialize (MctSessionLimits *limits);
75 : : MctSessionLimits *mct_session_limits_deserialize (GVariant *variant,
76 : : uid_t user_id,
77 : : GError **error);
78 : :
79 : : gboolean mct_session_limits_equal (MctSessionLimits *a,
80 : : MctSessionLimits *b);
81 : :
82 : : /**
83 : : * MctSessionLimitsBuilder:
84 : : *
85 : : * #MctSessionLimitsBuilder is a stack-allocated mutable structure used to build
86 : : * an #MctSessionLimits instance. Use mct_session_limits_builder_init(), various
87 : : * method calls to set properties of the session limits, and then
88 : : * mct_session_limits_builder_end(), to construct an #MctSessionLimits.
89 : : *
90 : : * Since: 0.5.0
91 : : */
92 : : typedef struct
93 : : {
94 : : /*< private >*/
95 : : guint u0;
96 : : guint u1;
97 : : guint u2;
98 : : unsigned int u3;
99 : : gpointer p0[9];
100 : : } MctSessionLimitsBuilder;
101 : :
102 : : GType mct_session_limits_builder_get_type (void);
103 : :
104 : : /**
105 : : * MCT_SESSION_LIMITS_BUILDER_INIT:
106 : : *
107 : : * Initialise a stack-allocated #MctSessionLimitsBuilder instance at declaration
108 : : * time.
109 : : *
110 : : * This is typically used with g_auto():
111 : : * |[
112 : : * g_auto(MctSessionLimitsBuilder) builder = MCT_SESSION_LIMITS_BUILDER_INIT ();
113 : : * ]|
114 : : *
115 : : * Since: 0.5.0
116 : : */
117 : : #define MCT_SESSION_LIMITS_BUILDER_INIT() \
118 : : { \
119 : : 0, /* MCT_SESSION_LIMITS_TYPE_NONE */ \
120 : : 0, \
121 : : 0, \
122 : : 0, \
123 : : /* padding: */ \
124 : : { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL } \
125 : : }
126 : :
127 : : void mct_session_limits_builder_init (MctSessionLimitsBuilder *builder);
128 : : void mct_session_limits_builder_clear (MctSessionLimitsBuilder *builder);
129 : :
130 : 22 : G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC (MctSessionLimitsBuilder,
131 : : mct_session_limits_builder_clear)
132 : :
133 : : MctSessionLimitsBuilder *mct_session_limits_builder_new (void);
134 : : MctSessionLimitsBuilder *mct_session_limits_builder_copy (MctSessionLimitsBuilder *builder);
135 : : void mct_session_limits_builder_free (MctSessionLimitsBuilder *builder);
136 : :
137 [ + + ]: 72 : G_DEFINE_AUTOPTR_CLEANUP_FUNC (MctSessionLimitsBuilder, mct_session_limits_builder_free)
138 : :
139 : : MctSessionLimits *mct_session_limits_builder_end (MctSessionLimitsBuilder *builder);
140 : :
141 : : void mct_session_limits_builder_set_none (MctSessionLimitsBuilder *builder);
142 : :
143 : : void mct_session_limits_builder_set_daily_schedule (MctSessionLimitsBuilder *builder,
144 : : guint start_time_secs,
145 : : guint end_time_secs);
146 : : void mct_session_limits_builder_set_daily_limit (MctSessionLimitsBuilder *builder,
147 : : unsigned int daily_limit_secs);
148 : :
149 : : G_END_DECLS
|