Skip to content

Commit

Permalink
gentl: store genicam URL in ArvDomDocument URL property
Browse files Browse the repository at this point in the history
  • Loading branch information
EmmanuelP committed Nov 15, 2023
1 parent 5c108bb commit 599f9d4
Showing 1 changed file with 44 additions and 23 deletions.
67 changes: 44 additions & 23 deletions src/arvgentldevice.c
Original file line number Diff line number Diff line change
Expand Up @@ -387,11 +387,11 @@ arv_gentl_device_init (ArvGenTLDevice *gentl_device)
}

static char *
_load_genicam (ArvGenTLDevice *gentl_device, size_t *size)
_load_genicam (ArvGenTLDevice *gentl_device, size_t *size, char **url, GError **error)
{
ArvGenTLDevicePrivate *priv = arv_gentl_device_get_instance_private (gentl_device);
ArvGenTLModule *gentl = arv_gentl_system_get_gentl(priv->gentl_system);

GError *local_error = NULL;
char filename[1024];
size_t filename_size = 1024;
char *genicam = NULL;
Expand All @@ -400,15 +400,19 @@ _load_genicam (ArvGenTLDevice *gentl_device, size_t *size)
guint64 file_address;
guint64 file_size;
INFO_DATATYPE info_data_type;
GC_ERROR error;
GC_ERROR gc_error;

g_return_val_if_fail (size != NULL, NULL);
g_return_val_if_fail (url != NULL, NULL);

*size = 0;
*url = NULL;

error = gentl->GCGetPortURLInfo(priv->port_handle, 0, URL_INFO_URL, &info_data_type, filename, &filename_size);
if (error != GC_ERR_SUCCESS) {
arv_warning_device("GCGetPortURLInfo: %d", error);
gc_error = gentl->GCGetPortURLInfo(priv->port_handle, 0, URL_INFO_URL, &info_data_type, filename, &filename_size);
if (gc_error != GC_ERR_SUCCESS) {
arv_warning_device("GCGetPortURLInfo: %d", gc_error);
g_set_error (error, ARV_DEVICE_ERROR, ARV_DEVICE_ERROR_NOT_FOUND,
"Failed to get PortURLInfo (%s)", arv_gentl_gc_error_to_string (gc_error));
return NULL;
}

Expand All @@ -420,16 +424,18 @@ _load_genicam (ArvGenTLDevice *gentl_device, size_t *size)
gsize len;

g_file_get_contents (path, &genicam, &len, NULL);
if (genicam)
if (genicam) {
*size = len;
*url = g_strdup (filename);
}
} else if (g_ascii_strcasecmp (scheme, "local") == 0) {
arv_info_device ("[GenTLDevice::load_genicam] Xml address = 0x%" G_GINT64_MODIFIER "x - "
"size = 0x%" G_GINT64_MODIFIER "x - %s", file_address, file_size, path);

if (file_size > 0) {
genicam = g_malloc (file_size);
if (arv_gentl_device_read_memory (ARV_DEVICE (gentl_device), file_address, file_size,
genicam, NULL)) {
genicam, &local_error)) {

if (arv_debug_check (ARV_DEBUG_CATEGORY_MISC, ARV_DEBUG_LEVEL_DEBUG)) {
GString *string = g_string_new ("");
Expand Down Expand Up @@ -463,22 +469,27 @@ _load_genicam (ArvGenTLDevice *gentl_device, size_t *size)
&tmp_buffer_size);

g_free (genicam);
file_size = tmp_buffer_size;
*size = tmp_buffer_size;
genicam = tmp_buffer;
} else
} else {
arv_warning_device ("[GenTLDevice::load_genicam] Invalid format");
g_clear_pointer (&genicam, g_free);
}
arv_zip_free (zip);
}
*size = file_size;
} else {
g_free (genicam);
genicam = NULL;
*size = 0;
}
}
} else if (g_ascii_strcasecmp (scheme, "http")) {
GFile *file;
GFileInputStream *stream;
} else {
*size = file_size;
}

if (genicam != NULL)
*url = g_strdup_printf ("%s:///%s;%lx;%lx", scheme, path,
file_address, file_size);
} else {
g_clear_pointer (&genicam, g_free);
}
}
} else if (g_ascii_strcasecmp (scheme, "http")) {
GFile *file;
GFileInputStream *stream;

file = g_file_new_for_uri (filename);
stream = g_file_read (file, NULL, NULL);
Expand All @@ -489,8 +500,10 @@ _load_genicam (ArvGenTLDevice *gentl_device, size_t *size)
data_stream = g_data_input_stream_new (G_INPUT_STREAM (stream));
genicam = g_data_input_stream_read_upto (data_stream, "", 0, &len, NULL, NULL);

if (genicam)
if (genicam) {
*size = len;
*url = g_strdup (filename);
}

g_object_unref (data_stream);
g_object_unref (stream);
Expand All @@ -500,6 +513,11 @@ _load_genicam (ArvGenTLDevice *gentl_device, size_t *size)
g_critical ("Unkown GENICAM url scheme: '%s'", filename);
}

if (local_error != NULL) {
arv_warning_device("Failed to load GENICAM data: %s", local_error->message);
g_propagate_error (error, local_error);
}

g_free (scheme);
g_free (path);

Expand Down Expand Up @@ -558,6 +576,7 @@ arv_gentl_device_constructed (GObject *self)
ArvGenTLDevice *gentl_device = ARV_GENTL_DEVICE (self);
ArvGenTLDevicePrivate *priv = arv_gentl_device_get_instance_private (gentl_device);
ArvGenTLModule *gentl = arv_gentl_system_get_gentl(priv->gentl_system);
char *url = NULL;

G_OBJECT_CLASS (arv_gentl_device_parent_class)->constructed (self);

Expand All @@ -579,7 +598,7 @@ arv_gentl_device_constructed (GObject *self)
return;
}

priv->genicam_xml = _load_genicam(gentl_device, &priv->genicam_xml_size);
priv->genicam_xml = _load_genicam (gentl_device, &priv->genicam_xml_size, &url, NULL);
if (priv->genicam_xml == NULL) {
arv_device_take_init_error (ARV_DEVICE (gentl_device),
g_error_new (ARV_DEVICE_ERROR, ARV_DEVICE_ERROR_GENICAM_NOT_FOUND,
Expand All @@ -589,6 +608,8 @@ arv_gentl_device_constructed (GObject *self)
}

priv->genicam = arv_gc_new (ARV_DEVICE(self), priv->genicam_xml, priv->genicam_xml_size);
arv_dom_document_set_url (ARV_DOM_DOCUMENT(priv->genicam), url);
g_free (url);

#if ARAVIS_HAS_EVENT
priv->event_thread_run = 1;
Expand Down

0 comments on commit 599f9d4

Please sign in to comment.