[gnome-network-displays/cc-tmp: 14/80] cc: compiles and sends pings every 5 seconds
- From: Benjamin Berg <bberg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-network-displays/cc-tmp: 14/80] cc: compiles and sends pings every 5 seconds
- Date: Fri, 9 Sep 2022 12:03:49 +0000 (UTC)
commit 5e13da72c6f62b03eade3140ff9610501a7968e9
Author: Anupam Kumar <kyteinsky gmail com>
Date: Wed Jul 27 07:50:07 2022 +0530
cc: compiles and sends pings every 5 seconds
todo:
async read
strong connect message
src/cc/cc-comm.c | 64 +++++++++++++++++++++++++++++++-----------------------
src/cc/cc-comm.h | 12 +++++++++-
src/cc/meson.build | 2 --
src/nd-cc-sink.c | 2 +-
src/nd-cc-sink.h | 9 --------
5 files changed, 49 insertions(+), 40 deletions(-)
---
diff --git a/src/cc/cc-comm.c b/src/cc/cc-comm.c
index 9f39e8d..79ca9a7 100644
--- a/src/cc/cc-comm.c
+++ b/src/cc/cc-comm.c
@@ -134,8 +134,9 @@ cc_comm_header_read_cb (GObject *source_object,
return;
}
+ // TODO
// if everything is well, read all `io_bytes`
- cc_comm_read (comm);
+ // cc_comm_read (comm);
}
void
@@ -150,7 +151,7 @@ cc_comm_read (CcComm *comm, uint8_t *buffer, gsize io_bytes)
io_bytes,
G_PRIORITY_DEFAULT,
NULL,
- (*GAsyncReadyCallback) cc_comm_header_read_cb,
+ cc_comm_header_read_cb,
comm);
}
@@ -158,9 +159,8 @@ cc_comm_read (CcComm *comm, uint8_t *buffer, gsize io_bytes)
void
cc_comm_listen (CcComm *comm)
{
- GInputStream *istream;
- gssize io_bytes;
- g_autofree uint8_t buffer[MAX_MSG_SIZE];
+ // gssize io_bytes;
+ // g_autofree uint8_t buffer[MAX_MSG_SIZE];
g_autofree uint8_t header_buffer[4];
cc_comm_read (comm, header_buffer, 4);
@@ -168,25 +168,25 @@ cc_comm_listen (CcComm *comm)
- if (io_bytes <= 0)
- {
- g_warning ("CCComm: Failed to read: %s", error->message);
- g_error_free (error);
- return FALSE;
- }
+ // if (io_bytes <= 0)
+ // {
+ // g_warning ("CCComm: Failed to read: %s", error->message);
+ // g_clear_error (error);
+ // return FALSE;
+ // }
- g_debug ("CCComm: Received %" G_GSSIZE_FORMAT " bytes", io_bytes);
- g_debug ("CCComm: Received data:");
- cc_comm_dump_message (buffer, io_bytes);
+ // g_debug ("CCComm: Received %" G_GSSIZE_FORMAT " bytes", io_bytes);
+ // g_debug ("CCComm: Received data:");
+ // cc_comm_dump_message (buffer, io_bytes);
- cc_comm_parse_received_data (buffer, io_bytes);
+ // cc_comm_parse_received_data (buffer, io_bytes);
}
-static gboolean
+gboolean
cc_comm_make_connection (CcComm *comm, gchar *remote_address, GError **error)
{
- g_autopr(GSocket) socket = NULL;
+ g_autoptr(GSocket) socket = NULL;
GSocketType socket_type;
GSocketFamily socket_family;
GSocketConnectable * connectable;
@@ -239,8 +239,6 @@ cc_comm_make_connection (CcComm *comm, gchar *remote_address, GError **error)
}
g_object_unref (enumerator);
- g_debug ("CCComm: Connected to %s", remote_address);
-
comm->con = G_IO_STREAM (g_socket_connection_factory_create_connection (socket));
tls_conn = g_tls_client_connection_new (comm->con, connectable, error);
@@ -264,8 +262,9 @@ cc_comm_make_connection (CcComm *comm, gchar *remote_address, GError **error)
g_debug ("CCComm: Connected to %s", remote_address);
+ // TODO
// start listening to all incoming messages
- cc_comm_listen_all (comm);
+ // cc_comm_listen (comm);
return TRUE;
}
@@ -284,23 +283,23 @@ cc_comm_tls_send (CcComm * comm,
{
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_CONNECTED,
"Connection has not been established");
- return FALSE:
+ return FALSE;
}
g_debug ("Writing data to Chromecast command channel:");
cc_comm_dump_message (message, size);
- ostream = g_io_stream_get_output_stream (G_IO_STREAM (comm->con))
+ ostream = g_io_stream_get_output_stream (G_IO_STREAM (comm->con));
// start sending data synchronously
while (size > 0)
{
- io_bytes = g_output_stream_write (ostream, message, size, NULL, &error);
+ io_bytes = g_output_stream_write (ostream, message, size, NULL, error);
if (io_bytes <= 0)
{
- g_warning ("CCComm: Failed to write: %s", error->message);
- g_error_free (error);
+ g_warning ("CCComm: Failed to write: %s", (*error)->message);
+ g_clear_error (error);
return FALSE;
}
@@ -350,7 +349,6 @@ cc_comm_build_message (gchar *namespace_,
gboolean
cc_comm_send_request (CcComm * comm, enum MessageType message_type, char *utf8_payload, GError **error)
{
- gboolean send_ok;
Castchannel__CastMessage message;
guint32 packed_size = 0;
gboolean expect_input = TRUE;
@@ -423,7 +421,19 @@ cc_comm_send_request (CcComm * comm, enum MessageType message_type, char *utf8_p
gboolean
cc_comm_send_ping (CcComm * comm)
{
- cc_comm_send_request(comm, MESSAGE_TYPE_PING, NULL);
+ g_autoptr(GError) error = NULL;
+
+ // if this errors out, we cancel the periodic ping by returning FALSE
+ if (!cc_comm_send_request(comm, MESSAGE_TYPE_PING, NULL, &error))
+ {
+ if (error != NULL)
+ {
+ g_warning ("CcComm: Failed to send ping message: %s", error->message);
+ return FALSE;
+ }
+ g_warning ("CcComm: Failed to send ping message");
+ return FALSE;
+ }
return TRUE;
}
diff --git a/src/cc/cc-comm.h b/src/cc/cc-comm.h
index 9ea8d93..6fe73fa 100644
--- a/src/cc/cc-comm.h
+++ b/src/cc/cc-comm.h
@@ -30,7 +30,17 @@ struct _CcComm
typedef struct _CcComm CcComm;
-gboolean cc_comm_make_connection (CcComm *comm, GError ** error);
+#define MAX_MSG_SIZE 64 * 1024
+
+enum MessageType {
+ MESSAGE_TYPE_CONNECT,
+ MESSAGE_TYPE_DISCONNECT,
+ MESSAGE_TYPE_PING,
+ MESSAGE_TYPE_PONG,
+ MESSAGE_TYPE_RECEIVER,
+};
+
+gboolean cc_comm_make_connection (CcComm *comm, gchar *remote_address, GError **error);
gboolean cc_comm_send_request (CcComm *sink, enum MessageType message_type, char *utf8_payload, GError
**error);
gboolean cc_comm_send_ping (CcComm *sink);
diff --git a/src/cc/meson.build b/src/cc/meson.build
index 1d0b6b3..25af912 100644
--- a/src/cc/meson.build
+++ b/src/cc/meson.build
@@ -16,8 +16,6 @@ cc_deps = [
dependency('gstreamer-video-1.0', version: '>= 1.14'),
dependency('gstreamer-rtsp-1.0', version: '>= 1.14'),
dependency('libprotobuf-c', version: '>= 1.0.0'),
- dependency('gio-2.0', version: '>= 2.50'),
- dependency('gtk+-3.0', version: '>= 3.22'),
]
cc_cast_channel = static_library(
diff --git a/src/nd-cc-sink.c b/src/nd-cc-sink.c
index 75432d7..9ae2638 100644
--- a/src/nd-cc-sink.c
+++ b/src/nd-cc-sink.c
@@ -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_make_connection(&self->comm, &error))
+ if (!cc_comm_make_connection(&self->comm, self->remote_address, &error))
{
self->state = ND_SINK_STATE_ERROR;
g_object_notify (G_OBJECT (self), "state");
diff --git a/src/nd-cc-sink.h b/src/nd-cc-sink.h
index 7802114..5f3a0fd 100644
--- a/src/nd-cc-sink.h
+++ b/src/nd-cc-sink.h
@@ -33,13 +33,4 @@ NdCCSink * nd_cc_sink_new (GSocketClient *client,
NdSinkState nd_cc_sink_get_state (NdCCSink *sink);
-#define MAX_MSG_SIZE 64 * 1024
-enum MessageType {
- MESSAGE_TYPE_CONNECT,
- MESSAGE_TYPE_DISCONNECT,
- MESSAGE_TYPE_PING,
- MESSAGE_TYPE_PONG,
- MESSAGE_TYPE_RECEIVER,
-};
-
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]