From 58c6e0f745a614b0c9ebbf5cff205d7f06346403 Mon Sep 17 00:00:00 2001 From: Yuto Hamaguchi Date: Wed, 29 Jan 2025 17:11:23 +0900 Subject: [PATCH 1/4] Add gv: option to select discovery network interface --- src/arvcameratest.c | 9 +++++++++ src/arvgvinterface.c | 25 ++++++++++++++++++------- src/arvinterface.c | 22 ++++++++++++++++++++++ src/arvinterfaceprivate.h | 2 ++ src/arvsystem.c | 23 +++++++++++++++++++++++ src/arvsystem.h | 1 + src/arvtool.c | 9 +++++++++ 7 files changed, 84 insertions(+), 7 deletions(-) diff --git a/src/arvcameratest.c b/src/arvcameratest.c index 2b4f66f2e..79939e1f4 100644 --- a/src/arvcameratest.c +++ b/src/arvcameratest.c @@ -45,6 +45,7 @@ static gboolean arv_option_show_version = FALSE; static gboolean arv_option_gv_allow_broadcast_discovery_ack = FALSE; static char *arv_option_gv_port_range = NULL; static gboolean arv_option_native_buffers = FALSE; +static char *arv_option_gv_discovery_interface = NULL; /* clang-format off */ static const GOptionEntry arv_option_entries[] = @@ -227,6 +228,11 @@ static const GOptionEntry arv_option_entries[] = &arv_option_gv_port_range, "GV port range", "-" }, + { + "gv-discovery-interface", '\0', 0, G_OPTION_ARG_STRING, + &arv_option_gv_discovery_interface, "Discovery using the interface", + "" + }, { "native-buffers", '\0', 0, G_OPTION_ARG_NONE, &arv_option_native_buffers, "Enable native buffers", @@ -506,6 +512,9 @@ main (int argc, char **argv) if (arv_option_gv_allow_broadcast_discovery_ack) arv_set_interface_flags ("GigEVision", ARV_GV_INTERFACE_FLAGS_ALLOW_BROADCAST_DISCOVERY_ACK); + if (arv_option_gv_discovery_interface) + arv_set_interface_discovery_option ("GigEVision", arv_option_gv_discovery_interface); + arv_enable_interface ("Fake"); arv_debug_enable (arv_option_debug_domains); diff --git a/src/arvgvinterface.c b/src/arvgvinterface.c index d29f00a15..e19251ec6 100644 --- a/src/arvgvinterface.c +++ b/src/arvgvinterface.c @@ -77,7 +77,7 @@ arv_gv_discover_socket_free (ArvGvDiscoverSocket *discover_socket) } static ArvGvDiscoverSocketList * -arv_gv_discover_socket_list_new (void) +arv_gv_discover_socket_list_new (const char *discovery_interface) { ArvGvDiscoverSocketList *socket_list; GSList *iter; @@ -92,7 +92,7 @@ arv_gv_discover_socket_list_new (void) return socket_list; for (iface_iter = ifaces; iface_iter != NULL; iface_iter = iface_iter->next) { - ArvGvDiscoverSocket *discover_socket = g_new0 (ArvGvDiscoverSocket, 1); + ArvGvDiscoverSocket *discover_socket; GSocketAddress *socket_address; GSocketAddress *socket_broadcast; GInetAddress *inet_address; @@ -101,6 +101,12 @@ arv_gv_discover_socket_list_new (void) char *inet_broadcast_string; GError *error = NULL; gint buffer_size = ARV_GV_INTERFACE_DISCOVERY_SOCKET_BUFFER_SIZE; + + if (discovery_interface != NULL) + if (g_strcmp0 (discovery_interface, arv_network_interface_get_name (iface_iter->data)) != 0) + continue; + + discover_socket = g_new0 (ArvGvDiscoverSocket, 1); socket_address = g_socket_address_new_from_native (arv_network_interface_get_addr(iface_iter->data), sizeof (struct sockaddr)); socket_broadcast = g_socket_address_new_from_native (arv_network_interface_get_broadaddr(iface_iter->data), @@ -354,7 +360,7 @@ struct _ArvGvInterfaceClass { G_DEFINE_TYPE_WITH_CODE (ArvGvInterface, arv_gv_interface, ARV_TYPE_INTERFACE, G_ADD_PRIVATE (ArvGvInterface)) static ArvGvInterfaceDeviceInfos * -_discover (GHashTable *devices, const char *device_id, gboolean allow_broadcast_discovery_ack) +_discover (GHashTable *devices, const char *device_id, gboolean allow_broadcast_discovery_ack, const char *discovery_interface) { ArvGvDiscoverSocketList *socket_list; GSList *iter; @@ -367,7 +373,7 @@ _discover (GHashTable *devices, const char *device_id, gboolean allow_broadcast_ if (devices != NULL) g_hash_table_remove_all (devices); - socket_list = arv_gv_discover_socket_list_new (); + socket_list = arv_gv_discover_socket_list_new (discovery_interface); if (socket_list->n_sockets < 1) { arv_gv_discover_socket_list_free (socket_list); @@ -484,8 +490,9 @@ static void arv_gv_interface_discover (ArvGvInterface *gv_interface) { int flags = arv_interface_get_flags (ARV_INTERFACE(gv_interface)); + const char *discovery_interface = arv_interface_get_discovery_option (ARV_INTERFACE (gv_interface)); - _discover (gv_interface->priv->devices, NULL, flags & ARV_GV_INTERFACE_FLAGS_ALLOW_BROADCAST_DISCOVERY_ACK); + _discover (gv_interface->priv->devices, NULL, flags & ARV_GV_INTERFACE_FLAGS_ALLOW_BROADCAST_DISCOVERY_ACK, discovery_interface); } static GInetAddress * @@ -553,6 +560,7 @@ arv_gv_interface_camera_locate (ArvGvInterface *gv_interface, GInetAddress *devi GList *ifaces; GList *iface_iter; struct sockaddr_in device_sockaddr; + const char *discovery_interface; device_socket_address = g_inet_socket_address_new(device_address, ARV_GVCP_PORT); @@ -580,7 +588,8 @@ arv_gv_interface_camera_locate (ArvGvInterface *gv_interface, GInetAddress *devi g_list_free_full (ifaces, (GDestroyNotify) arv_network_interface_free); } - socket_list = arv_gv_discover_socket_list_new(); + discovery_interface = arv_interface_get_discovery_option (ARV_INTERFACE (gv_interface)); + socket_list = arv_gv_discover_socket_list_new (discovery_interface); if (socket_list->n_sockets < 1) { arv_gv_discover_socket_list_free (socket_list); @@ -730,6 +739,7 @@ arv_gv_interface_open_device (ArvInterface *interface, const char *device_id, GE ArvGvInterfaceDeviceInfos *device_infos; GError *local_error = NULL; int flags; + const char *discovery_interface; device = _open_device (interface, ARV_GV_INTERFACE (interface)->priv->devices, device_id, &local_error); if (ARV_IS_DEVICE (device) || local_error != NULL) { @@ -739,7 +749,8 @@ arv_gv_interface_open_device (ArvInterface *interface, const char *device_id, GE } flags = arv_interface_get_flags (interface); - device_infos = _discover (NULL, device_id, flags & ARV_GVCP_DISCOVERY_PACKET_FLAGS_ALLOW_BROADCAST_ACK); + discovery_interface = arv_interface_get_discovery_option (interface); + device_infos = _discover (NULL, device_id, flags & ARV_GVCP_DISCOVERY_PACKET_FLAGS_ALLOW_BROADCAST_ACK, discovery_interface); if (device_infos != NULL) { GInetAddress *device_address; diff --git a/src/arvinterface.c b/src/arvinterface.c index 60c044391..2c996a057 100644 --- a/src/arvinterface.c +++ b/src/arvinterface.c @@ -36,6 +36,7 @@ typedef struct { GArray *device_ids; int flags; + char *discovery_interface; } ArvInterfacePrivate; G_DEFINE_ABSTRACT_TYPE_WITH_CODE (ArvInterface, arv_interface, G_TYPE_OBJECT, G_ADD_PRIVATE (ArvInterface)) @@ -111,6 +112,24 @@ arv_interface_get_flags (ArvInterface *iface) return priv->flags; } +void +arv_interface_set_discovery_option (ArvInterface *iface, const char *discovery_interface) +{ + ArvInterfacePrivate *priv = arv_interface_get_instance_private (iface); + g_return_if_fail (ARV_IS_INTERFACE (iface)); + + priv->discovery_interface = strdup (discovery_interface); +} + +const char * +arv_interface_get_discovery_option (ArvInterface *iface) +{ + ArvInterfacePrivate *priv = arv_interface_get_instance_private (iface); + g_return_val_if_fail (ARV_IS_INTERFACE (iface), 0); + + return priv->discovery_interface; +} + /** * arv_interface_get_n_devices: * @iface: a #ArvInterface @@ -397,6 +416,7 @@ arv_interface_init (ArvInterface *iface) ArvInterfacePrivate *priv = arv_interface_get_instance_private (iface); priv->device_ids = g_array_new (FALSE, TRUE, sizeof (ArvInterfaceDeviceIds *)); + priv->discovery_interface = NULL; } static void @@ -410,6 +430,8 @@ arv_interface_finalize (GObject *object) arv_interface_clear_device_ids (iface); g_array_free (priv->device_ids, TRUE); priv->device_ids = NULL; + g_free (priv->discovery_interface); + priv->discovery_interface = NULL; } static void diff --git a/src/arvinterfaceprivate.h b/src/arvinterfaceprivate.h index ec72c02cd..e6df5cbb8 100644 --- a/src/arvinterfaceprivate.h +++ b/src/arvinterfaceprivate.h @@ -48,6 +48,8 @@ typedef struct { void arv_interface_set_flags (ArvInterface *iface, int flags); int arv_interface_get_flags (ArvInterface *iface); +void arv_interface_set_discovery_option (ArvInterface *iface, const char *discovery_interface); +const char * arv_interface_get_discovery_option (ArvInterface *iface); G_END_DECLS diff --git a/src/arvsystem.c b/src/arvsystem.c index e7e067a92..e5dbc8d98 100644 --- a/src/arvsystem.c +++ b/src/arvsystem.c @@ -260,6 +260,29 @@ arv_set_interface_flags(const char *interface_id, int flags) g_warning ("[Arv::enable_interface] Unknown interface '%s'", interface_id); } +/** + * arv_set_interface_discovery_option: + * @interface_id: name of the interface + * @discovery_interface: name of the discovery network interface + * + * Set the name of discovery network interface. By default, all network interfaces are enabled + */ + +void +arv_set_interface_discovery_option (const char *interface_id, const char *discovery_interface) +{ + guint i; + g_return_if_fail (interface_id != NULL); + for (i = 0; i < G_N_ELEMENTS (interfaces); i++) + if (strcmp (interface_id, interfaces[i].interface_id) == 0) { + ArvInterface *iface; + iface = interfaces[i].get_interface_instance (); + arv_interface_set_discovery_option (iface, discovery_interface); + return; + } + g_warning ("[Arv::enable_interface] Unknown interface '%s'", interface_id); +} + /** * arv_update_device_list: * diff --git a/src/arvsystem.h b/src/arvsystem.h index 33ee3593f..3f5a40e2f 100644 --- a/src/arvsystem.h +++ b/src/arvsystem.h @@ -40,6 +40,7 @@ ARV_API const char * arv_get_interface_protocol (unsigned int in ARV_API void arv_enable_interface (const char *interface_id); ARV_API void arv_disable_interface (const char *interface_id); ARV_API void arv_set_interface_flags (const char *interface_id, int flags); +ARV_API void arv_set_interface_discovery_option (const char *interface_id, const char *discovery_interface); ARV_API void arv_update_device_list (void); ARV_API unsigned int arv_get_n_devices (void); diff --git a/src/arvtool.c b/src/arvtool.c index 2122a9d33..1f1c696ea 100644 --- a/src/arvtool.c +++ b/src/arvtool.c @@ -37,6 +37,7 @@ static gboolean arv_option_gv_allow_broadcast_discovery_ack = FALSE; static gboolean arv_option_show_time = FALSE; static gboolean arv_option_show_version = FALSE; static char *arv_option_gv_port_range = NULL; +static char *arv_option_gv_discovery_interface = NULL; static const GOptionEntry arv_option_entries[] = { @@ -82,6 +83,11 @@ static const GOptionEntry arv_option_entries[] = &arv_option_gv_port_range, "GV port range", "-" }, + { + "gv-discovery-interface", '\0', 0, G_OPTION_ARG_STRING, + &arv_option_gv_discovery_interface, "Discovery using the interface", + "" + }, { "debug", 'd', 0, G_OPTION_ARG_STRING, &arv_option_debug_domains, NULL, @@ -802,6 +808,9 @@ main (int argc, char **argv) if (arv_option_gv_allow_broadcast_discovery_ack) arv_set_interface_flags ("GigEVision", ARV_GV_INTERFACE_FLAGS_ALLOW_BROADCAST_DISCOVERY_ACK); + if (arv_option_gv_discovery_interface) + arv_set_interface_discovery_option ("GigEVision", arv_option_gv_discovery_interface); + device_id = arv_option_device_address != NULL ? arv_option_device_address : (is_glob_pattern ? NULL : arv_option_device_selection); From 685718d1d60461bf43fb05e815c71f4927c40f30 Mon Sep 17 00:00:00 2001 From: Yuto Hamaguchi Date: Thu, 6 Feb 2025 13:33:36 +0900 Subject: [PATCH 2/4] Rename the setter/getter name of the additional function --- src/arvgvinterface.c | 6 +++--- src/arvinterface.c | 4 ++-- src/arvinterfaceprivate.h | 4 ++-- src/arvsystem.c | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/arvgvinterface.c b/src/arvgvinterface.c index e19251ec6..04881fe8f 100644 --- a/src/arvgvinterface.c +++ b/src/arvgvinterface.c @@ -490,7 +490,7 @@ static void arv_gv_interface_discover (ArvGvInterface *gv_interface) { int flags = arv_interface_get_flags (ARV_INTERFACE(gv_interface)); - const char *discovery_interface = arv_interface_get_discovery_option (ARV_INTERFACE (gv_interface)); + const char *discovery_interface = arv_interface_get_discovery_interface_name (ARV_INTERFACE (gv_interface)); _discover (gv_interface->priv->devices, NULL, flags & ARV_GV_INTERFACE_FLAGS_ALLOW_BROADCAST_DISCOVERY_ACK, discovery_interface); } @@ -588,7 +588,7 @@ arv_gv_interface_camera_locate (ArvGvInterface *gv_interface, GInetAddress *devi g_list_free_full (ifaces, (GDestroyNotify) arv_network_interface_free); } - discovery_interface = arv_interface_get_discovery_option (ARV_INTERFACE (gv_interface)); + discovery_interface = arv_interface_get_discovery_interface_name (ARV_INTERFACE (gv_interface)); socket_list = arv_gv_discover_socket_list_new (discovery_interface); if (socket_list->n_sockets < 1) { @@ -749,7 +749,7 @@ arv_gv_interface_open_device (ArvInterface *interface, const char *device_id, GE } flags = arv_interface_get_flags (interface); - discovery_interface = arv_interface_get_discovery_option (interface); + discovery_interface = arv_interface_get_discovery_interface_name (interface); device_infos = _discover (NULL, device_id, flags & ARV_GVCP_DISCOVERY_PACKET_FLAGS_ALLOW_BROADCAST_ACK, discovery_interface); if (device_infos != NULL) { GInetAddress *device_address; diff --git a/src/arvinterface.c b/src/arvinterface.c index 2c996a057..c3bf5889a 100644 --- a/src/arvinterface.c +++ b/src/arvinterface.c @@ -113,7 +113,7 @@ arv_interface_get_flags (ArvInterface *iface) } void -arv_interface_set_discovery_option (ArvInterface *iface, const char *discovery_interface) +arv_interface_set_discovery_interface_name (ArvInterface *iface, const char *discovery_interface) { ArvInterfacePrivate *priv = arv_interface_get_instance_private (iface); g_return_if_fail (ARV_IS_INTERFACE (iface)); @@ -122,7 +122,7 @@ arv_interface_set_discovery_option (ArvInterface *iface, const char *discovery_i } const char * -arv_interface_get_discovery_option (ArvInterface *iface) +arv_interface_get_discovery_interface_name (ArvInterface *iface) { ArvInterfacePrivate *priv = arv_interface_get_instance_private (iface); g_return_val_if_fail (ARV_IS_INTERFACE (iface), 0); diff --git a/src/arvinterfaceprivate.h b/src/arvinterfaceprivate.h index e6df5cbb8..ba8e07e2b 100644 --- a/src/arvinterfaceprivate.h +++ b/src/arvinterfaceprivate.h @@ -48,8 +48,8 @@ typedef struct { void arv_interface_set_flags (ArvInterface *iface, int flags); int arv_interface_get_flags (ArvInterface *iface); -void arv_interface_set_discovery_option (ArvInterface *iface, const char *discovery_interface); -const char * arv_interface_get_discovery_option (ArvInterface *iface); +void arv_interface_set_discovery_interface_name (ArvInterface *iface, const char *discovery_interface); +const char * arv_interface_get_discovery_interface_name (ArvInterface *iface); G_END_DECLS diff --git a/src/arvsystem.c b/src/arvsystem.c index e5dbc8d98..41054172b 100644 --- a/src/arvsystem.c +++ b/src/arvsystem.c @@ -277,7 +277,7 @@ arv_set_interface_discovery_option (const char *interface_id, const char *discov if (strcmp (interface_id, interfaces[i].interface_id) == 0) { ArvInterface *iface; iface = interfaces[i].get_interface_instance (); - arv_interface_set_discovery_option (iface, discovery_interface); + arv_interface_set_discovery_interface_name (iface, discovery_interface); return; } g_warning ("[Arv::enable_interface] Unknown interface '%s'", interface_id); From 8b020379a4811a6aaf14608f64be0ca62ee82394 Mon Sep 17 00:00:00 2001 From: Yuto Hamaguchi Date: Fri, 7 Feb 2025 10:23:15 +0900 Subject: [PATCH 3/4] Move the setter/getter from ArvInterface to ArvGvInterface --- src/arvgvinterface.c | 22 +++++++++++++++++++--- src/arvgvinterfaceprivate.h | 2 ++ src/arvinterface.c | 22 ---------------------- src/arvinterfaceprivate.h | 2 -- src/arvsystem.c | 2 +- 5 files changed, 22 insertions(+), 28 deletions(-) diff --git a/src/arvgvinterface.c b/src/arvgvinterface.c index 04881fe8f..b60389dc2 100644 --- a/src/arvgvinterface.c +++ b/src/arvgvinterface.c @@ -345,6 +345,7 @@ arv_gv_interface_device_infos_unref (ArvGvInterfaceDeviceInfos *infos) typedef struct { GHashTable *devices; + char *discovery_interface; } ArvGvInterfacePrivate; struct _ArvGvInterface { @@ -359,6 +360,18 @@ struct _ArvGvInterfaceClass { G_DEFINE_TYPE_WITH_CODE (ArvGvInterface, arv_gv_interface, ARV_TYPE_INTERFACE, G_ADD_PRIVATE (ArvGvInterface)) +void +arv_gv_interface_set_discovery_interface_name (ArvInterface *interface, const char *discovery_interface) +{ + ARV_GV_INTERFACE (interface)->priv->discovery_interface = strdup (discovery_interface); +} + +const char * +arv_gv_interface_get_discovery_interface_name (ArvInterface *interface) +{ + return ARV_GV_INTERFACE (interface)->priv->discovery_interface; +} + static ArvGvInterfaceDeviceInfos * _discover (GHashTable *devices, const char *device_id, gboolean allow_broadcast_discovery_ack, const char *discovery_interface) { @@ -490,7 +503,7 @@ static void arv_gv_interface_discover (ArvGvInterface *gv_interface) { int flags = arv_interface_get_flags (ARV_INTERFACE(gv_interface)); - const char *discovery_interface = arv_interface_get_discovery_interface_name (ARV_INTERFACE (gv_interface)); + const char *discovery_interface = arv_gv_interface_get_discovery_interface_name (ARV_INTERFACE (gv_interface)); _discover (gv_interface->priv->devices, NULL, flags & ARV_GV_INTERFACE_FLAGS_ALLOW_BROADCAST_DISCOVERY_ACK, discovery_interface); } @@ -588,7 +601,7 @@ arv_gv_interface_camera_locate (ArvGvInterface *gv_interface, GInetAddress *devi g_list_free_full (ifaces, (GDestroyNotify) arv_network_interface_free); } - discovery_interface = arv_interface_get_discovery_interface_name (ARV_INTERFACE (gv_interface)); + discovery_interface = arv_gv_interface_get_discovery_interface_name (ARV_INTERFACE (gv_interface)); socket_list = arv_gv_discover_socket_list_new (discovery_interface); if (socket_list->n_sockets < 1) { @@ -749,7 +762,7 @@ arv_gv_interface_open_device (ArvInterface *interface, const char *device_id, GE } flags = arv_interface_get_flags (interface); - discovery_interface = arv_interface_get_discovery_interface_name (interface); + discovery_interface = arv_gv_interface_get_discovery_interface_name (interface); device_infos = _discover (NULL, device_id, flags & ARV_GVCP_DISCOVERY_PACKET_FLAGS_ALLOW_BROADCAST_ACK, discovery_interface); if (device_infos != NULL) { GInetAddress *device_address; @@ -810,6 +823,7 @@ arv_gv_interface_init (ArvGvInterface *gv_interface) gv_interface->priv->devices = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, (GDestroyNotify) arv_gv_interface_device_infos_unref); + gv_interface->priv->discovery_interface = NULL; } static void @@ -819,6 +833,8 @@ arv_gv_interface_finalize (GObject *object) g_hash_table_unref (gv_interface->priv->devices); gv_interface->priv->devices = NULL; + g_free (gv_interface->priv->discovery_interface); + gv_interface->priv->discovery_interface = NULL; G_OBJECT_CLASS (arv_gv_interface_parent_class)->finalize (object); } diff --git a/src/arvgvinterfaceprivate.h b/src/arvgvinterfaceprivate.h index a30255566..5da2d30bc 100644 --- a/src/arvgvinterfaceprivate.h +++ b/src/arvgvinterfaceprivate.h @@ -37,6 +37,8 @@ G_BEGIN_DECLS #define ARV_GV_INTERFACE_DISCOVERY_SOCKET_BUFFER_SIZE (256*1024) void arv_gv_interface_destroy_instance (void); +void arv_gv_interface_set_discovery_interface_name (ArvInterface *interface, const char *discovery_interface); +const char * arv_gv_interface_get_discovery_interface_name (ArvInterface *interface); G_END_DECLS diff --git a/src/arvinterface.c b/src/arvinterface.c index c3bf5889a..60c044391 100644 --- a/src/arvinterface.c +++ b/src/arvinterface.c @@ -36,7 +36,6 @@ typedef struct { GArray *device_ids; int flags; - char *discovery_interface; } ArvInterfacePrivate; G_DEFINE_ABSTRACT_TYPE_WITH_CODE (ArvInterface, arv_interface, G_TYPE_OBJECT, G_ADD_PRIVATE (ArvInterface)) @@ -112,24 +111,6 @@ arv_interface_get_flags (ArvInterface *iface) return priv->flags; } -void -arv_interface_set_discovery_interface_name (ArvInterface *iface, const char *discovery_interface) -{ - ArvInterfacePrivate *priv = arv_interface_get_instance_private (iface); - g_return_if_fail (ARV_IS_INTERFACE (iface)); - - priv->discovery_interface = strdup (discovery_interface); -} - -const char * -arv_interface_get_discovery_interface_name (ArvInterface *iface) -{ - ArvInterfacePrivate *priv = arv_interface_get_instance_private (iface); - g_return_val_if_fail (ARV_IS_INTERFACE (iface), 0); - - return priv->discovery_interface; -} - /** * arv_interface_get_n_devices: * @iface: a #ArvInterface @@ -416,7 +397,6 @@ arv_interface_init (ArvInterface *iface) ArvInterfacePrivate *priv = arv_interface_get_instance_private (iface); priv->device_ids = g_array_new (FALSE, TRUE, sizeof (ArvInterfaceDeviceIds *)); - priv->discovery_interface = NULL; } static void @@ -430,8 +410,6 @@ arv_interface_finalize (GObject *object) arv_interface_clear_device_ids (iface); g_array_free (priv->device_ids, TRUE); priv->device_ids = NULL; - g_free (priv->discovery_interface); - priv->discovery_interface = NULL; } static void diff --git a/src/arvinterfaceprivate.h b/src/arvinterfaceprivate.h index ba8e07e2b..ec72c02cd 100644 --- a/src/arvinterfaceprivate.h +++ b/src/arvinterfaceprivate.h @@ -48,8 +48,6 @@ typedef struct { void arv_interface_set_flags (ArvInterface *iface, int flags); int arv_interface_get_flags (ArvInterface *iface); -void arv_interface_set_discovery_interface_name (ArvInterface *iface, const char *discovery_interface); -const char * arv_interface_get_discovery_interface_name (ArvInterface *iface); G_END_DECLS diff --git a/src/arvsystem.c b/src/arvsystem.c index 41054172b..0995d93e5 100644 --- a/src/arvsystem.c +++ b/src/arvsystem.c @@ -277,7 +277,7 @@ arv_set_interface_discovery_option (const char *interface_id, const char *discov if (strcmp (interface_id, interfaces[i].interface_id) == 0) { ArvInterface *iface; iface = interfaces[i].get_interface_instance (); - arv_interface_set_discovery_interface_name (iface, discovery_interface); + arv_gv_interface_set_discovery_interface_name (iface, discovery_interface); return; } g_warning ("[Arv::enable_interface] Unknown interface '%s'", interface_id); From 784ce8c64d70cf46e4fc42eaaa865f42b59f4112 Mon Sep 17 00:00:00 2001 From: Yuto Hamaguchi Date: Fri, 7 Feb 2025 20:05:40 +0900 Subject: [PATCH 4/4] Add setter/getter to the public API, mutex, g_strdup --- src/arvcameratest.c | 2 +- src/arvgvinterface.c | 37 ++++++++++++++++++++++++++++++------- src/arvgvinterface.h | 2 ++ src/arvgvinterfaceprivate.h | 2 -- src/arvsystem.c | 23 ----------------------- src/arvsystem.h | 1 - src/arvtool.c | 2 +- 7 files changed, 34 insertions(+), 35 deletions(-) diff --git a/src/arvcameratest.c b/src/arvcameratest.c index 79939e1f4..7779e8f16 100644 --- a/src/arvcameratest.c +++ b/src/arvcameratest.c @@ -513,7 +513,7 @@ main (int argc, char **argv) arv_set_interface_flags ("GigEVision", ARV_GV_INTERFACE_FLAGS_ALLOW_BROADCAST_DISCOVERY_ACK); if (arv_option_gv_discovery_interface) - arv_set_interface_discovery_option ("GigEVision", arv_option_gv_discovery_interface); + arv_gv_interface_set_discovery_interface_name (arv_option_gv_discovery_interface); arv_enable_interface ("Fake"); diff --git a/src/arvgvinterface.c b/src/arvgvinterface.c index b60389dc2..1a724919f 100644 --- a/src/arvgvinterface.c +++ b/src/arvgvinterface.c @@ -346,6 +346,7 @@ arv_gv_interface_device_infos_unref (ArvGvInterfaceDeviceInfos *infos) typedef struct { GHashTable *devices; char *discovery_interface; + GMutex mutex; } ArvGvInterfacePrivate; struct _ArvGvInterface { @@ -361,15 +362,35 @@ struct _ArvGvInterfaceClass { G_DEFINE_TYPE_WITH_CODE (ArvGvInterface, arv_gv_interface, ARV_TYPE_INTERFACE, G_ADD_PRIVATE (ArvGvInterface)) void -arv_gv_interface_set_discovery_interface_name (ArvInterface *interface, const char *discovery_interface) +arv_gv_interface_set_discovery_interface_name (const char *discovery_interface) { - ARV_GV_INTERFACE (interface)->priv->discovery_interface = strdup (discovery_interface); + ArvInterface *interface; + ArvGvInterfacePrivate *priv; + + interface = arv_gv_interface_get_instance(); + priv = ARV_GV_INTERFACE (interface)->priv; + + g_mutex_lock(&priv->mutex); + g_clear_pointer (&priv->discovery_interface, g_free); + priv->discovery_interface = g_strdup (discovery_interface); + g_mutex_unlock(&priv->mutex); } const char * -arv_gv_interface_get_discovery_interface_name (ArvInterface *interface) +arv_gv_interface_get_discovery_interface_name (void) { - return ARV_GV_INTERFACE (interface)->priv->discovery_interface; + ArvInterface *interface; + ArvGvInterfacePrivate *priv; + const char *discovery_interface; + + interface = arv_gv_interface_get_instance(); + priv = ARV_GV_INTERFACE (interface)->priv; + + g_mutex_lock(&priv->mutex); + discovery_interface = priv->discovery_interface; + g_mutex_unlock(&priv->mutex); + + return discovery_interface; } static ArvGvInterfaceDeviceInfos * @@ -503,7 +524,7 @@ static void arv_gv_interface_discover (ArvGvInterface *gv_interface) { int flags = arv_interface_get_flags (ARV_INTERFACE(gv_interface)); - const char *discovery_interface = arv_gv_interface_get_discovery_interface_name (ARV_INTERFACE (gv_interface)); + const char *discovery_interface = arv_gv_interface_get_discovery_interface_name (); _discover (gv_interface->priv->devices, NULL, flags & ARV_GV_INTERFACE_FLAGS_ALLOW_BROADCAST_DISCOVERY_ACK, discovery_interface); } @@ -601,7 +622,7 @@ arv_gv_interface_camera_locate (ArvGvInterface *gv_interface, GInetAddress *devi g_list_free_full (ifaces, (GDestroyNotify) arv_network_interface_free); } - discovery_interface = arv_gv_interface_get_discovery_interface_name (ARV_INTERFACE (gv_interface)); + discovery_interface = arv_gv_interface_get_discovery_interface_name (); socket_list = arv_gv_discover_socket_list_new (discovery_interface); if (socket_list->n_sockets < 1) { @@ -762,7 +783,7 @@ arv_gv_interface_open_device (ArvInterface *interface, const char *device_id, GE } flags = arv_interface_get_flags (interface); - discovery_interface = arv_gv_interface_get_discovery_interface_name (interface); + discovery_interface = arv_gv_interface_get_discovery_interface_name (); device_infos = _discover (NULL, device_id, flags & ARV_GVCP_DISCOVERY_PACKET_FLAGS_ALLOW_BROADCAST_ACK, discovery_interface); if (device_infos != NULL) { GInetAddress *device_address; @@ -824,6 +845,7 @@ arv_gv_interface_init (ArvGvInterface *gv_interface) gv_interface->priv->devices = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, (GDestroyNotify) arv_gv_interface_device_infos_unref); gv_interface->priv->discovery_interface = NULL; + g_mutex_init(&gv_interface->priv->mutex); } static void @@ -835,6 +857,7 @@ arv_gv_interface_finalize (GObject *object) gv_interface->priv->devices = NULL; g_free (gv_interface->priv->discovery_interface); gv_interface->priv->discovery_interface = NULL; + g_mutex_clear(&gv_interface->priv->mutex); G_OBJECT_CLASS (arv_gv_interface_parent_class)->finalize (object); } diff --git a/src/arvgvinterface.h b/src/arvgvinterface.h index d8bc42c23..656794806 100644 --- a/src/arvgvinterface.h +++ b/src/arvgvinterface.h @@ -48,6 +48,8 @@ typedef enum { ARV_API G_DECLARE_FINAL_TYPE (ArvGvInterface, arv_gv_interface, ARV, GV_INTERFACE, ArvInterface) ARV_API ArvInterface * arv_gv_interface_get_instance (void); +ARV_API void arv_gv_interface_set_discovery_interface_name (const char *discovery_interface); +ARV_API const char * arv_gv_interface_get_discovery_interface_name (void); G_END_DECLS diff --git a/src/arvgvinterfaceprivate.h b/src/arvgvinterfaceprivate.h index 5da2d30bc..a30255566 100644 --- a/src/arvgvinterfaceprivate.h +++ b/src/arvgvinterfaceprivate.h @@ -37,8 +37,6 @@ G_BEGIN_DECLS #define ARV_GV_INTERFACE_DISCOVERY_SOCKET_BUFFER_SIZE (256*1024) void arv_gv_interface_destroy_instance (void); -void arv_gv_interface_set_discovery_interface_name (ArvInterface *interface, const char *discovery_interface); -const char * arv_gv_interface_get_discovery_interface_name (ArvInterface *interface); G_END_DECLS diff --git a/src/arvsystem.c b/src/arvsystem.c index 0995d93e5..e7e067a92 100644 --- a/src/arvsystem.c +++ b/src/arvsystem.c @@ -260,29 +260,6 @@ arv_set_interface_flags(const char *interface_id, int flags) g_warning ("[Arv::enable_interface] Unknown interface '%s'", interface_id); } -/** - * arv_set_interface_discovery_option: - * @interface_id: name of the interface - * @discovery_interface: name of the discovery network interface - * - * Set the name of discovery network interface. By default, all network interfaces are enabled - */ - -void -arv_set_interface_discovery_option (const char *interface_id, const char *discovery_interface) -{ - guint i; - g_return_if_fail (interface_id != NULL); - for (i = 0; i < G_N_ELEMENTS (interfaces); i++) - if (strcmp (interface_id, interfaces[i].interface_id) == 0) { - ArvInterface *iface; - iface = interfaces[i].get_interface_instance (); - arv_gv_interface_set_discovery_interface_name (iface, discovery_interface); - return; - } - g_warning ("[Arv::enable_interface] Unknown interface '%s'", interface_id); -} - /** * arv_update_device_list: * diff --git a/src/arvsystem.h b/src/arvsystem.h index 3f5a40e2f..33ee3593f 100644 --- a/src/arvsystem.h +++ b/src/arvsystem.h @@ -40,7 +40,6 @@ ARV_API const char * arv_get_interface_protocol (unsigned int in ARV_API void arv_enable_interface (const char *interface_id); ARV_API void arv_disable_interface (const char *interface_id); ARV_API void arv_set_interface_flags (const char *interface_id, int flags); -ARV_API void arv_set_interface_discovery_option (const char *interface_id, const char *discovery_interface); ARV_API void arv_update_device_list (void); ARV_API unsigned int arv_get_n_devices (void); diff --git a/src/arvtool.c b/src/arvtool.c index 1f1c696ea..971f375aa 100644 --- a/src/arvtool.c +++ b/src/arvtool.c @@ -809,7 +809,7 @@ main (int argc, char **argv) arv_set_interface_flags ("GigEVision", ARV_GV_INTERFACE_FLAGS_ALLOW_BROADCAST_DISCOVERY_ACK); if (arv_option_gv_discovery_interface) - arv_set_interface_discovery_option ("GigEVision", arv_option_gv_discovery_interface); + arv_gv_interface_set_discovery_interface_name (arv_option_gv_discovery_interface); device_id = arv_option_device_address != NULL ? arv_option_device_address :