diff options
author | Takashi Sakamoto <o-takashi@sakamocchi.jp> | 2022-04-18 07:22:29 +0900 |
---|---|---|
committer | 坂本 貴史 <o-takashi@sakamocchi.jp> | 2022-04-18 07:25:16 +0900 |
commit | 115a7e395bfee71704e701d7a6e44fecd8d8379a (patch) | |
tree | 8e191d1e821dc6945481fa5678d969bd79dbaaea | |
parent | edfa5ad1f45d07375a4bee162e349d243e81d83a (diff) | |
download | libhinoko-115a7e395bfee71704e701d7a6e44fecd8d8379a.tar.gz |
fw_iso_resource_once: move public API for allocation/deallocation asynchronously/synchronously
This commit moves existent public API from Hinoko.FwIsoResource.
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
-rwxr-xr-x | samples/iso-resource | 6 | ||||
-rw-r--r-- | src/fw_iso_resource.c | 156 | ||||
-rw-r--r-- | src/fw_iso_resource.h | 22 | ||||
-rw-r--r-- | src/fw_iso_resource_once.c | 133 | ||||
-rw-r--r-- | src/fw_iso_resource_once.h | 18 | ||||
-rw-r--r-- | src/hinoko.map | 8 | ||||
-rw-r--r-- | tests/fw-iso-resource | 4 | ||||
-rw-r--r-- | tests/fw-iso-resource-once | 4 |
8 files changed, 171 insertions, 180 deletions
diff --git a/samples/iso-resource b/samples/iso-resource index f8720a3..ce4c266 100755 --- a/samples/iso-resource +++ b/samples/iso-resource @@ -27,7 +27,7 @@ def handle_event(res, channel, bandwidth, exception, ev_name): # For Once mode. The allocation is bound to current generation of the bus and # lost automatically by bus reset without notification. -res = Hinoko.FwIsoResource.new() +res = Hinoko.FwIsoResourceOnce.new() res.open('/dev/fw0', 0) res.connect('allocated', handle_event, 'allocated') res.connect('deallocated', handle_event, 'deallocated') @@ -37,7 +37,7 @@ src.attach(ctx) for i in range(2): try: - res.allocate_once_sync((use_channel, ), use_bandwidth) + res.allocate_sync((use_channel, ), use_bandwidth, 100) except GLib.Error as e: if e.matches(Hinoko.fw_iso_resource_error_quark(), Hinoko.FwIsoResourceError.EVENT): print(e) @@ -48,7 +48,7 @@ for i in range(2): sleep(2) try: - res.deallocate_once_sync(use_channel, use_bandwidth) + res.deallocate_sync(use_channel, use_bandwidth, 100) except GLib.Error as e: if e.matches(Hinoko.fw_iso_resource_error_quark(), Hinoko.FwIsoResourceError.EVENT): print(e) diff --git a/src/fw_iso_resource.c b/src/fw_iso_resource.c index c2bae29..f8ee66a 100644 --- a/src/fw_iso_resource.c +++ b/src/fw_iso_resource.c @@ -187,91 +187,6 @@ void hinoko_fw_iso_resource_open(HinokoFwIsoResource *self, const gchar *path, } } -/** - * hinoko_fw_iso_resource_allocate_once_async: - * @self: A [class@FwIsoResource]. - * @channel_candidates: (array length=channel_candidates_count): The array with - * elements for numerical number for isochronous channel - * to be allocated. - * @channel_candidates_count: The number of channel candidates. - * @bandwidth: The amount of bandwidth to be allocated. - * @error: A [struct@GLib.Error]. Error can be generated with domain of Hinoko.FwIsoResourceError. - * - * Initiate allocation of isochronous resource without any wait. When the - * allocation finishes, [signal@FwIsoResource::allocated] signal is emit to notify the result, - * channel, and bandwidth. - */ -void hinoko_fw_iso_resource_allocate_once_async(HinokoFwIsoResource *self, - guint8 *channel_candidates, - gsize channel_candidates_count, - guint bandwidth, - GError **error) -{ - HinokoFwIsoResourcePrivate *priv; - struct fw_cdev_allocate_iso_resource res = {0}; - int i; - - g_return_if_fail(HINOKO_IS_FW_ISO_RESOURCE(self)); - 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_NOT_OPENED); - return; - } - - g_return_if_fail(channel_candidates != NULL); - g_return_if_fail(channel_candidates_count > 0); - g_return_if_fail(bandwidth > 0); - - 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->fd, FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE_ONCE, &res) < 0) - generate_syscall_error(error, errno, "ioctl(%s)", "FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE_ONCE"); -} - -/** - * hinoko_fw_iso_resource_deallocate_once_async: - * @self: A [class@FwIsoResource]. - * @channel: The channel number to be deallocated. - * @bandwidth: The amount of bandwidth to be deallocated. - * @error: A [struct@GLib.Error]. Error can be generated with domain of Hinoko.FwIsoResourceError. - * - * Initiate deallocation of isochronous resource without any wait. When the - * deallocation finishes, [signal@FwIsoResource::deallocated] signal is emit to notify the result, - * channel, and bandwidth. - */ -void hinoko_fw_iso_resource_deallocate_once_async(HinokoFwIsoResource *self, - guint channel, - guint bandwidth, - GError **error) -{ - HinokoFwIsoResourcePrivate *priv; - struct fw_cdev_allocate_iso_resource res = {0}; - - g_return_if_fail(HINOKO_IS_FW_ISO_RESOURCE(self)); - 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_NOT_OPENED); - return; - } - - g_return_if_fail(channel < 64); - g_return_if_fail(bandwidth > 0); - - res.channels = 1ull << channel; - res.bandwidth = bandwidth; - - if (ioctl(priv->fd, FW_CDEV_IOC_DEALLOCATE_ISO_RESOURCE_ONCE, &res) < 0) - generate_syscall_error(error, errno, "ioctl(%s)", "FW_CDEV_IOC_DEALLOCATE_ISO_RESOURCE_ONCE"); -} - static void handle_event_signal(HinokoFwIsoResource *self, guint channel, guint bandwidth, const GError *error, gpointer user_data) { @@ -320,67 +235,6 @@ void fw_iso_resource_waiter_wait(HinokoFwIsoResource *self, struct fw_iso_resour *error = w->error; // Delegate ownership. } -/** - * hinoko_fw_iso_resource_allocate_once_sync: - * @self: A [class@FwIsoResource]. - * @channel_candidates: (array length=channel_candidates_count): The array with - * elements for numerical number for isochronous channel - * to be allocated. - * @channel_candidates_count: The number of channel candidates. - * @bandwidth: The amount of bandwidth to be allocated. - * @error: A [struct@GLib.Error]. Error can be generated with domain of Hinoko.FwIsoResourceError. - * - * Initiate allocation of isochronous resource and wait for [signal@FwIsoResource::allocated] - * signal. - */ -void hinoko_fw_iso_resource_allocate_once_sync(HinokoFwIsoResource *self, - guint8 *channel_candidates, - gsize channel_candidates_count, - guint bandwidth, - GError **error) -{ - struct fw_iso_resource_waiter w; - - g_return_if_fail(HINOKO_IS_FW_ISO_RESOURCE(self)); - g_return_if_fail(error != NULL && *error == NULL); - - fw_iso_resource_waiter_init(HINOKO_FW_ISO_RESOURCE(self), &w, "allocated", 100); - - hinoko_fw_iso_resource_allocate_once_async(self, channel_candidates, - channel_candidates_count, - bandwidth, error); - - fw_iso_resource_waiter_wait(HINOKO_FW_ISO_RESOURCE(self), &w, error); -} - -/** - * hinoko_fw_iso_resource_deallocate_once_sync: - * @self: A [class@FwIsoResource]. - * @channel: The channel number to be deallocated. - * @bandwidth: The amount of bandwidth to be deallocated. - * @error: A [struct@GLib.Error]. Error can be generated with domain of Hinoko.FwIsoResourceError. - * - * Initiate deallocation of isochronous resource. When the deallocation is done, - * [signal@FwIsoResource::deallocated] signal is emit to notify the result, channel, and bandwidth. - */ -void hinoko_fw_iso_resource_deallocate_once_sync(HinokoFwIsoResource *self, - guint channel, - guint bandwidth, - GError **error) -{ - struct fw_iso_resource_waiter w; - - g_return_if_fail(HINOKO_IS_FW_ISO_RESOURCE(self)); - g_return_if_fail(error != NULL && *error == NULL); - - fw_iso_resource_waiter_init(HINOKO_FW_ISO_RESOURCE(self), &w, "allocated", 100); - - hinoko_fw_iso_resource_deallocate_once_async(self, channel, bandwidth, - error); - - fw_iso_resource_waiter_wait(HINOKO_FW_ISO_RESOURCE(self), &w, error); -} - // For internal use. void hinoko_fw_iso_resource_ioctl(HinokoFwIsoResource *self, unsigned long request, void *argp, @@ -390,7 +244,9 @@ void hinoko_fw_iso_resource_ioctl(HinokoFwIsoResource *self, g_return_if_fail(HINOKO_IS_FW_ISO_RESOURCE(self)); g_return_if_fail(request == FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE || - request == FW_CDEV_IOC_DEALLOCATE_ISO_RESOURCE); + request == FW_CDEV_IOC_DEALLOCATE_ISO_RESOURCE || + request == FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE_ONCE || + request == FW_CDEV_IOC_DEALLOCATE_ISO_RESOURCE_ONCE); priv = hinoko_fw_iso_resource_get_instance_private(self); if (priv->fd < 0) { @@ -408,6 +264,12 @@ void hinoko_fw_iso_resource_ioctl(HinokoFwIsoResource *self, case FW_CDEV_IOC_DEALLOCATE_ISO_RESOURCE: arg = "FW_CDEV_IOC_DEALLOCATE_ISO_RESOURCE"; break; + case FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE_ONCE: + arg = "FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE_ONCE"; + break; + case FW_CDEV_IOC_DEALLOCATE_ISO_RESOURCE_ONCE: + arg = "FW_CDEV_IOC_DEALLOCATE_ISO_RESOURCE_ONCE"; + break; default: arg = "Unknown"; break; diff --git a/src/fw_iso_resource.h b/src/fw_iso_resource.h index 1d70dce..cbe8f76 100644 --- a/src/fw_iso_resource.h +++ b/src/fw_iso_resource.h @@ -56,28 +56,6 @@ void hinoko_fw_iso_resource_create_source(HinokoFwIsoResource *self, guint hinoko_fw_iso_resource_calculate_bandwidth(guint bytes_per_payload, HinokoFwScode scode); -void hinoko_fw_iso_resource_allocate_once_async(HinokoFwIsoResource *self, - guint8 *channel_candidates, - gsize channel_candidates_count, - guint bandwidth, - GError **error); - -void hinoko_fw_iso_resource_deallocate_once_async(HinokoFwIsoResource *self, - guint channel, - guint bandwidth, - GError **error); - -void hinoko_fw_iso_resource_allocate_once_sync(HinokoFwIsoResource *self, - guint8 *channel_candidates, - gsize channel_candidates_count, - guint bandwidth, - GError **error); - -void hinoko_fw_iso_resource_deallocate_once_sync(HinokoFwIsoResource *self, - guint channel, - guint bandwidth, - GError **error); - G_END_DECLS #endif diff --git a/src/fw_iso_resource_once.c b/src/fw_iso_resource_once.c index 2f5daac..b0493a5 100644 --- a/src/fw_iso_resource_once.c +++ b/src/fw_iso_resource_once.c @@ -35,3 +35,136 @@ HinokoFwIsoResourceOnce *hinoko_fw_iso_resource_once_new() { return g_object_new(HINOKO_TYPE_FW_ISO_RESOURCE_ONCE, NULL); } + +/** + * hinoko_fw_iso_resource_once_allocate_async: + * @self: A [class@FwIsoResourceOnce]. + * @channel_candidates: (array length=channel_candidates_count): The array with elements for + * numeric number for isochronous channel to be allocated. + * @channel_candidates_count: The number of channel candidates. + * @bandwidth: The amount of bandwidth to be allocated. + * @error: A [struct@GLib.Error]. Error can be generated with domain of Hinoko.FwIsoResourceError. + * + * Initiate allocation of isochronous resource without any wait. When the allocation finishes, + * [signal@FwIsoResource::allocated] signal is emit to notify the result, channel, and bandwidth. + * + * Since: 0.7. + */ +void hinoko_fw_iso_resource_once_allocate_async(HinokoFwIsoResourceOnce *self, + guint8 *channel_candidates, + gsize channel_candidates_count, + guint bandwidth, GError **error) +{ + struct fw_cdev_allocate_iso_resource res = {0}; + int i; + + g_return_if_fail(HINOKO_IS_FW_ISO_RESOURCE_ONCE(self)); + g_return_if_fail(error != NULL && *error == NULL); + + g_return_if_fail(channel_candidates != NULL); + g_return_if_fail(channel_candidates_count > 0); + g_return_if_fail(bandwidth > 0); + + for (i = 0; i < channel_candidates_count; ++i) { + if (channel_candidates[i] < 64) + res.channels |= 1ull << channel_candidates[i]; + } + res.bandwidth = bandwidth; + + hinoko_fw_iso_resource_ioctl(HINOKO_FW_ISO_RESOURCE(self), + FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE_ONCE, &res, error); +} + +/** + * hinoko_fw_iso_resource_once_deallocate_async: + * @self: A [class@FwIsoResourceOnce]. + * @channel: The channel number to be deallocated. + * @bandwidth: The amount of bandwidth to be deallocated. + * @error: A [struct@GLib.Error]. Error can be generated with domain of Hinoko.FwIsoResourceError. + * + * Initiate deallocation of isochronous resource without any wait. When the + * deallocation finishes, [signal@FwIsoResource::deallocated] signal is emit to notify the result, + * channel, and bandwidth. + * + * Since: 0.7. + */ +void hinoko_fw_iso_resource_once_deallocate_async(HinokoFwIsoResourceOnce *self, guint channel, + guint bandwidth, GError **error) +{ + struct fw_cdev_allocate_iso_resource res = {0}; + + g_return_if_fail(HINOKO_IS_FW_ISO_RESOURCE_ONCE(self)); + g_return_if_fail(error != NULL && *error == NULL); + + g_return_if_fail(channel < 64); + g_return_if_fail(bandwidth > 0); + + res.channels = 1ull << channel; + res.bandwidth = bandwidth; + + hinoko_fw_iso_resource_ioctl(HINOKO_FW_ISO_RESOURCE(self), + FW_CDEV_IOC_DEALLOCATE_ISO_RESOURCE_ONCE, &res, error); +} + +/** + * hinoko_fw_iso_resource_once_allocate_sync: + * @self: A [class@FwIsoResourceOnce]. + * @channel_candidates: (array length=channel_candidates_count): The array with elements for + * numeric number for isochronous channel to be allocated. + * @channel_candidates_count: The number of channel candidates. + * @bandwidth: The amount of bandwidth to be allocated. + * @timeout_ms: The timeout to wait for allocated event. + * @error: A [struct@GLib.Error]. Error can be generated with domain of Hinoko.FwIsoResourceError. + * + * Initiate allocation of isochronous resource and wait for [signal@FwIsoResource::allocated] + * signal. + * + * Since: 0.7. + */ +void hinoko_fw_iso_resource_once_allocate_sync(HinokoFwIsoResourceOnce *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_ONCE(self)); + g_return_if_fail(error != NULL && *error == NULL); + + fw_iso_resource_waiter_init(HINOKO_FW_ISO_RESOURCE(self), &w, "allocated", timeout_ms); + + hinoko_fw_iso_resource_once_allocate_async(self, channel_candidates, + channel_candidates_count, bandwidth, error); + + fw_iso_resource_waiter_wait(HINOKO_FW_ISO_RESOURCE(self), &w, error); +} + +/** + * hinoko_fw_iso_resource_once_deallocate_sync: + * @self: A [class@FwIsoResourceOnce]. + * @channel: The channel number to be deallocated. + * @bandwidth: The amount of bandwidth to be deallocated. + * @timeout_ms: The timeout to wait for deallocated event. + * @error: A [struct@GLib.Error]. Error can be generated with domain of Hinoko.FwIsoResourceError. + * + * Initiate deallocation of isochronous resource and wait for [signal@FwIsoResource::deallocated] + * signal. + * + * Since: 0.7. + */ +void hinoko_fw_iso_resource_once_deallocate_sync(HinokoFwIsoResourceOnce *self, guint channel, + guint bandwidth, guint timeout_ms, + GError **error) +{ + struct fw_iso_resource_waiter w; + + g_return_if_fail(HINOKO_IS_FW_ISO_RESOURCE_ONCE(self)); + g_return_if_fail(error != NULL && *error == NULL); + + fw_iso_resource_waiter_init(HINOKO_FW_ISO_RESOURCE(self), &w, "deallocated", timeout_ms); + + hinoko_fw_iso_resource_once_deallocate_async(self, channel, bandwidth, error); + + fw_iso_resource_waiter_wait(HINOKO_FW_ISO_RESOURCE(self), &w, error); +} diff --git a/src/fw_iso_resource_once.h b/src/fw_iso_resource_once.h index ab1216b..1093162 100644 --- a/src/fw_iso_resource_once.h +++ b/src/fw_iso_resource_once.h @@ -17,6 +17,24 @@ struct _HinokoFwIsoResourceOnceClass { HinokoFwIsoResourceOnce *hinoko_fw_iso_resource_once_new(); +void hinoko_fw_iso_resource_once_allocate_async(HinokoFwIsoResourceOnce *self, + guint8 *channel_candidates, + gsize channel_candidates_count, + guint bandwidth, GError **error); + +void hinoko_fw_iso_resource_once_deallocate_async(HinokoFwIsoResourceOnce *self, guint channel, + guint bandwidth, GError **error); + +void hinoko_fw_iso_resource_once_allocate_sync(HinokoFwIsoResourceOnce *self, + guint8 *channel_candidates, + gsize channel_candidates_count, + guint bandwidth, guint timeout_ms, + GError **error); + +void hinoko_fw_iso_resource_once_deallocate_sync(HinokoFwIsoResourceOnce *self, guint channel, + guint bandwidth, guint timeout_ms, + GError **error); + G_END_DECLS #endif diff --git a/src/hinoko.map b/src/hinoko.map index a3a06fc..d6756ca 100644 --- a/src/hinoko.map +++ b/src/hinoko.map @@ -55,10 +55,6 @@ HINOKO_0_4_0 { "hinoko_fw_iso_resource_open"; "hinoko_fw_iso_resource_create_source"; "hinoko_fw_iso_resource_calculate_bandwidth"; - "hinoko_fw_iso_resource_allocate_once_async"; - "hinoko_fw_iso_resource_deallocate_once_async"; - "hinoko_fw_iso_resource_allocate_once_sync"; - "hinoko_fw_iso_resource_deallocate_once_sync"; "hinoko_fw_iso_resource_auto_get_type"; "hinoko_fw_iso_resource_auto_new"; @@ -96,4 +92,8 @@ HINOKO_0_7_0 { "hinoko_fw_iso_resource_once_get_type"; "hinoko_fw_iso_resource_once_new"; + "hinoko_fw_iso_resource_once_allocate_async"; + "hinoko_fw_iso_resource_once_deallocate_async"; + "hinoko_fw_iso_resource_once_allocate_sync"; + "hinoko_fw_iso_resource_once_deallocate_sync"; } HINOKO_0_5_0; diff --git a/tests/fw-iso-resource b/tests/fw-iso-resource index f83072b..0c14c1b 100644 --- a/tests/fw-iso-resource +++ b/tests/fw-iso-resource @@ -16,10 +16,6 @@ methods = ( 'open', 'create_source', 'calculate_bandwidth', - 'allocate_once_async', - 'deallocate_once_async', - 'allocate_once_sync', - 'deallocate_once_sync', ) vmethods = ( 'do_allocated', diff --git a/tests/fw-iso-resource-once b/tests/fw-iso-resource-once index 2117f15..1c092d9 100644 --- a/tests/fw-iso-resource-once +++ b/tests/fw-iso-resource-once @@ -13,6 +13,10 @@ target = Hinoko.FwIsoResourceOnce() props = () methods = ( 'new', + 'allocate_async', + 'deallocate_async', + 'allocate_sync', + 'deallocate_sync', ) vmethods = () signals = () |