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 [ + + ]: 650 : 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 : : gboolean mct_session_limits_get_active_extension (MctSessionLimits *limits,
70 : : GDateTime *now_dt,
71 : : uint64_t *out_start_time_secs,
72 : : unsigned int *out_duration_secs);
73 : :
74 : : gboolean mct_session_limits_check_time_remaining (MctSessionLimits *limits,
75 : : GDateTime *now_dt,
76 : : uint64_t active_session_time_today_secs,
77 : : guint64 *time_remaining_secs_out,
78 : : gboolean *time_limit_enabled_out,
79 : : gboolean *extension_active_out);
80 : :
81 : : GVariant *mct_session_limits_serialize (MctSessionLimits *limits);
82 : : MctSessionLimits *mct_session_limits_deserialize (GVariant *variant,
83 : : uid_t user_id,
84 : : GError **error);
85 : :
86 : : gboolean mct_session_limits_equal (MctSessionLimits *a,
87 : : MctSessionLimits *b);
88 : :
89 : : /**
90 : : * MctSessionLimitsBuilder:
91 : : *
92 : : * A stack-allocated mutable structure used to build an
93 : : * [struct@Malcontent.SessionLimits] instance. Use
94 : : * [method@Malcontent.SessionLimitsBuilder.init], various method calls to set
95 : : * properties of the session limits, and then
96 : : * [method@Malcontent.SessionLimitsBuilder.end], to construct an
97 : : * [struct@Malcontent.SessionLimits].
98 : : *
99 : : * Since: 0.14.0
100 : : */
101 : : typedef struct
102 : : {
103 : : /*< private >*/
104 : : guint u0;
105 : : guint u1;
106 : : guint u2;
107 : : guint u3;
108 : : unsigned int u4;
109 : : uint64_t u5;
110 : : unsigned int u6;
111 : : gpointer p0[9];
112 : : } MctSessionLimitsBuilder;
113 : :
114 : : GType mct_session_limits_builder_get_type (void);
115 : :
116 : : /**
117 : : * MCT_SESSION_LIMITS_BUILDER_INIT:
118 : : *
119 : : * Initialise a stack-allocated [struct@Malcontent.SessionLimitsBuilder]
120 : : * instance at declaration time.
121 : : *
122 : : * This is typically used with `g_auto()`:
123 : : * ```c
124 : : * g_auto(MctSessionLimitsBuilder) builder = MCT_SESSION_LIMITS_BUILDER_INIT ();
125 : : * ```
126 : : *
127 : : * Since: 0.14.0
128 : : */
129 : : #define MCT_SESSION_LIMITS_BUILDER_INIT() \
130 : : { \
131 : : 0, /* MCT_SESSION_LIMITS_TYPE_NONE */ \
132 : : 0, /* MCT_SESSION_LIMITS_TYPE_NONE */ \
133 : : 0, \
134 : : 0, \
135 : : 0, \
136 : : 0, \
137 : : 0, \
138 : : /* padding: */ \
139 : : { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL } \
140 : : }
141 : :
142 : : void mct_session_limits_builder_init (MctSessionLimitsBuilder *builder);
143 : : void mct_session_limits_builder_clear (MctSessionLimitsBuilder *builder);
144 : :
145 : 26 : G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC (MctSessionLimitsBuilder,
146 : : mct_session_limits_builder_clear)
147 : :
148 : : MctSessionLimitsBuilder *mct_session_limits_builder_new (void);
149 : : MctSessionLimitsBuilder *mct_session_limits_builder_copy (MctSessionLimitsBuilder *builder);
150 : : void mct_session_limits_builder_free (MctSessionLimitsBuilder *builder);
151 : :
152 [ + + ]: 316 : G_DEFINE_AUTOPTR_CLEANUP_FUNC (MctSessionLimitsBuilder, mct_session_limits_builder_free)
153 : :
154 : : MctSessionLimits *mct_session_limits_builder_end (MctSessionLimitsBuilder *builder);
155 : :
156 : : void mct_session_limits_builder_set_from_instance (MctSessionLimitsBuilder *builder,
157 : : MctSessionLimits *limits);
158 : :
159 : : void mct_session_limits_builder_set_none (MctSessionLimitsBuilder *builder);
160 : :
161 : : void mct_session_limits_builder_set_daily_schedule (MctSessionLimitsBuilder *builder,
162 : : gboolean enforced,
163 : : guint start_time_secs,
164 : : guint end_time_secs);
165 : : void mct_session_limits_builder_set_daily_limit (MctSessionLimitsBuilder *builder,
166 : : gboolean enforced,
167 : : unsigned int daily_limit_secs);
168 : :
169 : : void mct_session_limits_builder_set_active_extension (MctSessionLimitsBuilder *builder,
170 : : uint64_t start_time_secs,
171 : : unsigned int duration_secs);
172 : :
173 : : G_END_DECLS
|