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