diff options
author | Takashi Sakamoto <o-takashi@sakamocchi.jp> | 2022-05-25 16:29:36 +0900 |
---|---|---|
committer | Takashi Sakamoto <o-takashi@sakamocchi.jp> | 2022-05-25 16:29:36 +0900 |
commit | 67fcbb1a94d387866d48aa66333332c8f0ac836c (patch) | |
tree | b09b76302b851b84ad734ee83eea87f6c309791c | |
parent | 98c12c328d1e69826f927328f810d0c4a4963143 (diff) | |
download | libhinoko-67fcbb1a94d387866d48aa66333332c8f0ac836c.tar.gz |
fw_iso_ctx: add local function to get label of error
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
-rw-r--r-- | src/fw_iso_ctx.c | 40 | ||||
-rw-r--r-- | src/fw_iso_ctx_private.c | 13 | ||||
-rw-r--r-- | src/fw_iso_ctx_private.h | 12 |
3 files changed, 49 insertions, 16 deletions
diff --git a/src/fw_iso_ctx.c b/src/fw_iso_ctx.c index 5a74819..4e898b9 100644 --- a/src/fw_iso_ctx.c +++ b/src/fw_iso_ctx.c @@ -23,6 +23,46 @@ G_DEFINE_INTERFACE(HinokoFwIsoCtx, hinoko_fw_iso_ctx, G_TYPE_OBJECT) */ G_DEFINE_QUARK(hinoko-fw-iso-ctx-error-quark, hinoko_fw_iso_ctx_error) +/** + * hinoko_fw_iso_ctx_error_to_label: + * @code: One of Hinoko.FwIsoCtxError. + * @label: (out) (transfer none): The label of error code. + * + * Retrieve the label of error code. + */ +void hinoko_fw_iso_ctx_error_to_label(HinokoFwIsoCtxError code, const char **label) +{ + const char *const labels[7] = { + [HINOKO_FW_ISO_CTX_ERROR_FAILED] = "The system call fails", + [HINOKO_FW_ISO_CTX_ERROR_ALLOCATED] = + "The instance is already associated to any firewire character device", + [HINOKO_FW_ISO_CTX_ERROR_NOT_ALLOCATED] = + "The instance is not associated to any firewire character device", + [HINOKO_FW_ISO_CTX_ERROR_MAPPED] = + "The intermediate buffer is already mapped to the process", + [HINOKO_FW_ISO_CTX_ERROR_NOT_MAPPED] = + "The intermediate buffer is not mapped to the process", + [HINOKO_FW_ISO_CTX_ERROR_CHUNK_UNREGISTERED] = "No chunk registered before starting", + [HINOKO_FW_ISO_CTX_ERROR_NO_ISOC_CHANNEL] = "No isochronous channel available", + }; + + switch (code) { + case HINOKO_FW_ISO_CTX_ERROR_FAILED: + case HINOKO_FW_ISO_CTX_ERROR_ALLOCATED: + case HINOKO_FW_ISO_CTX_ERROR_NOT_ALLOCATED: + case HINOKO_FW_ISO_CTX_ERROR_MAPPED: + case HINOKO_FW_ISO_CTX_ERROR_NOT_MAPPED: + case HINOKO_FW_ISO_CTX_ERROR_CHUNK_UNREGISTERED: + case HINOKO_FW_ISO_CTX_ERROR_NO_ISOC_CHANNEL: + break; + default: + code = HINOKO_FW_ISO_CTX_ERROR_FAILED; + break; + } + + *label = labels[code]; +} + static void hinoko_fw_iso_ctx_default_init(HinokoFwIsoCtxInterface *iface) { /** diff --git a/src/fw_iso_ctx_private.c b/src/fw_iso_ctx_private.c index 0a8bfc1..1aadac3 100644 --- a/src/fw_iso_ctx_private.c +++ b/src/fw_iso_ctx_private.c @@ -6,19 +6,6 @@ #include <fcntl.h> #include <sys/mman.h> -const char *const fw_iso_ctx_err_msgs[7] = { - [HINOKO_FW_ISO_CTX_ERROR_ALLOCATED] = - "The instance is already associated to any firewire character device", - [HINOKO_FW_ISO_CTX_ERROR_NOT_ALLOCATED] = - "The instance is not associated to any firewire character device", - [HINOKO_FW_ISO_CTX_ERROR_MAPPED] = - "The intermediate buffer is already mapped to the process", - [HINOKO_FW_ISO_CTX_ERROR_NOT_MAPPED] = - "The intermediate buffer is not mapped to the process", - [HINOKO_FW_ISO_CTX_ERROR_CHUNK_UNREGISTERED] = "No chunk registered before starting", - [HINOKO_FW_ISO_CTX_ERROR_NO_ISOC_CHANNEL] = "No isochronous channel available", -}; - typedef struct { GSource src; gpointer tag; diff --git a/src/fw_iso_ctx_private.h b/src/fw_iso_ctx_private.h index f1de060..cda1980 100644 --- a/src/fw_iso_ctx_private.h +++ b/src/fw_iso_ctx_private.h @@ -8,10 +8,16 @@ #include <errno.h> #include <sys/ioctl.h> -extern const char *const fw_iso_ctx_err_msgs[7]; +// NOTE: make it public in future releases. +void hinoko_fw_iso_ctx_error_to_label(HinokoFwIsoCtxError code, const char **label); -#define generate_local_error(error, code) \ - g_set_error_literal(error, HINOKO_FW_ISO_CTX_ERROR, code, fw_iso_ctx_err_msgs[code]) +static inline void generate_local_error(GError **error, HinokoFwIsoCtxError code) +{ + const char *label; + + hinoko_fw_iso_ctx_error_to_label(code, &label); + g_set_error_literal(error, HINOKO_FW_ISO_CTX_ERROR, code, label); +} #define generate_syscall_error(error, errno, format, arg) \ g_set_error(error, HINOKO_FW_ISO_CTX_ERROR, \ |