LCOV - code coverage report
Current view: top level - glib/gio - gdebugcontroller.c (source / functions) Hit Total Coverage
Test: unnamed Lines: 11 11 100.0 %
Date: 2024-04-23 05:16:05 Functions: 4 4 100.0 %
Branches: 5 6 83.3 %

           Branch data     Line data    Source code
       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                 :            :  * GDebugController:
      33                 :            :  *
      34                 :            :  * `GDebugController` is an interface to expose control of debugging features and
      35                 :            :  * debug output.
      36                 :            :  *
      37                 :            :  * It is implemented on Linux using [class@Gio.DebugControllerDBus], which
      38                 :            :  * exposes a D-Bus interface to allow authenticated peers to control debug
      39                 :            :  * features in this process.
      40                 :            :  *
      41                 :            :  * Whether debug output is enabled is exposed as
      42                 :            :  * [property@Gio.DebugController:debug-enabled]. This controls
      43                 :            :  * [func@GLib.log_set_debug_enabled] by default. Application code may
      44                 :            :  * connect to the [signal@GObject.Object::notify] signal for it
      45                 :            :  * to control other parts of its debug infrastructure as necessary.
      46                 :            :  *
      47                 :            :  * If your application or service is using the default GLib log writer function,
      48                 :            :  * creating one of the built-in implementations of `GDebugController` should be
      49                 :            :  * all that’s needed to dynamically enable or disable debug output.
      50                 :            :  *
      51                 :            :  * Since: 2.72
      52                 :            :  */
      53                 :            : 
      54   [ +  +  +  -  :        258 : G_DEFINE_INTERFACE_WITH_CODE (GDebugController, g_debug_controller, G_TYPE_OBJECT,
                   +  + ]
      55                 :            :                               g_type_interface_add_prerequisite (g_define_type_id, G_TYPE_INITABLE))
      56                 :            : 
      57                 :            : static void
      58                 :          2 : g_debug_controller_default_init (GDebugControllerInterface *iface)
      59                 :            : {
      60                 :            :   /**
      61                 :            :    * GDebugController:debug-enabled:
      62                 :            :    *
      63                 :            :    * %TRUE if debug output should be exposed (for example by forwarding it to
      64                 :            :    * the journal), %FALSE otherwise.
      65                 :            :    *
      66                 :            :    * Since: 2.72
      67                 :            :    */
      68                 :          2 :   g_object_interface_install_property (iface,
      69                 :            :                                        g_param_spec_boolean ("debug-enabled", NULL, NULL,
      70                 :            :                                                              FALSE,
      71                 :            :                                                              G_PARAM_READWRITE |
      72                 :            :                                                              G_PARAM_STATIC_STRINGS |
      73                 :            :                                                              G_PARAM_EXPLICIT_NOTIFY));
      74                 :          2 : }
      75                 :            : 
      76                 :            : /**
      77                 :            :  * g_debug_controller_get_debug_enabled:
      78                 :            :  * @self: a #GDebugController
      79                 :            :  *
      80                 :            :  * Get the value of #GDebugController:debug-enabled.
      81                 :            :  *
      82                 :            :  * Returns: %TRUE if debug output should be exposed, %FALSE otherwise
      83                 :            :  * Since: 2.72
      84                 :            :  */
      85                 :            : gboolean
      86                 :          8 : g_debug_controller_get_debug_enabled (GDebugController *self)
      87                 :            : {
      88                 :            :   gboolean enabled;
      89                 :            : 
      90                 :          8 :   g_return_val_if_fail (G_IS_DEBUG_CONTROLLER (self), FALSE);
      91                 :            : 
      92                 :          8 :   g_object_get (G_OBJECT (self),
      93                 :            :                 "debug-enabled", &enabled,
      94                 :            :                 NULL);
      95                 :            : 
      96                 :          8 :   return enabled;
      97                 :            : }
      98                 :            : 
      99                 :            : /**
     100                 :            :  * g_debug_controller_set_debug_enabled:
     101                 :            :  * @self: a #GDebugController
     102                 :            :  * @debug_enabled: %TRUE if debug output should be exposed, %FALSE otherwise
     103                 :            :  *
     104                 :            :  * Set the value of #GDebugController:debug-enabled.
     105                 :            :  *
     106                 :            :  * Since: 2.72
     107                 :            :  */
     108                 :            : void
     109                 :          4 : g_debug_controller_set_debug_enabled (GDebugController *self,
     110                 :            :                                       gboolean          debug_enabled)
     111                 :            : {
     112                 :          4 :   g_return_if_fail (G_IS_DEBUG_CONTROLLER (self));
     113                 :            : 
     114                 :          4 :   g_object_set (G_OBJECT (self),
     115                 :            :                 "debug-enabled", debug_enabled,
     116                 :            :                 NULL);
     117                 :            : }

Generated by: LCOV version 1.14