LCOV - code coverage report
Current view: top level - src/plugins/bluez - valent-mux-io-stream.c (source / functions) Coverage Total Hit
Test: Code Coverage Lines: 65.6 % 64 42
Test Date: 2025-11-09 04:19:42 Functions: 81.8 % 11 9
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 31.8 % 22 7

             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                 :             : #define G_LOG_DOMAIN "valent-mux-io-stream"
       5                 :             : 
       6                 :             : #include "config.h"
       7                 :             : 
       8                 :             : #include <gio/gio.h>
       9                 :             : 
      10                 :             : #include "valent-bluez-muxer.h"
      11                 :             : #include "valent-mux-input-stream.h"
      12                 :             : #include "valent-mux-output-stream.h"
      13                 :             : 
      14                 :             : #include "valent-mux-io-stream.h"
      15                 :             : 
      16                 :             : struct _ValentMuxIOStream
      17                 :             : {
      18                 :             :   GIOStream         parent_instance;
      19                 :             : 
      20                 :             :   ValentBluezMuxer *muxer;
      21                 :             :   char             *uuid;
      22                 :             : 
      23                 :             :   GInputStream     *input_stream;
      24                 :             :   GOutputStream    *output_stream;
      25                 :             : };
      26                 :             : 
      27   [ +  +  +  - ]:           8 : G_DEFINE_FINAL_TYPE (ValentMuxIOStream, valent_mux_io_stream, G_TYPE_IO_STREAM)
      28                 :             : 
      29                 :             : typedef enum {
      30                 :             :   PROP_MUXER = 1,
      31                 :             :   PROP_UUID,
      32                 :             : } ValentMuxIOStreamProperty;
      33                 :             : 
      34                 :             : static GParamSpec *properties[PROP_UUID + 1] = { NULL, };
      35                 :             : 
      36                 :             : /*
      37                 :             :  * GIOStream
      38                 :             :  */
      39                 :             : static GInputStream *
      40                 :          13 : valent_mux_io_stream_get_input_stream (GIOStream *stream)
      41                 :             : {
      42                 :          13 :   ValentMuxIOStream *self = VALENT_MUX_IO_STREAM (stream);
      43                 :             : 
      44                 :          13 :   return self->input_stream;
      45                 :             : }
      46                 :             : 
      47                 :             : static GOutputStream *
      48                 :          11 : valent_mux_io_stream_get_output_stream (GIOStream *stream)
      49                 :             : {
      50                 :          11 :   ValentMuxIOStream *self = VALENT_MUX_IO_STREAM (stream);
      51                 :             : 
      52                 :          11 :   return self->output_stream;
      53                 :             : }
      54                 :             : 
      55                 :             : /*
      56                 :             :  * GObject
      57                 :             :  */
      58                 :             : static void
      59                 :           6 : valent_mux_io_stream_constructed (GObject *object)
      60                 :             : {
      61                 :           6 :   ValentMuxIOStream *self = VALENT_MUX_IO_STREAM (object);
      62                 :             : 
      63                 :           6 :   G_OBJECT_CLASS (valent_mux_io_stream_parent_class)->constructed (object);
      64                 :             : 
      65         [ -  + ]:           6 :   g_assert (VALENT_IS_BLUEZ_MUXER (self->muxer));
      66         [ +  - ]:           6 :   g_assert (g_uuid_string_is_valid (self->uuid));
      67                 :             : 
      68                 :           6 :   self->input_stream = g_object_new (VALENT_TYPE_MUX_INPUT_STREAM,
      69                 :             :                                      "muxer", self->muxer,
      70                 :             :                                      "uuid",  self->uuid,
      71                 :             :                                      NULL);
      72                 :           6 :   self->output_stream = g_object_new (VALENT_TYPE_MUX_OUTPUT_STREAM,
      73                 :             :                                       "muxer", self->muxer,
      74                 :             :                                       "uuid",  self->uuid,
      75                 :             :                                       NULL);
      76                 :           6 : }
      77                 :             : 
      78                 :             : static void
      79                 :           0 : valent_mux_io_stream_finalize (GObject *object)
      80                 :             : {
      81                 :           0 :   ValentMuxIOStream *self = VALENT_MUX_IO_STREAM (object);
      82                 :             : 
      83         [ #  # ]:           0 :   g_clear_object (&self->input_stream);
      84         [ #  # ]:           0 :   g_clear_object (&self->output_stream);
      85         [ #  # ]:           0 :   g_clear_object (&self->muxer);
      86         [ #  # ]:           0 :   g_clear_pointer (&self->uuid, g_free);
      87                 :             : 
      88                 :           0 :   G_OBJECT_CLASS (valent_mux_io_stream_parent_class)->finalize (object);
      89                 :           0 : }
      90                 :             : 
      91                 :             : static void
      92                 :           0 : valent_mux_io_stream_get_property (GObject    *object,
      93                 :             :                                    guint       prop_id,
      94                 :             :                                    GValue     *value,
      95                 :             :                                    GParamSpec *pspec)
      96                 :             : {
      97                 :           0 :   ValentMuxIOStream *self = VALENT_MUX_IO_STREAM (object);
      98                 :             : 
      99      [ #  #  # ]:           0 :   switch ((ValentMuxIOStreamProperty)prop_id)
     100                 :             :     {
     101                 :           0 :     case PROP_MUXER:
     102                 :           0 :       g_value_set_object (value, self->muxer);
     103                 :           0 :       break;
     104                 :             : 
     105                 :           0 :     case PROP_UUID:
     106                 :           0 :       g_value_set_string (value, self->uuid);
     107                 :           0 :       break;
     108                 :             : 
     109                 :           0 :     default:
     110                 :           0 :       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
     111                 :             :     }
     112                 :           0 : }
     113                 :             : 
     114                 :             : static void
     115                 :          12 : valent_mux_io_stream_set_property (GObject      *object,
     116                 :             :                                    guint         prop_id,
     117                 :             :                                    const GValue *value,
     118                 :             :                                    GParamSpec   *pspec)
     119                 :             : {
     120                 :          12 :   ValentMuxIOStream *self = VALENT_MUX_IO_STREAM (object);
     121                 :             : 
     122      [ +  +  - ]:          12 :   switch ((ValentMuxIOStreamProperty)prop_id)
     123                 :             :     {
     124                 :           6 :     case PROP_MUXER:
     125                 :           6 :       self->muxer = g_value_dup_object (value);
     126                 :           6 :       break;
     127                 :             : 
     128                 :           6 :     case PROP_UUID:
     129                 :           6 :       self->uuid = g_value_dup_string (value);
     130                 :           6 :       break;
     131                 :             : 
     132                 :           0 :     default:
     133                 :           0 :       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
     134                 :             :     }
     135                 :          12 : }
     136                 :             : 
     137                 :             : static void
     138                 :           1 : valent_mux_io_stream_class_init (ValentMuxIOStreamClass *klass)
     139                 :             : {
     140                 :           1 :   GObjectClass *object_class = G_OBJECT_CLASS (klass);
     141                 :           1 :   GIOStreamClass *stream_class = G_IO_STREAM_CLASS (klass);
     142                 :             : 
     143                 :           1 :   object_class->constructed = valent_mux_io_stream_constructed;
     144                 :           1 :   object_class->finalize = valent_mux_io_stream_finalize;
     145                 :           1 :   object_class->get_property = valent_mux_io_stream_get_property;
     146                 :           1 :   object_class->set_property = valent_mux_io_stream_set_property;
     147                 :             : 
     148                 :           1 :   stream_class->get_input_stream = valent_mux_io_stream_get_input_stream;
     149                 :           1 :   stream_class->get_output_stream = valent_mux_io_stream_get_output_stream;
     150                 :             : 
     151                 :           2 :   properties [PROP_MUXER] =
     152                 :           1 :     g_param_spec_object ("muxer", NULL, NULL,
     153                 :             :                          VALENT_TYPE_BLUEZ_MUXER,
     154                 :             :                          (G_PARAM_READWRITE |
     155                 :             :                           G_PARAM_CONSTRUCT_ONLY |
     156                 :             :                           G_PARAM_EXPLICIT_NOTIFY |
     157                 :             :                           G_PARAM_STATIC_STRINGS));
     158                 :             : 
     159                 :           2 :   properties [PROP_UUID] =
     160                 :           1 :     g_param_spec_string ("uuid", NULL, NULL,
     161                 :             :                          NULL,
     162                 :             :                          (G_PARAM_READWRITE |
     163                 :             :                           G_PARAM_CONSTRUCT_ONLY |
     164                 :             :                           G_PARAM_EXPLICIT_NOTIFY |
     165                 :             :                           G_PARAM_STATIC_STRINGS));
     166                 :             : 
     167                 :           1 :   g_object_class_install_properties (object_class, G_N_ELEMENTS (properties), properties);
     168                 :           1 : }
     169                 :             : 
     170                 :             : static void
     171                 :           6 : valent_mux_io_stream_init (ValentMuxIOStream *self)
     172                 :             : {
     173                 :           6 : }
     174                 :             : 
        

Generated by: LCOV version 2.0-1