aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>2022-05-05 16:16:39 +0900
committer坂本 貴史 <o-takashi@sakamocchi.jp>2022-05-05 20:51:53 +0900
commit087961c0793c922399927033d8f8a89d8ea73be1 (patch)
tree71bced42328eeaa86f201efe01faf1ea3d3cf741
parentd9e8b0724cd688a5fc7c62c8b64bc32df9e530b7 (diff)
downloadlibhinoko-087961c0793c922399927033d8f8a89d8ea73be1.tar.gz
fw_iso_resource_private: add structure to maintain state
It's required to have cache for state of IEEE 1394 bus so that object class which implements interface can support property for bus generation. This commit adds private structure to maintain state. Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
-rw-r--r--src/fw_iso_resource_auto.c18
-rw-r--r--src/fw_iso_resource_once.c18
-rw-r--r--src/fw_iso_resource_private.c35
-rw-r--r--src/fw_iso_resource_private.h20
4 files changed, 57 insertions, 34 deletions
diff --git a/src/fw_iso_resource_auto.c b/src/fw_iso_resource_auto.c
index 3a1357c..13460b3 100644
--- a/src/fw_iso_resource_auto.c
+++ b/src/fw_iso_resource_auto.c
@@ -10,7 +10,7 @@
* updates. The maintenance of allocated isochronous resource is done by Linux FireWire subsystem.
*/
typedef struct {
- int fd;
+ struct fw_iso_resource_state state;
gboolean is_allocated;
guint channel;
@@ -87,8 +87,7 @@ static void fw_iso_resource_auto_finalize(GObject *obj)
HinokoFwIsoResourceAutoPrivate *priv =
hinoko_fw_iso_resource_auto_get_instance_private(self);
- if (priv->fd >= 0)
- close(priv->fd);
+ fw_iso_resource_state_release(&priv->state);
G_OBJECT_CLASS(hinoko_fw_iso_resource_auto_parent_class)->finalize(obj);
}
@@ -127,7 +126,7 @@ static void hinoko_fw_iso_resource_auto_init(HinokoFwIsoResourceAuto *self)
HinokoFwIsoResourceAutoPrivate *priv =
hinoko_fw_iso_resource_auto_get_instance_private(self);
- priv->fd = -1;
+ fw_iso_resource_state_init(&priv->state);
g_mutex_init(&priv->mutex);
}
@@ -141,7 +140,7 @@ static gboolean fw_iso_resource_auto_open(HinokoFwIsoResource *inst, const gchar
self = HINOKO_FW_ISO_RESOURCE_AUTO(inst);
priv = hinoko_fw_iso_resource_auto_get_instance_private(self);
- return fw_iso_resource_open(&priv->fd, path, open_flag, error);
+ return fw_iso_resource_state_open(&priv->state, path, open_flag, error);
}
static void handle_iso_resource_event(HinokoFwIsoResourceAuto *self,
@@ -211,8 +210,9 @@ static gboolean fw_iso_resource_auto_create_source(HinokoFwIsoResource *inst, GS
self = HINOKO_FW_ISO_RESOURCE_AUTO(inst);
priv = hinoko_fw_iso_resource_auto_get_instance_private(self);
- return fw_iso_resource_create_source(priv->fd, inst, fw_iso_resource_auto_handle_event,
- source, error);
+ return fw_iso_resource_state_create_source(&priv->state, inst,
+ fw_iso_resource_auto_handle_event, source,
+ error);
}
static void fw_iso_resource_iface_init(HinokoFwIsoResourceInterface *iface)
@@ -280,7 +280,7 @@ void hinoko_fw_iso_resource_auto_allocate_async(HinokoFwIsoResourceAuto *self,
}
res.bandwidth = bandwidth;
- if (ioctl(priv->fd, FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE, &res) < 0) {
+ if (ioctl(priv->state.fd, FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE, &res) < 0) {
generate_syscall_error(error, errno, "ioctl(%s)",
"FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE");
} else {
@@ -319,7 +319,7 @@ void hinoko_fw_iso_resource_auto_deallocate_async(HinokoFwIsoResourceAuto *self,
dealloc.handle = priv->handle;
- if (ioctl(priv->fd, FW_CDEV_IOC_DEALLOCATE_ISO_RESOURCE, &dealloc) < 0) {
+ if (ioctl(priv->state.fd, FW_CDEV_IOC_DEALLOCATE_ISO_RESOURCE, &dealloc) < 0) {
generate_syscall_error(error, errno, "ioctl(%s)",
"FW_CDEV_IOC_DEALLOCATE_ISO_RESOURCE");
}
diff --git a/src/fw_iso_resource_once.c b/src/fw_iso_resource_once.c
index 62b7744..651eb42 100644
--- a/src/fw_iso_resource_once.c
+++ b/src/fw_iso_resource_once.c
@@ -11,7 +11,7 @@
* is left even if this object is destroyed, thus application is responsible for deallocation.
*/
typedef struct {
- int fd;
+ struct fw_iso_resource_state state;
} HinokoFwIsoResourceOncePrivate;
static void fw_iso_resource_iface_init(HinokoFwIsoResourceInterface *iface);
@@ -26,8 +26,7 @@ static void fw_iso_resource_once_finalize(GObject *obj)
HinokoFwIsoResourceOncePrivate *priv =
hinoko_fw_iso_resource_once_get_instance_private(self);
- if (priv->fd >= 0)
- close(priv->fd);
+ fw_iso_resource_state_release(&priv->state);
G_OBJECT_CLASS(hinoko_fw_iso_resource_once_parent_class)->finalize(obj);
}
@@ -44,7 +43,7 @@ static void hinoko_fw_iso_resource_once_init(HinokoFwIsoResourceOnce *self)
HinokoFwIsoResourceOncePrivate *priv =
hinoko_fw_iso_resource_once_get_instance_private(self);
- priv->fd = -1;
+ fw_iso_resource_state_init(&priv->state);
}
static gboolean fw_iso_resource_once_open(HinokoFwIsoResource *inst, const gchar *path,
@@ -57,7 +56,7 @@ static gboolean fw_iso_resource_once_open(HinokoFwIsoResource *inst, const gchar
self = HINOKO_FW_ISO_RESOURCE_ONCE(inst);
priv = hinoko_fw_iso_resource_once_get_instance_private(self);
- return fw_iso_resource_open(&priv->fd, path, open_flag, error);
+ return fw_iso_resource_state_open(&priv->state, path, open_flag, error);
}
static void handle_iso_resource_event(HinokoFwIsoResourceOnce *self,
@@ -103,8 +102,9 @@ static gboolean fw_iso_resource_once_create_source(HinokoFwIsoResource *inst, GS
self = HINOKO_FW_ISO_RESOURCE_ONCE(inst);
priv = hinoko_fw_iso_resource_once_get_instance_private(self);
- return fw_iso_resource_create_source(priv->fd, inst, fw_iso_resource_once_handle_event,
- source, error);
+ return fw_iso_resource_state_create_source(&priv->state, inst,
+ fw_iso_resource_once_handle_event, source,
+ error);
}
static void fw_iso_resource_iface_init(HinokoFwIsoResourceInterface *iface)
@@ -167,7 +167,7 @@ void hinoko_fw_iso_resource_once_allocate_async(HinokoFwIsoResourceOnce *self,
}
res.bandwidth = bandwidth;
- if (ioctl(priv->fd, FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE_ONCE, &res) < 0) {
+ if (ioctl(priv->state.fd, FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE_ONCE, &res) < 0) {
generate_syscall_error(error, errno, "ioctl(%s)",
"FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE_ONCE");
}
@@ -204,7 +204,7 @@ void hinoko_fw_iso_resource_once_deallocate_async(HinokoFwIsoResourceOnce *self,
res.channels = 1ull << channel;
res.bandwidth = bandwidth;
- if (ioctl(priv->fd, FW_CDEV_IOC_DEALLOCATE_ISO_RESOURCE_ONCE, &res) < 0) {
+ if (ioctl(priv->state.fd, FW_CDEV_IOC_DEALLOCATE_ISO_RESOURCE_ONCE, &res) < 0) {
generate_syscall_error(error, errno, "ioctl(%s)",
"FW_CDEV_IOC_DEALLOCATE_ISO_RESOURCE_ONCE");
}
diff --git a/src/fw_iso_resource_private.c b/src/fw_iso_resource_private.c
index 44f5e88..257d783 100644
--- a/src/fw_iso_resource_private.c
+++ b/src/fw_iso_resource_private.c
@@ -35,20 +35,32 @@ typedef struct {
void (*handle_event)(HinokoFwIsoResource *self, const union fw_cdev_event *event);
} FwIsoResourceSource;
-gboolean fw_iso_resource_open(int *fd, const gchar *path, gint open_flag, GError **error)
+void fw_iso_resource_state_init(struct fw_iso_resource_state *state)
+{
+ state->fd = -1;
+}
+
+void fw_iso_resource_state_release(struct fw_iso_resource_state *state)
+{
+ if (state->fd < 0)
+ close(state->fd);
+ state->fd = -1;
+}
+
+gboolean fw_iso_resource_state_open(struct fw_iso_resource_state *state, const gchar *path,
+ gint open_flag, GError **error)
{
- g_return_val_if_fail(fd != NULL, FALSE);
g_return_val_if_fail(path != NULL && strlen(path) > 0, FALSE);
g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
- if (*fd >= 0) {
+ if (state->fd >= 0) {
generate_local_error(error, HINOKO_FW_ISO_RESOURCE_ERROR_OPENED);
return FALSE;
}
open_flag |= O_RDONLY;
- *fd = open(path, open_flag);
- if (*fd < 0) {
+ state->fd = open(path, open_flag);
+ if (state->fd < 0) {
GFileError code = g_file_error_from_errno(errno);
if (code != G_FILE_ERROR_FAILED)
generate_file_error(error, code, "open(%s)", path);
@@ -115,10 +127,11 @@ static void finalize_src(GSource *source)
g_object_unref(src->self);
}
-gboolean fw_iso_resource_create_source(int fd, HinokoFwIsoResource *inst,
- void (*handle_event)(HinokoFwIsoResource *self,
- const union fw_cdev_event *event),
- GSource **source, GError **error)
+gboolean fw_iso_resource_state_create_source(struct fw_iso_resource_state *state,
+ HinokoFwIsoResource *inst,
+ void (*handle_event)(HinokoFwIsoResource *self,
+ const union fw_cdev_event *event),
+ GSource **source, GError **error)
{
static GSourceFuncs funcs = {
.check = check_src,
@@ -141,8 +154,8 @@ gboolean fw_iso_resource_create_source(int fd, HinokoFwIsoResource *inst,
src->buf = g_malloc0(page_size);
src->len = (gsize)page_size;
- src->tag = g_source_add_unix_fd(*source, fd, G_IO_IN);
- src->fd = fd;
+ 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;
diff --git a/src/fw_iso_resource_private.h b/src/fw_iso_resource_private.h
index db91413..d33ae61 100644
--- a/src/fw_iso_resource_private.h
+++ b/src/fw_iso_resource_private.h
@@ -16,12 +16,22 @@
HINOKO_FW_ISO_RESOURCE_ERROR_FAILED, \
format " %d(%s)", arg, errno, strerror(errno))
-gboolean fw_iso_resource_open(int *fd, const gchar *path, gint open_flag, GError **error);
+struct fw_iso_resource_state {
+ int fd;
+};
+
+void fw_iso_resource_state_init(struct fw_iso_resource_state *state);
+
+void fw_iso_resource_state_release(struct fw_iso_resource_state *state);
+
+gboolean fw_iso_resource_state_open(struct fw_iso_resource_state *state, const gchar *path,
+ gint open_flag, GError **error);
-gboolean fw_iso_resource_create_source(int fd, HinokoFwIsoResource *inst,
- void (*handle_event)(HinokoFwIsoResource *self,
- const union fw_cdev_event *event),
- GSource **source, GError **error);
+gboolean fw_iso_resource_state_create_source(struct fw_iso_resource_state *state,
+ HinokoFwIsoResource *inst,
+ void (*handle_event)(HinokoFwIsoResource *self,
+ const union fw_cdev_event *event),
+ GSource **source, GError **error);
struct fw_iso_resource_waiter {
GMutex mutex;