aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>2022-05-05 11:37:24 +0900
committer坂本 貴史 <o-takashi@sakamocchi.jp>2022-05-05 16:09:50 +0900
commit7180a9a1accdfcbf1dacdf9a747493640a51ea6b (patch)
treea4d16aa240ed365d4d12295bba02f1b5298cda2b
parented4a4a0eb951ce6c94102978cede4730cc7eab24 (diff)
downloadlibhinoko-7180a9a1accdfcbf1dacdf9a747493640a51ea6b.tar.gz
fw_iso_ctx: code refactoring to split GSource create function
It's planned to make Hinoko.FwIsoCtx as interface. It's convenient for derived object to use private helper function apart from public API to call virtual function. This commit splits current implementaion of Hinoko.FwIsoResource.create_source() into public API part and private implementation. For reasons, the private implementation is still in the same file. Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
-rw-r--r--src/fw_iso_ctx.c67
-rw-r--r--src/fw_iso_ctx_private.h6
2 files changed, 53 insertions, 20 deletions
diff --git a/src/fw_iso_ctx.c b/src/fw_iso_ctx.c
index b390b41..aede531 100644
--- a/src/fw_iso_ctx.c
+++ b/src/fw_iso_ctx.c
@@ -396,43 +396,43 @@ static void finalize_src(GSource *source)
}
/**
- * hinoko_fw_iso_ctx_create_source:
- * @self: A [class@FwIsoCtx].
+ * fw_iso_ctx_state_create_source:
+ * @state: A [struct@FwIsoCtxState].
* @source: (out): A [struct@GLib.Source].
* @error: A [struct@GLib.Error].
*
* Create [struct@GLib.Source] for [struct@GLib.MainContext] to dispatch events for isochronous
* context.
*/
-void hinoko_fw_iso_ctx_create_source(HinokoFwIsoCtx *self, GSource **source, GError **error)
+gboolean fw_iso_ctx_state_create_source(struct fw_iso_ctx_state *state, HinokoFwIsoCtx *inst,
+ gboolean (*handle_event)(HinokoFwIsoCtx *inst,
+ const union fw_cdev_event *event,
+ GError **error),
+ GSource **source, GError **error)
{
static GSourceFuncs funcs = {
.check = check_src,
.dispatch = dispatch_src,
.finalize = finalize_src,
};
- HinokoFwIsoCtxPrivate *priv;
FwIsoCtxSource *src;
- g_return_if_fail(HINOKO_IS_FW_ISO_CTX(self));
- g_return_if_fail(source != NULL);
- g_return_if_fail(error == NULL || *error == NULL);
+ g_return_val_if_fail(HINOKO_IS_FW_ISO_CTX(inst), FALSE);
+ g_return_val_if_fail(source != NULL, FALSE);
+ g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
- priv = hinoko_fw_iso_ctx_get_instance_private(self);
- if (priv->fd < 0) {
+ if (state->fd < 0) {
generate_local_error(error, HINOKO_FW_ISO_CTX_ERROR_NOT_ALLOCATED);
- return;
+ return FALSE;
}
*source = g_source_new(&funcs, sizeof(FwIsoCtxSource));
g_source_set_name(*source, "HinokoFwIsoCtx");
- g_source_set_priority(*source, G_PRIORITY_HIGH_IDLE);
- g_source_set_can_recurse(*source, TRUE);
src = (FwIsoCtxSource *)(*source);
- if (priv->mode != HINOKO_FW_ISO_CTX_MODE_RX_MULTIPLE) {
+ if (state->mode != HINOKO_FW_ISO_CTX_MODE_RX_MULTIPLE) {
// MEMO: Linux FireWire subsystem queues isochronous event
// independently of interrupt flag when the same number of
// bytes as one page is stored in the buffer of header. To
@@ -444,18 +444,45 @@ void hinoko_fw_iso_ctx_create_source(HinokoFwIsoCtx *self, GSource **source, GEr
}
src->buf = g_malloc0(src->len);
- src->tag = g_source_add_unix_fd(*source, priv->fd, G_IO_IN);
- src->fd = priv->fd;
- src->self = g_object_ref(self);
+ src->tag = g_source_add_unix_fd(*source, state->fd, G_IO_IN);
+ src->fd = state->fd;
+ src->self = g_object_ref(inst);
+ src->handle_event = handle_event;
+
+ return TRUE;
+}
+/**
+ * hinoko_fw_iso_ctx_create_source:
+ * @self: A [class@FwIsoCtx].
+ * @source: (out): A [struct@GLib.Source].
+ * @error: A [struct@GLib.Error].
+ *
+ * Create [struct@GLib.Source] for [struct@GLib.MainContext] to dispatch events for isochronous
+ * context.
+ */
+void hinoko_fw_iso_ctx_create_source(HinokoFwIsoCtx *self, GSource **source, GError **error)
+{
+ HinokoFwIsoCtxPrivate *priv;
+
+ gboolean (*handle_event)(HinokoFwIsoCtx *inst, const union fw_cdev_event *event,
+ GError **error);
+
+ g_return_if_fail(HINOKO_IS_FW_ISO_CTX(self));
+ g_return_if_fail(source != NULL);
+ g_return_if_fail(error == NULL || *error == NULL);
+
+ priv = hinoko_fw_iso_ctx_get_instance_private(self);
if (HINOKO_IS_FW_ISO_RX_SINGLE(self))
- src->handle_event = fw_iso_rx_single_handle_event;
+ handle_event = fw_iso_rx_single_handle_event;
else if (HINOKO_IS_FW_ISO_RX_MULTIPLE(self))
- src->handle_event = fw_iso_rx_multiple_handle_event;
+ handle_event = fw_iso_rx_multiple_handle_event;
else if (HINOKO_IS_FW_ISO_TX(self))
- src->handle_event = fw_iso_tx_handle_event;
+ handle_event = fw_iso_tx_handle_event;
else
- src->handle_event = fw_iso_ctx_handle_event_real;
+ handle_event = fw_iso_ctx_handle_event_real;
+
+ fw_iso_ctx_state_create_source(priv, self, handle_event, source, error);
}
/**
diff --git a/src/fw_iso_ctx_private.h b/src/fw_iso_ctx_private.h
index 7cfa27f..64597b4 100644
--- a/src/fw_iso_ctx_private.h
+++ b/src/fw_iso_ctx_private.h
@@ -71,6 +71,12 @@ gboolean fw_iso_ctx_state_flush_completions(struct fw_iso_ctx_state *state, GErr
gboolean fw_iso_ctx_state_get_cycle_timer(struct fw_iso_ctx_state *state, gint clock_id,
HinokoCycleTimer *const *cycle_timer, GError **error);
+gboolean fw_iso_ctx_state_create_source(struct fw_iso_ctx_state *state, HinokoFwIsoCtx *inst,
+ gboolean (*handle_event)(HinokoFwIsoCtx *inst,
+ const union fw_cdev_event *event,
+ GError **error),
+ GSource **source, GError **error);
+
void hinoko_fw_iso_ctx_allocate(HinokoFwIsoCtx *self, const char *path,
HinokoFwIsoCtxMode mode, HinokoFwScode scode,
guint channel, guint header_size,