aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>2022-05-07 13:57:57 +0900
committer坂本 貴史 <o-takashi@sakamocchi.jp>2022-05-07 15:50:18 +0900
commita6a5dbf6981b28274bce7bf62766df711de20e88 (patch)
tree122764f94710326b7a5f51d424c4bb392efa6959
parente232cf091b47282aeee078a6ca205e99ca1b29d0 (diff)
downloadlibhinoko-a6a5dbf6981b28274bce7bf62766df711de20e88.tar.gz
fw_iso_resource_auto: 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_auto.c97
1 files changed, 55 insertions, 42 deletions
diff --git a/src/fw_iso_resource_auto.c b/src/fw_iso_resource_auto.c
index 0315449..bdbcd31 100644
--- a/src/fw_iso_resource_auto.c
+++ b/src/fw_iso_resource_auto.c
@@ -140,6 +140,58 @@ static gboolean fw_iso_resource_auto_open(HinokoFwIsoResource *inst, const gchar
return fw_iso_resource_state_open(&priv->state, path, open_flag, error);
}
+static gboolean fw_iso_resource_auto_allocate_async(HinokoFwIsoResource *inst,
+ guint8 *channel_candidates,
+ gsize channel_candidates_count,
+ guint bandwidth,
+ GError **error)
+{
+ HinokoFwIsoResourceAuto *self;
+ HinokoFwIsoResourceAutoPrivate *priv;
+ struct fw_cdev_allocate_iso_resource res = {0};
+ gboolean result;
+ int i;
+
+ g_return_val_if_fail(HINOKO_IS_FW_ISO_RESOURCE_AUTO(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_AUTO(inst);
+ priv = hinoko_fw_iso_resource_auto_get_instance_private(self);
+ if (priv->state.fd < 0) {
+ generate_coded_error(error, HINOKO_FW_ISO_RESOURCE_ERROR_NOT_OPENED);
+ return FALSE;
+ }
+
+ g_mutex_lock(&priv->mutex);
+
+ if (priv->is_allocated) {
+ generate_local_error(error, HINOKO_FW_ISO_RESOURCE_AUTO_ERROR_ALLOCATED);
+ result = FALSE;
+ goto end;
+ }
+
+ 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, &res) < 0) {
+ generate_ioctl_error(error, errno, FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE);
+ result = FALSE;
+ } else {
+ priv->handle = res.handle;
+ result = TRUE;
+ }
+end:
+ g_mutex_unlock(&priv->mutex);
+
+ return result;
+}
+
static void handle_iso_resource_event(HinokoFwIsoResourceAuto *self,
const struct fw_cdev_event_iso_resource *ev)
{
@@ -279,48 +331,9 @@ gboolean hinoko_fw_iso_resource_auto_allocate_async(HinokoFwIsoResourceAuto *sel
guint bandwidth,
GError **error)
{
- HinokoFwIsoResourceAutoPrivate *priv;
- struct fw_cdev_allocate_iso_resource res = {0};
- gboolean result;
- int i;
-
- g_return_val_if_fail(HINOKO_IS_FW_ISO_RESOURCE_AUTO(self), 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);
-
- priv = hinoko_fw_iso_resource_auto_get_instance_private(self);
- if (priv->state.fd < 0) {
- generate_coded_error(error, HINOKO_FW_ISO_RESOURCE_ERROR_NOT_OPENED);
- return FALSE;
- }
-
- g_mutex_lock(&priv->mutex);
-
- if (priv->is_allocated) {
- generate_local_error(error, HINOKO_FW_ISO_RESOURCE_AUTO_ERROR_ALLOCATED);
- result = FALSE;
- goto end;
- }
-
- 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, &res) < 0) {
- generate_ioctl_error(error, errno, FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE);
- result = FALSE;
- } else {
- priv->handle = res.handle;
- result = TRUE;
- }
-end:
- g_mutex_unlock(&priv->mutex);
-
- return result;
+ return fw_iso_resource_auto_allocate_async(HINOKO_FW_ISO_RESOURCE(self),
+ channel_candidates, channel_candidates_count,
+ bandwidth, error);
}
/**