diff options
author | Takashi Sakamoto <o-takashi@sakamocchi.jp> | 2022-05-07 13:57:57 +0900 |
---|---|---|
committer | 坂本 貴史 <o-takashi@sakamocchi.jp> | 2022-05-07 15:50:18 +0900 |
commit | a6bdc52f10c05ef63251aab15a84af9186d13def (patch) | |
tree | 5096ebdc90dbf1c914ec72d0e95677d79efffbed | |
parent | a6a5dbf6981b28274bce7bf62766df711de20e88 (diff) | |
download | libhinoko-a6bdc52f10c05ef63251aab15a84af9186d13def.tar.gz |
fw_iso_resource_once: code refactoring to split asynchronous allocation function
The signature for allocation API is the same in both of
Hinoko.FwIsoResourceAuto and Hinoko.FwIsoResourceOnce, therefore they
can be defined as interface.
This commit is a preparation.
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
-rw-r--r-- | src/fw_iso_resource_once.c | 70 |
1 files changed, 40 insertions, 30 deletions
diff --git a/src/fw_iso_resource_once.c b/src/fw_iso_resource_once.c index fb0b901..dd72172 100644 --- a/src/fw_iso_resource_once.c +++ b/src/fw_iso_resource_once.c @@ -71,6 +71,43 @@ static gboolean fw_iso_resource_once_open(HinokoFwIsoResource *inst, const gchar return fw_iso_resource_state_open(&priv->state, path, open_flag, error); } +static gboolean fw_iso_resource_once_allocate_async(HinokoFwIsoResource *inst, + guint8 *channel_candidates, + gsize channel_candidates_count, + guint bandwidth, GError **error) +{ + HinokoFwIsoResourceOnce *self; + HinokoFwIsoResourceOncePrivate *priv; + + struct fw_cdev_allocate_iso_resource res = {0}; + int i; + + g_return_val_if_fail(HINOKO_IS_FW_ISO_RESOURCE_ONCE(inst), FALSE); + g_return_val_if_fail(channel_candidates != NULL, FALSE); + g_return_val_if_fail(channel_candidates_count > 0, FALSE); + g_return_val_if_fail(bandwidth > 0, FALSE); + g_return_val_if_fail(error == NULL || *error == NULL, FALSE); + + self = HINOKO_FW_ISO_RESOURCE_ONCE(inst); + priv = hinoko_fw_iso_resource_once_get_instance_private(self); + if (priv->state.fd < 0) { + generate_coded_error(error, HINOKO_FW_ISO_RESOURCE_ERROR_NOT_OPENED); + return FALSE; + } + + for (i = 0; i < channel_candidates_count; ++i) { + if (channel_candidates[i] < 64) + res.channels |= 1ull << channel_candidates[i]; + } + res.bandwidth = bandwidth; + + if (ioctl(priv->state.fd, FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE_ONCE, &res) < 0) { + generate_ioctl_error(error, errno, FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE_ONCE); + return FALSE; + } + + return TRUE; +} static void handle_iso_resource_event(HinokoFwIsoResourceOnce *self, const struct fw_cdev_event_iso_resource *ev) { @@ -185,36 +222,9 @@ gboolean hinoko_fw_iso_resource_once_allocate_async(HinokoFwIsoResourceOnce *sel gsize channel_candidates_count, guint bandwidth, GError **error) { - HinokoFwIsoResourceOncePrivate *priv; - - struct fw_cdev_allocate_iso_resource res = {0}; - int i; - - g_return_val_if_fail(HINOKO_IS_FW_ISO_RESOURCE_ONCE(self), FALSE); - g_return_val_if_fail(error == NULL || *error == NULL, FALSE); - - g_return_val_if_fail(channel_candidates != NULL, FALSE); - g_return_val_if_fail(channel_candidates_count > 0, FALSE); - g_return_val_if_fail(bandwidth > 0, FALSE); - - priv = hinoko_fw_iso_resource_once_get_instance_private(self); - if (priv->state.fd < 0) { - generate_coded_error(error, HINOKO_FW_ISO_RESOURCE_ERROR_NOT_OPENED); - return FALSE; - } - - for (i = 0; i < channel_candidates_count; ++i) { - if (channel_candidates[i] < 64) - res.channels |= 1ull << channel_candidates[i]; - } - res.bandwidth = bandwidth; - - if (ioctl(priv->state.fd, FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE_ONCE, &res) < 0) { - generate_ioctl_error(error, errno, FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE_ONCE); - return FALSE; - } - - return TRUE; + return fw_iso_resource_once_allocate_async(HINOKO_FW_ISO_RESOURCE(self), + channel_candidates, channel_candidates_count, + bandwidth, error); } /** |