[gnome-network-displays/cc-tmp: 63/80] cc: pass userdata instead of the whole closure




commit f173fa02521d30c46ff1ef0d1e1827e76b6c3a68
Author: Anupam Kumar <kyteinsky gmail com>
Date:   Tue Sep 6 00:38:03 2022 +0530

    cc: pass userdata instead of the whole closure

 src/cc/cc-comm.c | 18 +++++++++---------
 src/cc/cc-comm.h |  6 +++---
 src/cc/cc-ctrl.c | 12 ++++++------
 src/cc/cc-ctrl.h |  6 +++---
 src/nd-cc-sink.c | 10 ++++++----
 5 files changed, 27 insertions(+), 25 deletions(-)
---
diff --git a/src/cc/cc-comm.c b/src/cc/cc-comm.c
index 49b64ab..e1d0f7c 100644
--- a/src/cc/cc-comm.c
+++ b/src/cc/cc-comm.c
@@ -62,7 +62,7 @@ cc_comm_parse_received_data (CcComm *comm, uint8_t * input_buffer, gssize input_
 
   g_clear_pointer (&comm->message_buffer, g_free);
 
-  comm->closure->message_received_cb (comm->closure, message);
+  comm->closure->message_received_cb (comm->closure->userdata, message);
 
   cast__channel__cast_message__free_unpacked (message, NULL);
 }
