[aravis/error] gv_device: actually report communication error.
- From: Emmanuel Pacaud <emmanuel src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [aravis/error] gv_device: actually report communication error.
- Date: Thu, 10 May 2012 12:47:35 +0000 (UTC)
commit 3057c94683c13b8624e5bf1b6736b73622820215
Author: Emmanuel Pacaud <emmanuel gnome org>
Date: Thu May 10 14:46:09 2012 +0200
gv_device: actually report communication error.
Only timeout for now. We should also handle write error, when control
access is not granted.
docs/reference/aravis/aravis-sections.txt | 2 +
src/arvdevice.c | 26 ++++++---
src/arvdevice.h | 23 +++++----
src/arvfakedevice.c | 8 ++--
src/arvgcport.c | 4 +-
src/arvgvdevice.c | 84 +++++++++++++++++++----------
src/arvtool.c | 4 +-
tests/arvtest.c | 10 ++--
8 files changed, 102 insertions(+), 59 deletions(-)
---
diff --git a/docs/reference/aravis/aravis-sections.txt b/docs/reference/aravis/aravis-sections.txt
index 73130c5..a93ae96 100644
--- a/docs/reference/aravis/aravis-sections.txt
+++ b/docs/reference/aravis/aravis-sections.txt
@@ -205,8 +205,10 @@ ArvGcPortClass
<SECTION>
<FILE>arvdevice</FILE>
<TITLE>ArvDevice</TITLE>
+ARV_DEVICE_ERROR
ArvDevice
ArvDeviceStatus
+arv_device_error_quark
arv_device_create_stream
arv_device_read_memory
arv_device_write_memory
diff --git a/src/arvdevice.c b/src/arvdevice.c
index 93bc665..61e5e94 100644
--- a/src/arvdevice.c
+++ b/src/arvdevice.c
@@ -49,6 +49,12 @@ static guint arv_device_signals[ARV_DEVICE_SIGNAL_LAST] = {0};
static GObjectClass *parent_class = NULL;
+GQuark
+arv_device_error_quark (void)
+{
+ return g_quark_from_static_string ("arv-device-error-quark");
+}
+
/**
* arv_device_create_stream:
* @device: a #ArvDevice
@@ -69,40 +75,44 @@ arv_device_create_stream (ArvDevice *device, ArvStreamCallback callback, void *u
}
gboolean
-arv_device_read_memory (ArvDevice *device, guint32 address, guint32 size, void *buffer)
+arv_device_read_memory (ArvDevice *device, guint32 address, guint32 size, void *buffer, GError **error)
{
g_return_val_if_fail (ARV_IS_DEVICE (device), FALSE);
g_return_val_if_fail (buffer != NULL, FALSE);
g_return_val_if_fail (size > 0, FALSE);
+ g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
- return ARV_DEVICE_GET_CLASS (device)->read_memory (device, address, size, buffer);
+ return ARV_DEVICE_GET_CLASS (device)->read_memory (device, address, size, buffer, error);
}
gboolean
-arv_device_write_memory (ArvDevice *device, guint32 address, guint32 size, void *buffer)
+arv_device_write_memory (ArvDevice *device, guint32 address, guint32 size, void *buffer, GError **error)
{
g_return_val_if_fail (ARV_IS_DEVICE (device), FALSE);
g_return_val_if_fail (buffer != NULL, FALSE);
g_return_val_if_fail (size > 0, FALSE);
+ g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
- return ARV_DEVICE_GET_CLASS (device)->write_memory (device, address, size, buffer);
+ return ARV_DEVICE_GET_CLASS (device)->write_memory (device, address, size, buffer, error);
}
gboolean
-arv_device_read_register (ArvDevice *device, guint32 address, guint32 *value)
+arv_device_read_register (ArvDevice *device, guint32 address, guint32 *value, GError **error)
{
g_return_val_if_fail (ARV_IS_DEVICE (device), FALSE);
g_return_val_if_fail (value != NULL, FALSE);
+ g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
- return ARV_DEVICE_GET_CLASS (device)->read_register (device, address, value);
+ return ARV_DEVICE_GET_CLASS (device)->read_register (device, address, value, error);
}
gboolean
-arv_device_write_register (ArvDevice *device, guint32 address, guint32 value)
+arv_device_write_register (ArvDevice *device, guint32 address, guint32 value, GError **error)
{
g_return_val_if_fail (ARV_IS_DEVICE (device), FALSE);
+ g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
- return ARV_DEVICE_GET_CLASS (device)->write_register (device, address, value);
+ return ARV_DEVICE_GET_CLASS (device)->write_register (device, address, value, error);
}
/**
diff --git a/src/arvdevice.h b/src/arvdevice.h
index 1e2eab4..41c2c0b 100644
--- a/src/arvdevice.h
+++ b/src/arvdevice.h
@@ -28,6 +28,8 @@
G_BEGIN_DECLS
+#define ARV_DEVICE_ERROR arv_device_error_quark()
+
/**
* ArvDeviceStatus:
* @ARV_DEVICE_STATUS_UNKNOWN: unknown status
@@ -67,10 +69,10 @@ struct _ArvDeviceClass {
const char * (*get_genicam_xml) (ArvDevice *device, size_t *size);
ArvGc * (*get_genicam) (ArvDevice *device);
- gboolean (*read_memory) (ArvDevice *device, guint32 address, guint32 size, void *buffer);
- gboolean (*write_memory) (ArvDevice *device, guint32 address, guint32 size, void *buffer);
- gboolean (*read_register) (ArvDevice *device, guint32 address, guint32 *value);
- gboolean (*write_register) (ArvDevice *device, guint32 address, guint32 value);
+ gboolean (*read_memory) (ArvDevice *device, guint32 address, guint32 size, void *buffer, GError **error);
+ gboolean (*write_memory) (ArvDevice *device, guint32 address, guint32 size, void *buffer, GError **error);
+ gboolean (*read_register) (ArvDevice *device, guint32 address, guint32 *value, GError **error);
+ gboolean (*write_register) (ArvDevice *device, guint32 address, guint32 value, GError **error);
/* signals */
void (*control_lost) (ArvDevice *device);
@@ -78,13 +80,14 @@ struct _ArvDeviceClass {
GType arv_device_get_type (void);
+GQuark arv_device_error_quark (void);
+
ArvStream * arv_device_create_stream (ArvDevice *device, ArvStreamCallback callback, void *user_data);
-gboolean arv_device_read_memory (ArvDevice *device, guint32 address, guint32 size,
- void *buffer);
-gboolean arv_device_write_memory (ArvDevice *device, guint32 address, guint32 size,
- void *buffer);
-gboolean arv_device_read_register (ArvDevice *device, guint32 address, guint32 *value);
-gboolean arv_device_write_register (ArvDevice *device, guint32 address, guint32 value);
+
+gboolean arv_device_read_memory (ArvDevice *device, guint32 address, guint32 size, void *buffer, GError **error);
+gboolean arv_device_write_memory (ArvDevice *device, guint32 address, guint32 size, void *buffer, GError **error);
+gboolean arv_device_read_register (ArvDevice *device, guint32 address, guint32 *value, GError **error);
+gboolean arv_device_write_register (ArvDevice *device, guint32 address, guint32 value, GError **error);
const char * arv_device_get_genicam_xml (ArvDevice *device, size_t *size);
ArvGc * arv_device_get_genicam (ArvDevice *device);
diff --git a/src/arvfakedevice.c b/src/arvfakedevice.c
index 2c6951d..88c3c86 100644
--- a/src/arvfakedevice.c
+++ b/src/arvfakedevice.c
@@ -74,25 +74,25 @@ arv_fake_device_get_genicam (ArvDevice *device)
}
static gboolean
-arv_fake_device_read_memory (ArvDevice *device, guint32 address, guint32 size, void *buffer)
+arv_fake_device_read_memory (ArvDevice *device, guint32 address, guint32 size, void *buffer, GError **error)
{
return arv_fake_camera_read_memory (ARV_FAKE_DEVICE (device)->priv->camera, address, size, buffer);
}
static gboolean
-arv_fake_device_write_memory (ArvDevice *device, guint32 address, guint32 size, void *buffer)
+arv_fake_device_write_memory (ArvDevice *device, guint32 address, guint32 size, void *buffer, GError **error)
{
return arv_fake_camera_write_memory (ARV_FAKE_DEVICE (device)->priv->camera, address, size, buffer);
}
static gboolean
-arv_fake_device_read_register (ArvDevice *device, guint32 address, guint32 *value)
+arv_fake_device_read_register (ArvDevice *device, guint32 address, guint32 *value, GError **error)
{
return arv_fake_camera_read_register (ARV_FAKE_DEVICE (device)->priv->camera, address, value);
}
static gboolean
-arv_fake_device_write_register (ArvDevice *device, guint32 address, guint32 value)
+arv_fake_device_write_register (ArvDevice *device, guint32 address, guint32 value, GError **error)
{
return arv_fake_camera_write_register (ARV_FAKE_DEVICE (device)->priv->camera, address, value);
}
diff --git a/src/arvgcport.c b/src/arvgcport.c
index 8cf2a89..937b95f 100644
--- a/src/arvgcport.c
+++ b/src/arvgcport.c
@@ -53,7 +53,7 @@ arv_gc_port_read (ArvGcPort *port, void *buffer, guint64 address, guint64 length
genicam = arv_gc_node_get_genicam (ARV_GC_NODE (port));
device = arv_gc_get_device (genicam);
- arv_device_read_memory (device, address, length, buffer);
+ arv_device_read_memory (device, address, length, buffer, error);
}
void
@@ -68,7 +68,7 @@ arv_gc_port_write (ArvGcPort *port, void *buffer, guint64 address, guint64 lengt
genicam = arv_gc_node_get_genicam (ARV_GC_NODE (port));
device = arv_gc_get_device (genicam);
- arv_device_write_memory (device, address, length, buffer);
+ arv_device_write_memory (device, address, length, buffer, error);
}
ArvGcNode *
diff --git a/src/arvgvdevice.c b/src/arvgvdevice.c
index 53c1dbe..dc844ff 100644
--- a/src/arvgvdevice.c
+++ b/src/arvgvdevice.c
@@ -83,7 +83,7 @@ static GRegex *arv_gv_device_url_regex = NULL;
}
static gboolean
-_read_memory (ArvGvDeviceIOData *io_data, guint32 address, guint32 size, void *buffer)
+_read_memory (ArvGvDeviceIOData *io_data, guint32 address, guint32 size, void *buffer, GError **error)
{
ArvGvcpPacket *packet;
size_t packet_size;
@@ -146,11 +146,17 @@ _read_memory (ArvGvDeviceIOData *io_data, guint32 address, guint32 size, void *b
g_mutex_unlock (io_data->mutex);
+ if (!success) {
+ if (error != NULL && *error == NULL)
+ *error = g_error_new (ARV_DEVICE_ERROR, ARV_DEVICE_STATUS_TIMEOUT,
+ "[ArvDevice::read_memory] Timeout");
+ }
+
return success;
}
static gboolean
-_write_memory (ArvGvDeviceIOData *io_data, guint32 address, guint32 size, void *buffer)
+_write_memory (ArvGvDeviceIOData *io_data, guint32 address, guint32 size, void *buffer, GError **error)
{
ArvGvcpPacket *packet;
size_t packet_size;
@@ -209,11 +215,17 @@ _write_memory (ArvGvDeviceIOData *io_data, guint32 address, guint32 size, void *
g_mutex_unlock (io_data->mutex);
+ if (!success) {
+ if (error != NULL && *error == NULL)
+ *error = g_error_new (ARV_DEVICE_ERROR, ARV_DEVICE_STATUS_TIMEOUT,
+ "[ArvDevice::write_memory] Timeout");
+ }
+
return success;
}
gboolean
-_read_register (ArvGvDeviceIOData *io_data, guint32 address, guint32 *value_placeholder)
+_read_register (ArvGvDeviceIOData *io_data, guint32 address, guint32 *value_placeholder, GError **error)
{
ArvGvcpPacket *packet;
size_t packet_size;
@@ -268,14 +280,19 @@ _read_register (ArvGvDeviceIOData *io_data, guint32 address, guint32 *value_plac
g_mutex_unlock (io_data->mutex);
- if (!success)
+ if (!success) {
*value_placeholder = 0;
+ if (error != NULL && *error == NULL)
+ *error = g_error_new (ARV_DEVICE_ERROR, ARV_DEVICE_STATUS_TIMEOUT,
+ "[ArvDevice::read_register] Timeout");
+ }
+
return success;
}
gboolean
-_write_register (ArvGvDeviceIOData *io_data, guint32 address, guint32 value)
+_write_register (ArvGvDeviceIOData *io_data, guint32 address, guint32 value, GError **error)
{
ArvGvcpPacket *packet;
size_t packet_size;
@@ -330,6 +347,12 @@ _write_register (ArvGvDeviceIOData *io_data, guint32 address, guint32 value)
g_mutex_unlock (io_data->mutex);
+ if (!success) {
+ if (error != NULL && *error == NULL)
+ *error = g_error_new (ARV_DEVICE_ERROR, ARV_DEVICE_STATUS_TIMEOUT,
+ "[ArvDevice::write_register] Timeout");
+ }
+
return success;
}
@@ -364,7 +387,7 @@ arv_gv_device_heartbeat_thread (void *data)
g_timer_start (timer);
- while (!_read_register (io_data, ARV_GVBS_CONTROL_CHANNEL_PRIVILEGE_OFFSET, &value) &&
+ while (!_read_register (io_data, ARV_GVBS_CONTROL_CHANNEL_PRIVILEGE_OFFSET, &value, NULL) &&
g_timer_elapsed (timer, NULL) < ARV_GV_DEVICE_HEARTBEAT_RETRY_TIMEOUT_S &&
!thread_data->cancel) {
g_usleep (ARV_GV_DEVICE_HEARTBEAT_RETRY_DELAY_US);
@@ -404,7 +427,7 @@ arv_gv_device_take_control (ArvGvDevice *gv_device)
success = arv_device_write_register (ARV_DEVICE (gv_device),
ARV_GVBS_CONTROL_CHANNEL_PRIVILEGE_OFFSET,
- ARV_GVBS_CONTROL_CHANNEL_PRIVILEGE_CONTROL);
+ ARV_GVBS_CONTROL_CHANNEL_PRIVILEGE_CONTROL, NULL);
gv_device->priv->io_data->is_controller = success;
@@ -422,7 +445,7 @@ arv_gv_device_leave_control (ArvGvDevice *gv_device)
gv_device->priv->io_data->is_controller = FALSE;
success = arv_device_write_register (ARV_DEVICE (gv_device),
- ARV_GVBS_CONTROL_CHANNEL_PRIVILEGE_OFFSET, 0);
+ ARV_GVBS_CONTROL_CHANNEL_PRIVILEGE_OFFSET, 0, NULL);
return success;
}
@@ -437,10 +460,10 @@ arv_gv_device_get_timestamp_tick_frequency (ArvGvDevice *gv_device)
if (arv_device_read_register (ARV_DEVICE (gv_device),
ARV_GVBS_TIMESTAMP_TICK_FREQUENCY_HIGH_OFFSET,
- ×tamp_tick_frequency_high) &&
+ ×tamp_tick_frequency_high, NULL) &&
arv_device_read_register (ARV_DEVICE (gv_device),
ARV_GVBS_TIMESTAMP_TICK_FREQUENCY_LOW_OFFSET,
- ×tamp_tick_frequency_low)) {
+ ×tamp_tick_frequency_low, NULL)) {
guint64 timestamp_tick_frequency;
timestamp_tick_frequency = ((guint64) timestamp_tick_frequency_high << 32) |
@@ -476,7 +499,7 @@ _load_genicam (ArvGvDevice *gv_device, guint32 address, size_t *size)
*size = 0;
- if (!arv_device_read_memory (ARV_DEVICE (gv_device), address, ARV_GVBS_XML_URL_SIZE, filename))
+ if (!arv_device_read_memory (ARV_DEVICE (gv_device), address, ARV_GVBS_XML_URL_SIZE, filename, NULL))
return NULL;
filename[ARV_GVBS_XML_URL_SIZE - 1] = '\0';
@@ -504,7 +527,7 @@ _load_genicam (ArvGvDevice *gv_device, guint32 address, size_t *size)
if (file_size > 0) {
genicam = g_malloc (file_size);
if (arv_device_read_memory (ARV_DEVICE (gv_device), file_address, file_size,
- genicam)) {
+ genicam, NULL)) {
genicam [file_size - 1] = '\0';
if (g_str_has_suffix (tokens[2], ".zip")) {
@@ -623,7 +646,7 @@ arv_gv_device_create_stream (ArvDevice *device, ArvStreamCallback callback, void
GInetAddress *interface_address;
GInetAddress *device_address;
- arv_device_read_register (device, ARV_GVBS_N_STREAM_CHANNELS_OFFSET, &n_stream_channels);
+ arv_device_read_register (device, ARV_GVBS_N_STREAM_CHANNELS_OFFSET, &n_stream_channels, NULL);
arv_debug_device ("[GvDevice::create_stream] Number of stream channels = %d", n_stream_channels);
if (n_stream_channels < 1)
@@ -655,9 +678,14 @@ arv_gv_device_create_stream (ArvDevice *device, ArvStreamCallback callback, void
stream_port = arv_gv_stream_get_port (ARV_GV_STREAM (stream));
- arv_device_write_register (device, ARV_GVBS_STREAM_CHANNEL_0_IP_ADDRESS_OFFSET,
- g_htonl(*((guint32 *) address_bytes)));
- arv_device_write_register (device, ARV_GVBS_STREAM_CHANNEL_0_PORT_OFFSET, stream_port);
+ if (!arv_device_write_register (device, ARV_GVBS_STREAM_CHANNEL_0_IP_ADDRESS_OFFSET,
+ g_htonl(*((guint32 *) address_bytes)), NULL) ||
+ !arv_device_write_register (device, ARV_GVBS_STREAM_CHANNEL_0_PORT_OFFSET, stream_port, NULL)) {
+ arv_warning_device ("[GvDevice::create_stream] Stream configuration failed");
+
+ g_object_unref (stream);
+ return NULL;
+ }
arv_debug_device ("[GvDevice::create_stream] Stream port = %d", stream_port);
@@ -672,8 +700,8 @@ arv_gv_device_get_genicam (ArvDevice *device)
return gv_device->priv->genicam;
}
-gboolean
-arv_gv_device_read_memory (ArvDevice *device, guint32 address, guint32 size, void *buffer)
+static gboolean
+arv_gv_device_read_memory (ArvDevice *device, guint32 address, guint32 size, void *buffer, GError **error)
{
ArvGvDevice *gv_device = ARV_GV_DEVICE (device);
int i;
@@ -683,15 +711,15 @@ arv_gv_device_read_memory (ArvDevice *device, guint32 address, guint32 size, voi
block_size = MIN (ARV_GVCP_DATA_SIZE_MAX, size - i * ARV_GVCP_DATA_SIZE_MAX);
if (!_read_memory (gv_device->priv->io_data,
address + i * ARV_GVCP_DATA_SIZE_MAX,
- block_size, buffer + i * ARV_GVCP_DATA_SIZE_MAX))
+ block_size, buffer + i * ARV_GVCP_DATA_SIZE_MAX, error))
return FALSE;
}
return TRUE;
}
-gboolean
-arv_gv_device_write_memory (ArvDevice *device, guint32 address, guint32 size, void *buffer)
+static gboolean
+arv_gv_device_write_memory (ArvDevice *device, guint32 address, guint32 size, void *buffer, GError **error)
{
ArvGvDevice *gv_device = ARV_GV_DEVICE (device);
int i;
@@ -701,27 +729,27 @@ arv_gv_device_write_memory (ArvDevice *device, guint32 address, guint32 size, vo
block_size = MIN (ARV_GVCP_DATA_SIZE_MAX, size - i * ARV_GVCP_DATA_SIZE_MAX);
if (!_write_memory (gv_device->priv->io_data,
address + i * ARV_GVCP_DATA_SIZE_MAX,
- block_size, buffer + i * ARV_GVCP_DATA_SIZE_MAX))
+ block_size, buffer + i * ARV_GVCP_DATA_SIZE_MAX, error))
return FALSE;
}
return TRUE;
}
-gboolean
-arv_gv_device_read_register (ArvDevice *device, guint32 address, guint32 *value)
+static gboolean
+arv_gv_device_read_register (ArvDevice *device, guint32 address, guint32 *value, GError **error)
{
ArvGvDevice *gv_device = ARV_GV_DEVICE (device);
- return _read_register (gv_device->priv->io_data, address, value);
+ return _read_register (gv_device->priv->io_data, address, value, error);
}
-gboolean
-arv_gv_device_write_register (ArvDevice *device, guint32 address, guint32 value)
+static gboolean
+arv_gv_device_write_register (ArvDevice *device, guint32 address, guint32 value, GError **error)
{
ArvGvDevice *gv_device = ARV_GV_DEVICE (device);
- return _write_register (gv_device->priv->io_data, address, value);
+ return _write_register (gv_device->priv->io_data, address, value, error);
}
ArvDevice *
diff --git a/src/arvtool.c b/src/arvtool.c
index e816c09..37ee87a 100644
--- a/src/arvtool.c
+++ b/src/arvtool.c
@@ -125,10 +125,10 @@ arv_tool_execute_command (int argc, char **argv, const char *device_name)
arv_device_write_register (device,
address,
g_ascii_strtoll (tokens[1],
- NULL, 0));
+ NULL, 0), NULL); /* TODO error handling */
}
- arv_device_read_register (device, address, &value);
+ arv_device_read_register (device, address, &value, NULL); /* TODO error handling */
printf ("R[0x%08x] = 0x%08x\n",
address, value);
diff --git a/tests/arvtest.c b/tests/arvtest.c
index 8570caa..5862575 100644
--- a/tests/arvtest.c
+++ b/tests/arvtest.c
@@ -181,14 +181,14 @@ main (int argc, char **argv)
for (i = 0; i < 30; i++)
arv_stream_push_buffer (stream, arv_buffer_new (value, NULL));
- arv_device_read_register (device, ARV_GVBS_STREAM_CHANNEL_0_PORT_OFFSET, &value);
+ arv_device_read_register (device, ARV_GVBS_STREAM_CHANNEL_0_PORT_OFFSET, &value, NULL);
g_print ("stream port = %d (%d)\n", value, arv_gv_stream_get_port (ARV_GV_STREAM (stream)));
- arv_device_read_memory (device, 0x00014150, 8, memory_buffer);
- arv_device_read_memory (device, 0x000000e8, 16, memory_buffer);
+ arv_device_read_memory (device, 0x00014150, 8, memory_buffer, NULL);
+ arv_device_read_memory (device, 0x000000e8, 16, memory_buffer, NULL);
arv_device_read_memory (device,
ARV_GVBS_USER_DEFINED_NAME_OFFSET,
- ARV_GVBS_USER_DEFINED_NAME_SIZE, memory_buffer);
+ ARV_GVBS_USER_DEFINED_NAME_SIZE, memory_buffer, NULL);
node = arv_gc_get_node (genicam, "AcquisitionStart");
arv_gc_command_execute (ARV_GC_COMMAND (node), NULL);
@@ -205,7 +205,7 @@ main (int argc, char **argv)
} while (buffer != NULL);
} while (!cancel);
- arv_device_read_register (device, ARV_GVBS_STREAM_CHANNEL_0_PORT_OFFSET, &value);
+ arv_device_read_register (device, ARV_GVBS_STREAM_CHANNEL_0_PORT_OFFSET, &value, NULL);
g_print ("stream port = %d (%d)\n", value, arv_gv_stream_get_port (ARV_GV_STREAM (stream)));
arv_stream_get_statistics (stream, &n_processed_buffers, &n_failures, &n_underruns);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]