[gnome-network-displays/cc-tmp: 70/80] cc: move declarations to top
- From: Benjamin Berg <bberg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-network-displays/cc-tmp: 70/80] cc: move declarations to top
- Date: Fri, 9 Sep 2022 12:03:52 +0000 (UTC)
commit 602ac5946dc2f3f0180f04e13ded37aebb88f613
Author: Anupam Kumar <kyteinsky gmail com>
Date: Tue Sep 6 14:04:11 2022 +0530
cc: move declarations to top
src/cc/cc-comm.c | 12 ++++++++----
src/cc/cc-comm.h | 2 +-
src/cc/cc-ctrl.c | 7 +++++--
src/cc/cc-json-helper.c | 36 ++++++++++++++++++++++++------------
4 files changed, 38 insertions(+), 19 deletions(-)
---
diff --git a/src/cc/cc-comm.c b/src/cc/cc-comm.c
index 2a9c6e1..332ff48 100644
--- a/src/cc/cc-comm.c
+++ b/src/cc/cc-comm.c
@@ -101,6 +101,7 @@ cc_comm_message_read_cb (GObject *source_object,
gpointer user_data)
{
g_autoptr(GError) error = NULL;
+ CcComm *comm;
gboolean success;
gsize io_bytes;
@@ -109,7 +110,7 @@ cc_comm_message_read_cb (GObject *source_object,
if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
return;
- CcComm * comm = (CcComm *) user_data;
+ comm = (CcComm *) user_data;
if (!comm->con)
{
@@ -152,6 +153,8 @@ cc_comm_header_read_cb (GObject *source_object,
gpointer user_data)
{
g_autoptr(GError) error = NULL;
+ CcComm *comm;
+ GInputStream *istream;
gboolean success;
gsize io_bytes;
guint32 message_size;
@@ -161,7 +164,7 @@ cc_comm_header_read_cb (GObject *source_object,
if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
return;
- CcComm *comm = (CcComm *) user_data;
+ comm = (CcComm *) user_data;
if (!comm->con)
{
@@ -170,7 +173,7 @@ cc_comm_header_read_cb (GObject *source_object,
return;
}
- GInputStream *istream = g_io_stream_get_input_stream (G_IO_STREAM (comm->con));
+ istream = g_io_stream_get_input_stream (G_IO_STREAM (comm->con));
if (G_INPUT_STREAM (source_object) != istream)
{
@@ -430,6 +433,7 @@ cc_comm_send_request (CcComm *comm,
{
Cast__Channel__CastMessage message;
guint32 packed_size = 0;
+ guint32 packed_size_be;
g_autofree uint8_t *sock_buffer = NULL;
switch (message_type)
@@ -470,7 +474,7 @@ cc_comm_send_request (CcComm *comm,
packed_size = cast__channel__cast_message__get_packed_size (&message);
sock_buffer = malloc (4 + packed_size);
- guint32 packed_size_be = GUINT32_TO_BE (packed_size);
+ packed_size_be = GUINT32_TO_BE (packed_size);
memcpy (sock_buffer, &packed_size_be, 4);
cast__channel__cast_message__pack (&message, 4 + sock_buffer);
diff --git a/src/cc/cc-comm.h b/src/cc/cc-comm.h
index 99dca2e..a7be17f 100644
--- a/src/cc/cc-comm.h
+++ b/src/cc/cc-comm.h
@@ -45,7 +45,7 @@ struct _CcComm
CcCommClosure *closure;
/*< private >*/
- guint8 header_buffer [4];
+ guint8 header_buffer[4];
guint8 *message_buffer;
};
diff --git a/src/cc/cc-ctrl.c b/src/cc/cc-ctrl.c
index 80b7cdf..3270d48 100644
--- a/src/cc/cc-ctrl.c
+++ b/src/cc/cc-ctrl.c
@@ -529,6 +529,7 @@ cc_ctrl_handle_received_msg (gpointer userdata,
g_autoptr(GError) error = NULL;
g_autoptr(JsonParser) parser = NULL;
g_autoptr(JsonReader) reader = NULL;
+ CcReceivedMessageType type;
parser = json_parser_new ();
if (!json_parser_load_from_data (parser, message->payload_utf8, -1, &error))
@@ -540,7 +541,7 @@ cc_ctrl_handle_received_msg (gpointer userdata,
reader = json_reader_new (json_parser_get_root (parser));
- CcReceivedMessageType type = cc_json_helper_get_message_type (message, reader);
+ type = cc_json_helper_get_message_type (message, reader);
if (!(type == CC_RWAIT_TYPE_PING || type == CC_RWAIT_TYPE_PONG || type == -1))
{
@@ -608,13 +609,15 @@ cc_ctrl_fatal_error (CcCtrl *ctrl)
void
cc_ctrl_fatal_error_closure (gpointer userdata, GError *error)
{
+ CcCtrl *ctrl;
+
/* XXX: add error arg in end_stream and display an error message to user */
if (error)
g_warning ("CcCtrl: Fatal error: %s", error->message);
else
g_error ("CcCtrl: Fatal error");
- CcCtrl *ctrl = (CcCtrl *) userdata;
+ ctrl = (CcCtrl *) userdata;
cc_ctrl_fatal_error (ctrl);
}
diff --git a/src/cc/cc-json-helper.c b/src/cc/cc-json-helper.c
index f65f9c2..8025ca6 100644
--- a/src/cc/cc-json-helper.c
+++ b/src/cc/cc-json-helper.c
@@ -25,8 +25,11 @@ cc_json_helper_build_internal (JsonBuilder *builder,
{
for (gchar *key = first_key; key != NULL; key = va_arg (var_args, gchar *))
{
+ CcJsonType type;
+ g_autoptr(GArray) arr = NULL;
+
json_builder_set_member_name (builder, key);
- CcJsonType type = va_arg (var_args, CcJsonType);
+ type = va_arg (var_args, CcJsonType);
g_assert (type >= CC_JSON_TYPE_STRING && type <= CC_JSON_TYPE_ARRAY_OBJECT);
@@ -61,10 +64,9 @@ cc_json_helper_build_internal (JsonBuilder *builder,
}
json_builder_begin_array (builder);
- g_autoptr (GArray) arr = va_arg (var_args, GArray *);
- guint i;
+ arr = va_arg (var_args, GArray *);
- for (i = 0; i < arr->len; i++)
+ for (guint i = 0; i < arr->len; i++)
{
switch (type)
{
@@ -105,17 +107,20 @@ JsonNode *
cc_json_helper_build_node (gchar *first_key,
...)
{
+ JsonBuilder *builder;
+ JsonNode *node;
+
va_list var_args;
va_start (var_args, first_key);
- JsonBuilder *builder = json_builder_new ();
+ builder = json_builder_new ();
json_builder_begin_object (builder);
cc_json_helper_build_internal (builder, first_key, var_args);
json_builder_end_object (builder);
- JsonNode *node = json_builder_get_root (builder);
+ node = json_builder_get_root (builder);
va_end (var_args);
g_object_unref (builder);
@@ -128,22 +133,27 @@ cc_json_helper_build_string (/* gboolean pretty_print, */
gchar *first_key,
...)
{
+ JsonBuilder *builder;
+ JsonNode *root;
+ JsonGenerator *gen;
+ gchar *output;
+
va_list var_args;
va_start (var_args, first_key);
- JsonBuilder *builder = json_builder_new ();
+ builder = json_builder_new ();
json_builder_begin_object (builder);
cc_json_helper_build_internal (builder, first_key, var_args);
json_builder_end_object (builder);
- JsonNode *root = json_builder_get_root (builder);
- JsonGenerator *gen = json_generator_new ();
+ root = json_builder_get_root (builder);
+ gen = json_generator_new ();
/* json_generator_set_pretty (gen, pretty_print); */
json_generator_set_root (gen, root);
- gchar *output = json_generator_to_data (gen, NULL);
+ output = json_generator_to_data (gen, NULL);
va_end (var_args);
json_node_free (root);
@@ -156,10 +166,11 @@ cc_json_helper_build_string (/* gboolean pretty_print, */
gchar *
cc_json_helper_node_to_string (JsonNode *node)
{
+ gchar *output;
JsonGenerator *gen = json_generator_new ();
json_generator_set_root (gen, node);
- gchar *output = json_generator_to_data (gen, NULL);
+ output = json_generator_to_data (gen, NULL);
g_object_unref (gen);
@@ -218,6 +229,7 @@ void
cc_json_helper_dump_message (Cast__Channel__CastMessage *message, gboolean borked)
{
JsonNode *payload_utf8_node;
+ gchar *output;
JsonParser *parser = json_parser_new ();
g_autoptr(GError) error = NULL;
@@ -239,7 +251,7 @@ cc_json_helper_dump_message (Cast__Channel__CastMessage *message, gboolean borke
payload_utf8_node = json_parser_get_root (parser);
- gchar *output = cc_json_helper_build_string (
+ output = cc_json_helper_build_string (
"source_id", CC_JSON_TYPE_STRING, message->source_id,
"destination_id", CC_JSON_TYPE_STRING, message->destination_id,
"namespace", CC_JSON_TYPE_STRING, message->namespace_,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]