diff options
author | Takashi Sakamoto <o-takashi@sakamocchi.jp> | 2022-05-05 11:37:24 +0900 |
---|---|---|
committer | 坂本 貴史 <o-takashi@sakamocchi.jp> | 2022-05-05 16:09:50 +0900 |
commit | 66c10a4bcc74d06973685cb9a28a2612ee1f71e8 (patch) | |
tree | 66bb09947f43c3df37480b3a60e6f20e328aa9b0 | |
parent | 2df2c1875b9cc59eab87f443278163c5ca79292c (diff) | |
download | libhinoko-66c10a4bcc74d06973685cb9a28a2612ee1f71e8.tar.gz |
fw_iso_ctx: code refactoring to split start function
It's planned to make Hinoko.FwIsoCtx as interface. It's convenient
for derived object to use private helper function instead of instance
method.
This commit splits current implementaion of Hinoko.FwIsoCtx.start()
into internal API part and private implementation.
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
-rw-r--r-- | src/fw_iso_ctx.c | 52 | ||||
-rw-r--r-- | src/fw_iso_ctx_private.c | 74 | ||||
-rw-r--r-- | src/fw_iso_ctx_private.h | 3 |
3 files changed, 78 insertions, 51 deletions
diff --git a/src/fw_iso_ctx.c b/src/fw_iso_ctx.c index 5cd9ae7..5283499 100644 --- a/src/fw_iso_ctx.c +++ b/src/fw_iso_ctx.c @@ -498,63 +498,13 @@ void hinoko_fw_iso_ctx_create_source(HinokoFwIsoCtx *self, GSource **source, GEr void hinoko_fw_iso_ctx_start(HinokoFwIsoCtx *self, const guint16 *cycle_match, guint32 sync, HinokoFwIsoCtxMatchFlag tags, GError **error) { - struct fw_cdev_start_iso arg = {0}; HinokoFwIsoCtxPrivate *priv; - gint cycle; g_return_if_fail(HINOKO_IS_FW_ISO_CTX(self)); g_return_if_fail(error == NULL || *error == NULL); priv = hinoko_fw_iso_ctx_get_instance_private(self); - if (priv->fd < 0) { - generate_local_error(error, HINOKO_FW_ISO_CTX_ERROR_NOT_ALLOCATED); - return; - } - - if (priv->addr == NULL) { - generate_local_error(error, HINOKO_FW_ISO_CTX_ERROR_NOT_MAPPED); - return; - } - - if (cycle_match == NULL) { - cycle = -1; - } else { - g_return_if_fail(cycle_match[0] < 4); - g_return_if_fail(cycle_match[1] < 8000); - - cycle = (cycle_match[0] << 13) | cycle_match[1]; - } - - if (priv->mode == HINOKO_FW_ISO_CTX_MODE_TX) { - g_return_if_fail(sync == 0); - g_return_if_fail(tags == 0); - } else { - g_return_if_fail(sync < 16); - g_return_if_fail(tags <= (HINOKO_FW_ISO_CTX_MATCH_FLAG_TAG0 | - HINOKO_FW_ISO_CTX_MATCH_FLAG_TAG1 | - HINOKO_FW_ISO_CTX_MATCH_FLAG_TAG2 | - HINOKO_FW_ISO_CTX_MATCH_FLAG_TAG3)); - } - - // Not prepared. - if (priv->data_length == 0) { - generate_local_error(error, HINOKO_FW_ISO_CTX_ERROR_CHUNK_UNREGISTERED); - return; - } - - if (!fw_iso_ctx_state_queue_chunks(priv, error)) - return; - - arg.sync = sync; - arg.cycle = cycle; - arg.tags = tags; - arg.handle = priv->handle; - if (ioctl(priv->fd, FW_CDEV_IOC_START_ISO, &arg) < 0) { - generate_syscall_error(error, errno, "ioctl(%s)", "FW_CDEV_IOC_START_ISO"); - return; - } - - priv->running = TRUE; + (void)fw_iso_ctx_state_start(priv, cycle_match, sync, tags, error); } /** diff --git a/src/fw_iso_ctx_private.c b/src/fw_iso_ctx_private.c index 5597e0f..d157184 100644 --- a/src/fw_iso_ctx_private.c +++ b/src/fw_iso_ctx_private.c @@ -374,3 +374,77 @@ gboolean fw_iso_ctx_state_queue_chunks(struct fw_iso_ctx_state *state, GError ** return TRUE; } + +/** + * fw_iso_ctx_state_start: + * @state: A [struct@FwIsoCtxState]. + * @cycle_match: (array fixed-size=2) (element-type guint16) (in) (nullable): The isochronous cycle + * to start packet processing. The first element should be the second part of + * isochronous cycle, up to 3. The second element should be the cycle part of + * isochronous cycle, up to 7999. + * @sync: The value of sync field in isochronous header for packet processing, up to 15. + * @tags: The value of tag field in isochronous header for packet processing. + * @error: A [struct@GLib.Error]. + * + * Start isochronous context. + */ +gboolean fw_iso_ctx_state_start(struct fw_iso_ctx_state *state, const guint16 *cycle_match, + guint32 sync, HinokoFwIsoCtxMatchFlag tags, GError **error) +{ + struct fw_cdev_start_iso arg = {0}; + gint cycle; + + g_return_val_if_fail(error == NULL || *error == NULL, FALSE); + + if (state->fd < 0) { + generate_local_error(error, HINOKO_FW_ISO_CTX_ERROR_NOT_ALLOCATED); + return FALSE; + } + + if (state->addr == NULL) { + generate_local_error(error, HINOKO_FW_ISO_CTX_ERROR_NOT_MAPPED); + return FALSE; + } + + if (cycle_match == NULL) { + cycle = -1; + } else { + g_return_val_if_fail(cycle_match[0] < 4, FALSE); + g_return_val_if_fail(cycle_match[1] < 8000, FALSE); + + cycle = (cycle_match[0] << 13) | cycle_match[1]; + } + + if (state->mode == HINOKO_FW_ISO_CTX_MODE_TX) { + g_return_val_if_fail(sync == 0, FALSE); + g_return_val_if_fail(tags == 0, FALSE); + } else { + g_return_val_if_fail(sync < 16, FALSE); + g_return_val_if_fail(tags <= (HINOKO_FW_ISO_CTX_MATCH_FLAG_TAG0 | + HINOKO_FW_ISO_CTX_MATCH_FLAG_TAG1 | + HINOKO_FW_ISO_CTX_MATCH_FLAG_TAG2 | + HINOKO_FW_ISO_CTX_MATCH_FLAG_TAG3), FALSE); + } + + // Not prepared. + if (state->data_length == 0) { + generate_local_error(error, HINOKO_FW_ISO_CTX_ERROR_CHUNK_UNREGISTERED); + return FALSE; + } + + if (!fw_iso_ctx_state_queue_chunks(state, error)) + return FALSE; + + arg.sync = sync; + arg.cycle = cycle; + arg.tags = tags; + arg.handle = state->handle; + if (ioctl(state->fd, FW_CDEV_IOC_START_ISO, &arg) < 0) { + generate_syscall_error(error, errno, "ioctl(%s)", "FW_CDEV_IOC_START_ISO"); + return FALSE; + } + + state->running = TRUE; + + return TRUE; +} diff --git a/src/fw_iso_ctx_private.h b/src/fw_iso_ctx_private.h index afb387a..8790297 100644 --- a/src/fw_iso_ctx_private.h +++ b/src/fw_iso_ctx_private.h @@ -59,6 +59,9 @@ gboolean fw_iso_ctx_state_register_chunk(struct fw_iso_ctx_state *state, gboolea GError **error); gboolean fw_iso_ctx_state_queue_chunks(struct fw_iso_ctx_state *state, GError **error); +gboolean fw_iso_ctx_state_start(struct fw_iso_ctx_state *state, const guint16 *cycle_match, + guint32 sync, HinokoFwIsoCtxMatchFlag tags, GError **error); + void hinoko_fw_iso_ctx_allocate(HinokoFwIsoCtx *self, const char *path, HinokoFwIsoCtxMode mode, HinokoFwScode scode, guint channel, guint header_size, |