LCOV - code coverage report
Current view: top level - src/plugins/bluez - valent-mux-output-stream.c (source / functions) Coverage Total Hit
Test: Code Coverage Lines: 66.0 % 94 62
Test Date: 2025-11-09 04:19:42 Functions: 73.3 % 15 11
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 36.4 % 22 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-output-stream"
       5                 :             : 
       6                 :             : #include "config.h"
       7                 :             : 
       8                 :             : #include <gio/gio.h>
       9                 :             : 
      10                 :             : #include "valent-bluez-muxer.h"
      11                 :             : 
      12                 :             : #include "valent-mux-output-stream.h"
      13                 :             : 
      14                 :             : 
      15                 :             : struct _ValentMuxOutputStream
      16                 :             : {
      17                 :             :   GOutputStream     parent_instance;
      18                 :             : 
      19                 :             :   ValentBluezMuxer *muxer;
      20                 :             :   char             *uuid;
      21                 :             : };
      22                 :             : 
      23                 :             : static void   g_pollable_output_stream_iface_init (GPollableOutputStreamInterface *iface);
      24                 :             : 
      25   [ +  +  +  - ]:          18 : G_DEFINE_FINAL_TYPE_WITH_CODE (ValentMuxOutputStream, valent_mux_output_stream, G_TYPE_OUTPUT_STREAM,
      26                 :             :                                G_IMPLEMENT_INTERFACE (G_TYPE_POLLABLE_OUTPUT_STREAM, g_pollable_output_stream_iface_init))
      27                 :             : 
      28                 :             : typedef enum {
      29                 :             :   PROP_MUXER = 1,
      30                 :             :   PROP_UUID,
      31                 :             : } ValentMuxOutputStreamProperty;
      32                 :             : 
      33                 :             : static GParamSpec *properties[PROP_UUID + 1] = { NULL, };
      34                 :             : 
      35                 :             : /*
      36                 :             :  * GPollableOutputStream
      37                 :             :  */
      38                 :             : static GSource *
      39                 :           5 : valent_mux_output_stream_create_source (GPollableOutputStream *pollable,
      40                 :             :                                         GCancellable          *cancellable)
      41                 :             : {
      42                 :           5 :   ValentMuxOutputStream *self = VALENT_MUX_OUTPUT_STREAM (pollable);
      43                 :          10 :   g_autoptr (GSource) muxer_source = NULL;
      44                 :             : 
      45                 :          10 :   muxer_source = valent_bluez_muxer_create_source (self->muxer,
      46                 :           5 :                                                    self->uuid,
      47                 :             :                                                    (G_IO_OUT | G_IO_HUP |G_IO_ERR));
      48                 :             : 
      49         [ +  - ]:           5 :   return g_pollable_source_new_full (pollable, muxer_source, cancellable);
      50                 :             : }
      51                 :             : 
      52                 :             : static gboolean
      53                 :           0 : valent_mux_output_stream_is_writable (GPollableOutputStream *pollable)
      54                 :             : {
      55                 :           0 :   ValentMuxOutputStream *self = VALENT_MUX_OUTPUT_STREAM (pollable);
      56                 :             : 
      57                 :           0 :   return valent_bluez_muxer_condition_check (self->muxer,
      58                 :           0 :                                              self->uuid,
      59                 :             :                                              (G_IO_OUT | G_IO_HUP | G_IO_ERR));
      60                 :             : }
      61                 :             : 
      62                 :             : static gssize
      63                 :          12 : valent_mux_output_stream_write_nonblocking (GPollableOutputStream  *pollable,
      64                 :             :                                             const void             *buffer,
      65                 :             :                                             gsize                   count,
      66                 :             :                                             GError                **error)
      67                 :             : {
      68                 :          12 :   ValentMuxOutputStream *self = VALENT_MUX_OUTPUT_STREAM (pollable);
      69                 :          12 :   gssize ret;
      70                 :             : 
      71                 :          12 :   VALENT_ENTRY;
      72                 :             : 
      73                 :          24 :   ret = valent_bluez_muxer_channel_write (self->muxer,
      74                 :          12 :                                           self->uuid,
      75                 :             :                                           buffer,
      76                 :             :                                           count,
      77                 :             :                                           FALSE,
      78                 :             :                                           NULL,
      79                 :             :                                           error);
      80                 :             : 
      81                 :          12 :   VALENT_RETURN (ret);
      82                 :             : }
      83                 :             : 
      84                 :             : static void
      85                 :           1 : g_pollable_output_stream_iface_init (GPollableOutputStreamInterface *iface)
      86                 :             : {
      87                 :           1 :   iface->create_source = valent_mux_output_stream_create_source;
      88                 :           1 :   iface->is_writable = valent_mux_output_stream_is_writable;
      89                 :           1 :   iface->write_nonblocking = valent_mux_output_stream_write_nonblocking;
      90                 :           1 : }
      91                 :             : 
      92                 :             : /*
      93                 :             :  * GOutputStream
      94                 :             :  */
      95                 :             : static gboolean
      96                 :           5 : valent_mux_output_stream_close (GOutputStream  *stream,
      97                 :             :                                 GCancellable   *cancellable,
      98                 :             :                                 GError        **error)
      99                 :             : {
     100                 :           5 :   ValentMuxOutputStream *self = VALENT_MUX_OUTPUT_STREAM (stream);
     101                 :           5 :   gboolean ret;
     102                 :             : 
     103                 :           5 :   VALENT_ENTRY;
     104                 :             : 
     105         [ -  + ]:           5 :   g_assert (VALENT_IS_MUX_OUTPUT_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 gboolean
     116                 :           5 : valent_mux_output_stream_flush (GOutputStream  *stream,
     117                 :             :                                 GCancellable   *cancellable,
     118                 :             :                                 GError        **error)
     119                 :             : {
     120                 :           5 :   ValentMuxOutputStream *self = VALENT_MUX_OUTPUT_STREAM (stream);
     121                 :           5 :   gboolean ret;
     122                 :             : 
     123                 :           5 :   VALENT_ENTRY;
     124                 :             : 
     125         [ -  + ]:           5 :   g_assert (VALENT_IS_MUX_OUTPUT_STREAM (stream));
     126                 :             : 
     127                 :          10 :   ret = valent_bluez_muxer_channel_flush (self->muxer,
     128                 :           5 :                                           self->uuid,
     129                 :             :                                           cancellable,
     130                 :             :                                           error);
     131                 :             : 
     132                 :           5 :   VALENT_RETURN (ret);
     133                 :             : }
     134                 :             : 
     135                 :             : static gssize
     136                 :           0 : valent_mux_output_stream_write (GOutputStream  *stream,
     137                 :             :                                 const void     *buffer,
     138                 :             :                                 size_t          count,
     139                 :             :                                 GCancellable   *cancellable,
     140                 :             :                                 GError        **error)
     141                 :             : {
     142                 :           0 :   ValentMuxOutputStream *self = VALENT_MUX_OUTPUT_STREAM (stream);
     143                 :           0 :   gssize ret;
     144                 :             : 
     145                 :           0 :   VALENT_ENTRY;
     146                 :             : 
     147         [ #  # ]:           0 :   g_assert (VALENT_IS_MUX_OUTPUT_STREAM (stream));
     148                 :             : 
     149                 :           0 :   ret = valent_bluez_muxer_channel_write (self->muxer,
     150                 :           0 :                                           self->uuid,
     151                 :             :                                           buffer,
     152                 :             :                                           count,
     153                 :             :                                           TRUE,
     154                 :             :                                           cancellable,
     155                 :             :                                           error);
     156                 :             : 
     157                 :           0 :   VALENT_RETURN (ret);
     158                 :             : }
     159                 :             : 
     160                 :             : /*
     161                 :             :  * GObject
     162                 :             :  */
     163                 :             : static void
     164                 :           0 : valent_mux_output_stream_finalize (GObject *object)
     165                 :             : {
     166                 :           0 :   ValentMuxOutputStream *self = VALENT_MUX_OUTPUT_STREAM (object);
     167                 :             : 
     168         [ #  # ]:           0 :   g_clear_object (&self->muxer);
     169         [ #  # ]:           0 :   g_clear_pointer (&self->uuid, g_free);
     170                 :             : 
     171                 :           0 :   G_OBJECT_CLASS (valent_mux_output_stream_parent_class)->finalize (object);
     172                 :           0 : }
     173                 :             : 
     174                 :             : static void
     175                 :           0 : valent_mux_output_stream_get_property (GObject    *object,
     176                 :             :                                        guint       prop_id,
     177                 :             :                                        GValue     *value,
     178                 :             :                                        GParamSpec *pspec)
     179                 :             : {
     180                 :           0 :   ValentMuxOutputStream *self = VALENT_MUX_OUTPUT_STREAM (object);
     181                 :             : 
     182      [ #  #  # ]:           0 :   switch ((ValentMuxOutputStreamProperty)prop_id)
     183                 :             :     {
     184                 :           0 :     case PROP_MUXER:
     185                 :           0 :       g_value_set_object (value, self->muxer);
     186                 :           0 :       break;
     187                 :             : 
     188                 :           0 :     case PROP_UUID:
     189                 :           0 :       g_value_set_string (value, self->uuid);
     190                 :           0 :       break;
     191                 :             : 
     192                 :           0 :     default:
     193                 :           0 :       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
     194                 :             :     }
     195                 :           0 : }
     196                 :             : 
     197                 :             : static void
     198                 :          12 : valent_mux_output_stream_set_property (GObject      *object,
     199                 :             :                                        guint         prop_id,
     200                 :             :                                        const GValue *value,
     201                 :             :                                        GParamSpec   *pspec)
     202                 :             : {
     203                 :          12 :   ValentMuxOutputStream *self = VALENT_MUX_OUTPUT_STREAM (object);
     204                 :             : 
     205      [ +  +  - ]:          12 :   switch ((ValentMuxOutputStreamProperty)prop_id)
     206                 :             :     {
     207                 :           6 :     case PROP_MUXER:
     208                 :           6 :       self->muxer = g_value_dup_object (value);
     209                 :           6 :       break;
     210                 :             : 
     211                 :           6 :     case PROP_UUID:
     212                 :           6 :       self->uuid = g_value_dup_string (value);
     213                 :           6 :       break;
     214                 :             : 
     215                 :           0 :     default:
     216                 :           0 :       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
     217                 :             :     }
     218                 :          12 : }
     219                 :             : 
     220                 :             : static void
     221                 :           1 : valent_mux_output_stream_class_init (ValentMuxOutputStreamClass *klass)
     222                 :             : {
     223                 :           1 :   GObjectClass *object_class = G_OBJECT_CLASS (klass);
     224                 :           1 :   GOutputStreamClass *stream_class = G_OUTPUT_STREAM_CLASS (klass);
     225                 :             : 
     226                 :           1 :   object_class->finalize = valent_mux_output_stream_finalize;
     227                 :           1 :   object_class->get_property = valent_mux_output_stream_get_property;
     228                 :           1 :   object_class->set_property = valent_mux_output_stream_set_property;
     229                 :             : 
     230                 :           1 :   stream_class->close_fn = valent_mux_output_stream_close;
     231                 :           1 :   stream_class->flush = valent_mux_output_stream_flush;
     232                 :           1 :   stream_class->write_fn = valent_mux_output_stream_write;
     233                 :             : 
     234                 :           2 :   properties [PROP_MUXER] =
     235                 :           1 :     g_param_spec_object ("muxer", NULL, NULL,
     236                 :             :                          VALENT_TYPE_BLUEZ_MUXER,
     237                 :             :                          (G_PARAM_READWRITE |
     238                 :             :                           G_PARAM_CONSTRUCT_ONLY |
     239                 :             :                           G_PARAM_EXPLICIT_NOTIFY |
     240                 :             :                           G_PARAM_STATIC_STRINGS));
     241                 :             : 
     242                 :           2 :   properties [PROP_UUID] =
     243                 :           1 :     g_param_spec_string ("uuid", NULL, NULL,
     244                 :             :                          NULL,
     245                 :             :                          (G_PARAM_READWRITE |
     246                 :             :                           G_PARAM_CONSTRUCT_ONLY |
     247                 :             :                           G_PARAM_EXPLICIT_NOTIFY |
     248                 :             :                           G_PARAM_STATIC_STRINGS));
     249                 :             : 
     250                 :           1 :   g_object_class_install_properties (object_class, G_N_ELEMENTS (properties), properties);
     251                 :           1 : }
     252                 :             : 
     253                 :             : static void
     254                 :           6 : valent_mux_output_stream_init (ValentMuxOutputStream *self)
     255                 :             : {
     256                 :           6 : }
     257                 :             : 
        

Generated by: LCOV version 2.0-1