[gnome-color-manager: 51/80] Add a bare framework for sensor devices



commit dcf0f40f551b3fca7c273c24b439e0e4aad7fcde
Author: Richard Hughes <richard hughsie com>
Date:   Sat Jul 17 23:13:32 2010 +0100

    Add a bare framework for sensor devices

 src/Makefile.am       |    4 +
 src/gcm-sensor-huey.c |  146 ++++++++++++++++++++++++++++
 src/gcm-sensor-huey.h |   66 +++++++++++++
 src/gcm-sensor.c      |  251 +++++++++++++++++++++++++++++++++++++++++++++++++
 src/gcm-sensor.h      |   99 +++++++++++++++++++
 5 files changed, 566 insertions(+), 0 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 0900d3a..53d8ddd 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -393,6 +393,10 @@ install-data-hook:
 	fi
 
 gcm_huey_example_SOURCES =				\
+	gcm-sensor.c					\
+	gcm-sensor.h					\
+	gcm-sensor-huey.c				\
+	gcm-sensor-huey.h				\
 	gcm-huey-example.c
 
 gcm_huey_example_LDADD =				\
diff --git a/src/gcm-sensor-huey.c b/src/gcm-sensor-huey.c
new file mode 100644
index 0000000..4988b23
--- /dev/null
+++ b/src/gcm-sensor-huey.c
@@ -0,0 +1,146 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2010 Richard Hughes <richard hughsie com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+/**
+ * SECTION:gcm-sensor-huey
+ * @short_description: functionality to talk to the HUEY colorimeter.
+ *
+ * This object contains all the low level logic for the HUEY hardware.
+ */
+
+#include "config.h"
+
+#include <glib-object.h>
+
+#include "gcm-sensor-huey.h"
+
+static void     gcm_sensor_huey_finalize	(GObject     *object);
+
+#define GCM_SENSOR_HUEY_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GCM_TYPE_SENSOR_HUEY, GcmSensorHueyPrivate))
+
+/**
+ * GcmSensorHueyPrivate:
+ *
+ * Private #GcmSensorHuey data
+ **/
+struct _GcmSensorHueyPrivate
+{
+	guint				 dave;
+};
+
+G_DEFINE_TYPE (GcmSensorHuey, gcm_sensor_huey, GCM_TYPE_SENSOR)
+
+/**
+ * gcm_sensor_huey_get_ambient:
+ **/
+static gboolean
+gcm_sensor_huey_get_ambient (GcmSensor *sensor_, gdouble *value, GError **error)
+{
+//	GcmSensorHuey *sensor = GCM_SENSOR_HUEY (sensor_);
+	return TRUE;
+}
+
+/**
+ * gcm_sensor_huey_set_leds:
+ **/
+static gboolean
+gcm_sensor_huey_set_leds (GcmSensor *sensor_, guint8 value, GError **error)
+{
+//	GcmSensorHuey *sensor = GCM_SENSOR_HUEY (sensor_);
+	return TRUE;
+}
+
+/**
+ * gcm_sensor_huey_sample:
+ **/
+static gboolean
+gcm_sensor_huey_sample (GcmSensor *sensor_, GcmColorXYZ *value, GError **error)
+{
+//	GcmSensorHuey *sensor = GCM_SENSOR_HUEY (sensor_);
+	return TRUE;
+}
+
+/**
+ * gcm_sensor_huey_startup:
+ **/
+static gboolean
+gcm_sensor_huey_startup (GcmSensor *sensor_, GError **error)
+{
+//	GcmSensorHuey *sensor = GCM_SENSOR_HUEY (sensor_);
+	return TRUE;
+}
+
+/**
+ * gcm_sensor_huey_class_init:
+ **/
+static void
+gcm_sensor_huey_class_init (GcmSensorHueyClass *klass)
+{
+	GObjectClass *object_class = G_OBJECT_CLASS (klass);
+	GcmSensorClass *parent_class = GCM_SENSOR_CLASS (klass);
+	object_class->finalize = gcm_sensor_huey_finalize;
+
+	/* setup klass links */
+	parent_class->get_ambient = gcm_sensor_huey_get_ambient;
+	parent_class->set_leds = gcm_sensor_huey_set_leds;
+	parent_class->sample = gcm_sensor_huey_sample;
+	parent_class->startup = gcm_sensor_huey_startup;
+
+	g_type_class_add_private (klass, sizeof (GcmSensorHueyPrivate));
+}
+
+/**
+ * gcm_sensor_huey_init:
+ **/
+static void
+gcm_sensor_huey_init (GcmSensorHuey *sensor)
+{
+	GcmSensorHueyPrivate *priv;
+
+	priv = sensor->priv = GCM_SENSOR_HUEY_GET_PRIVATE (sensor);
+
+}
+
+/**
+ * gcm_sensor_huey_finalize:
+ **/
+static void
+gcm_sensor_huey_finalize (GObject *object)
+{
+//	GcmSensorHuey *sensor = GCM_SENSOR_HUEY (object);
+//	GcmSensorHueyPrivate *priv = sensor->priv;
+
+	G_OBJECT_CLASS (gcm_sensor_huey_parent_class)->finalize (object);
+}
+
+/**
+ * gcm_sensor_huey_new:
+ *
+ * Return value: a new GcmSensorHuey object.
+ **/
+GcmSensorHuey *
+gcm_sensor_huey_new (void)
+{
+	GcmSensorHuey *sensor;
+	sensor = g_object_new (GCM_TYPE_SENSOR_HUEY, NULL);
+	return GCM_SENSOR_HUEY (sensor);
+}
+
diff --git a/src/gcm-sensor-huey.h b/src/gcm-sensor-huey.h
new file mode 100644
index 0000000..ab460bb
--- /dev/null
+++ b/src/gcm-sensor-huey.h
@@ -0,0 +1,66 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2010 Richard Hughes <richard hughsie com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef __GCM_SENSOR_HUEY_H
+#define __GCM_SENSOR_HUEY_H
+
+#include <glib-object.h>
+#include <libcolor-glib.h>
+
+#include "gcm-sensor.h"
+
+G_BEGIN_DECLS
+
+#define GCM_TYPE_SENSOR_HUEY		(gcm_sensor_huey_get_type ())
+#define GCM_SENSOR_HUEY(o)		(G_TYPE_CHECK_INSTANCE_CAST ((o), GCM_TYPE_SENSOR_HUEY, GcmSensorHuey))
+#define GCM_SENSOR_HUEY_CLASS(k)	(G_TYPE_CHECK_CLASS_CAST((k), GCM_TYPE_SENSOR_HUEY, GcmSensorHueyClass))
+#define GCM_IS_SENSOR_HUEY(o)		(G_TYPE_CHECK_INSTANCE_TYPE ((o), GCM_TYPE_SENSOR_HUEY))
+#define GCM_IS_SENSOR_HUEY_CLASS(k)	(G_TYPE_CHECK_CLASS_TYPE ((k), GCM_TYPE_SENSOR_HUEY))
+#define GCM_SENSOR_HUEY_GET_CLASS(o)	(G_TYPE_INSTANCE_GET_CLASS ((o), GCM_TYPE_SENSOR_HUEY, GcmSensorHueyClass))
+
+typedef struct _GcmSensorHueyPrivate	GcmSensorHueyPrivate;
+typedef struct _GcmSensorHuey		GcmSensorHuey;
+typedef struct _GcmSensorHueyClass	GcmSensorHueyClass;
+
+struct _GcmSensorHuey
+{
+	 GcmSensor		 parent;
+	 GcmSensorHueyPrivate	*priv;
+};
+
+struct _GcmSensorHueyClass
+{
+	GcmSensorClass	parent_class;
+	/* padding for future expansion */
+	void (*_gcm_reserved1) (void);
+	void (*_gcm_reserved2) (void);
+	void (*_gcm_reserved3) (void);
+	void (*_gcm_reserved4) (void);
+	void (*_gcm_reserved5) (void);
+};
+
+GType		 gcm_sensor_huey_get_type		 (void);
+GcmSensorHuey	*gcm_sensor_huey_new			 (void);
+
+G_END_DECLS
+
+#endif /* __GCM_SENSOR_HUEY_H */
+
diff --git a/src/gcm-sensor.c b/src/gcm-sensor.c
new file mode 100644
index 0000000..49fe0fc
--- /dev/null
+++ b/src/gcm-sensor.c
@@ -0,0 +1,251 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2010 Richard Hughes <richard hughsie com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+/**
+ * SECTION:gcm-sensor
+ * @short_description: Sensor object
+ *
+ * This object allows abstract handling of color sensors.
+ */
+
+#include "config.h"
+
+#include <glib-object.h>
+
+#include "gcm-sensor.h"
+
+static void     gcm_sensor_finalize	(GObject     *object);
+
+#define GCM_SENSOR_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GCM_TYPE_SENSOR, GcmSensorPrivate))
+
+/**
+ * GcmSensorPrivate:
+ *
+ * Private #GcmSensor data
+ **/
+struct _GcmSensorPrivate
+{
+	gchar				*device;
+};
+
+enum {
+	PROP_0,
+	PROP_DEVICE,
+	PROP_LAST
+};
+
+G_DEFINE_TYPE (GcmSensor, gcm_sensor, G_TYPE_OBJECT)
+
+/**
+ * gcm_sensor_startup:
+ **/
+gboolean
+gcm_sensor_startup (GcmSensor *sensor, GError **error)
+{
+	GcmSensorClass *klass = GCM_SENSOR_GET_CLASS (sensor);
+	gboolean ret = FALSE;
+
+	/* coldplug source */
+	if (klass->startup == NULL) {
+		g_set_error_literal (error,
+				     GCM_SENSOR_ERROR,
+				     GCM_SENSOR_ERROR_INTERNAL,
+				     "no klass support");
+		goto out;
+	}
+
+	/* proxy */
+	ret = klass->startup (sensor, error);
+out:
+	return ret;
+}
+
+/**
+ * gcm_sensor_get_ambient:
+ **/
+gboolean
+gcm_sensor_get_ambient (GcmSensor *sensor, gdouble *value, GError **error)
+{
+	GcmSensorClass *klass = GCM_SENSOR_GET_CLASS (sensor);
+	gboolean ret = FALSE;
+
+	/* coldplug source */
+	if (klass->get_ambient == NULL) {
+		g_set_error_literal (error,
+				     GCM_SENSOR_ERROR,
+				     GCM_SENSOR_ERROR_INTERNAL,
+				     "no klass support");
+		goto out;
+	}
+
+	/* proxy */
+	ret = klass->get_ambient (sensor, value, error);
+out:
+	return ret;
+}
+
+/**
+ * gcm_sensor_sample:
+ **/
+gboolean
+gcm_sensor_sample (GcmSensor *sensor, GcmColorXYZ *value, GError **error)
+{
+	GcmSensorClass *klass = GCM_SENSOR_GET_CLASS (sensor);
+	gboolean ret = FALSE;
+
+	/* coldplug source */
+	if (klass->sample == NULL) {
+		g_set_error_literal (error,
+				     GCM_SENSOR_ERROR,
+				     GCM_SENSOR_ERROR_INTERNAL,
+				     "no klass support");
+		goto out;
+	}
+
+	/* proxy */
+	ret = klass->sample (sensor, value, error);
+out:
+	return ret;
+}
+
+/**
+ * gcm_sensor_set_leds:
+ **/
+gboolean
+gcm_sensor_set_leds (GcmSensor *sensor, guint8 value, GError **error)
+{
+	GcmSensorClass *klass = GCM_SENSOR_GET_CLASS (sensor);
+	gboolean ret = FALSE;
+
+	/* coldplug source */
+	if (klass->set_leds == NULL) {
+		g_set_error_literal (error,
+				     GCM_SENSOR_ERROR,
+				     GCM_SENSOR_ERROR_INTERNAL,
+				     "no klass support");
+		goto out;
+	}
+
+	/* proxy */
+	ret = klass->set_leds (sensor, value, error);
+out:
+	return ret;
+}
+
+/**
+ * gcm_sensor_get_property:
+ **/
+static void
+gcm_sensor_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
+{
+	GcmSensor *sensor = GCM_SENSOR (object);
+	GcmSensorPrivate *priv = sensor->priv;
+
+	switch (prop_id) {
+	case PROP_DEVICE:
+		g_value_set_string (value, priv->device);
+		break;
+	default:
+		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+		break;
+	}
+}
+
+/**
+ * gcm_sensor_set_property:
+ **/
+static void
+gcm_sensor_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
+{
+	GcmSensor *sensor = GCM_SENSOR (object);
+	GcmSensorPrivate *priv = sensor->priv;
+
+	switch (prop_id) {
+	case PROP_DEVICE:
+		g_free (priv->device);
+		priv->device = g_strdup (g_value_get_string (value));
+		break;
+	default:
+		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+		break;
+	}
+}
+
+/**
+ * gcm_sensor_class_init:
+ **/
+static void
+gcm_sensor_class_init (GcmSensorClass *klass)
+{
+	GParamSpec *pspec;
+	GObjectClass *object_class = G_OBJECT_CLASS (klass);
+	object_class->finalize = gcm_sensor_finalize;
+	object_class->get_property = gcm_sensor_get_property;
+	object_class->set_property = gcm_sensor_set_property;
+
+	/**
+	 * GcmSensor:device:
+	 */
+	pspec = g_param_spec_string ("device", NULL, NULL,
+				     NULL,
+				     G_PARAM_READWRITE);
+	g_object_class_install_property (object_class, PROP_DEVICE, pspec);
+
+	g_type_class_add_private (klass, sizeof (GcmSensorPrivate));
+}
+
+/**
+ * gcm_sensor_init:
+ **/
+static void
+gcm_sensor_init (GcmSensor *sensor)
+{
+	sensor->priv = GCM_SENSOR_GET_PRIVATE (sensor);
+	sensor->priv->device = NULL;
+}
+
+/**
+ * gcm_sensor_finalize:
+ **/
+static void
+gcm_sensor_finalize (GObject *object)
+{
+	GcmSensor *sensor = GCM_SENSOR (object);
+	GcmSensorPrivate *priv = sensor->priv;
+
+	g_free (priv->device);
+
+	G_OBJECT_CLASS (gcm_sensor_parent_class)->finalize (object);
+}
+
+/**
+ * gcm_sensor_new:
+ *
+ * Return value: a new GcmSensor object.
+ **/
+GcmSensor *
+gcm_sensor_new (void)
+{
+	GcmSensor *sensor;
+	sensor = g_object_new (GCM_TYPE_SENSOR, NULL);
+	return GCM_SENSOR (sensor);
+}
+
diff --git a/src/gcm-sensor.h b/src/gcm-sensor.h
new file mode 100644
index 0000000..5fd1f6d
--- /dev/null
+++ b/src/gcm-sensor.h
@@ -0,0 +1,99 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2010 Richard Hughes <richard hughsie com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef __GCM_SENSOR_H
+#define __GCM_SENSOR_H
+
+#include <glib-object.h>
+#include <libcolor-glib.h>
+
+G_BEGIN_DECLS
+
+#define GCM_TYPE_SENSOR		(gcm_sensor_get_type ())
+#define GCM_SENSOR(o)		(G_TYPE_CHECK_INSTANCE_CAST ((o), GCM_TYPE_SENSOR, GcmSensor))
+#define GCM_SENSOR_CLASS(k)	(G_TYPE_CHECK_CLASS_CAST((k), GCM_TYPE_SENSOR, GcmSensorClass))
+#define GCM_IS_SENSOR(o)	(G_TYPE_CHECK_INSTANCE_TYPE ((o), GCM_TYPE_SENSOR))
+#define GCM_IS_SENSOR_CLASS(k)	(G_TYPE_CHECK_CLASS_TYPE ((k), GCM_TYPE_SENSOR))
+#define GCM_SENSOR_GET_CLASS(o)	(G_TYPE_INSTANCE_GET_CLASS ((o), GCM_TYPE_SENSOR, GcmSensorClass))
+
+typedef struct _GcmSensorPrivate	GcmSensorPrivate;
+typedef struct _GcmSensor		GcmSensor;
+typedef struct _GcmSensorClass		GcmSensorClass;
+
+struct _GcmSensor
+{
+	 GObject			 parent;
+	 GcmSensorPrivate		*priv;
+};
+
+struct _GcmSensorClass
+{
+	GObjectClass	parent_class;
+	/* vtable */
+	gboolean	 (*get_ambient)			(GcmSensor	*sensor,
+							 gdouble	*value,
+							 GError		**error);
+	gboolean	 (*set_leds)			(GcmSensor	*sensor,
+							 guint8		 value,
+							 GError		**error);
+	gboolean	 (*sample)			(GcmSensor	*sensor,
+							 GcmColorXYZ	*value,
+							 GError		**error);
+	gboolean	 (*startup)			(GcmSensor	*sensor,
+							 GError		**error);
+	/* padding for future expansion */
+	void (*_gcm_reserved1) (void);
+	void (*_gcm_reserved2) (void);
+	void (*_gcm_reserved3) (void);
+	void (*_gcm_reserved4) (void);
+	void (*_gcm_reserved5) (void);
+};
+
+typedef enum
+{
+	GCM_SENSOR_ERROR_USER_ABORT,
+	GCM_SENSOR_ERROR_NO_SUPPORT,
+	GCM_SENSOR_ERROR_NO_DATA,
+	GCM_SENSOR_ERROR_INTERNAL
+} GcmSensorError;
+
+/* dummy */
+#define GCM_SENSOR_ERROR	1
+
+GType		 gcm_sensor_get_type			(void);
+GcmSensor	*gcm_sensor_new				(void);
+
+gboolean	 gcm_sensor_get_ambient			(GcmSensor	*sensor,
+							 gdouble	*value,
+							 GError		**error);
+gboolean	 gcm_sensor_set_leds			(GcmSensor	*sensor,
+							 guint8		 value,
+							 GError		**error);
+gboolean	 gcm_sensor_sample			(GcmSensor	*sensor,
+							 GcmColorXYZ	*value,
+							 GError		**error);
+gboolean	 gcm_sensor_startup			(GcmSensor	*sensor,
+							 GError		**error);
+
+G_END_DECLS
+
+#endif /* __GCM_SENSOR_H */
+



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]