aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>2022-05-04 17:18:29 +0900
committer坂本 貴史 <o-takashi@sakamocchi.jp>2022-05-05 08:10:07 +0900
commitc88f3d6b8e26680dab94b9023cdcd24adca21646 (patch)
tree75f58fc69a69b7a43ed57532c4ae69c75a8142a5
parenteab1a247c221e2173b320b3481abb592bc70752d (diff)
downloadlibhinoko-c88f3d6b8e26680dab94b9023cdcd24adca21646.tar.gz
fw_iso_ctx: code refactoring to add cache of file descriptor
GSource generated by call of Hinoko.FwIsoCtx.create_source() accesses to private data of Hinoko.FwIsoCtx to refer to file descriptor, however it's necessarily convenient since it's planned to make the class as interface. This commit puts cache of file descriptor to private structure for the source. Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
-rw-r--r--src/fw_iso_ctx.c14
1 files changed, 5 insertions, 9 deletions
diff --git a/src/fw_iso_ctx.c b/src/fw_iso_ctx.c
index cdf8cbf..33545cf 100644
--- a/src/fw_iso_ctx.c
+++ b/src/fw_iso_ctx.c
@@ -76,6 +76,7 @@ typedef struct {
unsigned int len;
void *buf;
HinokoFwIsoCtx *self;
+ int fd;
} FwIsoCtxSource;
enum fw_iso_ctx_prop_type {
@@ -707,22 +708,16 @@ static void handle_irq_mc_event(const struct fw_cdev_event_iso_interrupt_mc *ev,
static gboolean dispatch_src(GSource *gsrc, GSourceFunc cb, gpointer user_data)
{
FwIsoCtxSource *src = (FwIsoCtxSource *)gsrc;
- HinokoFwIsoCtx *self = src->self;
- HinokoFwIsoCtxPrivate *priv =
- hinoko_fw_iso_ctx_get_instance_private(self);
GIOCondition condition;
GError *error;
int len;
const union fw_cdev_event *event;
- if (priv->fd < 0)
- return G_SOURCE_REMOVE;
-
condition = g_source_query_unix_fd(gsrc, src->tag);
if (condition & G_IO_ERR)
return G_SOURCE_REMOVE;
- len = read(priv->fd, src->buf, src->len);
+ len = read(src->fd, src->buf, src->len);
if (len < 0) {
if (errno != EAGAIN) {
generate_file_error(&error, g_file_error_from_errno(errno),
@@ -753,8 +748,8 @@ static gboolean dispatch_src(GSource *gsrc, GSourceFunc cb, gpointer user_data)
// Just be sure to continue to process this source.
return G_SOURCE_CONTINUE;
error:
- hinoko_fw_iso_ctx_stop(self);
- g_signal_emit(self, fw_iso_ctx_sigs[FW_ISO_CTX_SIG_TYPE_STOPPED], 0, error);
+ hinoko_fw_iso_ctx_stop(src->self);
+ g_signal_emit(src->self, fw_iso_ctx_sigs[FW_ISO_CTX_SIG_TYPE_STOPPED], 0, error);
g_clear_error(&error);
return G_SOURCE_REMOVE;
}
@@ -818,6 +813,7 @@ void hinoko_fw_iso_ctx_create_source(HinokoFwIsoCtx *self, GSource **gsrc,
src->buf = g_malloc0(src->len);
src->tag = g_source_add_unix_fd(*gsrc, priv->fd, G_IO_IN);
+ src->fd = priv->fd;
src->self = g_object_ref(self);
}