aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>2022-05-25 16:29:36 +0900
committerTakashi Sakamoto <o-takashi@sakamocchi.jp>2022-05-25 16:29:36 +0900
commit400018eac70111cfa817d985394d0581cd309a5f (patch)
tree6f393a95cb09f55f60abfe0bc83f6560f42de3d8
parent67fcbb1a94d387866d48aa66333332c8f0ac836c (diff)
downloadlibhinoko-400018eac70111cfa817d985394d0581cd309a5f.tar.gz
fw_iso_resource: add local function to get label of error
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
-rw-r--r--src/fw_iso_resource.c36
-rw-r--r--src/fw_iso_resource_private.c9
-rw-r--r--src/fw_iso_resource_private.h13
3 files changed, 45 insertions, 13 deletions
diff --git a/src/fw_iso_resource.c b/src/fw_iso_resource.c
index 69d0549..f971b32 100644
--- a/src/fw_iso_resource.c
+++ b/src/fw_iso_resource.c
@@ -23,6 +23,42 @@ G_DEFINE_INTERFACE(HinokoFwIsoResource, hinoko_fw_iso_resource, G_TYPE_OBJECT)
*/
G_DEFINE_QUARK(hinoko-fw-iso-resource-error-quark, hinoko_fw_iso_resource_error)
+/**
+ * hinoko_fw_iso_resource_error_to_label:
+ * @code: One of Hinoko.FwIsoResourceError.
+ * @label: (out) (transfer none): The label of error code.
+ *
+ * Retrieve the label of error code.
+ */
+void hinoko_fw_iso_resource_error_to_label(HinokoFwIsoResourceError code, const char **label)
+{
+ const char *const labels[] = {
+ [HINOKO_FW_ISO_RESOURCE_ERROR_FAILED] = "The system call fails",
+ [HINOKO_FW_ISO_RESOURCE_ERROR_OPENED] =
+ "The instance is already associated to any firewire character device",
+ [HINOKO_FW_ISO_RESOURCE_ERROR_NOT_OPENED] =
+ "The instance is not associated to any firewire character device",
+ [HINOKO_FW_ISO_RESOURCE_ERROR_TIMEOUT] =
+ "No event to the request arrives within timeout.",
+ [HINOKO_FW_ISO_RESOURCE_ERROR_EVENT] =
+ "Event for the request arrives but includes error code",
+ };
+
+ switch (code) {
+ case HINOKO_FW_ISO_RESOURCE_ERROR_FAILED:
+ case HINOKO_FW_ISO_RESOURCE_ERROR_OPENED:
+ case HINOKO_FW_ISO_RESOURCE_ERROR_NOT_OPENED:
+ case HINOKO_FW_ISO_RESOURCE_ERROR_TIMEOUT:
+ case HINOKO_FW_ISO_RESOURCE_ERROR_EVENT:
+ break;
+ default:
+ code = HINOKO_FW_ISO_RESOURCE_ERROR_FAILED;
+ break;
+ }
+
+ *label = labels[code];
+}
+
static void hinoko_fw_iso_resource_default_init(HinokoFwIsoResourceInterface *iface)
{
/**
diff --git a/src/fw_iso_resource_private.c b/src/fw_iso_resource_private.c
index e947cb8..5c0702b 100644
--- a/src/fw_iso_resource_private.c
+++ b/src/fw_iso_resource_private.c
@@ -5,15 +5,6 @@
#include <sys/stat.h>
#include <fcntl.h>
-const char *const fw_iso_resource_err_msgs[HINOKO_FW_ISO_RESOURCE_ERROR_EVENT + 1] = {
- [HINOKO_FW_ISO_RESOURCE_ERROR_OPENED] =
- "The instance is already associated to any firewire character device",
- [HINOKO_FW_ISO_RESOURCE_ERROR_NOT_OPENED] =
- "The instance is not associated to any firewire character device",
- [HINOKO_FW_ISO_RESOURCE_ERROR_TIMEOUT] =
- "No event to the request arrives within timeout.",
-};
-
#define generate_file_error(error, code, format, arg) \
g_set_error(error, G_FILE_ERROR, code, format, arg)
diff --git a/src/fw_iso_resource_private.h b/src/fw_iso_resource_private.h
index f7ca0db..a64ff6a 100644
--- a/src/fw_iso_resource_private.h
+++ b/src/fw_iso_resource_private.h
@@ -13,11 +13,16 @@
#define ALLOCATED_SIGNAL_NAME "allocated"
#define DEALLOCATED_SIGNAL_NAME "deallocated"
-extern const char *const fw_iso_resource_err_msgs[HINOKO_FW_ISO_RESOURCE_ERROR_EVENT + 1];
+// NOTE: make it public in later releases.
+void hinoko_fw_iso_resource_error_to_label(HinokoFwIsoResourceError code, const char **label);
-#define generate_coded_error(error, code) \
- g_set_error_literal(error, HINOKO_FW_ISO_RESOURCE_ERROR, code, \
- fw_iso_resource_err_msgs[code])
+static inline void generate_coded_error(GError **error, HinokoFwIsoResourceError code)
+{
+ const char *label;
+
+ hinoko_fw_iso_resource_error_to_label(code, &label);
+ g_set_error_literal(error, HINOKO_FW_ISO_RESOURCE_ERROR, code, label);
+}
#define generate_syscall_error(error, errno, format, arg) \
g_set_error(error, HINOKO_FW_ISO_RESOURCE_ERROR, \