aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>2022-05-03 07:57:47 +0900
committer坂本 貴史 <o-takashi@sakamocchi.jp>2022-05-03 08:31:29 +0900
commitff781a8f99791b6af95894a512dc77d2097f3463 (patch)
treeb67d5e2fde4c43df45628c76e3e77a7d070ecb0d
parent6b925f5d131a46cadb416d7cf22ee5b2c5f25d24 (diff)
downloadlibhinoko-ff781a8f99791b6af95894a512dc77d2097f3463.tar.gz
fw_iso_resource_[auto|once]: code refactoring to initialize local file descritor for future use
The ownership of file descriptor is delegated to derived objects in future. This commit is a preparation for it. Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
-rw-r--r--src/fw_iso_resource_auto.c14
-rw-r--r--src/fw_iso_resource_once.c20
2 files changed, 33 insertions, 1 deletions
diff --git a/src/fw_iso_resource_auto.c b/src/fw_iso_resource_auto.c
index ef459ee..b967b3a 100644
--- a/src/fw_iso_resource_auto.c
+++ b/src/fw_iso_resource_auto.c
@@ -78,6 +78,18 @@ static void fw_iso_resource_auto_get_property(GObject *obj, guint id,
g_mutex_unlock(&priv->mutex);
}
+static void fw_iso_resource_auto_finalize(GObject *obj)
+{
+ HinokoFwIsoResourceAuto *self = HINOKO_FW_ISO_RESOURCE_AUTO(obj);
+ HinokoFwIsoResourceAutoPrivate *priv =
+ hinoko_fw_iso_resource_auto_get_instance_private(self);
+
+ if (priv->fd >= 0)
+ close(priv->fd);
+
+ G_OBJECT_CLASS(hinoko_fw_iso_resource_auto_parent_class)->finalize(obj);
+}
+
static gboolean fw_iso_resource_auto_open(HinokoFwIsoResource *inst, const gchar *path,
gint open_flag, GError **error);
@@ -90,6 +102,7 @@ static void hinoko_fw_iso_resource_auto_class_init(HinokoFwIsoResourceAutoClass
HinokoFwIsoResourceClass *parent_class = HINOKO_FW_ISO_RESOURCE_CLASS(klass);
gobject_class->get_property = fw_iso_resource_auto_get_property;
+ gobject_class->finalize = fw_iso_resource_auto_finalize;
parent_class->open = fw_iso_resource_auto_open;
parent_class->create_source = fw_iso_resource_auto_create_source;
@@ -121,6 +134,7 @@ static void hinoko_fw_iso_resource_auto_init(HinokoFwIsoResourceAuto *self)
HinokoFwIsoResourceAutoPrivate *priv =
hinoko_fw_iso_resource_auto_get_instance_private(self);
+ priv->fd = -1;
g_mutex_init(&priv->mutex);
}
diff --git a/src/fw_iso_resource_once.c b/src/fw_iso_resource_once.c
index 065e0b4..742ae8d 100644
--- a/src/fw_iso_resource_once.c
+++ b/src/fw_iso_resource_once.c
@@ -17,6 +17,18 @@ typedef struct {
G_DEFINE_TYPE_WITH_CODE(HinokoFwIsoResourceOnce, hinoko_fw_iso_resource_once, HINOKO_TYPE_FW_ISO_RESOURCE,
G_ADD_PRIVATE(HinokoFwIsoResourceOnce))
+static void fw_iso_resource_once_finalize(GObject *obj)
+{
+ HinokoFwIsoResourceOnce *self = HINOKO_FW_ISO_RESOURCE_ONCE(obj);
+ HinokoFwIsoResourceOncePrivate *priv =
+ hinoko_fw_iso_resource_once_get_instance_private(self);
+
+ if (priv->fd >= 0)
+ close(priv->fd);
+
+ G_OBJECT_CLASS(hinoko_fw_iso_resource_once_parent_class)->finalize(obj);
+}
+
static gboolean fw_iso_resource_once_open(HinokoFwIsoResource *inst, const gchar *path,
gint open_flag, GError **error);
@@ -25,15 +37,21 @@ static gboolean fw_iso_resource_once_create_source(HinokoFwIsoResource *inst, GS
static void hinoko_fw_iso_resource_once_class_init(HinokoFwIsoResourceOnceClass *klass)
{
+ GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
HinokoFwIsoResourceClass *parent_class = HINOKO_FW_ISO_RESOURCE_CLASS(klass);
+ gobject_class->finalize = fw_iso_resource_once_finalize;
+
parent_class->open = fw_iso_resource_once_open;
parent_class->create_source = fw_iso_resource_once_create_source;
}
static void hinoko_fw_iso_resource_once_init(HinokoFwIsoResourceOnce *self)
{
- return;
+ HinokoFwIsoResourceOncePrivate *priv =
+ hinoko_fw_iso_resource_once_get_instance_private(self);
+
+ priv->fd = -1;
}
static gboolean fw_iso_resource_once_open(HinokoFwIsoResource *inst, const gchar *path,