aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>2022-04-18 07:22:29 +0900
committer坂本 貴史 <o-takashi@sakamocchi.jp>2022-04-18 07:25:16 +0900
commit9c08724ca500fdf6e0db3943e778b5641fb03f16 (patch)
treee6f16145e20c5d947eb88ccf5d1a49dea5bc09a8
parent815e6ce478890e4eb0734be18a6942f68f746c27 (diff)
downloadlibhinoko-9c08724ca500fdf6e0db3943e778b5641fb03f16.tar.gz
fw_iso_resource: internal code refactoring to dispatch event
The parameter of event for allocation/deallocation can be parsed to variables of basic type such like unsigned integer. This commit parses it before calling implementation of derived object. Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
-rw-r--r--src/fw_iso_resource.c28
-rw-r--r--src/fw_iso_resource_auto.c19
-rw-r--r--src/internal.h5
3 files changed, 30 insertions, 22 deletions
diff --git a/src/fw_iso_resource.c b/src/fw_iso_resource.c
index b4cfb39..a4716c6 100644
--- a/src/fw_iso_resource.c
+++ b/src/fw_iso_resource.c
@@ -446,15 +446,9 @@ static void handle_iso_resource_event(HinokoFwIsoResource *self,
{
guint channel;
guint bandwidth;
- int sig_type;
+ enum fw_iso_resource_sig_type signal_type;
GError *error = NULL;
- // To change state machine for auto mode.
- if (HINOKO_IS_FW_ISO_RESOURCE_AUTO(self)) {
- hinoko_fw_iso_resource_auto_handle_event(
- HINOKO_FW_ISO_RESOURCE_AUTO(self), ev);
- }
-
if (ev->channel >= 0) {
channel = ev->channel;
bandwidth = ev->bandwidth;
@@ -465,12 +459,24 @@ static void handle_iso_resource_event(HinokoFwIsoResource *self,
}
if (ev->type == FW_CDEV_EVENT_ISO_RESOURCE_ALLOCATED)
- sig_type = FW_ISO_RESOURCE_SIG_ALLOCATED;
+ signal_type = FW_ISO_RESOURCE_SIG_ALLOCATED;
else
- sig_type = FW_ISO_RESOURCE_SIG_DEALLOCATED;
+ signal_type = FW_ISO_RESOURCE_SIG_DEALLOCATED;
+
+ // To change state machine for auto mode.
+ if (HINOKO_IS_FW_ISO_RESOURCE_AUTO(self)) {
+ const char *signal_name;
+
+ if (signal_type == FW_ISO_RESOURCE_SIG_ALLOCATED)
+ signal_name = "allocated";
+ else
+ signal_name = "deallocated";
+
+ hinoko_fw_iso_resource_auto_handle_event(HINOKO_FW_ISO_RESOURCE_AUTO(self),
+ channel, bandwidth, signal_name, error);
+ }
- g_signal_emit(self, fw_iso_resource_sigs[sig_type],
- 0, channel, bandwidth, error);
+ g_signal_emit(self, fw_iso_resource_sigs[signal_type], 0, channel, bandwidth, error);
if (error != NULL)
g_clear_error(&error);
diff --git a/src/fw_iso_resource_auto.c b/src/fw_iso_resource_auto.c
index 75fa004..1ae68f0 100644
--- a/src/fw_iso_resource_auto.c
+++ b/src/fw_iso_resource_auto.c
@@ -349,25 +349,26 @@ void hinoko_fw_iso_resource_auto_deallocate_sync(HinokoFwIsoResourceAuto *self,
*error = w.error; // Delegate ownership.
}
-void hinoko_fw_iso_resource_auto_handle_event(HinokoFwIsoResourceAuto *self,
- struct fw_cdev_event_iso_resource *ev)
+void hinoko_fw_iso_resource_auto_handle_event(HinokoFwIsoResourceAuto *self, guint channel,
+ guint bandwidth, const char *signal_name,
+ const GError *error)
{
HinokoFwIsoResourceAutoPrivate *priv =
hinoko_fw_iso_resource_auto_get_instance_private(self);
- if (ev->type == FW_CDEV_EVENT_ISO_RESOURCE_ALLOCATED) {
- if (ev->channel >= 0) {
+ if (!strcmp(signal_name, "allocated")) {
+ if (error == NULL) {
g_mutex_lock(&priv->mutex);
- priv->channel = ev->channel;
- priv->bandwidth = ev->bandwidth;
+ priv->channel = channel;
+ priv->bandwidth = bandwidth;
priv->allocated = TRUE;
g_mutex_unlock(&priv->mutex);
}
- } else {
- if (ev->channel >= 0) {
+ } else if (!strcmp(signal_name, "deallocated")) {
+ if (error == NULL) {
g_mutex_lock(&priv->mutex);
priv->channel = 0;
- priv->bandwidth -= ev->bandwidth;
+ priv->bandwidth -= bandwidth;
priv->allocated = FALSE;
g_mutex_unlock(&priv->mutex);
}
diff --git a/src/internal.h b/src/internal.h
index 3d2a9fa..9abfff8 100644
--- a/src/internal.h
+++ b/src/internal.h
@@ -43,7 +43,8 @@ void hinoko_fw_iso_resource_ioctl(HinokoFwIsoResource *self,
unsigned long request, void *argp,
GError **error);
-void hinoko_fw_iso_resource_auto_handle_event(HinokoFwIsoResourceAuto *self,
- struct fw_cdev_event_iso_resource *ev);
+void hinoko_fw_iso_resource_auto_handle_event(HinokoFwIsoResourceAuto *self, guint channel,
+ guint bandwidth, const char *signal_name,
+ const GError *error);
#endif