|
|
536eb0 |
From e30b0ce5c46c0e2a75b6e38759876ba1369b2168 Mon Sep 17 00:00:00 2001
|
|
|
536eb0 |
From: Frediano Ziglio <freddy77@gmail.com>
|
|
|
536eb0 |
Date: Fri, 16 Sep 2022 20:14:28 +0100
|
|
|
536eb0 |
Subject: [PATCH 3/8] Use typedef on redirect structure to simplify some
|
|
|
536eb0 |
statements
|
|
|
536eb0 |
|
|
|
536eb0 |
Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
|
|
|
536eb0 |
---
|
|
|
536eb0 |
tools/usbredirect.c | 26 +++++++++++++-------------
|
|
|
536eb0 |
1 file changed, 13 insertions(+), 13 deletions(-)
|
|
|
536eb0 |
|
|
|
536eb0 |
diff --git a/tools/usbredirect.c b/tools/usbredirect.c
|
|
|
536eb0 |
index 98e5a8c..89a42a6 100644
|
|
|
536eb0 |
--- a/tools/usbredirect.c
|
|
|
536eb0 |
+++ b/tools/usbredirect.c
|
|
|
536eb0 |
@@ -22,7 +22,7 @@
|
|
|
536eb0 |
#include <gio/gwin32outputstream.h>
|
|
|
536eb0 |
#endif
|
|
|
536eb0 |
|
|
|
536eb0 |
-struct redirect {
|
|
|
536eb0 |
+typedef struct redirect {
|
|
|
536eb0 |
struct {
|
|
|
536eb0 |
int vendor;
|
|
|
536eb0 |
int product;
|
|
|
536eb0 |
@@ -40,7 +40,7 @@ struct redirect {
|
|
|
536eb0 |
int watch_server_id;
|
|
|
536eb0 |
|
|
|
536eb0 |
GMainLoop *main_loop;
|
|
|
536eb0 |
-};
|
|
|
536eb0 |
+} redirect;
|
|
|
536eb0 |
|
|
|
536eb0 |
static bool
|
|
|
536eb0 |
parse_opt_device(const char *device, int *vendor, int *product)
|
|
|
536eb0 |
@@ -124,7 +124,7 @@ parse_opt_uri(const char *uri, char **adr, int *port)
|
|
|
536eb0 |
return true;
|
|
|
536eb0 |
}
|
|
|
536eb0 |
|
|
|
536eb0 |
-static struct redirect *
|
|
|
536eb0 |
+static redirect *
|
|
|
536eb0 |
parse_opts(int *argc, char ***argv)
|
|
|
536eb0 |
{
|
|
|
536eb0 |
char *device = NULL;
|
|
|
536eb0 |
@@ -132,7 +132,7 @@ parse_opts(int *argc, char ***argv)
|
|
|
536eb0 |
char *localaddr = NULL;
|
|
|
536eb0 |
gboolean keepalive = FALSE;
|
|
|
536eb0 |
gint verbosity = 0; /* none */
|
|
|
536eb0 |
- struct redirect *self = NULL;
|
|
|
536eb0 |
+ redirect *self = NULL;
|
|
|
536eb0 |
|
|
|
536eb0 |
GOptionEntry entries[] = {
|
|
|
536eb0 |
{ "device", 0, 0, G_OPTION_ARG_STRING, &device, "Local USB device to be redirected", NULL },
|
|
|
536eb0 |
@@ -161,7 +161,7 @@ parse_opts(int *argc, char ***argv)
|
|
|
536eb0 |
goto end;
|
|
|
536eb0 |
}
|
|
|
536eb0 |
|
|
|
536eb0 |
- self = g_new0(struct redirect, 1);
|
|
|
536eb0 |
+ self = g_new0(redirect, 1);
|
|
|
536eb0 |
if (!parse_opt_device(device, &self->device.vendor, &self->device.product)) {
|
|
|
536eb0 |
g_printerr("Failed to parse device: '%s' - expected: vendor:product or busnum-devnum\n", device);
|
|
|
536eb0 |
g_clear_pointer(&self, g_free);
|
|
|
536eb0 |
@@ -201,7 +201,7 @@ end:
|
|
|
536eb0 |
static gpointer
|
|
|
536eb0 |
thread_handle_libusb_events(gpointer user_data)
|
|
|
536eb0 |
{
|
|
|
536eb0 |
- struct redirect *self = (struct redirect *) user_data;
|
|
|
536eb0 |
+ redirect *self = (redirect *) user_data;
|
|
|
536eb0 |
|
|
|
536eb0 |
int res = 0;
|
|
|
536eb0 |
const char *desc = "";
|
|
|
536eb0 |
@@ -279,7 +279,7 @@ usbredir_log_cb(void *priv, int level, const char *msg)
|
|
|
536eb0 |
static int
|
|
|
536eb0 |
usbredir_read_cb(void *priv, uint8_t *data, int count)
|
|
|
536eb0 |
{
|
|
|
536eb0 |
- struct redirect *self = (struct redirect *) priv;
|
|
|
536eb0 |
+ redirect *self = (redirect *) priv;
|
|
|
536eb0 |
GIOStream *iostream = G_IO_STREAM(self->connection);
|
|
|
536eb0 |
GError *err = NULL;
|
|
|
536eb0 |
|
|
|
536eb0 |
@@ -307,7 +307,7 @@ usbredir_read_cb(void *priv, uint8_t *data, int count)
|
|
|
536eb0 |
static int
|
|
|
536eb0 |
usbredir_write_cb(void *priv, uint8_t *data, int count)
|
|
|
536eb0 |
{
|
|
|
536eb0 |
- struct redirect *self = (struct redirect *) priv;
|
|
|
536eb0 |
+ redirect *self = (redirect *) priv;
|
|
|
536eb0 |
GIOStream *iostream = G_IO_STREAM(self->connection);
|
|
|
536eb0 |
GError *err = NULL;
|
|
|
536eb0 |
|
|
|
536eb0 |
@@ -335,7 +335,7 @@ usbredir_write_cb(void *priv, uint8_t *data, int count)
|
|
|
536eb0 |
static void
|
|
|
536eb0 |
usbredir_write_flush_cb(void *user_data)
|
|
|
536eb0 |
{
|
|
|
536eb0 |
- struct redirect *self = (struct redirect *) user_data;
|
|
|
536eb0 |
+ redirect *self = (redirect *) user_data;
|
|
|
536eb0 |
if (!self || !self->usbredirhost) {
|
|
|
536eb0 |
return;
|
|
|
536eb0 |
}
|
|
|
536eb0 |
@@ -386,7 +386,7 @@ usbredir_unlock_lock(void *user_data)
|
|
|
536eb0 |
static gboolean
|
|
|
536eb0 |
connection_handle_io_cb(GIOChannel *source, GIOCondition condition, gpointer user_data)
|
|
|
536eb0 |
{
|
|
|
536eb0 |
- struct redirect *self = (struct redirect *) user_data;
|
|
|
536eb0 |
+ redirect *self = (redirect *) user_data;
|
|
|
536eb0 |
|
|
|
536eb0 |
if (condition & G_IO_ERR || condition & G_IO_HUP) {
|
|
|
536eb0 |
g_warning("Connection: err=%d, hup=%d - exiting", (condition & G_IO_ERR), (condition & G_IO_HUP));
|
|
|
536eb0 |
@@ -418,7 +418,7 @@ end:
|
|
|
536eb0 |
static gboolean
|
|
|
536eb0 |
signal_handler(gpointer user_data)
|
|
|
536eb0 |
{
|
|
|
536eb0 |
- struct redirect *self = (struct redirect *) user_data;
|
|
|
536eb0 |
+ redirect *self = (redirect *) user_data;
|
|
|
536eb0 |
g_main_loop_quit(self->main_loop);
|
|
|
536eb0 |
return G_SOURCE_REMOVE;
|
|
|
536eb0 |
}
|
|
|
536eb0 |
@@ -430,7 +430,7 @@ connection_incoming_cb(GSocketService *service,
|
|
|
536eb0 |
GObject *source_object,
|
|
|
536eb0 |
gpointer user_data)
|
|
|
536eb0 |
{
|
|
|
536eb0 |
- struct redirect *self = (struct redirect *) user_data;
|
|
|
536eb0 |
+ redirect *self = (redirect *) user_data;
|
|
|
536eb0 |
self->connection = g_object_ref(client_connection);
|
|
|
536eb0 |
|
|
|
536eb0 |
/* Add a GSource watch to handle polling for us and handle IO in the callback */
|
|
|
536eb0 |
@@ -455,7 +455,7 @@ main(int argc, char *argv[])
|
|
|
536eb0 |
goto err_init;
|
|
|
536eb0 |
}
|
|
|
536eb0 |
|
|
|
536eb0 |
- struct redirect *self = parse_opts(&argc, &argv);
|
|
|
536eb0 |
+ redirect *self = parse_opts(&argc, &argv);
|
|
|
536eb0 |
if (!self) {
|
|
|
536eb0 |
/* specific issues logged in parse_opts() */
|
|
|
536eb0 |
return 1;
|
|
|
536eb0 |
--
|
|
|
536eb0 |
2.39.0
|
|
|
536eb0 |
|