aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>2023-07-23 10:49:49 +0900
committerTakashi Sakamoto <o-takashi@sakamocchi.jp>2023-10-03 21:45:12 +0900
commitef577dca8c76e9b2b6456f4d17b7c32e035e3b1f (patch)
treefaf6f7ad8c0f6ee96d0ebd7a7ab5b2c935544bf7
parentbcd7fb95274fde242b6d7d299fc4ebb03c63e905 (diff)
downloadlibhinawa-ef577dca8c76e9b2b6456f4d17b7c32e035e3b1f.tar.gz
fw_node: change signature of FwNode.open()
The function was defined to return void, while it has an argument for GLib.Error. In GNOME convention, such function should return gboolean. This commit change the signature according to the convention. Furthermore, flag argument is newly added so that applicatin can select options such like O_CLOEXEC. Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
-rwxr-xr-xsamples/gtk32
-rwxr-xr-xsamples/gtk42
-rwxr-xr-xsamples/qt52
-rw-r--r--src/fw_node.c25
-rw-r--r--src/fw_node.h3
-rw-r--r--src/hinawa.map6
6 files changed, 25 insertions, 15 deletions
diff --git a/samples/gtk3 b/samples/gtk3
index 268a4d2..aa0ebd7 100755
--- a/samples/gtk3
+++ b/samples/gtk3
@@ -27,7 +27,7 @@ def main() -> int:
try:
node = Hinawa.FwNode.new()
- node.open(str(path))
+ _ = node.open(str(path), 0)
common.print_fw_node_information(node)
except Exception as e:
msg = str(e)
diff --git a/samples/gtk4 b/samples/gtk4
index 1475a4f..97c3e91 100755
--- a/samples/gtk4
+++ b/samples/gtk4
@@ -27,7 +27,7 @@ def main() -> int:
try:
node = Hinawa.FwNode.new()
- node.open(str(path))
+ _ = node.open(str(path), 0)
common.print_fw_node_information(node)
except Exception as e:
msg = str(e)
diff --git a/samples/qt5 b/samples/qt5
index c9a28b7..019b068 100755
--- a/samples/qt5
+++ b/samples/qt5
@@ -39,7 +39,7 @@ def main() -> int:
try:
node = Hinawa.FwNode.new()
- node.open(str(path))
+ _ = node.open(str(path), 0)
common.print_fw_node_information(node)
except Exception as e:
msg = str(e)
diff --git a/src/fw_node.c b/src/fw_node.c
index 8f54f6e..3efbc4c 100644
--- a/src/fw_node.c
+++ b/src/fw_node.c
@@ -333,30 +333,33 @@ static int update_info(HinawaFwNode *self)
* hinawa_fw_node_open:
* @self: A [class@FwNode]
* @path: A path to Linux FireWire character device
+ * @open_flag: The flag of `open(2)` system call. `O_RDONLY` is fulfilled internally.
* @error: A [struct@GLib.Error]. Error can be generated with two domains; GLib.Error and
* Hinawa.FwNodeError.
*
* Open Linux FireWire character device to operate node on IEEE 1394 bus.
*
- * Since: 1.4.
+ * Returns: TRUE if the overall operation finishes successfully, otherwise FALSE.
+ *
+ * Since: 3.0.
*/
-void hinawa_fw_node_open(HinawaFwNode *self, const gchar *path,
- GError **error)
+gboolean hinawa_fw_node_open(HinawaFwNode *self, const gchar *path, gint open_flag, GError **error)
{
HinawaFwNodePrivate *priv;
int err;
- g_return_if_fail(HINAWA_IS_FW_NODE(self));
- g_return_if_fail(path != NULL && strlen(path) > 0);
- g_return_if_fail(error == NULL || *error == NULL);
+ g_return_val_if_fail(HINAWA_IS_FW_NODE(self), FALSE);
+ g_return_val_if_fail(path != NULL && strlen(path) > 0, FALSE);
+ g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
priv = hinawa_fw_node_get_instance_private(self);
if (priv->fd >= 0) {
generate_local_error(error, HINAWA_FW_NODE_ERROR_OPENED);
- return;
+ return FALSE;
}
- priv->fd = open(path, O_RDONLY);
+ open_flag |= O_RDONLY;
+ priv->fd = open(path, open_flag);
if (priv->fd < 0) {
if (errno == ENODEV) {
generate_local_error(error, HINAWA_FW_NODE_ERROR_DISCONNECTED);
@@ -367,7 +370,7 @@ void hinawa_fw_node_open(HinawaFwNode *self, const gchar *path,
else
generate_syscall_error(error, errno, "open(%s)", path);
}
- return;
+ return FALSE;
}
g_mutex_lock(&priv->mutex);
@@ -381,7 +384,11 @@ void hinawa_fw_node_open(HinawaFwNode *self, const gchar *path,
generate_syscall_error(error, errno, "ioctl(%s)", "FW_CDEV_IOC_GET_INFO");
close(priv->fd);
priv->fd = -1;
+
+ return FALSE;
}
+
+ return TRUE;
}
/**
diff --git a/src/fw_node.h b/src/fw_node.h
index 818a463..15bb339 100644
--- a/src/fw_node.h
+++ b/src/fw_node.h
@@ -41,8 +41,7 @@ struct _HinawaFwNodeClass {
HinawaFwNode *hinawa_fw_node_new(void);
-void hinawa_fw_node_open(HinawaFwNode *self, const gchar *path,
- GError **error);
+gboolean hinawa_fw_node_open(HinawaFwNode *self, const gchar *path, gint open_flag, GError **error);
void hinawa_fw_node_get_config_rom(HinawaFwNode *self, const guint8 **image,
gsize *length, GError **error);
diff --git a/src/hinawa.map b/src/hinawa.map
index 4e439e0..e9719ce 100644
--- a/src/hinawa.map
+++ b/src/hinawa.map
@@ -35,7 +35,6 @@ HINAWA_1_3_0 {
HINAWA_1_4_0 {
"hinawa_fw_node_get_type";
"hinawa_fw_node_new";
- "hinawa_fw_node_open";
"hinawa_fw_node_create_source";
"hinawa_fw_resp_reserve";
@@ -110,3 +109,8 @@ HINAWA_2_6_0 {
"hinawa_fw_fcp_command_with_tstamp";
"hinawa_fw_fcp_avc_transaction_with_tstamp";
} HINAWA_2_5_0;
+
+HINAWA_3_0_0 {
+ global:
+ "hinawa_fw_node_open";
+} HINAWA_2_6_0;