LCOV - code coverage report
Current view: top level - src/plugins/bluez - valent-mux-input-stream.c (source / functions) Coverage Total Hit
Test: Code Coverage Lines: 71.8 % 85 61
Test Date: 2025-11-09 04:19:42 Functions: 78.6 % 14 11
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 40.0 % 20 8

             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-input-stream"
       5                 :             : 
       6                 :             : #include "config.h"
       7                 :             : 
       8                 :             : #include <gio/gio.h>
       9                 :             : 
      10                 :             : #include "valent-bluez-muxer.h"
      11                 :             : 
      12                 :             : #include "valent-mux-input-stream.h"
      13                 :             : 
      14                 :             : 
      15                 :             : struct _ValentMuxInputStream
      16                 :             : {
      17                 :             :   GInputStream      parent_instance;
      18                 :             : 
      19                 :             :   ValentBluezMuxer *muxer;
      20                 :             :   char             *uuid;
      21                 :             : };
      22                 :             : 
      23                 :             : static void   g_pollable_input_stream_iface_init (GPollableInputStreamInterface *iface);
      24                 :             : 
      25   [ +  +  +  - ]:        3891 : G_DEFINE_FINAL_TYPE_WITH_CODE (ValentMuxInputStream, valent_mux_input_stream, G_TYPE_INPUT_STREAM,
      26                 :             :                                G_IMPLEMENT_INTERFACE (G_TYPE_POLLABLE_INPUT_STREAM, g_pollable_input_stream_iface_init))
      27                 :             : 
      28                 :             : typedef enum {
      29                 :             :   PROP_MUXER = 1,
      30                 :             :   PROP_UUID,
      31                 :             : } ValentMuxInputStreamProperty;
      32                 :             : 
      33                 :             : static GParamSpec *properties[PROP_UUID + 1] = { NULL, };
      34                 :             : 
      35                 :             : /*
      36                 :             :  * GPollableInputStream
      37                 :             :  */
      38                 :             : static GSource *
      39                 :           6 : valent_mux_input_stream_create_source (GPollableInputStream *pollable,
      40                 :             :                                        GCancellable         *cancellable)
      41                 :             : {
      42                 :           6 :   ValentMuxInputStream *self = VALENT_MUX_INPUT_STREAM (pollable);
      43                 :          12 :   g_autoptr (GSource) muxer_source = NULL;
      44                 :             : 
      45                 :          12 :   muxer_source = valent_bluez_muxer_create_source (self->muxer,
      46                 :           6 :                                                    self->uuid,
      47                 :             :                                                    (G_IO_IN | G_IO_HUP));
      48                 :             : 
      49         [ +  - ]:           6 :   return g_pollable_source_new_full (pollable, muxer_source, cancellable);
      50                 :             : }
      51                 :             : 
      52                 :             : static gboolean
      53                 :           0 : valent_mux_input_stream_is_readable (GPollableInputStream *pollable)
      54                 :             : {
      55                 :           0 :   ValentMuxInputStream *self = VALENT_MUX_INPUT_STREAM (pollable);
      56                 :             : 
      57                 :           0 :   return valent_bluez_muxer_condition_check (self->muxer,
      58                 :           0 :                                              self->uuid,
      59                 :             :                                              (G_IO_IN | G_IO_HUP));
      60                 :             : }
      61                 :             : 
      62                 :             : static gssize
      63                 :          10 : valent_mux_input_stream_read_nonblocking (GPollableInputStream  *pollable,
      64                 :             :                                           void                  *buffer,
      65                 :             :                                           gsize                  count,
      66                 :             :                                           GError               **error)
      67                 :             : {
      68                 :          10 :   ValentMuxInputStream *self = VALENT_MUX_INPUT_STREAM (pollable);
      69                 :          10 :   gssize ret;
      70                 :             : 
      71                 :          10 :   VALENT_ENTRY;
      72                 :             : 
      73                 :          20 :   ret = valent_bluez_muxer_channel_read (self->muxer,
      74                 :          10 :                                          self->uuid,
      75                 :             :                                          buffer,
      76                 :             :                                          count,
      77                 :             :                                          FALSE,
      78                 :             :                                          NULL,
      79                 :             :                                          error);
      80                 :             : 
      81                 :          10 :   VALENT_RETURN (ret);
      82                 :             : }
      83                 :             : 
      84                 :             : static void
      85                 :           1 : g_pollable_input_stream_iface_init (GPollableInputStreamInterface *iface)
      86                 :             : {
      87                 :           1 :   iface->create_source = valent_mux_input_stream_create_source;
      88                 :           1 :   iface->is_readable = valent_mux_input_stream_is_readable;
      89                 :           1 :   iface->read_nonblocking = valent_mux_input_stream_read_nonblocking;
      90                 :           1 : }
      91                 :             : 
      92                 :             : /*
      93                 :             :  * GInputStream
      94                 :             :  */
      95                 :             : static gboolean
      96                 :           5 : valent_mux_input_stream_close (GInputStream  *stream,
      97                 :             :                                GCancellable  *cancellable,
      98                 :             :                                GError       **error)
      99                 :             : {
     100                 :           5 :   ValentMuxInputStream *self = VALENT_MUX_INPUT_STREAM (stream);
     101                 :           5 :   gboolean ret;
     102                 :             : 
     103                 :           5 :   VALENT_ENTRY;
     104                 :             : 
     105         [ -  + ]:           5 :   g_assert (VALENT_IS_MUX_INPUT_STREAM (stream));
     106                 :             : 
     107                 :          10 :   ret = valent_bluez_muxer_channel_close (self->muxer,
     108                 :           5 :                                           self->uuid,
     109                 :             :                                           cancellable,
     110                 :             :                                           error);
     111                 :             : 
     112                 :           5 :   VALENT_RETURN (ret);
     113                 :             : }
     114                 :             : 
     115                 :             : static gssize
     116                 :        3878 : valent_mux_input_stream_read (GInputStream  *stream,
     117                 :             :                               void          *buffer,
     118                 :             :                               size_t         count,
     119                 :             :                               GCancellable  *cancellable,
     120                 :             :                               GError       **error)
     121                 :             : {
     122                 :        3878 :   ValentMuxInputStream *self = VALENT_MUX_INPUT_STREAM (stream);
     123                 :        3878 :   gssize ret;
     124                 :             : 
     125                 :        3878 :   VALENT_ENTRY;
     126                 :             : 
     127         [ -  + ]:        3878 :   g_assert (VALENT_IS_MUX_INPUT_STREAM (stream));
     128                 :             : 
     129                 :        7756 :   ret = valent_bluez_muxer_channel_read (self->muxer,
     130                 :        3878 :                                          self->uuid,
     131                 :             :                                          buffer,
     132                 :             :                                          count,
     133                 :             :                                          TRUE,
     134                 :             :                                          cancellable,
     135                 :             :                                          error);
     136                 :             : 
     137                 :        3878 :   VALENT_RETURN (ret);
     138                 :             : }
     139                 :             : 
     140                 :             : /*
     141                 :             :  * GObject
     142                 :             :  */
     143                 :             : static void
     144                 :           0 : valent_mux_input_stream_finalize (GObject *object)
     145                 :             : {
     146                 :           0 :   ValentMuxInputStream *self = VALENT_MUX_INPUT_STREAM (object);
     147                 :             : 
     148         [ #  # ]:           0 :   g_clear_object (&self->muxer);
     149         [ #  # ]:           0 :   g_clear_pointer (&self->uuid, g_free);
     150                 :             : 
     151                 :           0 :   G_OBJECT_CLASS (valent_mux_input_stream_parent_class)->finalize (object);
     152                 :           0 : }
     153                 :             : 
     154                 :             : static void
     155                 :           0 : valent_mux_input_stream_get_property (GObject    *object,
     156                 :             :                                       guint       prop_id,
     157                 :             :                                       GValue     *value,
     158                 :             :                                       GParamSpec *pspec)
     159                 :             : {
     160                 :           0 :   ValentMuxInputStream *self = VALENT_MUX_INPUT_STREAM (object);
     161                 :             : 
     162      [ #  #  # ]:           0 :   switch ((ValentMuxInputStreamProperty)prop_id)
     163                 :             :     {
     164                 :           0 :     case PROP_MUXER:
     165                 :           0 :       g_value_set_object (value, self->muxer);
     166                 :           0 :       break;
     167                 :             : 
     168                 :           0 :     case PROP_UUID:
     169                 :           0 :       g_value_set_string (value, self->uuid);
     170                 :           0 :       break;
     171                 :             : 
     172                 :           0 :     default:
     173                 :           0 :       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
     174                 :             :     }
     175                 :           0 : }
     176                 :             : 
     177                 :             : static void
     178                 :          12 : valent_mux_input_stream_set_property (GObject      *object,
     179                 :             :                                       guint         prop_id,
     180                 :             :                                       const GValue *value,
     181                 :             :                                       GParamSpec   *pspec)
     182                 :             : {
     183                 :          12 :   ValentMuxInputStream *self = VALENT_MUX_INPUT_STREAM (object);
     184                 :             : 
     185      [ +  +  - ]:          12 :   switch ((ValentMuxInputStreamProperty)prop_id)
     186                 :             :     {
     187                 :           6 :     case PROP_MUXER:
     188                 :           6 :       self->muxer = g_value_dup_object (value);
     189                 :           6 :       break;
     190                 :             : 
     191                 :           6 :     case PROP_UUID:
     192                 :           6 :       self->uuid = g_value_dup_string (value);
     193                 :           6 :       break;
     194                 :             : 
     195                 :           0 :     default:
     196                 :           0 :       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
     197                 :             :     }
     198                 :          12 : }
     199                 :             : 
     200                 :             : static void
     201                 :           1 : valent_mux_input_stream_class_init (ValentMuxInputStreamClass *klass)
     202                 :             : {
     203                 :           1 :   GObjectClass *object_class = G_OBJECT_CLASS (klass);
     204                 :           1 :   GInputStreamClass *stream_class = G_INPUT_STREAM_CLASS (klass);
     205                 :             : 
     206                 :           1 :   object_class->finalize = valent_mux_input_stream_finalize;
     207                 :           1 :   object_class->get_property = valent_mux_input_stream_get_property;
     208                 :           1 :   object_class->set_property = valent_mux_input_stream_set_property;
     209                 :             : 
     210                 :           1 :   stream_class->close_fn = valent_mux_input_stream_close;
     211                 :           1 :   stream_class->read_fn = valent_mux_input_stream_read;
     212                 :             : 
     213                 :           2 :   properties [PROP_MUXER] =
     214                 :           1 :     g_param_spec_object ("muxer", NULL, NULL,
     215                 :             :                          VALENT_TYPE_BLUEZ_MUXER,
     216                 :             :                          (G_PARAM_READWRITE |
     217                 :             :                           G_PARAM_CONSTRUCT_ONLY |
     218                 :             :                           G_PARAM_EXPLICIT_NOTIFY |
     219                 :             :                           G_PARAM_STATIC_STRINGS));
     220                 :             : 
     221                 :           2 :   properties [PROP_UUID] =
     222                 :           1 :     g_param_spec_string ("uuid", NULL, NULL,
     223                 :             :                          NULL,
     224                 :             :                          (G_PARAM_READWRITE |
     225                 :             :                           G_PARAM_CONSTRUCT_ONLY |
     226                 :             :                           G_PARAM_EXPLICIT_NOTIFY |
     227                 :             :                           G_PARAM_STATIC_STRINGS));
     228                 :             : 
     229                 :           1 :   g_object_class_install_properties (object_class, G_N_ELEMENTS (properties), properties);
     230                 :           1 : }
     231                 :             : 
     232                 :             : static void
     233                 :           6 : valent_mux_input_stream_init (ValentMuxInputStream *self)
     234                 :             : {
     235                 :           6 : }
     236                 :             : 
        

Generated by: LCOV version 2.0-1