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
commitc80ac3c83e91e5f40d0d272733972e4624241823 (patch)
tree6e6c74458e9cd3f73cb9cc48650581bea17ce7e1
parent54da6fd071b365350a4728947a12d7c6e8e3ff8c (diff)
downloadlibhinoko-c80ac3c83e91e5f40d0d272733972e4624241823.tar.gz
fw_iso_resource: code refactoring to split open function
It's planned to make Hinoko.FwIsoResource as interface. It's convenient for derived object to use private helper function to open file descriptor apart from public API to call virtual function. This commit splits current implementaion of Hinoko.FwIsoResource.open() into public API part and private implementation. Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
-rw-r--r--src/fw_iso_resource.c44
-rw-r--r--src/fw_iso_resource_private.h1
2 files changed, 29 insertions, 16 deletions
diff --git a/src/fw_iso_resource.c b/src/fw_iso_resource.c
index 7f601b9..0c0ac5e 100644
--- a/src/fw_iso_resource.c
+++ b/src/fw_iso_resource.c
@@ -135,6 +135,30 @@ static void hinoko_fw_iso_resource_init(HinokoFwIsoResource *self)
priv->fd = -1;
}
+gboolean fw_iso_resource_open(int *fd, 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) {
+ generate_local_error(error, HINOKO_FW_ISO_RESOURCE_ERROR_OPENED);
+ return FALSE;
+ }
+
+ open_flag |= O_RDONLY;
+ *fd = open(path, open_flag);
+ if (*fd < 0) {
+ GFileError code = g_file_error_from_errno(errno);
+ if (code != G_FILE_ERROR_FAILED)
+ generate_file_error(error, code, "open(%s)", path);
+ else
+ generate_syscall_error(error, errno, "open(%s)", path);
+ return FALSE;
+ }
+
+ return TRUE;
+}
/**
* hinoko_fw_iso_resource_open:
* @self: A [class@FwIsoResource].
@@ -147,30 +171,18 @@ static void hinoko_fw_iso_resource_init(HinokoFwIsoResource *self)
* Open Linux FireWire character device to delegate any request for isochronous
* resource management to Linux FireWire subsystem.
*/
-void hinoko_fw_iso_resource_open(HinokoFwIsoResource *self, const gchar *path,
- gint open_flag, GError **error)
+void hinoko_fw_iso_resource_open(HinokoFwIsoResource *self, const gchar *path, gint open_flag,
+ GError **error)
{
HinokoFwIsoResourcePrivate *priv;
g_return_if_fail(HINOKO_IS_FW_ISO_RESOURCE(self));
+ g_return_if_fail(path != NULL && strlen(path) > 0);
g_return_if_fail(error == NULL || *error == NULL);
priv = hinoko_fw_iso_resource_get_instance_private(self);
- if (priv->fd >= 0) {
- generate_local_error(error, HINOKO_FW_ISO_RESOURCE_ERROR_OPENED);
- return;
- }
-
- open_flag |= O_RDONLY;
- priv->fd = open(path, open_flag);
- if (priv->fd < 0) {
- GFileError code = g_file_error_from_errno(errno);
- if (code != G_FILE_ERROR_FAILED)
- generate_file_error(error, code, "open(%s)", path);
- else
- generate_syscall_error(error, errno, "open(%s)", path);
- }
+ (void)fw_iso_resource_open(&priv->fd, path, open_flag, error);
}
static void handle_event_signal(HinokoFwIsoResource *self, guint channel, guint bandwidth,
diff --git a/src/fw_iso_resource_private.h b/src/fw_iso_resource_private.h
index d8ff66e..46da230 100644
--- a/src/fw_iso_resource_private.h
+++ b/src/fw_iso_resource_private.h
@@ -10,6 +10,7 @@
#define ALLOCATED_SIGNAL_NAME "allocated"
#define DEALLOCATED_SIGNAL_NAME "deallocated"
+gboolean fw_iso_resource_open(int *fd, const gchar *path, gint open_flag, GError **error);
void hinoko_fw_iso_resource_ioctl(HinokoFwIsoResource *self,
unsigned long request, void *argp,
GError **error);