aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>2022-05-03 07:57:47 +0900
committer坂本 貴史 <o-takashi@sakamocchi.jp>2022-05-03 08:31:29 +0900
commitf477583836372c371460333754a921e4b608a296 (patch)
treee49e4d901045ed9adcdeaa6cdd51f7e65186fc35
parentc80ac3c83e91e5f40d0d272733972e4624241823 (diff)
downloadlibhinoko-f477583836372c371460333754a921e4b608a296.tar.gz
fw_iso_resource: code refactoring to split create_source function
It's planned to make Hinoko.FwIsoResource as interface. It's convenient for derived object to use private helper function to create GSource 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. Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
-rw-r--r--src/fw_iso_resource.c67
-rw-r--r--src/fw_iso_resource_private.h7
2 files changed, 50 insertions, 24 deletions
diff --git a/src/fw_iso_resource.c b/src/fw_iso_resource.c
index 0c0ac5e..2a0d441 100644
--- a/src/fw_iso_resource.c
+++ b/src/fw_iso_resource.c
@@ -359,17 +359,11 @@ static void finalize_src(GSource *source)
g_object_unref(src->self);
}
-/**
- * hinoko_fw_iso_resource_create_source:
- * @self: A [class@FwIsoResource].
- * @source: (out): A [struct@GLib.Source]
- * @error: A [struct@GLib.Error].
- *
- * Create [struct@GLib.Source] for [struct@GLib.MainContext] to dispatch events for isochronous
- * resource.
- */
-void hinoko_fw_iso_resource_create_source(HinokoFwIsoResource *self,
- GSource **source, GError **error)
+gboolean fw_iso_resource_create_source(int fd, HinokoFwIsoResource *inst,
+ void (*handle_event)(HinokoFwIsoResource *self,
+ const char *signal_name, guint channel,
+ guint bandwidth, const GError *error),
+ GSource **source, GError **error)
{
static GSourceFuncs funcs = {
.check = check_src,
@@ -377,35 +371,60 @@ void hinoko_fw_iso_resource_create_source(HinokoFwIsoResource *self,
.finalize = finalize_src,
};
long page_size = sysconf(_SC_PAGESIZE);
- HinokoFwIsoResourcePrivate *priv;
FwIsoResourceSource *src;
- g_return_if_fail(HINOKO_IS_FW_ISO_RESOURCE(self));
- g_return_if_fail(error == NULL || *error == NULL);
-
- priv = hinoko_fw_iso_resource_get_instance_private(self);
+ g_return_val_if_fail(HINOKO_IS_FW_ISO_RESOURCE(inst), FALSE);
+ g_return_val_if_fail(source != NULL, FALSE);
+ g_return_val_if_fail(error != NULL && *error == NULL, FALSE);
*source = g_source_new(&funcs, sizeof(FwIsoResourceSource));
g_source_set_name(*source, "HinokoFwIsoResource");
- g_source_set_priority(*source, G_PRIORITY_HIGH_IDLE);
- g_source_set_can_recurse(*source, TRUE);
src = (FwIsoResourceSource *)(*source);
src->buf = g_malloc0(page_size);
src->len = (gsize)page_size;
- 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, fd, G_IO_IN);
+ src->fd = fd;
+ src->self = g_object_ref(inst);
+ src->handle_event = handle_event;
+
+ return TRUE;
+}
+
+/**
+ * hinoko_fw_iso_resource_create_source:
+ * @self: A [class@FwIsoResource].
+ * @source: (out): A [struct@GLib.Source]
+ * @error: A [struct@GLib.Error].
+ *
+ * Create [struct@GLib.Source] for [struct@GLib.MainContext] to dispatch events for isochronous
+ * resource.
+ */
+void hinoko_fw_iso_resource_create_source(HinokoFwIsoResource *self, GSource **source,
+ GError **error)
+{
+ HinokoFwIsoResourcePrivate *priv;
+
+ void (*handle_event)(HinokoFwIsoResource *self, const char *signal_name, guint channel,
+ guint bandwidth, const GError *error);
+
+ g_return_if_fail(HINOKO_IS_FW_ISO_RESOURCE(self));
+ g_return_if_fail(source != NULL);
+ g_return_if_fail(error == NULL || *error == NULL);
+
+ priv = hinoko_fw_iso_resource_get_instance_private(self);
if (HINOKO_IS_FW_ISO_RESOURCE_AUTO(self))
- src->handle_event = fw_iso_resource_auto_handle_event;
+ handle_event = fw_iso_resource_auto_handle_event;
else if (HINOKO_IS_FW_ISO_RESOURCE_ONCE(self))
- src->handle_event = fw_iso_resource_once_handle_event;
+ handle_event = fw_iso_resource_once_handle_event;
else
- src->handle_event = fw_iso_resource_handle_event;
+ handle_event = fw_iso_resource_handle_event;
+
+ (void)fw_iso_resource_create_source(priv->fd, self, handle_event, source, error);
}
/**
diff --git a/src/fw_iso_resource_private.h b/src/fw_iso_resource_private.h
index 46da230..6ddf570 100644
--- a/src/fw_iso_resource_private.h
+++ b/src/fw_iso_resource_private.h
@@ -11,6 +11,13 @@
#define DEALLOCATED_SIGNAL_NAME "deallocated"
gboolean fw_iso_resource_open(int *fd, const gchar *path, gint open_flag, GError **error);
+
+gboolean fw_iso_resource_create_source(int fd, HinokoFwIsoResource *inst,
+ void (*handle_event)(HinokoFwIsoResource *self,
+ const char *signal_name, guint channel,
+ guint bandwidth, const GError *error),
+ GSource **source, GError **error);
+
void hinoko_fw_iso_resource_ioctl(HinokoFwIsoResource *self,
unsigned long request, void *argp,
GError **error);