Branch data Line data Source code
1 : : /* GIO - GLib Input, Output and Streaming Library
2 : : *
3 : : * Copyright 2019 Red Hat, Inc
4 : : * Copyright 2021 Igalia S.L.
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
19 : : * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
20 : : */
21 : :
22 : : #include "config.h"
23 : : #include "glib.h"
24 : : #include "glibintl.h"
25 : :
26 : : #include "gpowerprofilemonitor.h"
27 : : #include "ginetaddress.h"
28 : : #include "ginetsocketaddress.h"
29 : : #include "ginitable.h"
30 : : #include "gioenumtypes.h"
31 : : #include "giomodule-priv.h"
32 : : #include "gtask.h"
33 : :
34 : : /**
35 : : * GPowerProfileMonitor:
36 : : *
37 : : * `GPowerProfileMonitor` makes it possible for applications as well as OS
38 : : * components to monitor system power profiles and act upon them. It currently
39 : : * only exports whether the system is in “Power Saver” mode (known as
40 : : * “Low Power” mode on some systems).
41 : : *
42 : : * When in “Low Power” mode, it is recommended that applications:
43 : : * - disable automatic downloads;
44 : : * - reduce the rate of refresh from online sources such as calendar or
45 : : * email synchronisation;
46 : : * - reduce the use of expensive visual effects.
47 : : *
48 : : * It is also likely that OS components providing services to applications will
49 : : * lower their own background activity, for the sake of the system.
50 : : *
51 : : * There are a variety of tools that exist for power consumption analysis, but those
52 : : * usually depend on the OS and hardware used. On Linux, one could use `upower` to
53 : : * monitor the battery discharge rate, `powertop` to check on the background activity
54 : : * or activity at all), `sysprof` to inspect CPU usage, and `intel_gpu_time` to
55 : : * profile GPU usage.
56 : : *
57 : : * Don’t forget to disconnect the [signal@GObject.Object::notify] signal for
58 : : * [property@Gio.PowerProfileMonitor:power-saver-enabled], and unref the
59 : : * `GPowerProfileMonitor` itself when exiting.
60 : : *
61 : : * Since: 2.70
62 : : */
63 : :
64 : : /**
65 : : * GPowerProfileMonitorInterface:
66 : : * @g_iface: The parent interface.
67 : : *
68 : : * The virtual function table for #GPowerProfileMonitor.
69 : : *
70 : : * Since: 2.70
71 : : */
72 : :
73 : 363 : G_DEFINE_INTERFACE_WITH_CODE (GPowerProfileMonitor, g_power_profile_monitor, G_TYPE_OBJECT,
74 : : g_type_interface_add_prerequisite (g_define_type_id, G_TYPE_INITABLE))
75 : :
76 : :
77 : : /**
78 : : * g_power_profile_monitor_dup_default:
79 : : *
80 : : * Gets a reference to the default #GPowerProfileMonitor for the system.
81 : : *
82 : : * Returns: (not nullable) (transfer full): a new reference to the default #GPowerProfileMonitor
83 : : *
84 : : * Since: 2.70
85 : : */
86 : : GPowerProfileMonitor *
87 : 1 : g_power_profile_monitor_dup_default (void)
88 : : {
89 : 1 : return g_object_ref (_g_io_module_get_default (G_POWER_PROFILE_MONITOR_EXTENSION_POINT_NAME,
90 : : "GIO_USE_POWER_PROFILE_MONITOR",
91 : : NULL));
92 : : }
93 : :
94 : : /**
95 : : * g_power_profile_monitor_get_power_saver_enabled:
96 : : * @monitor: a #GPowerProfileMonitor
97 : : *
98 : : * Gets whether the system is in “Power Saver” mode.
99 : : *
100 : : * You are expected to listen to the
101 : : * #GPowerProfileMonitor::notify::power-saver-enabled signal to know when the profile has
102 : : * changed.
103 : : *
104 : : * Returns: Whether the system is in “Power Saver” mode.
105 : : *
106 : : * Since: 2.70
107 : : */
108 : : gboolean
109 : 0 : g_power_profile_monitor_get_power_saver_enabled (GPowerProfileMonitor *monitor)
110 : : {
111 : : gboolean enabled;
112 : 0 : g_object_get (monitor, "power-saver-enabled", &enabled, NULL);
113 : 0 : return enabled;
114 : : }
115 : :
116 : : static void
117 : 2 : g_power_profile_monitor_default_init (GPowerProfileMonitorInterface *iface)
118 : : {
119 : : /**
120 : : * GPowerProfileMonitor:power-saver-enabled:
121 : : *
122 : : * Whether “Power Saver” mode is enabled on the system.
123 : : *
124 : : * Since: 2.70
125 : : */
126 : 2 : g_object_interface_install_property (iface,
127 : : g_param_spec_boolean ("power-saver-enabled", NULL, NULL,
128 : : FALSE,
129 : : G_PARAM_READABLE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY));
130 : 2 : }
|