Skip to content

Commit

Permalink
genicam: store genicam URL in ArvDomDocument URL property
Browse files Browse the repository at this point in the history
  • Loading branch information
EmmanuelP authored and eudoxos committed Nov 4, 2023
1 parent 7b261fe commit fad5c5b
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 61 deletions.
19 changes: 13 additions & 6 deletions src/arvfakecamera.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ typedef struct {

char *genicam_xml;
size_t genicam_xml_size;
char *genicam_xml_url;

guint32 frame_id;
double trigger_frequency;
Expand Down Expand Up @@ -939,6 +940,13 @@ arv_fake_camera_get_heartbeat_timeout (ArvFakeCamera *camera)
return value;
}

const char *
arv_fake_camera_get_genicam_xml_url (ArvFakeCamera *camera){
g_return_val_if_fail (ARV_IS_FAKE_CAMERA (camera), NULL);

return camera->priv->genicam_xml_url;
}

/**
* arv_fake_camera_get_genicam_xml:
* @camera: a #ArvFakeCamera
Expand Down Expand Up @@ -970,7 +978,6 @@ arv_fake_camera_new_full (const char *serial_number, const char *genicam_filenam
GError *error = NULL;
char *filename;
void *memory;
char *xml_url;

g_return_val_if_fail (serial_number != NULL, NULL);
g_return_val_if_fail (*serial_number != '\0', NULL);
Expand Down Expand Up @@ -1027,11 +1034,10 @@ arv_fake_camera_new_full (const char *serial_number, const char *genicam_filenam
strcpy (((char *) memory) + ARV_GVBS_DEVICE_VERSION_OFFSET, ARAVIS_VERSION);
strcpy (((char *) memory) + ARV_GVBS_SERIAL_NUMBER_OFFSET, serial_number);

xml_url = g_strdup_printf ("Local:arv-fake-camera.xml;%x;%x",
ARV_FAKE_CAMERA_MEMORY_SIZE,
(unsigned int) fake_camera->priv->genicam_xml_size);
strcpy (((char *) memory) + ARV_GVBS_XML_URL_0_OFFSET, xml_url);
g_free (xml_url);
fake_camera->priv->genicam_xml_url = g_strdup_printf ("Local:///arv-fake-camera.xml;%x;%x",
ARV_FAKE_CAMERA_MEMORY_SIZE,
(unsigned int) fake_camera->priv->genicam_xml_size);
strcpy (((char *) memory) + ARV_GVBS_XML_URL_0_OFFSET, fake_camera->priv->genicam_xml_url);

arv_fake_camera_write_register (fake_camera, ARV_FAKE_CAMERA_REGISTER_SENSOR_WIDTH,
ARV_FAKE_CAMERA_SENSOR_WIDTH);
Expand Down Expand Up @@ -1103,6 +1109,7 @@ arv_fake_camera_finalize (GObject *object)
g_mutex_clear (&fake_camera->priv->fill_pattern_mutex);
g_clear_pointer (&fake_camera->priv->memory, g_free);
g_clear_pointer (&fake_camera->priv->genicam_xml, g_free);
g_clear_pointer (&fake_camera->priv->genicam_xml_url, g_free);

G_OBJECT_CLASS (arv_fake_camera_parent_class)->finalize (object);
}
Expand Down
1 change: 1 addition & 0 deletions src/arvfakecamera.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ ARV_API gboolean arv_fake_camera_is_in_software_trigger_mode (ArvFakeCamera *ca
ARV_API gboolean arv_fake_camera_check_and_acknowledge_software_trigger (ArvFakeCamera *camera);

ARV_API const char * arv_fake_camera_get_genicam_xml (ArvFakeCamera *camera, size_t *size);
ARV_API const char * arv_fake_camera_get_genicam_xml_url (ArvFakeCamera *camera);

G_END_DECLS

Expand Down
1 change: 1 addition & 0 deletions src/arvfakedevice.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ arv_fake_device_constructed (GObject *self)
}

arv_gc_set_default_gv_features(priv->genicam);
arv_dom_document_set_url(ARV_DOM_DOCUMENT(priv->genicam), arv_fake_camera_get_genicam_xml_url(priv->camera));
}

static void
Expand Down
96 changes: 49 additions & 47 deletions src/arvgvdevice.c
Original file line number Diff line number Diff line change
Expand Up @@ -1258,7 +1258,7 @@ arv_gv_device_is_controller (ArvGvDevice *gv_device)
}

static char *
_load_genicam (ArvGvDevice *gv_device, guint32 address, size_t *size, GError **error)
_load_genicam (ArvGvDevice *gv_device, guint32 address, size_t *size, char **url, GError **error)
{
GError *local_error = NULL;
char filename[ARV_GVBS_XML_URL_SIZE];
Expand All @@ -1269,8 +1269,10 @@ _load_genicam (ArvGvDevice *gv_device, guint32 address, size_t *size, GError **
guint64 file_size;

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

*size = 0;
*url = NULL;

if (!arv_gv_device_read_memory (ARV_DEVICE (gv_device), address, ARV_GVBS_XML_URL_SIZE, filename, error))
return NULL;
Expand All @@ -1287,8 +1289,10 @@ _load_genicam (ArvGvDevice *gv_device, guint32 address, size_t *size, GError **
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 ("[GvDevice::load_genicam] Xml address = 0x%" G_GINT64_MODIFIER "x - "
"size = 0x%" G_GINT64_MODIFIER "x - %s", file_address, file_size, path);
Expand Down Expand Up @@ -1330,17 +1334,22 @@ _load_genicam (ArvGvDevice *gv_device, guint32 address, size_t *size, GError **
&tmp_buffer_size);

g_free (genicam);
file_size = tmp_buffer_size;
*size = tmp_buffer_size;
genicam = tmp_buffer;
} else
} else {
arv_warning_device ("[GvDevice::load_genicam] Invalid format");
g_clear_pointer (&genicam, g_free);
}
arv_zip_free (zip);
} else {
*size = file_size;
}
*size = file_size;

if (genicam != NULL)
*url = g_strdup_printf ("%s:///%s;%lx;%lx", scheme, path,
file_address, file_size);
} else {
g_free (genicam);
genicam = NULL;
*size = 0;
g_clear_pointer (&genicam, g_free);
}
}
} else if (g_ascii_strcasecmp (scheme, "http")) {
Expand All @@ -1356,8 +1365,10 @@ _load_genicam (ArvGvDevice *gv_device, guint32 address, size_t *size, GError **
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 @@ -1368,51 +1379,26 @@ _load_genicam (ArvGvDevice *gv_device, guint32 address, size_t *size, GError **
}
}

g_free (scheme);
g_free (path);

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);

return genicam;
}

static const char *
_get_genicam_xml (ArvDevice *device, size_t *size, GError **error)
arv_gv_device_get_genicam_xml (ArvDevice *device, size_t *size)
{
ArvGvDevice *gv_device = ARV_GV_DEVICE (device);
ArvGvDevicePrivate *priv = arv_gv_device_get_instance_private (gv_device);
GError *local_error = NULL;
char *xml;

if (priv->genicam_xml != NULL) {
*size = priv->genicam_xml_size;
return priv->genicam_xml;
}

*size = 0;

xml = _load_genicam (gv_device, ARV_GVBS_XML_URL_0_OFFSET, size, &local_error);
if (xml == NULL && local_error == NULL)
xml = _load_genicam (gv_device, ARV_GVBS_XML_URL_1_OFFSET, size, &local_error);

if (local_error != NULL) {
g_propagate_error (error, local_error);
return NULL;
}

priv->genicam_xml = xml;
priv->genicam_xml_size = *size;
ArvGvDevicePrivate *priv = arv_gv_device_get_instance_private (ARV_GV_DEVICE (device));

return xml;
}
if (size != NULL)
*size = priv->genicam_xml_size;

static const char *
arv_gv_device_get_genicam_xml (ArvDevice *device, size_t *size)
{
return _get_genicam_xml (device, size, NULL);
return priv->genicam_xml;
}

void
Expand Down Expand Up @@ -1830,15 +1816,31 @@ static void
arv_gv_device_load_genicam (ArvGvDevice *gv_device, GError **error)
{
ArvGvDevicePrivate *priv = arv_gv_device_get_instance_private (gv_device);
const char *genicam;
GError *local_error = NULL;
char *url = NULL;
char *xml;
size_t size;

genicam = _get_genicam_xml (ARV_DEVICE (gv_device), &size, error);
if (genicam != NULL) {
priv->genicam = arv_gc_new (ARV_DEVICE (gv_device), genicam, size);
size = 0;

arv_gc_set_default_gv_features(priv->genicam);
xml = _load_genicam (gv_device, ARV_GVBS_XML_URL_0_OFFSET, &size, &url, &local_error);
if (xml == NULL && local_error == NULL)
xml = _load_genicam (gv_device, ARV_GVBS_XML_URL_1_OFFSET, &size, &url, &local_error);

if (local_error != NULL) {
g_propagate_error (error, local_error);
g_free (xml);
g_free (url);
return;
}

priv->genicam_xml = xml;
priv->genicam_xml_size = size;
priv->genicam = arv_gc_new (ARV_DEVICE (gv_device), xml, size);
arv_gc_set_default_gv_features(priv->genicam);
arv_dom_document_set_url (ARV_DOM_DOCUMENT(priv->genicam), url);

g_free (url);
}

/* ArvDevice implemenation */
Expand Down
26 changes: 18 additions & 8 deletions src/arvuvdevice.c
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,7 @@ _bootstrap (ArvUvDevice *uv_device)
void *data;
char manufacturer[64];
gboolean success = TRUE;
char *genicam_url = NULL;

