diff mbox series

[12/25] efw-downloader: subcmd-device: open firewire character device by HinawaFwNode

Message ID 20200821073111.134857-13-o-takashi@sakamocchi.jp (mailing list archive)
State New, archived
Headers show
Series alsa-tools: efw-downloader: add initial version of firmwre downloader for Echo Audio Fireworks devices | expand

Commit Message

Takashi Sakamoto Aug. 21, 2020, 7:30 a.m. UTC
In device sub command, all of operations require actual communication to
the target device. Linux firewire subsystem allows applications to do it
via call of ioctl to firewire character device.

This commit opens firewire character device, with assist of HinawaFwNode.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
---
 efw-downloader/src/subcmd-device.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
diff mbox series

Patch

diff --git a/efw-downloader/src/subcmd-device.c b/efw-downloader/src/subcmd-device.c
index 739944e..e1be025 100644
--- a/efw-downloader/src/subcmd-device.c
+++ b/efw-downloader/src/subcmd-device.c
@@ -7,6 +7,10 @@ 
 
 #include "efw-proto.h"
 
+#define report_error(error, msg)                                                    \
+        fprintf(stderr, "Fail to %s: %s %d %s\n",                                   \
+                msg, g_quark_to_string(error->domain), error->code, error->message)
+
 static int print_help()
 {
     printf("Usage\n"
@@ -50,6 +54,7 @@  int subcmd_device(int argc, char **argv)
     GError *error = NULL;
     const char *path;
     const char *op_name;
+    HinawaFwNode *node;
     EfwProto *proto;
     int err;
     int i;
@@ -66,8 +71,22 @@  int subcmd_device(int argc, char **argv)
     if (i == G_N_ELEMENTS(entries))
         return print_help();
 
+    node = hinawa_fw_node_new();
+    hinawa_fw_node_open(node, path, &error);
+    if (error != NULL) {
+        if (g_error_matches(error, G_FILE_ERROR, G_FILE_ERROR_NOENT))
+            fprintf(stderr, "File not found: %s\n", path);
+        else if (g_error_matches(error, G_FILE_ERROR, G_FILE_ERROR_ACCES))
+            fprintf(stderr, "Permission denied: %s\n", path);
+        else
+            report_error(error, "open the node");
+        goto err;
+    }
+
     entry->op(argc, argv, proto, &error);
 
+    g_object_unref(node);
+err:
     if (error != NULL) {
         g_clear_error(&error);
         return EXIT_FAILURE;