[gnome-network-displays/cc-tmp: 12/80] Drop connection name use and ensure connection function




commit 14887d7e4d22a9f0985303838d8713bea089f5c4
Author: Benjamin Berg <bberg redhat com>
Date:   Tue Jul 26 13:27:10 2022 +0200

    Drop connection name use and ensure connection function

 src/cc/cc-comm.c | 50 +++++++-------------------------------------------
 src/cc/cc-comm.h |  4 ++--
 src/nd-cc-sink.c | 10 +++++-----
 3 files changed, 14 insertions(+), 50 deletions(-)
---
diff --git a/src/cc/cc-comm.c b/src/cc/cc-comm.c
index 110e42c..466fd53 100644
--- a/src/cc/cc-comm.c
+++ b/src/cc/cc-comm.c
@@ -268,24 +268,6 @@ cc_comm_make_connection (NdCCSink *sink, GError **error)
   return TRUE;
 }
 
-gboolean
-cc_comm_ensure_connection (NdCCSink * sink, GError ** error)
-{
-  NdCCSink * self = ND_CC_SINK (sink);
-  g_autoptr(GError) err = NULL;
-
-  if (!G_IS_TLS_CONNECTION (self->connection) && !cc_comm_make_connection (self, &err))
-  {
-    g_warning ("CCComm: Failed to make connection: %s", err->message);
-    g_propagate_error (error, g_steal_pointer (&err));
-    return FALSE;
-  }
-
-  g_assert (G_IS_TLS_CONNECTION (self->connection));
-
-  return TRUE;
-}
-
 gboolean
 cc_comm_tls_send (NdCCSink      * sink,
                   uint8_t       * message,
@@ -304,7 +286,7 @@ cc_comm_tls_send (NdCCSink      * sink,
       return FALSE:
     }
 
-  g_debug ("Writing data:");
+  g_debug ("Writing data to Chromecast command channel:");
   cc_comm_dump_message (message, size);
 
   ostream = g_io_stream_get_output_stream (G_IO_STREAM (self->connection))
@@ -365,10 +347,9 @@ cc_comm_build_message (gchar *namespace_,
 }
 
 gboolean
-cc_comm_send_request (NdCCSink *sink, enum MessageType message_type, char *utf8_payload)
+cc_comm_send_request (NdCCSink *sink, enum MessageType message_type, char *utf8_payload, GError **error)
 {
   NdCCSink *self = ND_CC_SINK (sink);
-  g_autoptr(GError) error = NULL;
   gboolean send_ok;
   Castchannel__CastMessage message;
   guint32 packed_size = 0;
@@ -432,27 +413,11 @@ cc_comm_send_request (NdCCSink *sink, enum MessageType message_type, char *utf8_
   memcpy(sock_buffer, &packed_size_be, 4);
   castchannel__cast_message__pack(&message, 4 + sock_buffer);
 
-  g_debug("Sending message to %s:%s", self->remote_address, self->remote_name);
-  send_ok = cc_comm_tls_send (self,
-                              sock_buffer,
-                              packed_size+4,
-                              expect_input,
-                              &error);
-
-  if (!send_ok || error != NULL)
-  {
-    if (error != NULL)
-      g_warning ("CCComm: Failed to connect to Chromecast: %s", error->message);
-    else
-      g_warning ("CCComm: Failed to connect to Chromecast");
-
-    self->state = ND_SINK_STATE_ERROR;
-    g_object_notify (G_OBJECT (self), "state");
-    g_clear_object (&self->server);
-    return FALSE;
-  }
-
-  return TRUE;
+  return cc_comm_tls_send (self,
+                           sock_buffer,
+                           packed_size+4,
+                           expect_input,
+                           error);
 }
 
 gboolean
@@ -460,7 +425,6 @@ cc_comm_send_ping (gpointer userdata)
 {
   NdCCSink *self = ND_CC_SINK (userdata);
 
-  if (!cc_comm_ensure_connection(self, &error)) return FALSE;
   cc_comm_send_request(self, MESSAGE_TYPE_PING, NULL);
 
   return TRUE;
diff --git a/src/cc/cc-comm.h b/src/cc/cc-comm.h
index 2f535c1..28e60af 100644
--- a/src/cc/cc-comm.h
+++ b/src/cc/cc-comm.h
@@ -23,8 +23,8 @@
 
 G_BEGIN_DECLS
 
-gboolean cc_comm_ensure_connection (NdCCSink * sink, GError ** error);
-gboolean cc_comm_send_request (NdCCSink *sink, enum MessageType message_type, char *utf8_payload);
+gboolean cc_comm_make_connection (NdCCSink * sink, GError ** error);
+gboolean cc_comm_send_request (NdCCSink *sink, enum MessageType message_type, char *utf8_payload, GError 
**error);
 gboolean cc_comm_send_ping (gpointer userdata);
 
 G_END_DECLS
diff --git a/src/nd-cc-sink.c b/src/nd-cc-sink.c
index 4865c99..51df8e8 100644
--- a/src/nd-cc-sink.c
+++ b/src/nd-cc-sink.c
@@ -261,7 +261,7 @@ static void
 closed_cb (NdCCSink *sink, CCClient *client)
 {
   /* Connection was closed, do a clean shutdown */
-  cc_comm_send_request(ND_CC_SINK (sink), MESSAGE_TYPE_DISCONNECT, NULL);
+  cc_comm_send_request(ND_CC_SINK (sink), MESSAGE_TYPE_DISCONNECT, NULL, NULL);
 
   nd_cc_sink_sink_stop_stream (ND_SINK (sink));
 }
@@ -329,7 +329,7 @@ nd_cc_sink_sink_start_stream (NdSink *sink)
   g_debug ("NdCCSink: Attempting connection to Chromecast: %s", self->remote_name);
 
   // open a TLS connection to the CC device
-  if (!cc_comm_ensure_connection(self, &error))
+  if (!cc_comm_make_connection(self, &error))
     {
       self->state = ND_SINK_STATE_ERROR;
       g_object_notify (G_OBJECT (self), "state");
@@ -341,16 +341,16 @@ nd_cc_sink_sink_start_stream (NdSink *sink)
   // TODO: listen to all incoming messages
 
   // open up a virtual connection to the device
-  cc_comm_send_request(self, MESSAGE_TYPE_CONNECT, NULL);
+  cc_comm_send_request(self, MESSAGE_TYPE_CONNECT, NULL, NULL);
 
   // send pings to device every 5 seconds
   self->ping_timeout_handle = g_timeout_add_seconds(5, cc_comm_send_ping, self);
 
   // send req to get status
-  cc_comm_send_request(self, MESSAGE_TYPE_RECEIVER, "{\"type\": \"GET_STATUS\"}");
+  cc_comm_send_request(self, MESSAGE_TYPE_RECEIVER, "{\"type\": \"GET_STATUS\"}", NULL);
 
   // send req to open youtube
-  cc_comm_send_request(self, MESSAGE_TYPE_RECEIVER, "{ \"type\": \"LAUNCH\", \"appId\": \"YouTube\", 
\"requestId\": 1 }");
+  cc_comm_send_request(self, MESSAGE_TYPE_RECEIVER, "{ \"type\": \"LAUNCH\", \"appId\": \"YouTube\", 
\"requestId\": 1 }", NULL);
 
   self->server = wfd_server_new ();
   self->server_source_id = gst_rtsp_server_attach (GST_RTSP_SERVER (self->server), NULL);


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