[aravis] Start a fake device implementation.
- From: Emmanuel Pacaud <emmanuel src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [aravis] Start a fake device implementation.
- Date: Mon, 3 May 2010 20:20:49 +0000 (UTC)
commit c4a1445ade23a1c5d1ab343e3a78f1605a5058ad
Author: Emmanuel Pacaud <emmanuel gnome org>
Date: Mon May 3 22:20:18 2010 +0200
Start a fake device implementation.
src/Makefile.am | 8 ++-
src/arvfakedevice.c | 116 ++++++++++++++++++++++++++++++++++++++++
src/arvfakedevice.h | 57 ++++++++++++++++++++
src/arvfakestream.c | 148 +++++++++++++++++++++++++++++++++++++++++++++++++++
src/arvfakestream.h | 57 ++++++++++++++++++++
src/arvtypes.h | 3 +
6 files changed, 387 insertions(+), 2 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index d05355b..29966e5 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -57,7 +57,9 @@ libaravis_la_SOURCES = \
arvgvsp.c \
arvgvinterface.c \
arvgvdevice.c \
- arvgvstream.c
+ arvgvstream.c \
+ arvfakedevice.c \
+ arvfakestream.c
ARAVIS_HDRS = \
arv.h \
@@ -93,7 +95,9 @@ ARAVIS_HDRS = \
arvgvsp.h \
arvgvinterface.h \
arvgvdevice.h \
- arvgvstream.h
+ arvgvstream.h \
+ arvfakedevice.h \
+ arvfakestream.h
libaravis_ladir = $(includedir)/aravis
libaravis_la_HEADERS = $(ARAVIS_HDRS)
diff --git a/src/arvfakedevice.c b/src/arvfakedevice.c
new file mode 100644
index 0000000..f44658b
--- /dev/null
+++ b/src/arvfakedevice.c
@@ -0,0 +1,116 @@
+/* Aravis - Digital camera library
+ *
+ * Copyright © 2009-2010 Emmanuel Pacaud
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Author: Emmanuel Pacaud <emmanuel gnome org>
+ */
+
+#include <arvfakedevice.h>
+#include <arvfakestream.h>
+#include <arvdebug.h>
+
+static GObjectClass *parent_class = NULL;
+
+struct _ArvFakeDevicePrivate {
+ char *name;
+};
+
+/* ArvFakeDevice implemenation */
+
+/* ArvDevice implemenation */
+
+static ArvStream *
+arv_fake_device_new_stream (ArvDevice *device, ArvStreamCallback callback, void *user_data)
+{
+ return NULL;
+}
+
+gboolean
+arv_fake_device_read_memory (ArvDevice *device, guint32 address, guint32 size, void *buffer)
+{
+ return FALSE;
+}
+
+gboolean
+arv_fake_device_write_memory (ArvDevice *device, guint32 address, guint32 size, void *buffer)
+{
+ return FALSE;
+}
+
+gboolean
+arv_fake_device_read_register (ArvDevice *device, guint32 address, guint32 *value)
+{
+ return FALSE;
+}
+
+gboolean
+arv_fake_device_write_register (ArvDevice *device, guint32 address, guint32 value)
+{
+ return FALSE;
+}
+
+ArvDevice *
+arv_fake_device_new (const char *name)
+{
+ ArvFakeDevice *fake_device;
+
+ g_return_val_if_fail (name != NULL, NULL);
+
+ fake_device = g_object_new (ARV_TYPE_FAKE_DEVICE, NULL);
+
+ fake_device->priv->name = g_strdup (name);
+
+ return ARV_DEVICE (fake_device);
+}
+
+static void
+arv_fake_device_init (ArvFakeDevice *fake_device)
+{
+ fake_device->priv = G_TYPE_INSTANCE_GET_PRIVATE (fake_device, ARV_TYPE_FAKE_DEVICE, ArvFakeDevicePrivate);
+}
+
+static void
+arv_fake_device_finalize (GObject *object)
+{
+ ArvFakeDevice *fake_device = ARV_FAKE_DEVICE (object);
+
+ g_free (fake_device->priv->name);
+
+ parent_class->finalize (object);
+}
+
+static void
+arv_fake_device_class_init (ArvFakeDeviceClass *fake_device_class)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (fake_device_class);
+ ArvDeviceClass *device_class = ARV_DEVICE_CLASS (fake_device_class);
+
+ g_type_class_add_private (fake_device_class, sizeof (ArvFakeDevicePrivate));
+
+ parent_class = g_type_class_peek_parent (fake_device_class);
+
+ object_class->finalize = arv_fake_device_finalize;
+
+ device_class->new_stream = arv_fake_device_new_stream;
+ device_class->read_memory = arv_fake_device_read_memory;
+ device_class->write_memory = arv_fake_device_write_memory;
+ device_class->read_register = arv_fake_device_read_register;
+ device_class->write_register = arv_fake_device_write_register;
+}
+
+G_DEFINE_TYPE (ArvFakeDevice, arv_fake_device, ARV_TYPE_DEVICE)
diff --git a/src/arvfakedevice.h b/src/arvfakedevice.h
new file mode 100644
index 0000000..26e08e6
--- /dev/null
+++ b/src/arvfakedevice.h
@@ -0,0 +1,57 @@
+/* Aravis - Digital camera library
+ *
+ * Copyright © 2009-2010 Emmanuel Pacaud
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Author: Emmanuel Pacaud <emmanuel gnome org>
+ */
+
+#ifndef ARV_FAKE_DEVICE_H
+#define ARV_FAKE_DEVICE_H
+
+#include <arvtypes.h>
+#include <arvdevice.h>
+
+G_BEGIN_DECLS
+
+#define ARV_TYPE_FAKE_DEVICE (arv_fake_device_get_type ())
+#define ARV_FAKE_DEVICE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), ARV_TYPE_FAKE_DEVICE, ArvFakeDevice))
+#define ARV_FAKE_DEVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), ARV_TYPE_FAKE_DEVICE, ArvFakeDeviceClass))
+#define ARV_IS_FAKE_DEVICE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), ARV_TYPE_FAKE_DEVICE))
+#define ARV_IS_FAKE_DEVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), ARV_TYPE_FAKE_DEVICE))
+#define ARV_FAKE_DEVICE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), ARV_TYPE_FAKE_DEVICE, ArvFakeDeviceClass))
+
+typedef struct _ArvFakeDeviceClass ArvFakeDeviceClass;
+typedef struct _ArvFakeDevicePrivate ArvFakeDevicePrivate;
+
+struct _ArvFakeDevice {
+ ArvDevice device;
+
+ ArvFakeDevicePrivate *priv;
+};
+
+struct _ArvFakeDeviceClass {
+ ArvDeviceClass parent_class;
+};
+
+GType arv_fake_device_get_type (void);
+
+ArvDevice * arv_fake_device_new (const char *name);
+
+G_END_DECLS
+
+#endif
diff --git a/src/arvfakestream.c b/src/arvfakestream.c
new file mode 100644
index 0000000..b7e8502
--- /dev/null
+++ b/src/arvfakestream.c
@@ -0,0 +1,148 @@
+/* Aravis - Digital camera library
+ *
+ * Copyright © 2009-2010 Emmanuel Pacaud
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Author: Emmanuel Pacaud <emmanuel gnome org>
+ */
+
+#include <arvfakestream.h>
+#include <arvbuffer.h>
+#include <arvdebug.h>
+
+static GObjectClass *parent_class = NULL;
+
+/* Acquisition thread */
+
+typedef struct {
+ ArvStreamCallback callback;
+ void *user_data;
+
+ gboolean cancel;
+ GAsyncQueue *input_queue;
+ GAsyncQueue *output_queue;
+
+ /* Statistics */
+
+ guint n_processed_buffers;
+ guint n_failures;
+ guint n_underruns;
+} ArvFakeStreamThreadData;
+
+static void *
+arv_fake_stream_thread (void *data)
+{
+ ArvFakeStreamThreadData *thread_data = data;
+
+ if (thread_data->callback != NULL)
+ thread_data->callback (thread_data->user_data, ARV_STREAM_CALLBACK_TYPE_INIT, NULL);
+
+ if (thread_data->callback != NULL)
+ thread_data->callback (thread_data->user_data, ARV_STREAM_CALLBACK_TYPE_EXIT, NULL);
+
+ return NULL;
+}
+
+/* ArvFakeStream implemenation */
+
+ArvStream *
+arv_fake_stream_new (ArvStreamCallback callback, void *user_data)
+{
+ ArvFakeStream *fake_stream;
+ ArvFakeStreamThreadData *thread_data;
+ ArvStream *stream;
+
+ fake_stream = g_object_new (ARV_TYPE_FAKE_STREAM, NULL);
+
+ stream = ARV_STREAM (fake_stream);
+
+ thread_data = g_new (ArvFakeStreamThreadData, 1);
+ thread_data->callback = callback;
+ thread_data->user_data = user_data;
+ thread_data->cancel = FALSE;
+ thread_data->input_queue = stream->input_queue;
+ thread_data->output_queue = stream->output_queue;
+
+ thread_data->n_processed_buffers = 0;
+ thread_data->n_failures = 0;
+ thread_data->n_underruns = 0;
+
+ fake_stream->thread_data = thread_data;
+
+ fake_stream->thread = g_thread_create (arv_fake_stream_thread, fake_stream->thread_data, TRUE, NULL);
+
+ return ARV_STREAM (fake_stream);
+}
+
+/* ArvStream implementation */
+
+static void
+arv_fake_stream_get_statistics (ArvStream *stream,
+ guint64 *n_processed_buffers,
+ guint64 *n_failures,
+ guint64 *n_underruns)
+{
+ ArvFakeStream *fake_stream = ARV_FAKE_STREAM (stream);
+ ArvFakeStreamThreadData *thread_data;
+
+ thread_data = fake_stream->thread_data;
+
+ *n_processed_buffers = thread_data->n_processed_buffers;
+ *n_failures = thread_data->n_failures;
+ *n_underruns = thread_data->n_underruns;
+}
+
+static void
+arv_fake_stream_init (ArvFakeStream *fake_stream)
+{
+}
+
+static void
+arv_fake_stream_finalize (GObject *object)
+{
+ ArvFakeStream *fake_stream = ARV_FAKE_STREAM (object);
+
+ if (fake_stream->thread != NULL) {
+ ArvFakeStreamThreadData *thread_data;
+
+ thread_data = fake_stream->thread_data;
+
+ thread_data->cancel = TRUE;
+ g_thread_join (fake_stream->thread);
+ g_free (thread_data);
+
+ fake_stream->thread_data = NULL;
+ fake_stream->thread = NULL;
+ }
+
+ parent_class->finalize (object);
+}
+
+static void
+arv_fake_stream_class_init (ArvFakeStreamClass *fake_stream_class)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (fake_stream_class);
+ ArvStreamClass *stream_class = ARV_STREAM_CLASS (fake_stream_class);
+
+ parent_class = g_type_class_peek_parent (fake_stream_class);
+
+ object_class->finalize = arv_fake_stream_finalize;
+
+ stream_class->get_statistics = arv_fake_stream_get_statistics;
+}
+
+G_DEFINE_TYPE (ArvFakeStream, arv_fake_stream, ARV_TYPE_STREAM)
diff --git a/src/arvfakestream.h b/src/arvfakestream.h
new file mode 100644
index 0000000..d5abdfa
--- /dev/null
+++ b/src/arvfakestream.h
@@ -0,0 +1,57 @@
+/* Aravis - Digital camera library
+ *
+ * Copyright © 2009-2010 Emmanuel Pacaud
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Author: Emmanuel Pacaud <emmanuel gnome org>
+ */
+
+#ifndef ARV_FAKE_STREAM_H
+#define ARV_FAKE_STREAM_H
+
+#include <arvtypes.h>
+#include <arvstream.h>
+
+G_BEGIN_DECLS
+
+#define ARV_TYPE_FAKE_STREAM (arv_fake_stream_get_type ())
+#define ARV_FAKE_STREAM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), ARV_TYPE_FAKE_STREAM, ArvFakeStream))
+#define ARV_FAKE_STREAM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), ARV_TYPE_FAKE_STREAM, ArvFakeStreamClass))
+#define ARV_IS_FAKE_STREAM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), ARV_TYPE_FAKE_STREAM))
+#define ARV_IS_FAKE_STREAM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), ARV_TYPE_FAKE_STREAM))
+#define ARV_FAKE_STREAM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), ARV_TYPE_FAKE_STREAM, ArvFakeStreamClass))
+
+typedef struct _ArvFakeStreamClass ArvFakeStreamClass;
+
+struct _ArvFakeStream {
+ ArvStream stream;
+
+ GThread *thread;
+ void *thread_data;
+};
+
+struct _ArvFakeStreamClass {
+ ArvStreamClass parent_class;
+};
+
+GType arv_fake_stream_get_type (void);
+
+ArvStream * arv_fake_stream_new (ArvStreamCallback callback, void *user_data);
+
+G_END_DECLS
+
+#endif
diff --git a/src/arvtypes.h b/src/arvtypes.h
index 97c5c0c..3dab35d 100644
--- a/src/arvtypes.h
+++ b/src/arvtypes.h
@@ -59,6 +59,9 @@ typedef struct _ArvGvInterface ArvGvInterface;
typedef struct _ArvGvDevice ArvGvDevice;
typedef struct _ArvGvStream ArvGvStream;
+typedef struct _ArvFakeDevice ArvFakeDevice;
+typedef struct _ArvFakeStream ArvFakeStream;
+
typedef struct _ArvZip ArvZip;
typedef struct _ArvZipFile ArvZipFile;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]