arv_info_device ("Get genicam");

Expand Down Expand Up @@ -632,9 +633,9 @@ _bootstrap (ArvUvDevice *uv_device)
const char *zip_filename;

zip_filename = arv_zip_file_get_name (zip_files->data);
priv->genicam_xml = arv_zip_get_file (zip,
zip_filename,
&priv->genicam_xml_size);
priv->genicam_xml = arv_zip_get_file (zip,
zip_filename,
&priv->genicam_xml_size);

arv_info_device ("zip file = %s", zip_filename);

Expand All @@ -649,6 +650,11 @@ _bootstrap (ArvUvDevice *uv_device)
priv->genicam = arv_gc_new (ARV_DEVICE (uv_device),
priv->genicam_xml,
priv->genicam_xml_size);

genicam_url = g_strdup_printf("local:///DeviceU3V.zip;%lx;%lx",
entry.address, entry.size);
arv_dom_document_set_url(ARV_DOM_DOCUMENT(priv->genicam), genicam_url);
g_free (genicam_url);
}

arv_zip_free (zip);
Expand All @@ -662,11 +668,15 @@ _bootstrap (ArvUvDevice *uv_device)
priv->genicam = arv_gc_new (ARV_DEVICE (uv_device),
priv->genicam_xml,
priv->genicam_xml_size);
}
break;
default:
arv_warning_device ("Unknown USB3Vision manifest schema type (%d)", schema_type);
}
genicam_url = g_strdup_printf("local:///DeviceU3V.xml;%lx;%lx",
entry.address, entry.size);
arv_dom_document_set_url(ARV_DOM_DOCUMENT(priv->genicam), genicam_url);
g_free (genicam_url);
}
break;
default:
arv_warning_device ("Unknown USB3Vision manifest schema type (%d)", schema_type);
}

#if 0
arv_info_device("GENICAM\n:%s", priv->genicam_xml);
Expand Down

0 comments on commit fad5c5b

Please sign in to comment.