@@ -116,7 +116,7 @@ cc_comm_message_read_cb (GObject      *source_object,
   if (!comm->con)
     {
       g_error ("CcComm: Connection error while reading message body");
-      comm->closure->fatal_error_cb (comm->closure, NULL);
+      comm->closure->fatal_error_cb (comm->closure->userdata, NULL);
       return;
     }
 
@@ -131,11 +131,11 @@ cc_comm_message_read_cb (GObject      *source_object,
       if (error)
         {
           g_error ("CcComm: Error reading message from stream: %s", error->message);
-          comm->closure->fatal_error_cb (comm->closure, g_steal_pointer (&error));
+          comm->closure->fatal_error_cb (comm->closure->userdata, g_steal_pointer (&error));
           return;
         }
       g_error ("CcComm: Error reading message from stream.");
-      comm->closure->fatal_error_cb (comm->closure, NULL);
+      comm->closure->fatal_error_cb (comm->closure->userdata, NULL);
       return;
     }
 
@@ -167,7 +167,7 @@ cc_comm_header_read_cb (GObject      *source_object,
   if (!comm->con)
     {
       g_error ("CcComm: Connection error while reading header");
-      comm->closure->fatal_error_cb (comm->closure, NULL);
+      comm->closure->fatal_error_cb (comm->closure->userdata, NULL);
       return;
     }
 
@@ -184,11 +184,11 @@ cc_comm_header_read_cb (GObject      *source_object,
       if (error)
         {
           g_error ("CcComm: Error reading header from stream: %s", error->message);
-          comm->closure->fatal_error_cb (comm->closure, g_steal_pointer (&error));
+          comm->closure->fatal_error_cb (comm->closure->userdata, g_steal_pointer (&error));
           return;
         }
       g_error ("CcComm: Error reading header from stream.");
-      comm->closure->fatal_error_cb (comm->closure, NULL);
+      comm->closure->fatal_error_cb (comm->closure->userdata, NULL);
       return;
     }
 
@@ -333,7 +333,7 @@ cc_comm_tls_send (CcComm  * comm,
   if (!G_IS_TLS_CONNECTION (comm->con))
     {
       g_error ("Connection has not been established");
-      comm->closure->fatal_error_cb (comm->closure, NULL);
+      comm->closure->fatal_error_cb (comm->closure->userdata, NULL);
       return FALSE;
     }
 
@@ -349,7 +349,7 @@ cc_comm_tls_send (CcComm  * comm,
       if (io_bytes <= 0)
         {
           g_warning ("CcComm: Failed to write: %s", err->message);
-          comm->closure->fatal_error_cb (comm->closure, g_steal_pointer (&err));
+          comm->closure->fatal_error_cb (comm->closure->userdata, g_steal_pointer (&err));
           return FALSE;
         }
 
diff --git a/src/cc/cc-comm.h b/src/cc/cc-comm.h
index 80b2a80..273cece 100644
--- a/src/cc/cc-comm.h
+++ b/src/cc/cc-comm.h
@@ -29,10 +29,10 @@ G_BEGIN_DECLS
 struct _CcCommClosure
 {
   gpointer userdata;
-  void     (*message_received_cb) (struct _CcCommClosure      *closure,
+  void     (*message_received_cb) (gpointer                    userdata,
                                    Cast__Channel__CastMessage *message);
-  void     (*fatal_error_cb) (struct _CcCommClosure *closure,
-                              GError                *error);
+  void     (*fatal_error_cb) (gpointer userdata,
+                              GError  *error);
 };
 
 typedef struct _CcCommClosure CcCommClosure;
diff --git a/src/cc/cc-ctrl.c b/src/cc/cc-ctrl.c
index c439b54..078c62b 100644
--- a/src/cc/cc-ctrl.c
+++ b/src/cc/cc-ctrl.c
@@ -284,7 +284,7 @@ cc_ctrl_send_offer (CcCtrl *ctrl, gchar *destination_id, GError **error)
 
   /* look into [ adaptive_playout_delay, rtpExtensions, rtpPayloadType, rtpProfile, aes stuff, ssrc 
increment in received msg ] */
 
-  Offer *offer = ctrl->closure->get_offer_message (ctrl->closure);
+  Offer *offer = ctrl->closure->get_offer_message (ctrl->closure->userdata);
   JsonNode *audio_source_node = build_audio_source (&offer->audio_stream);
   JsonNode *video_source_node = build_video_source (&offer->video_stream);
 
@@ -521,10 +521,10 @@ cc_ctrl_handle_close (CcCtrl *ctrl, Cast__Channel__CastMessage *message)
 }
 
 void
-cc_ctrl_handle_received_msg (CcCommClosure              *closure,
+cc_ctrl_handle_received_msg (gpointer                    userdata,
                              Cast__Channel__CastMessage *message)
 {
-  CcCtrl *ctrl = (CcCtrl *) closure->userdata;
+  CcCtrl *ctrl = (CcCtrl *) userdata;
 
   g_autoptr(GError) error = NULL;
   g_autoptr(JsonParser) parser = NULL;
@@ -601,12 +601,12 @@ cc_ctrl_fatal_error (CcCtrl *ctrl)
   if (ctrl->state == CC_CTRL_STATE_ERROR) /* function has already been called */
     return;
 
-  ctrl->closure->end_stream (ctrl->closure);
+  ctrl->closure->end_stream (ctrl->closure->userdata);
   ctrl->state = CC_CTRL_STATE_ERROR;
 }
 
 void
-cc_ctrl_fatal_error_closure (CcCommClosure *closure, GError *error)
+cc_ctrl_fatal_error_closure (gpointer userdata, GError *error)
 {
   /* XXX: add error arg in end_stream and display an error message to user */
   if (error)
@@ -614,7 +614,7 @@ cc_ctrl_fatal_error_closure (CcCommClosure *closure, GError *error)
   else
     g_error ("CcCtrl: Fatal error");
 
-  CcCtrl *ctrl = (CcCtrl *) closure->userdata;
+  CcCtrl *ctrl = (CcCtrl *) userdata;
   cc_ctrl_fatal_error (ctrl);
 }
 
diff --git a/src/cc/cc-ctrl.h b/src/cc/cc-ctrl.h
index 024ac8e..b905362 100644
--- a/src/cc/cc-ctrl.h
+++ b/src/cc/cc-ctrl.h
@@ -39,9 +39,9 @@ typedef enum {
 struct _CcCtrlClosure
 {
   gpointer userdata;
-  Offer  * (*get_offer_message) (struct _CcCtrlClosure *closure);
-  void     (*start_stream) (struct _CcCtrlClosure *closure);
-  void     (*end_stream) (struct _CcCtrlClosure *closure);
+  Offer  * (*get_offer_message) (gpointer userdata);
+  void     (*start_stream) (gpointer userdata);
+  void     (*end_stream) (gpointer userdata);
 };
 
 typedef struct _CcCtrlClosure CcCtrlClosure;
diff --git a/src/nd-cc-sink.c b/src/nd-cc-sink.c
index 5fe6369..ab38bac 100644
--- a/src/nd-cc-sink.c
+++ b/src/nd-cc-sink.c
@@ -307,16 +307,18 @@ server_create_audio_source_cb (NdCCSink *sink, WfdServer *server)
 }
 
 static void
-nd_cc_sink_start_webrtc_stream (CcCtrlClosure *closure)
+nd_cc_sink_start_webrtc_stream (gpointer userdata)
 {
+  NdCCSink *sink = ND_CC_SINK (userdata);
+
   /* TODO */
   g_debug ("Received webrtc stream signal from ctrl");
 }
 
 static void
-nd_cc_sink_error_in_ctrl (CcCtrlClosure *closure)
+nd_cc_sink_error_in_ctrl (gpointer userdata)
 {
-  nd_cc_sink_sink_stop_stream (ND_SINK (closure->userdata));
+  nd_cc_sink_sink_stop_stream (ND_SINK (userdata));
 }
 
 CcCtrlClosure *
@@ -327,7 +329,7 @@ nd_cc_sink_get_callback_closure (NdCCSink *sink)
   closure->userdata = sink;
   closure->start_stream = nd_cc_sink_start_webrtc_stream;
   closure->end_stream = nd_cc_sink_error_in_ctrl;
-  return closure;
+  return g_steal_pointer (&closure);
 }
 
 static NdSink *


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]