aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>2022-05-05 21:15:33 +0900
committer坂本 貴史 <o-takashi@sakamocchi.jp>2022-05-06 08:31:24 +0900
commitf0b1a1f830be5b0f9fd1fbcdbf9a55382c8860a2 (patch)
tree3e389054a57c67465a130342f90ed2092d6c5de9
parent0462aff82cb5e5284e21bbdeb35d248e93956f5e (diff)
downloadlibhinoko-f0b1a1f830be5b0f9fd1fbcdbf9a55382c8860a2.tar.gz
fw_iso_resource_auto: rewrite public API to return gboolean according to GNOME convention
In GNOME convention, the throw function to report error at GError argument should return gboolean value to report the overall operation finishes successfully or not. On the other hand, it's implemented to return void in Hinoko.FwIsoResourceAuto. This commit rewrite such public APIs with loss of backward compatibility. Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
-rw-r--r--src/fw_iso_resource_auto.c99
-rw-r--r--src/fw_iso_resource_auto.h34
-rw-r--r--src/fw_iso_resource_once.c4
-rw-r--r--src/fw_iso_resource_private.c19
-rw-r--r--src/fw_iso_resource_private.h4
-rw-r--r--src/hinoko.map4
6 files changed, 99 insertions, 65 deletions
diff --git a/src/fw_iso_resource_auto.c b/src/fw_iso_resource_auto.c
index c7a69a8..492a326 100644
--- a/src/fw_iso_resource_auto.c
+++ b/src/fw_iso_resource_auto.c
@@ -268,34 +268,39 @@ HinokoFwIsoResourceAuto *hinoko_fw_iso_resource_auto_new()
*
* Initiate allocation of isochronous resource. When the allocation is done,
* [signal@FwIsoResource::allocated] signal is emit to notify the result, channel, and bandwidth.
+ *
+ * Returns: TRUE if the overall operation finished successfully, else FALSE.
+ *
+ * Since: 0.7.
*/
-void hinoko_fw_iso_resource_auto_allocate_async(HinokoFwIsoResourceAuto *self,
- guint8 *channel_candidates,
- gsize channel_candidates_count,
- guint bandwidth,
- GError **error)
+gboolean hinoko_fw_iso_resource_auto_allocate_async(HinokoFwIsoResourceAuto *self,
+ guint8 *channel_candidates,
+ gsize channel_candidates_count,
+ guint bandwidth,
+ GError **error)
{
HinokoFwIsoResourceAutoPrivate *priv;
struct fw_cdev_allocate_iso_resource res = {0};
+ gboolean result;
int i;
- g_return_if_fail(HINOKO_IS_FW_ISO_RESOURCE_AUTO(self));
- g_return_if_fail(error == NULL || *error == NULL);
+ 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;
+ return FALSE;
}
- g_return_if_fail(channel_candidates != NULL);
- g_return_if_fail(channel_candidates_count > 0);
- g_return_if_fail(bandwidth > 0);
-
g_mutex_lock(&priv->mutex);
if (priv->is_allocated) {
generate_local_error(error, HINOKO_FW_ISO_RESOURCE_AUTO_ERROR_ALLOCATED);
+ result = FALSE;
goto end;
}
@@ -305,12 +310,17 @@ void hinoko_fw_iso_resource_auto_allocate_async(HinokoFwIsoResourceAuto *self,
}
res.bandwidth = bandwidth;
- if (ioctl(priv->state.fd, FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE, &res) < 0)
+ if (ioctl(priv->state.fd, FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE, &res) < 0) {
generate_ioctl_error(error, errno, FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE);
- else
+ result = FALSE;
+ } else {
priv->handle = res.handle;
+ result = TRUE;
+ }
end:
g_mutex_unlock(&priv->mutex);
+
+ return result;
}
/**
@@ -321,35 +331,47 @@ end:
*
* Initiate deallocation of isochronous resource. When the deallocation is done,
* [signal@FwIsoResource::deallocated] signal is emit to notify the result, channel, and bandwidth.
+ *
+ * Returns: TRUE if the overall operation finished successfully, else FALSE.
+ *
+ * Since: 0.7.
*/
-void hinoko_fw_iso_resource_auto_deallocate_async(HinokoFwIsoResourceAuto *self,
- GError **error)
+gboolean hinoko_fw_iso_resource_auto_deallocate_async(HinokoFwIsoResourceAuto *self,
+ GError **error)
{
HinokoFwIsoResourceAutoPrivate *priv;
struct fw_cdev_deallocate dealloc = {0};
+ gboolean result;
- g_return_if_fail(HINOKO_IS_FW_ISO_RESOURCE_AUTO(self));
- g_return_if_fail(error == NULL || *error == NULL);
+ g_return_val_if_fail(HINOKO_IS_FW_ISO_RESOURCE_AUTO(self), 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;
+ return FALSE;
}
g_mutex_lock(&priv->mutex);
if (!priv->is_allocated) {
generate_local_error(error, HINOKO_FW_ISO_RESOURCE_AUTO_ERROR_NOT_ALLOCATED);
+ result = FALSE;
goto end;
}
dealloc.handle = priv->handle;
- if (ioctl(priv->state.fd, FW_CDEV_IOC_DEALLOCATE_ISO_RESOURCE, &dealloc) < 0)
+ if (ioctl(priv->state.fd, FW_CDEV_IOC_DEALLOCATE_ISO_RESOURCE, &dealloc) < 0) {
generate_ioctl_error(error, errno, FW_CDEV_IOC_DEALLOCATE_ISO_RESOURCE);
+ result = FALSE;
+ } else {
+ result = TRUE;
+ }
end:
g_mutex_unlock(&priv->mutex);
+
+ return result;
}
/**
@@ -367,27 +389,28 @@ end:
* signal. When the call is successful, [property@FwIsoResourceAuto:channel] and
* [property@FwIsoResourceAuto:bandwidth] properties are available.
*
+ * Returns: TRUE if the overall operation finished successfully, else FALSE.
+ *
* Since: 0.7.
*/
-void hinoko_fw_iso_resource_auto_allocate_sync(HinokoFwIsoResourceAuto *self,
- guint8 *channel_candidates,
- gsize channel_candidates_count,
- guint bandwidth, guint timeout_ms,
- GError **error)
+gboolean hinoko_fw_iso_resource_auto_allocate_sync(HinokoFwIsoResourceAuto *self,
+ guint8 *channel_candidates,
+ gsize channel_candidates_count,
+ guint bandwidth, guint timeout_ms,
+ GError **error)
{
struct fw_iso_resource_waiter w;
- g_return_if_fail(HINOKO_IS_FW_ISO_RESOURCE_AUTO(self));
- g_return_if_fail(error == NULL || *error == NULL);
+ g_return_val_if_fail(HINOKO_IS_FW_ISO_RESOURCE_AUTO(self), FALSE);
+ g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
fw_iso_resource_waiter_init(&w, HINOKO_FW_ISO_RESOURCE(self), ALLOCATED_SIGNAL_NAME,
timeout_ms);
- hinoko_fw_iso_resource_auto_allocate_async(self, channel_candidates,
- channel_candidates_count,
- bandwidth, error);
+ (void)hinoko_fw_iso_resource_auto_allocate_async(self, channel_candidates,
+ channel_candidates_count, bandwidth, error);
- fw_iso_resource_waiter_wait(&w, HINOKO_FW_ISO_RESOURCE(self), error);
+ return fw_iso_resource_waiter_wait(&w, HINOKO_FW_ISO_RESOURCE(self), error);
}
/**
@@ -400,20 +423,22 @@ void hinoko_fw_iso_resource_auto_allocate_sync(HinokoFwIsoResourceAuto *self,
* Initiate deallocation of isochronous resource. When the deallocation is done,
* [signal@FwIsoResource::deallocated] signal is emit to notify the result, channel, and bandwidth.
*
+ * Returns: TRUE if the overall operation finished successfully, else FALSE.
+ *
* Since: 0.7.
*/
-void hinoko_fw_iso_resource_auto_deallocate_sync(HinokoFwIsoResourceAuto *self, guint timeout_ms,
- GError **error)
+gboolean hinoko_fw_iso_resource_auto_deallocate_sync(HinokoFwIsoResourceAuto *self,
+ guint timeout_ms, GError **error)
{
struct fw_iso_resource_waiter w;
- g_return_if_fail(HINOKO_IS_FW_ISO_RESOURCE_AUTO(self));
- g_return_if_fail(error == NULL || *error == NULL);
+ g_return_val_if_fail(HINOKO_IS_FW_ISO_RESOURCE_AUTO(self), FALSE);
+ g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
fw_iso_resource_waiter_init(&w, HINOKO_FW_ISO_RESOURCE(self), DEALLOCATED_SIGNAL_NAME,
timeout_ms);
- hinoko_fw_iso_resource_auto_deallocate_async(self, error);
+ (void)hinoko_fw_iso_resource_auto_deallocate_async(self, error);
- fw_iso_resource_waiter_wait(&w, HINOKO_FW_ISO_RESOURCE(self), error);
+ return fw_iso_resource_waiter_wait(&w, HINOKO_FW_ISO_RESOURCE(self), error);
}
diff --git a/src/fw_iso_resource_auto.h b/src/fw_iso_resource_auto.h
index b324ad2..ed4aa67 100644
--- a/src/fw_iso_resource_auto.h
+++ b/src/fw_iso_resource_auto.h
@@ -19,23 +19,23 @@ struct _HinokoFwIsoResourceAutoClass {
GObjectClass parent_class;
};
-HinokoFwIsoResourceAuto *hinoko_fw_iso_resource_auto_new();
-
-void hinoko_fw_iso_resource_auto_allocate_async(HinokoFwIsoResourceAuto *self,
- guint8 *channel_candidates,
- gsize channel_candidates_count,
- guint bandwidth,
- GError **error);
-void hinoko_fw_iso_resource_auto_allocate_sync(HinokoFwIsoResourceAuto *self,
- guint8 *channel_candidates,
- gsize channel_candidates_count,
- guint bandwidth, guint timeout_ms,
- GError **error);
-
-void hinoko_fw_iso_resource_auto_deallocate_async(HinokoFwIsoResourceAuto *self,
- GError **error);
-void hinoko_fw_iso_resource_auto_deallocate_sync(HinokoFwIsoResourceAuto *self, guint timeout_ms,
- GError **error);
+HinokoFwIsoResourceAuto *hinoko_fw_iso_resource_auto_new(void);
+
+gboolean hinoko_fw_iso_resource_auto_allocate_async(HinokoFwIsoResourceAuto *self,
+ guint8 *channel_candidates,
+ gsize channel_candidates_count,
+ guint bandwidth,
+ GError **error);
+gboolean hinoko_fw_iso_resource_auto_allocate_sync(HinokoFwIsoResourceAuto *self,
+ guint8 *channel_candidates,
+ gsize channel_candidates_count,
+ guint bandwidth, guint timeout_ms,
+ GError **error);
+
+gboolean hinoko_fw_iso_resource_auto_deallocate_async(HinokoFwIsoResourceAuto *self,
+ GError **error);
+gboolean hinoko_fw_iso_resource_auto_deallocate_sync(HinokoFwIsoResourceAuto *self,
+ guint timeout_ms, GError **error);
G_END_DECLS
diff --git a/src/fw_iso_resource_once.c b/src/fw_iso_resource_once.c
index 8c32378..e0eec5b 100644
--- a/src/fw_iso_resource_once.c
+++ b/src/fw_iso_resource_once.c
@@ -282,7 +282,7 @@ void hinoko_fw_iso_resource_once_allocate_sync(HinokoFwIsoResourceOnce *self,
hinoko_fw_iso_resource_once_allocate_async(self, channel_candidates,
channel_candidates_count, bandwidth, error);
- fw_iso_resource_waiter_wait(&w, HINOKO_FW_ISO_RESOURCE(self), error);
+ (void)fw_iso_resource_waiter_wait(&w, HINOKO_FW_ISO_RESOURCE(self), error);
}
/**
@@ -312,5 +312,5 @@ void hinoko_fw_iso_resource_once_deallocate_sync(HinokoFwIsoResourceOnce *self,
hinoko_fw_iso_resource_once_deallocate_async(self, channel, bandwidth, error);
- fw_iso_resource_waiter_wait(&w, HINOKO_FW_ISO_RESOURCE(self), error);
+ (void)fw_iso_resource_waiter_wait(&w, HINOKO_FW_ISO_RESOURCE(self), error);
}
diff --git a/src/fw_iso_resource_private.c b/src/fw_iso_resource_private.c
index d4e7071..e947cb8 100644
--- a/src/fw_iso_resource_private.c
+++ b/src/fw_iso_resource_private.c
@@ -233,12 +233,14 @@ void fw_iso_resource_waiter_init(struct fw_iso_resource_waiter *w, HinokoFwIsoRe
w->handler_id = g_signal_connect(self, signal_name, G_CALLBACK(handle_event_signal), w);
}
-void fw_iso_resource_waiter_wait(struct fw_iso_resource_waiter *w, HinokoFwIsoResource *self,
- GError **error)
+gboolean fw_iso_resource_waiter_wait(struct fw_iso_resource_waiter *w, HinokoFwIsoResource *self,
+ GError **error)
{
+ gboolean result;
+
if (*error != NULL) {
g_signal_handler_disconnect(self, w->handler_id);
- return;
+ return FALSE;
}
g_mutex_lock(&w->mutex);
@@ -249,10 +251,17 @@ void fw_iso_resource_waiter_wait(struct fw_iso_resource_waiter *w, HinokoFwIsoRe
g_signal_handler_disconnect(self, w->handler_id);
g_mutex_unlock(&w->mutex);
- if (w->handled == FALSE)
+ if (w->handled == FALSE) {
generate_coded_error(error, HINOKO_FW_ISO_RESOURCE_ERROR_TIMEOUT);
- else if (w->error != NULL)
+ result = FALSE;
+ } else if (w->error != NULL) {
*error = w->error; // Delegate ownership.
+ result = FALSE;
+ } else {
+ result = TRUE;
+ }
+
+ return result;
}
void parse_iso_resource_event(const struct fw_cdev_event_iso_resource *ev, guint *channel,
diff --git a/src/fw_iso_resource_private.h b/src/fw_iso_resource_private.h
index 8246e7c..f7ca0db 100644
--- a/src/fw_iso_resource_private.h
+++ b/src/fw_iso_resource_private.h
@@ -69,8 +69,8 @@ struct fw_iso_resource_waiter {
void fw_iso_resource_waiter_init(struct fw_iso_resource_waiter *w, HinokoFwIsoResource *self,
const char *signal_name, guint timeout_ms);
-void fw_iso_resource_waiter_wait(struct fw_iso_resource_waiter *w, HinokoFwIsoResource *self,
- GError **error);
+gboolean fw_iso_resource_waiter_wait(struct fw_iso_resource_waiter *w, HinokoFwIsoResource *self,
+ GError **error);
void parse_iso_resource_event(const struct fw_cdev_event_iso_resource *ev, guint *channel,
guint *bandwidth, const char **signal_name, GError **error);
diff --git a/src/hinoko.map b/src/hinoko.map
index 882ee88..40e7567 100644
--- a/src/hinoko.map
+++ b/src/hinoko.map
@@ -27,8 +27,6 @@ HINOKO_0_4_0 {
"hinoko_fw_iso_resource_calculate_bandwidth";
"hinoko_fw_iso_resource_auto_new";
- "hinoko_fw_iso_resource_auto_allocate_async";
- "hinoko_fw_iso_resource_auto_deallocate_async";
} HINOKO_0_3_0;
HINOKO_0_5_0 {
@@ -77,6 +75,8 @@ HINOKO_0_7_0 {
"hinoko_fw_iso_resource_create_source";
"hinoko_fw_iso_resource_auto_get_type";
+ "hinoko_fw_iso_resource_auto_allocate_async";
+ "hinoko_fw_iso_resource_auto_deallocate_async";
"hinoko_fw_iso_resource_auto_allocate_sync";
"hinoko_fw_iso_resource_auto_deallocate_sync";