LCOV - code coverage report
Current view: top level - src/libvalent/core - valent-component-private.h (source / functions) Coverage Total Hit
Test: Code Coverage Lines: 100.0 % 28 28
Test Date: 2024-05-05 22:34:11 Functions: 100.0 % 3 3
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 60.0 % 20 12

             Branch data     Line data    Source code
       1                 :             : // SPDX-License-Identifier: GPL-3.0-or-later
       2                 :             : // SPDX-FileCopyrightText: Andy Holmes <andrew.g.r.holmes@gmail.com>
       3                 :             : 
       4                 :             : #pragma once
       5                 :             : 
       6                 :             : #include "valent-component.h"
       7                 :             : #include "valent-context.h"
       8                 :             : 
       9                 :             : #define VALENT_PLUGIN_SCHEMA "ca.andyholmes.Valent.Plugin"
      10                 :             : 
      11                 :             : G_BEGIN_DECLS
      12                 :             : 
      13                 :             : _VALENT_EXTERN
      14                 :             : GObject * valent_component_get_preferred (ValentComponent *self);
      15                 :             : 
      16                 :             : 
      17                 :             : /*< private >
      18                 :             :  * ValentPlugin:
      19                 :             :  * @parent: (type GObject.Object): the owner of the plugin
      20                 :             :  * @context: the plugin context
      21                 :             :  * @info: the plugin info
      22                 :             :  * @extension: the plugin extension
      23                 :             :  * @cancellable: the initialization cancellable
      24                 :             :  * @settings: the plugin settings
      25                 :             :  *
      26                 :             :  * A `struct` for representing a plugin pod.
      27                 :             :  */
      28                 :             : typedef struct
      29                 :             : {
      30                 :             :   gpointer        parent;
      31                 :             :   ValentContext  *context;
      32                 :             :   PeasPluginInfo *info;
      33                 :             :   GObject        *extension;
      34                 :             :   GCancellable   *cancellable;
      35                 :             : 
      36                 :             :   /*< private >*/
      37                 :             :   GSettings      *settings;
      38                 :             : } ValentPlugin;
      39                 :             : 
      40                 :             : 
      41                 :             : /*< private >
      42                 :             :  * valent_plugin_new:
      43                 :             :  * @parent: (type GObject.Object): the parent
      44                 :             :  * @parent_context: the parent context
      45                 :             :  * @info: the plugin info
      46                 :             :  *
      47                 :             :  * Create a new `ValentPlugin`.
      48                 :             :  *
      49                 :             :  * Returns: (transfer full): a new `ValentPlugin`
      50                 :             :  */
      51                 :             : static inline ValentPlugin *
      52                 :         272 : valent_plugin_new (gpointer        parent,
      53                 :             :                    ValentContext  *parent_context,
      54                 :             :                    PeasPluginInfo *info,
      55                 :             :                    GCallback       enable_func)
      56                 :             : {
      57                 :         272 :   ValentPlugin *plugin = NULL;
      58                 :             : 
      59         [ +  - ]:         272 :   g_assert (G_IS_OBJECT (parent));
      60         [ -  + ]:         272 :   g_assert (VALENT_IS_CONTEXT (parent_context));
      61         [ -  + ]:         272 :   g_assert (info != NULL);
      62                 :             : 
      63                 :         272 :   plugin = g_new0 (ValentPlugin, 1);
      64                 :         272 :   plugin->parent = parent;
      65                 :         272 :   plugin->info = g_object_ref (info);
      66                 :         272 :   plugin->context = valent_context_get_plugin_context (parent_context, info);
      67                 :         272 :   plugin->settings = valent_context_create_settings (plugin->context,
      68                 :             :                                                      VALENT_PLUGIN_SCHEMA);
      69                 :             : 
      70                 :         272 :   g_signal_connect_swapped (plugin->settings,
      71                 :             :                             "changed::enabled",
      72                 :             :                             enable_func,
      73                 :             :                             plugin);
      74                 :             : 
      75                 :         272 :   return g_steal_pointer (&plugin);
      76                 :             : }
      77                 :             : 
      78                 :             : /*< private >
      79                 :             :  * valent_plugin_get_enabled:
      80                 :             :  * @data: a `ValentPlugin`
      81                 :             :  *
      82                 :             :  * Get whether the plugin is enabled.
      83                 :             :  *
      84                 :             :  * Returns: %TRUE if enabled, %FALSE if not
      85                 :             :  */
      86                 :             : static inline gboolean
      87                 :         280 : valent_plugin_get_enabled (ValentPlugin *plugin)
      88                 :             : {
      89         [ +  - ]:         280 :   g_assert (plugin != NULL);
      90                 :             : 
      91                 :         280 :   return g_settings_get_boolean (plugin->settings, "enabled");
      92                 :             : }
      93                 :             : 
      94                 :             : /*< private >
      95                 :             :  * valent_plugin_free:
      96                 :             :  * @data: a `ValentPlugin`
      97                 :             :  *
      98                 :             :  * Free a `ValentPlugin`.
      99                 :             :  */
     100                 :             : static inline void
     101                 :         248 : valent_plugin_free (gpointer data)
     102                 :             : {
     103                 :         248 :   ValentPlugin *plugin = (ValentPlugin *)data;
     104                 :             : 
     105         [ +  - ]:         248 :   g_assert (data != NULL);
     106                 :             : 
     107                 :         248 :   g_cancellable_cancel (plugin->cancellable);
     108                 :         248 :   g_signal_handlers_disconnect_by_data (plugin->settings, plugin);
     109                 :             : 
     110                 :         248 :   plugin->parent = NULL;
     111         [ +  - ]:         248 :   g_clear_object (&plugin->info);
     112         [ +  + ]:         248 :   g_clear_object (&plugin->cancellable);
     113         [ +  - ]:         248 :   g_clear_object (&plugin->context);
     114         [ +  + ]:         248 :   g_clear_object (&plugin->extension);
     115         [ +  - ]:         248 :   g_clear_object (&plugin->settings);
     116                 :         248 :   g_clear_pointer (&plugin, g_free);
     117                 :         248 : }
     118                 :             : 
     119                 :             : G_END_DECLS
     120                 :             : 
        

Generated by: LCOV version 2.0-1