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 | 3ebe80cfb840ad8ec94fd6f51b270d74becdf316 (patch) | |
tree | a4f6e08feee244114050615fabe4a9b99581ff4c | |
parent | a6bdc52f10c05ef63251aab15a84af9186d13def (diff) | |
download | libhinoko-3ebe80cfb840ad8ec94fd6f51b270d74becdf316.tar.gz |
fw_iso_resource: add interface and implementation for resource allocation
The signature for allocation API is the same in both of
Hinoko.FwIsoResourceAuto and Hinoko.FwIsoResourceOnce, therefore they
can be defined as interface.
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
-rw-r--r-- | src/fw_iso_resource.c | 73 | ||||
-rw-r--r-- | src/fw_iso_resource.h | 14 | ||||
-rw-r--r-- | src/fw_iso_resource_auto.c | 69 | ||||
-rw-r--r-- | src/fw_iso_resource_auto.h | 11 | ||||
-rw-r--r-- | src/fw_iso_resource_once.c | 64 | ||||
-rw-r--r-- | src/fw_iso_resource_once.h | 11 | ||||
-rw-r--r-- | src/hinoko.map | 6 |
7 files changed, 91 insertions, 157 deletions
diff --git a/src/fw_iso_resource.c b/src/fw_iso_resource.c index c201538..a82a923 100644 --- a/src/fw_iso_resource.c +++ b/src/fw_iso_resource.c @@ -130,6 +130,79 @@ gboolean hinoko_fw_iso_resource_create_source(HinokoFwIsoResource *self, GSource } /** + * hinoko_fw_iso_resource_allocate_async: + * @self: A [iface@FwIsoResource]. + * @channel_candidates: (array length=channel_candidates_count): The array with elements for + * numeric number of 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 + * as well as domain depending on each implementation. + * + * Initiate allocation of isochronous resource without any wait. One of the candidates is actually + * allocated for channel. When the allocation finishes, [signal@FwIsoResource::allocated] signal is + * emitted to notify the result, channel, and bandwidth. + * + * Returns: TRUE if the overall operation finishes successfully, otherwise FALSE. + * + * Since: 0.7. + */ +gboolean hinoko_fw_iso_resource_allocate_async(HinokoFwIsoResource *self, + guint8 *channel_candidates, + gsize channel_candidates_count, + guint bandwidth, GError **error) +{ + g_return_val_if_fail(HINOKO_IS_FW_ISO_RESOURCE(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); + + return HINOKO_FW_ISO_RESOURCE_GET_IFACE(self)->allocate_async(self, channel_candidates, + channel_candidates_count, + bandwidth, error); +} + +/** + * hinoko_fw_iso_resource_allocate_sync: + * @self: A [iface@FwIsoResource]. + * @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 + * as well as domain depending on each implementation. + * + * Initiate allocation of isochronous resource and wait for [signal@FwIsoResource::allocated] + * signal. One of the candidates is actually allocated for channel. + * + * Returns: TRUE if the overall operation finishes successfully, otherwise FALSE. + * + * Since: 0.7. + */ +gboolean hinoko_fw_iso_resource_allocate_sync(HinokoFwIsoResource *self, + guint8 *channel_candidates, + gsize channel_candidates_count, + guint bandwidth, guint timeout_ms, GError **error) +{ + struct fw_iso_resource_waiter w; + + g_return_val_if_fail(HINOKO_IS_FW_ISO_RESOURCE(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); + + fw_iso_resource_waiter_init(&w, self, ALLOCATED_SIGNAL_NAME, timeout_ms); + + (void)hinoko_fw_iso_resource_allocate_async(self, channel_candidates, + channel_candidates_count, bandwidth, error); + + return fw_iso_resource_waiter_wait(&w, self, error); +} + +/** * hinoko_fw_iso_resource_calculate_bandwidth: * @bytes_per_payload: The number of bytes in payload of isochronous packet. * @scode: The speed of transmission. diff --git a/src/fw_iso_resource.h b/src/fw_iso_resource.h index 9a89b24..2b3c966 100644 --- a/src/fw_iso_resource.h +++ b/src/fw_iso_resource.h @@ -20,6 +20,10 @@ struct _HinokoFwIsoResourceInterface { gboolean (*open)(HinokoFwIsoResource *self, const gchar *path, gint open_flag, GError **error); + gboolean (*allocate_async)(HinokoFwIsoResource *self, + guint8 *channel_candidates, gsize channel_candidates_count, + guint bandwidth, GError **error); + gboolean (*create_source)(HinokoFwIsoResource *self, GSource **source, GError **error); /** @@ -59,6 +63,16 @@ gboolean hinoko_fw_iso_resource_open(HinokoFwIsoResource *self, const gchar *pat gboolean hinoko_fw_iso_resource_create_source(HinokoFwIsoResource *self, GSource **source, GError **error); +gboolean hinoko_fw_iso_resource_allocate_async(HinokoFwIsoResource *self, + guint8 *channel_candidates, + gsize channel_candidates_count, + guint bandwidth, GError **error); + +gboolean hinoko_fw_iso_resource_allocate_sync(HinokoFwIsoResource *self, + guint8 *channel_candidates, + gsize channel_candidates_count, + guint bandwidth, guint timeout_ms, GError **error); + guint hinoko_fw_iso_resource_calculate_bandwidth(guint bytes_per_payload, HinokoFwScode scode); diff --git a/src/fw_iso_resource_auto.c b/src/fw_iso_resource_auto.c index bdbcd31..4cb59a4 100644 --- a/src/fw_iso_resource_auto.c +++ b/src/fw_iso_resource_auto.c @@ -291,6 +291,7 @@ static gboolean fw_iso_resource_auto_create_source(HinokoFwIsoResource *inst, GS static void fw_iso_resource_iface_init(HinokoFwIsoResourceInterface *iface) { iface->open = fw_iso_resource_auto_open; + iface->allocate_async = fw_iso_resource_auto_allocate_async; iface->create_source = fw_iso_resource_auto_create_source; } @@ -308,35 +309,6 @@ HinokoFwIsoResourceAuto *hinoko_fw_iso_resource_auto_new() } /** - * hinoko_fw_iso_resource_auto_allocate_async: - * @self: A [class@FwIsoResourceAuto] - * @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 and Hinoko.FwIsoResourceAutoError. - * - * 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, otherwise FALSE. - * - * Since: 0.7. - */ -gboolean hinoko_fw_iso_resource_auto_allocate_async(HinokoFwIsoResourceAuto *self, - guint8 *channel_candidates, - gsize channel_candidates_count, - guint bandwidth, - GError **error) -{ - return fw_iso_resource_auto_allocate_async(HINOKO_FW_ISO_RESOURCE(self), - channel_candidates, channel_candidates_count, - bandwidth, error); -} - -/** * hinoko_fw_iso_resource_auto_deallocate_async: * @self: A [class@FwIsoResourceAuto] * @error: A [struct@GLib.Error]. Error can be generated with domain of @@ -388,45 +360,6 @@ end: } /** - * hinoko_fw_iso_resource_auto_allocate_sync: - * @self: A [class@FwIsoResourceAuto] - * @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. - * @timeout_ms: The timeout to wait for allocated event. - * @error: A [struct@GLib.Error]. Error can be generated with domain of - * Hinoko.FwIsoResourceError, and Hinoko.FwIsoResourceAutoError. - * - * Initiate allocation of isochronous resource and wait for [signal@FwIsoResource::allocated] - * signal. When the call is successful, [property@FwIsoResourceAuto:channel] and - * [property@FwIsoResourceAuto:bandwidth] properties are available. - * - * Returns: TRUE if the overall operation finished successfully, otherwise FALSE. - * - * Since: 0.7. - */ -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_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); - - (void)hinoko_fw_iso_resource_auto_allocate_async(self, channel_candidates, - channel_candidates_count, bandwidth, error); - - return fw_iso_resource_waiter_wait(&w, HINOKO_FW_ISO_RESOURCE(self), error); -} - -/** * hinoko_fw_iso_resource_auto_deallocate_sync: * @self: A [class@FwIsoResourceAuto] * @timeout_ms: The timeout to wait for allocated event by milli second unit. diff --git a/src/fw_iso_resource_auto.h b/src/fw_iso_resource_auto.h index ed4aa67..44c67c0 100644 --- a/src/fw_iso_resource_auto.h +++ b/src/fw_iso_resource_auto.h @@ -21,17 +21,6 @@ struct _HinokoFwIsoResourceAutoClass { 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, diff --git a/src/fw_iso_resource_once.c b/src/fw_iso_resource_once.c index dd72172..99d01a5 100644 --- a/src/fw_iso_resource_once.c +++ b/src/fw_iso_resource_once.c @@ -183,6 +183,7 @@ static gboolean fw_iso_resource_once_create_source(HinokoFwIsoResource *inst, GS static void fw_iso_resource_iface_init(HinokoFwIsoResourceInterface *iface) { iface->open = fw_iso_resource_once_open; + iface->allocate_async = fw_iso_resource_once_allocate_async; iface->create_source = fw_iso_resource_once_create_source; } @@ -202,32 +203,6 @@ HinokoFwIsoResourceOnce *hinoko_fw_iso_resource_once_new() } /** - * 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. - * - * Returns: TRUE if the overall operation finishes successfully, otherwise FALSE. - * - * Since: 0.7. - */ -gboolean hinoko_fw_iso_resource_once_allocate_async(HinokoFwIsoResourceOnce *self, - guint8 *channel_candidates, - gsize channel_candidates_count, - guint bandwidth, GError **error) -{ - return fw_iso_resource_once_allocate_async(HINOKO_FW_ISO_RESOURCE(self), - channel_candidates, channel_candidates_count, - bandwidth, error); -} - -/** * hinoko_fw_iso_resource_once_deallocate_async: * @self: A [class@FwIsoResourceOnce]. * @channel: The channel number to be deallocated. @@ -273,43 +248,6 @@ gboolean hinoko_fw_iso_resource_once_deallocate_async(HinokoFwIsoResourceOnce *s } /** - * 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. - * - * Returns: TRUE if the overall operation finishes successfully, otherwise FALSE. - * - * Since: 0.7. - */ -gboolean 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_val_if_fail(HINOKO_IS_FW_ISO_RESOURCE_ONCE(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); - - (void)hinoko_fw_iso_resource_once_allocate_async(self, channel_candidates, - channel_candidates_count, bandwidth, error); - - return fw_iso_resource_waiter_wait(&w, HINOKO_FW_ISO_RESOURCE(self), error); -} - -/** * hinoko_fw_iso_resource_once_deallocate_sync: * @self: A [class@FwIsoResourceOnce]. * @channel: The channel number to be deallocated. diff --git a/src/fw_iso_resource_once.h b/src/fw_iso_resource_once.h index 949aceb..d645a7f 100644 --- a/src/fw_iso_resource_once.h +++ b/src/fw_iso_resource_once.h @@ -17,20 +17,9 @@ struct _HinokoFwIsoResourceOnceClass { HinokoFwIsoResourceOnce *hinoko_fw_iso_resource_once_new(); -gboolean hinoko_fw_iso_resource_once_allocate_async(HinokoFwIsoResourceOnce *self, - guint8 *channel_candidates, - gsize channel_candidates_count, - guint bandwidth, GError **error); - gboolean hinoko_fw_iso_resource_once_deallocate_async(HinokoFwIsoResourceOnce *self, guint channel, guint bandwidth, GError **error); -gboolean hinoko_fw_iso_resource_once_allocate_sync(HinokoFwIsoResourceOnce *self, - guint8 *channel_candidates, - gsize channel_candidates_count, - guint bandwidth, guint timeout_ms, - GError **error); - gboolean hinoko_fw_iso_resource_once_deallocate_sync(HinokoFwIsoResourceOnce *self, guint channel, guint bandwidth, guint timeout_ms, GError **error); diff --git a/src/hinoko.map b/src/hinoko.map index 40e7567..cf60eb9 100644 --- a/src/hinoko.map +++ b/src/hinoko.map @@ -73,17 +73,15 @@ HINOKO_0_7_0 { "hinoko_fw_iso_resource_get_type"; "hinoko_fw_iso_resource_open"; "hinoko_fw_iso_resource_create_source"; + "hinoko_fw_iso_resource_allocate_async"; + "hinoko_fw_iso_resource_allocate_sync"; "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"; "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; |