/src/glib/gio/gdebugcontroller.c
Line  | Count  | Source (jump to first uncovered line)  | 
1  |  | /* GIO - GLib Input, Output and Streaming Library  | 
2  |  |  *  | 
3  |  |  * Copyright © 2021 Endless OS Foundation, LLC  | 
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  | 
18  |  |  * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.  | 
19  |  |  *  | 
20  |  |  * SPDX-License-Identifier: LGPL-2.1-or-later  | 
21  |  |  */  | 
22  |  |  | 
23  |  | #include "config.h"  | 
24  |  | #include "glib.h"  | 
25  |  | #include "glibintl.h"  | 
26  |  |  | 
27  |  | #include "gdebugcontroller.h"  | 
28  |  | #include "ginitable.h"  | 
29  |  | #include "giomodule-priv.h"  | 
30  |  |  | 
31  |  | /**  | 
32  |  |  * SECTION:gdebugcontroller  | 
33  |  |  * @title: GDebugController  | 
34  |  |  * @short_description: Debugging controller  | 
35  |  |  * @include: gio/gio.h  | 
36  |  |  *  | 
37  |  |  * #GDebugController is an interface to expose control of debugging features and  | 
38  |  |  * debug output.  | 
39  |  |  *  | 
40  |  |  * It is implemented on Linux using #GDebugControllerDBus, which exposes a D-Bus  | 
41  |  |  * interface to allow authenticated peers to control debug features in this  | 
42  |  |  * process.  | 
43  |  |  *  | 
44  |  |  * Whether debug output is enabled is exposed as  | 
45  |  |  * #GDebugController:debug-enabled. This controls g_log_set_debug_enabled() by  | 
46  |  |  * default. Application code may connect to the #GObject::notify signal for it  | 
47  |  |  * to control other parts of its debug infrastructure as necessary.  | 
48  |  |  *  | 
49  |  |  * If your application or service is using the default GLib log writer function,  | 
50  |  |  * creating one of the built-in implementations of #GDebugController should be  | 
51  |  |  * all that’s needed to dynamically enable or disable debug output.  | 
52  |  |  *  | 
53  |  |  * Since: 2.72  | 
54  |  |  */  | 
55  |  |  | 
56  |  | G_DEFINE_INTERFACE_WITH_CODE (GDebugController, g_debug_controller, G_TYPE_OBJECT,  | 
57  |  |                               g_type_interface_add_prerequisite (g_define_type_id, G_TYPE_INITABLE))  | 
58  |  |  | 
59  |  | static void  | 
60  |  | g_debug_controller_default_init (GDebugControllerInterface *iface)  | 
61  | 0  | { | 
62  |  |   /**  | 
63  |  |    * GDebugController:debug-enabled:  | 
64  |  |    *  | 
65  |  |    * %TRUE if debug output should be exposed (for example by forwarding it to  | 
66  |  |    * the journal), %FALSE otherwise.  | 
67  |  |    *  | 
68  |  |    * Since: 2.72  | 
69  |  |    */  | 
70  | 0  |   g_object_interface_install_property (iface,  | 
71  | 0  |                                        g_param_spec_boolean ("debug-enabled", | 
72  | 0  |                                                              "Debug Enabled",  | 
73  | 0  |                                                              "Whether to expose debug output",  | 
74  | 0  |                                                              FALSE,  | 
75  | 0  |                                                              G_PARAM_READWRITE |  | 
76  | 0  |                                                              G_PARAM_STATIC_STRINGS |  | 
77  | 0  |                                                              G_PARAM_EXPLICIT_NOTIFY));  | 
78  | 0  | }  | 
79  |  |  | 
80  |  | /**  | 
81  |  |  * g_debug_controller_get_debug_enabled:  | 
82  |  |  * @self: a #GDebugController  | 
83  |  |  *  | 
84  |  |  * Get the value of #GDebugController:debug-enabled.  | 
85  |  |  *  | 
86  |  |  * Returns: %TRUE if debug output should be exposed, %FALSE otherwise  | 
87  |  |  * Since: 2.72  | 
88  |  |  */  | 
89  |  | gboolean  | 
90  |  | g_debug_controller_get_debug_enabled (GDebugController *self)  | 
91  | 0  | { | 
92  | 0  |   gboolean enabled;  | 
93  |  | 
  | 
94  | 0  |   g_return_val_if_fail (G_IS_DEBUG_CONTROLLER (self), FALSE);  | 
95  |  |  | 
96  | 0  |   g_object_get (G_OBJECT (self),  | 
97  | 0  |                 "debug-enabled", &enabled,  | 
98  | 0  |                 NULL);  | 
99  |  | 
  | 
100  | 0  |   return enabled;  | 
101  | 0  | }  | 
102  |  |  | 
103  |  | /**  | 
104  |  |  * g_debug_controller_set_debug_enabled:  | 
105  |  |  * @self: a #GDebugController  | 
106  |  |  * @debug_enabled: %TRUE if debug output should be exposed, %FALSE otherwise  | 
107  |  |  *  | 
108  |  |  * Set the value of #GDebugController:debug-enabled.  | 
109  |  |  *  | 
110  |  |  * Since: 2.72  | 
111  |  |  */  | 
112  |  | void  | 
113  |  | g_debug_controller_set_debug_enabled (GDebugController *self,  | 
114  |  |                                       gboolean          debug_enabled)  | 
115  | 0  | { | 
116  | 0  |   g_return_if_fail (G_IS_DEBUG_CONTROLLER (self));  | 
117  |  |  | 
118  | 0  |   g_object_set (G_OBJECT (self),  | 
119  | 0  |                 "debug-enabled", debug_enabled,  | 
120  | 0  |                 NULL);  | 
121  | 0  | }  |