[gnome-color-manager: 74/80] trivial: handle the device setup in GcmSensor, not GcmSensorClient



commit 7549421c78b42ee9563f53bc19968d7f30aa0de0
Author: Richard Hughes <richard hughsie com>
Date:   Mon Jul 19 10:24:30 2010 +0100

    trivial: handle the device setup in GcmSensor, not GcmSensorClient

 libcolor-glib/gcm-sensor-client.c |   39 +-----
 libcolor-glib/gcm-sensor-huey.c   |   56 ++-------
 libcolor-glib/gcm-sensor.c        |  248 +++++++++++++++++++++++++++++++------
 libcolor-glib/gcm-sensor.h        |   34 ++++-
 libcolor-glib/gcm-xserver.c       |    1 -
 src/gcm-calibrate.h               |    3 +-
 src/gcm-huey-example.c            |    8 +-
 7 files changed, 254 insertions(+), 135 deletions(-)
---
diff --git a/libcolor-glib/gcm-sensor-client.c b/libcolor-glib/gcm-sensor-client.c
index 6179fdf..11f6420 100644
--- a/libcolor-glib/gcm-sensor-client.c
+++ b/libcolor-glib/gcm-sensor-client.c
@@ -157,11 +157,7 @@ gcm_sensor_client_get_present (GcmSensorClient *sensor_client)
 static gboolean
 gcm_sensor_client_device_add (GcmSensorClient *sensor_client, GUdevDevice *device)
 {
-	const gchar *vendor;
-	const gchar *model;
-	GcmSensorKind sensor_client_kind;
 	gboolean ret;
-	const gchar *kind_str;
 	GcmSensorClientPrivate *priv = sensor_client->priv;
 
 	/* interesting device? */
@@ -171,38 +167,13 @@ gcm_sensor_client_device_add (GcmSensorClient *sensor_client, GUdevDevice *devic
 
 	/* get data */
 	egg_debug ("adding color management device: %s", g_udev_device_get_sysfs_path (device));
-	priv->present = TRUE;
 	priv->sensor = gcm_sensor_new ();
+	ret = gcm_sensor_set_from_device (priv->sensor, device, NULL);
+	if (!ret)
+		goto out;
 
-	/* vendor */
-	vendor = g_udev_device_get_property (device, "ID_VENDOR_FROM_DATABASE");
-	if (vendor == NULL)
-		vendor = g_udev_device_get_property (device, "ID_VENDOR");
-	if (vendor == NULL)
-		vendor = g_udev_device_get_sysfs_attr (device, "manufacturer");
-
-	/* model */
-	model = g_udev_device_get_property (device, "ID_MODEL_FROM_DATABASE");
-	if (model == NULL)
-		model = g_udev_device_get_property (device, "ID_MODEL");
-	if (model == NULL)
-		model = g_udev_device_get_sysfs_attr (device, "product");
-
-	/* try to get type */
-	kind_str = g_udev_device_get_property (device, "GCM_KIND");
-	sensor_client_kind = gcm_sensor_kind_from_string (kind_str);
-	if (sensor_client_kind == GCM_SENSOR_KIND_UNKNOWN)
-		egg_warning ("Failed to recognize color device: %s", model);
-
-	g_object_set (priv->sensor,
-		      "vendor", vendor,
-		      "model", model,
-		      "supports-display", g_udev_device_get_property_as_boolean (device, "GCM_TYPE_DISPLAY"),
-		      "supports-projector",g_udev_device_get_property_as_boolean (device, "GCM_TYPE_PROJECTOR"),
-		      "supports-printer", g_udev_device_get_property_as_boolean (device, "GCM_TYPE_PRINTER"),
-		      "supports-spot", g_udev_device_get_property_as_boolean (device, "GCM_TYPE_SPOT"),
-		      "kind", sensor_client_kind,
-		      NULL);
+	/* success */
+	priv->present = TRUE;
 
 	/* signal the addition */
 	egg_debug ("emit: changed");
diff --git a/libcolor-glib/gcm-sensor-huey.c b/libcolor-glib/gcm-sensor-huey.c
index d22c5f9..a94fa10 100644
--- a/libcolor-glib/gcm-sensor-huey.c
+++ b/libcolor-glib/gcm-sensor-huey.c
@@ -719,56 +719,13 @@ out:
 static gboolean
 gcm_sensor_huey_find_device (GcmSensorHuey *sensor_huey, GError **error)
 {
-	struct libusb_device_descriptor desc;
 	libusb_device **devs = NULL;
-	libusb_device *dev;
 	gint retval;
-	gint cnt;
-	gint i = 0;
 	gboolean ret = FALSE;
 
-	/* get device */
-	cnt = libusb_get_device_list (NULL, &devs);
-	if (cnt < 0) {
-		g_set_error (error, GCM_SENSOR_ERROR,
-			     GCM_SENSOR_ERROR_INTERNAL,
-			     "failed to get device list: %s", libusb_strerror (cnt));
-		goto out;
-	}
-
-	/* find device */
-	for (i=0; i<cnt; i++) {
-		dev = devs[i];
-
-		/* get descriptor */
-		retval = libusb_get_device_descriptor (dev, &desc);
-		if (retval < 0) {
-			g_warning ("failed to get device descriptor for %02x:%02x, possibly faulty hardware",
-				   libusb_get_bus_number (dev), libusb_get_device_address (dev));
-			continue;
-		}
-
-		/* does match HUEY? */
-		if (desc.idVendor == HUEY_VENDOR_ID &&
-		    desc.idProduct == HUEY_PRODUCT_ID) {
-			ret = TRUE;
-			sensor_huey->priv->device = libusb_ref_device (dev);
-			break;
-		}
-	}
-
-	/* not found */
-	if (!ret) {
-		g_set_error_literal (error, GCM_SENSOR_ERROR,
-				     GCM_SENSOR_ERROR_INTERNAL,
-				     "no compatible hardware attached");
-		goto out;
-	}
-
 	/* open device */
-	retval = libusb_open (sensor_huey->priv->device, &sensor_huey->priv->handle);
-	if (retval < 0) {
-		ret = FALSE;
+	sensor_huey->priv->handle = libusb_open_device_with_vid_pid (NULL, HUEY_VENDOR_ID, HUEY_PRODUCT_ID);
+	if (sensor_huey->priv->handle == NULL) {
 		g_set_error (error, GCM_SENSOR_ERROR,
 			     GCM_SENSOR_ERROR_INTERNAL,
 			     "failed to open device: %s", libusb_strerror (retval));
@@ -778,7 +735,6 @@ gcm_sensor_huey_find_device (GcmSensorHuey *sensor_huey, GError **error)
 	/* set configuration and interface */
 	retval = libusb_set_configuration (sensor_huey->priv->handle, 1);
 	if (retval < 0) {
-		ret = FALSE;
 		g_set_error (error, GCM_SENSOR_ERROR,
 			     GCM_SENSOR_ERROR_INTERNAL,
 			     "failed to set configuration: %s", libusb_strerror (retval));
@@ -786,12 +742,14 @@ gcm_sensor_huey_find_device (GcmSensorHuey *sensor_huey, GError **error)
 	}
 	retval = libusb_claim_interface (sensor_huey->priv->handle, 0);
 	if (retval < 0) {
-		ret = FALSE;
 		g_set_error (error, GCM_SENSOR_ERROR,
 			     GCM_SENSOR_ERROR_INTERNAL,
 			     "failed to claim interface: %s", libusb_strerror (retval));
 		goto out;
 	}
+
+	/* success */
+	ret = TRUE;
 out:
 	libusb_free_device_list (devs, 1);
 	return ret;
@@ -909,7 +867,9 @@ GcmSensor *
 gcm_sensor_huey_new (void)
 {
 	GcmSensorHuey *sensor;
-	sensor = g_object_new (GCM_TYPE_SENSOR_HUEY, NULL);
+	sensor = g_object_new (GCM_TYPE_SENSOR_HUEY,
+			       "native", TRUE,
+			       NULL);
 	return GCM_SENSOR (sensor);
 }
 
diff --git a/libcolor-glib/gcm-sensor.c b/libcolor-glib/gcm-sensor.c
index f64b368..61915d1 100644
--- a/libcolor-glib/gcm-sensor.c
+++ b/libcolor-glib/gcm-sensor.c
@@ -31,6 +31,7 @@
 #include <glib-object.h>
 
 #include "gcm-sensor.h"
+#include "egg-debug.h"
 
 static void     gcm_sensor_finalize	(GObject     *object);
 
@@ -43,6 +44,8 @@ static void     gcm_sensor_finalize	(GObject     *object);
  **/
 struct _GcmSensorPrivate
 {
+	gboolean			 native;
+	gboolean			 done_startup;
 	GcmSensorKind			 kind;
 	GcmSensorOutputType		 output_type;
 	gboolean			 supports_display;
@@ -56,6 +59,7 @@ struct _GcmSensorPrivate
 
 enum {
 	PROP_0,
+	PROP_NATIVE,
 	PROP_VENDOR,
 	PROP_MODEL,
 	PROP_KIND,
@@ -71,6 +75,11 @@ G_DEFINE_TYPE (GcmSensor, gcm_sensor, G_TYPE_OBJECT)
 
 /**
  * gcm_sensor_get_model:
+ * @sensor: a valid #GcmSensor instance
+ *
+ * Gets the sensor model.
+ *
+ * Return value: a string.
  **/
 const gchar *
 gcm_sensor_get_model (GcmSensor *sensor)
@@ -80,6 +89,11 @@ gcm_sensor_get_model (GcmSensor *sensor)
 
 /**
  * gcm_sensor_get_vendor:
+ * @sensor: a valid #GcmSensor instance
+ *
+ * Gets the sensor vendor.
+ *
+ * Return value: a string.
  **/
 const gchar *
 gcm_sensor_get_vendor (GcmSensor *sensor)
@@ -89,6 +103,11 @@ gcm_sensor_get_vendor (GcmSensor *sensor)
 
 /**
  * gcm_sensor_supports_display:
+ * @sensor: a valid #GcmSensor instance
+ *
+ * Returns if the sensor supports profiling a display.
+ *
+ * Return value: %TRUE or %FALSE.
  **/
 gboolean
 gcm_sensor_supports_display (GcmSensor *sensor)
@@ -98,6 +117,11 @@ gcm_sensor_supports_display (GcmSensor *sensor)
 
 /**
  * gcm_sensor_supports_projector:
+ * @sensor: a valid #GcmSensor instance
+ *
+ * Returns if the sensor supports profiling a projector.
+ *
+ * Return value: %TRUE or %FALSE.
  **/
 gboolean
 gcm_sensor_supports_projector (GcmSensor *sensor)
@@ -107,6 +131,11 @@ gcm_sensor_supports_projector (GcmSensor *sensor)
 
 /**
  * gcm_sensor_supports_printer:
+ * @sensor: a valid #GcmSensor instance
+ *
+ * Returns if the sensor supports profiling a printer.
+ *
+ * Return value: %TRUE or %FALSE.
  **/
 gboolean
 gcm_sensor_supports_printer (GcmSensor *sensor)
@@ -116,6 +145,11 @@ gcm_sensor_supports_printer (GcmSensor *sensor)
 
 /**
  * gcm_sensor_supports_spot:
+ * @sensor: a valid #GcmSensor instance
+ *
+ * Returns if the sensor supports getting a spot color.
+ *
+ * Return value: %TRUE or %FALSE.
  **/
 gboolean
 gcm_sensor_supports_spot (GcmSensor *sensor)
@@ -125,6 +159,11 @@ gcm_sensor_supports_spot (GcmSensor *sensor)
 
 /**
  * gcm_sensor_get_kind:
+ * @sensor: a valid #GcmSensor instance
+ *
+ * Returns the sensor kind.
+ *
+ * Return value: the sensor kind, e.g. %GCM_SENSOR_KIND_HUEY
  **/
 GcmSensorKind
 gcm_sensor_get_kind (GcmSensor *sensor)
@@ -134,6 +173,11 @@ gcm_sensor_get_kind (GcmSensor *sensor)
 
 /**
  * gcm_sensor_set_output_type:
+ * @sensor: a valid #GcmSensor instance
+ * @output_type: the output type, e.g. %GCM_SENSOR_OUTPUT_TYPE_LCD
+ *
+ * Set the output type. Different sensors may do different
+ * things depending on the output type.
  **/
 void
 gcm_sensor_set_output_type (GcmSensor *sensor, GcmSensorOutputType output_type)
@@ -143,6 +187,12 @@ gcm_sensor_set_output_type (GcmSensor *sensor, GcmSensorOutputType output_type)
 
 /**
  * gcm_sensor_get_output_type:
+ * @sensor: a valid #GcmSensor instance
+ *
+ * Returns the set output type. Different sensors may do different
+ * things depending on the output type.
+ *
+ * Return value: the output type, e.g. %GCM_SENSOR_OUTPUT_TYPE_LCD
  **/
 GcmSensorOutputType
 gcm_sensor_get_output_type (GcmSensor *sensor)
@@ -151,7 +201,80 @@ gcm_sensor_get_output_type (GcmSensor *sensor)
 }
 
 /**
+ * gcm_sensor_get_is_native:
+ * @sensor: a valid #GcmSensor instance
+ *
+ * Sensor support can be built in, for instance the HUEY, or rely on
+ * external frameworks such as argyllcms. Native sensor support is done
+ * internally without calling out to other frameworks.
+ *
+ * Return value: %TRUE for internal, native, support.
+ **/
+gboolean
+gcm_sensor_get_is_native (GcmSensor *sensor)
+{
+	return sensor->priv->native;
+}
+
+/**
+ * gcm_sensor_set_from_device:
+ * @sensor: a valid #GcmSensor instance
+ * @device: a #GUdevDevice
+ * @error: a #GError or %NULL
+ *
+ * Set up some details about the sensor from the raw device.
+ * We aim to get as much as possible from UDEV.
+ *
+ * Return value: %TRUE for success.
+ **/
+gboolean
+gcm_sensor_set_from_device (GcmSensor *sensor, GUdevDevice *device, GError **error)
+{
+	const gchar *kind_str;
+	GcmSensorPrivate *priv = sensor->priv;
+
+	/* device */
+	priv->device = g_strdup (g_udev_device_get_sysfs_path (device));
+
+	/* vendor */
+	priv->vendor = g_strdup (g_udev_device_get_property (device, "ID_VENDOR_FROM_DATABASE"));
+	if (priv->vendor == NULL)
+		priv->vendor = g_strdup (g_udev_device_get_property (device, "ID_VENDOR"));
+	if (priv->vendor == NULL)
+		priv->vendor = g_strdup (g_udev_device_get_sysfs_attr (device, "manufacturer"));
+
+	/* model */
+	priv->model = g_strdup (g_udev_device_get_property (device, "ID_MODEL_FROM_DATABASE"));
+	if (priv->model == NULL)
+		priv->model = g_strdup (g_udev_device_get_property (device, "ID_MODEL"));
+	if (priv->model == NULL)
+		priv->model = g_strdup (g_udev_device_get_sysfs_attr (device, "product"));
+
+	/* try to get type */
+	kind_str = g_udev_device_get_property (device, "GCM_KIND");
+	priv->kind = gcm_sensor_kind_from_string (kind_str);
+	if (priv->kind == GCM_SENSOR_KIND_UNKNOWN)
+		egg_warning ("Failed to recognize color device: %s", priv->model);
+
+	priv->supports_display = g_udev_device_get_property_as_boolean (device, "GCM_TYPE_DISPLAY");
+	priv->supports_projector = g_udev_device_get_property_as_boolean (device, "GCM_TYPE_PROJECTOR");
+	priv->supports_printer = g_udev_device_get_property_as_boolean (device, "GCM_TYPE_PRINTER");
+	priv->supports_spot = g_udev_device_get_property_as_boolean (device, "GCM_TYPE_SPOT");
+	return TRUE;
+}
+
+/**
  * gcm_sensor_startup:
+ * @sensor: a valid #GcmSensor instance
+ * @error: a #GError or %NULL
+ *
+ * Starts up the device, which can mean connecting to it and uploading
+ * firmware, or just reading configuration details for it.
+ *
+ * You probably don't need to use this function manually, as it is done
+ * automatically as soon as the sensor is required.
+ *
+ * Return value: %TRUE for success.
  **/
 gboolean
 gcm_sensor_startup (GcmSensor *sensor, GError **error)
@@ -159,6 +282,15 @@ gcm_sensor_startup (GcmSensor *sensor, GError **error)
 	GcmSensorClass *klass = GCM_SENSOR_GET_CLASS (sensor);
 	gboolean ret = FALSE;
 
+	/* already done */
+	if (sensor->priv->done_startup) {
+		g_set_error_literal (error,
+				     GCM_SENSOR_ERROR,
+				     GCM_SENSOR_ERROR_INTERNAL,
+				     "already started");
+		goto out;
+	}
+
 	/* coldplug source */
 	if (klass->startup == NULL) {
 		g_set_error_literal (error,
@@ -170,12 +302,24 @@ gcm_sensor_startup (GcmSensor *sensor, GError **error)
 
 	/* proxy */
 	ret = klass->startup (sensor, error);
+	if (!ret)
+		goto out;
+
+	/* success */
+	sensor->priv->done_startup = TRUE;
 out:
 	return ret;
 }
 
 /**
  * gcm_sensor_get_ambient:
+ * @sensor: a valid #GcmSensor instance
+ * @value: The returned value
+ * @error: a #GError or %NULL
+ *
+ * Gets the ambient light level of the sensor in Lux.
+ *
+ * Return value: %TRUE for success.
  **/
 gboolean
 gcm_sensor_get_ambient (GcmSensor *sensor, gdouble *value, GError **error)
@@ -183,6 +327,13 @@ gcm_sensor_get_ambient (GcmSensor *sensor, gdouble *value, GError **error)
 	GcmSensorClass *klass = GCM_SENSOR_GET_CLASS (sensor);
 	gboolean ret = FALSE;
 
+	/* do startup if not yet done */
+	if (!sensor->priv->done_startup) {
+		ret = gcm_sensor_startup (sensor, error);
+		if (!ret)
+			goto out;
+	}
+
 	/* coldplug source */
 	if (klass->get_ambient == NULL) {
 		g_set_error_literal (error,
@@ -200,6 +351,13 @@ out:
 
 /**
  * gcm_sensor_sample:
+ * @sensor: a valid #GcmSensor instance
+ * @value: The returned value
+ * @error: a #GError or %NULL
+ *
+ * Sample the color and store as a XYZ value.
+ *
+ * Return value: %TRUE for success.
  **/
 gboolean
 gcm_sensor_sample (GcmSensor *sensor, GcmColorXYZ *value, GError **error)
@@ -207,6 +365,13 @@ gcm_sensor_sample (GcmSensor *sensor, GcmColorXYZ *value, GError **error)
 	GcmSensorClass *klass = GCM_SENSOR_GET_CLASS (sensor);
 	gboolean ret = FALSE;
 
+	/* do startup if not yet done */
+	if (!sensor->priv->done_startup) {
+		ret = gcm_sensor_startup (sensor, error);
+		if (!ret)
+			goto out;
+	}
+
 	/* coldplug source */
 	if (klass->sample == NULL) {
 		g_set_error_literal (error,
@@ -224,6 +389,13 @@ out:
 
 /**
  * gcm_sensor_set_leds:
+ * @sensor: a valid #GcmSensor instance
+ * @value: The LED bitmask
+ * @error: a #GError or %NULL
+ *
+ * Sets the LED output state for the device.
+ *
+ * Return value: %TRUE for success.
  **/
 gboolean
 gcm_sensor_set_leds (GcmSensor *sensor, guint8 value, GError **error)
@@ -231,7 +403,14 @@ gcm_sensor_set_leds (GcmSensor *sensor, guint8 value, GError **error)
 	GcmSensorClass *klass = GCM_SENSOR_GET_CLASS (sensor);
 	gboolean ret = FALSE;
 
-	/* coldplug source */
+	/* do startup if not yet done */
+	if (!sensor->priv->done_startup) {
+		ret = gcm_sensor_startup (sensor, error);
+		if (!ret)
+			goto out;
+	}
+
+	/* set LEDs */
 	if (klass->set_leds == NULL) {
 		g_set_error_literal (error,
 				     GCM_SENSOR_ERROR,
@@ -248,6 +427,11 @@ out:
 
 /**
  * gcm_sensor_kind_to_string:
+ * @sensor_kind: a #GcmSensorKind
+ *
+ * Gets the sensor kind as a string.
+ *
+ * Return value: the sensor kind, e.g. 'huey'.
  **/
 const gchar *
 gcm_sensor_kind_to_string (GcmSensorKind sensor_kind)
@@ -277,6 +461,11 @@ gcm_sensor_kind_to_string (GcmSensorKind sensor_kind)
 
 /**
  * gcm_sensor_kind_from_string:
+ * @sensor_kind: the sensor kind, e.g. 'huey'.
+ *
+ * Gets the sensor kind as a enumerated value.
+ *
+ * Return value: a #GcmSensorKind
  **/
 GcmSensorKind
 gcm_sensor_kind_from_string (const gchar *sensor_kind)
@@ -314,6 +503,9 @@ gcm_sensor_get_property (GObject *object, guint prop_id, GValue *value, GParamSp
 	GcmSensorPrivate *priv = sensor->priv;
 
 	switch (prop_id) {
+	case PROP_NATIVE:
+		g_value_set_boolean (value, priv->native);
+		break;
 	case PROP_VENDOR:
 		g_value_set_string (value, priv->vendor);
 		break;
@@ -354,32 +546,8 @@ gcm_sensor_set_property (GObject *object, guint prop_id, const GValue *value, GP
 	GcmSensorPrivate *priv = sensor->priv;
 
 	switch (prop_id) {
-	case PROP_DEVICE:
-		g_free (priv->device);
-		priv->device = g_value_dup_string (value);
-		break;
-	case PROP_VENDOR:
-		g_free (priv->vendor);
-		priv->vendor = g_value_dup_string (value);
-		break;
-	case PROP_MODEL:
-		g_free (priv->model);
-		priv->model = g_value_dup_string (value);
-		break;
-	case PROP_KIND:
-		priv->kind = g_value_get_uint (value);
-		break;
-	case PROP_SUPPORTS_DISPLAY:
-		priv->supports_display = g_value_get_boolean (value);
-		break;
-	case PROP_SUPPORTS_PROJECTOR:
-		priv->supports_projector = g_value_get_boolean (value);
-		break;
-	case PROP_SUPPORTS_PRINTER:
-		priv->supports_printer = g_value_get_boolean (value);
-		break;
-	case PROP_SUPPORTS_SPOT:
-		priv->supports_spot = g_value_get_boolean (value);
+	case PROP_NATIVE:
+		priv->native = g_value_get_boolean (value);
 		break;
 	default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -400,11 +568,19 @@ gcm_sensor_class_init (GcmSensorClass *klass)
 	object_class->set_property = gcm_sensor_set_property;
 
 	/**
+	 * GcmSensor:native:
+	 */
+	pspec = g_param_spec_boolean ("native", NULL, NULL,
+				      FALSE,
+				      G_PARAM_READWRITE);
+	g_object_class_install_property (object_class, PROP_NATIVE, pspec);
+
+	/**
 	 * GcmSensor:vendor:
 	 */
 	pspec = g_param_spec_string ("vendor", NULL, NULL,
 				     NULL,
-				     G_PARAM_READWRITE);
+				     G_PARAM_READABLE);
 	g_object_class_install_property (object_class, PROP_VENDOR, pspec);
 
 	/**
@@ -412,7 +588,7 @@ gcm_sensor_class_init (GcmSensorClass *klass)
 	 */
 	pspec = g_param_spec_string ("model", NULL, NULL,
 				     NULL,
-				     G_PARAM_READWRITE);
+				     G_PARAM_READABLE);
 	g_object_class_install_property (object_class, PROP_MODEL, pspec);
 
 	/**
@@ -420,7 +596,7 @@ gcm_sensor_class_init (GcmSensorClass *klass)
 	 */
 	pspec = g_param_spec_uint ("kind", NULL, NULL,
 				   0, G_MAXUINT, GCM_SENSOR_KIND_UNKNOWN,
-				   G_PARAM_READWRITE);
+				   G_PARAM_READABLE);
 	g_object_class_install_property (object_class, PROP_KIND, pspec);
 
 	/**
@@ -428,7 +604,7 @@ gcm_sensor_class_init (GcmSensorClass *klass)
 	 */
 	pspec = g_param_spec_boolean ("supports-display", NULL, NULL,
 				      FALSE,
-				      G_PARAM_READWRITE);
+				      G_PARAM_READABLE);
 	g_object_class_install_property (object_class, PROP_SUPPORTS_DISPLAY, pspec);
 
 	/**
@@ -436,7 +612,7 @@ gcm_sensor_class_init (GcmSensorClass *klass)
 	 */
 	pspec = g_param_spec_boolean ("supports-projector", NULL, NULL,
 				      FALSE,
-				      G_PARAM_READWRITE);
+				      G_PARAM_READABLE);
 	g_object_class_install_property (object_class, PROP_SUPPORTS_PROJECTOR, pspec);
 
 
@@ -445,7 +621,7 @@ gcm_sensor_class_init (GcmSensorClass *klass)
 	 */
 	pspec = g_param_spec_boolean ("supports-printer", NULL, NULL,
 				      FALSE,
-				      G_PARAM_READWRITE);
+				      G_PARAM_READABLE);
 	g_object_class_install_property (object_class, PROP_SUPPORTS_PRINTER, pspec);
 
 	/**
@@ -453,7 +629,7 @@ gcm_sensor_class_init (GcmSensorClass *klass)
 	 */
 	pspec = g_param_spec_boolean ("supports-spot", NULL, NULL,
 				      FALSE,
-				      G_PARAM_READWRITE);
+				      G_PARAM_READABLE);
 	g_object_class_install_property (object_class, PROP_SUPPORTS_SPOT, pspec);
 
 	/**
@@ -461,7 +637,7 @@ gcm_sensor_class_init (GcmSensorClass *klass)
 	 */
 	pspec = g_param_spec_string ("device", NULL, NULL,
 				     NULL,
-				     G_PARAM_READWRITE);
+				     G_PARAM_READABLE);
 	g_object_class_install_property (object_class, PROP_DEVICE, pspec);
 
 	g_type_class_add_private (klass, sizeof (GcmSensorPrivate));
@@ -497,7 +673,7 @@ gcm_sensor_finalize (GObject *object)
 /**
  * gcm_sensor_new:
  *
- * Return value: a new GcmSensor object.
+ * Return value: a new #GcmSensor object.
  **/
 GcmSensor *
 gcm_sensor_new (void)
diff --git a/libcolor-glib/gcm-sensor.h b/libcolor-glib/gcm-sensor.h
index 54a0186..ec46885 100644
--- a/libcolor-glib/gcm-sensor.h
+++ b/libcolor-glib/gcm-sensor.h
@@ -27,6 +27,7 @@
 #define __GCM_SENSOR_H
 
 #include <glib-object.h>
+#include <gudev/gudev.h>
 
 #include <gcm-common.h>
 
@@ -72,6 +73,11 @@ struct _GcmSensorClass
 	void (*_gcm_reserved5) (void);
 };
 
+/**
+ * GcmSensorError:
+ *
+ * The error code.
+ **/
 typedef enum {
 	GCM_SENSOR_ERROR_USER_ABORT,
 	GCM_SENSOR_ERROR_NO_SUPPORT,
@@ -79,6 +85,11 @@ typedef enum {
 	GCM_SENSOR_ERROR_INTERNAL
 } GcmSensorError;
 
+/**
+ * GcmSensorOutputType:
+ *
+ * The output type.
+ **/
 typedef enum {
 	GCM_SENSOR_OUTPUT_TYPE_UNKNOWN,
 	GCM_SENSOR_OUTPUT_TYPE_LCD,
@@ -86,6 +97,11 @@ typedef enum {
 	GCM_SENSOR_OUTPUT_TYPE_PROJECTOR
 } GcmSensorOutputType;
 
+/**
+ * GcmSensorKind:
+ *
+ * The sensor type.
+ **/
 typedef enum {
 	GCM_SENSOR_KIND_HUEY,
 	GCM_SENSOR_KIND_COLOR_MUNKI,
@@ -107,16 +123,19 @@ GType			 gcm_sensor_get_type		(void);
 GcmSensor		*gcm_sensor_new			(void);
 
 gboolean		 gcm_sensor_get_ambient		(GcmSensor		*sensor,
-							gdouble			*value,
-							GError			**error);
+							 gdouble		*value,
+							 GError			**error);
 gboolean		 gcm_sensor_set_leds		(GcmSensor		*sensor,
-							guint8			 value,
-							GError			**error);
+							 guint8			 value,
+							 GError			**error);
 gboolean		 gcm_sensor_sample		(GcmSensor		*sensor,
-							GcmColorXYZ		*value,
-							GError			**error);
+							 GcmColorXYZ		*value,
+							 GError			**error);
 gboolean		 gcm_sensor_startup		(GcmSensor		*sensor,
-							GError			**error);
+							 GError			**error);
+gboolean		 gcm_sensor_set_from_device	(GcmSensor		*sensor,
+							 GUdevDevice		*device,
+							 GError			**error);
 void			 gcm_sensor_set_output_type	(GcmSensor		*sensor,
 							 GcmSensorOutputType	 output_type);
 GcmSensorOutputType	 gcm_sensor_get_output_type	(GcmSensor		*sensor);
@@ -127,6 +146,7 @@ gboolean		 gcm_sensor_supports_display	(GcmSensor 		*sensor);
 gboolean		 gcm_sensor_supports_projector	(GcmSensor 		*sensor);
 gboolean		 gcm_sensor_supports_printer	(GcmSensor		*sensor);
 gboolean		 gcm_sensor_supports_spot	(GcmSensor		*sensor);
+gboolean		 gcm_sensor_get_is_native	(GcmSensor		*sensor);
 const gchar		*gcm_sensor_kind_to_string	(GcmSensorKind		 sensor_kind);
 GcmSensorKind		 gcm_sensor_kind_from_string	(const gchar		*sensor_kind);
 
diff --git a/libcolor-glib/gcm-xserver.c b/libcolor-glib/gcm-xserver.c
index 94642b6..4712a5e 100644
--- a/libcolor-glib/gcm-xserver.c
+++ b/libcolor-glib/gcm-xserver.c
@@ -71,7 +71,6 @@ G_DEFINE_TYPE (GcmXserver, gcm_xserver, G_TYPE_OBJECT)
 
 /**
  * gcm_xserver_get_root_window_profile_data:
- *
  * @xserver: a valid %GcmXserver instance
  * @data: the data that is returned from the XServer. Free with g_free()
  * @length: the size of the returned data, or %NULL if you don't care
diff --git a/src/gcm-calibrate.h b/src/gcm-calibrate.h
index 80c4f77..e222356 100644
--- a/src/gcm-calibrate.h
+++ b/src/gcm-calibrate.h
@@ -70,8 +70,7 @@ struct _GcmCalibrateClass
 	void (*_gcm_reserved5) (void);
 };
 
-typedef enum
-{
+typedef enum {
 	GCM_CALIBRATE_ERROR_USER_ABORT,
 	GCM_CALIBRATE_ERROR_NO_SUPPORT,
 	GCM_CALIBRATE_ERROR_NO_DATA,
diff --git a/src/gcm-huey-example.c b/src/gcm-huey-example.c
index c0a820f..053cb09 100644
--- a/src/gcm-huey-example.c
+++ b/src/gcm-huey-example.c
@@ -42,14 +42,8 @@ main (void)
 
 	g_type_init ();
 
-	/* start sensor */
+	/* create new sensor */
 	sensor = gcm_sensor_huey_new ();
-	ret = gcm_sensor_startup (sensor, &error);
-	if (!ret) {
-		g_warning ("failed to start sensor: %s", error->message);
-		g_error_free (error);
-		goto out;
-	}
 
 	/* set LEDs */
 	ret = gcm_sensor_set_leds (sensor, 0x0f, &error);



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