[gnome-color-manager] trivial: add getters and setters for GcmEdid and GcmDmi



commit 3107c4606aa5f2f3e6b356330fbdf0f2a884ae66
Author: Richard Hughes <richard hughsie com>
Date:   Wed Mar 24 20:44:34 2010 +0000

    trivial: add getters and setters for GcmEdid and GcmDmi

 src/gcm-device-xrandr.c |   75 +++++++++-------------------
 src/gcm-dmi.c           |   96 ++++++++++++++++++++++++-------------
 src/gcm-dmi.h           |    3 +
 src/gcm-edid.c          |  123 +++++++++++++++++++++++++++++++++++++----------
 src/gcm-edid.h          |    8 +++
 5 files changed, 195 insertions(+), 110 deletions(-)
---
diff --git a/src/gcm-device-xrandr.c b/src/gcm-device-xrandr.c
index 96e15d0..7fdac19 100644
--- a/src/gcm-device-xrandr.c
+++ b/src/gcm-device-xrandr.c
@@ -99,8 +99,8 @@ static gchar *
 gcm_device_xrandr_get_output_name (GcmDeviceXrandr *device_xrandr, GnomeRROutput *output)
 {
 	const gchar *output_name;
-	gchar *name = NULL;
-	gchar *vendor = NULL;
+	const gchar *name;
+	const gchar *vendor;
 	GString *string;
 	gboolean ret;
 	guint width = 0;
@@ -120,19 +120,15 @@ gcm_device_xrandr_get_output_name (GcmDeviceXrandr *device_xrandr, GnomeRROutput
 	ret = gcm_utils_output_is_lcd_internal (output_name);
 	if (ret) {
 		/* find the machine details */
-		g_object_get (priv->dmi,
-			      "name", &name,
-			      "vendor", &vendor,
-			      NULL);
+		name = gcm_dmi_get_name (priv->dmi);
+		vendor = gcm_dmi_get_vendor (priv->dmi);
 
 		/* TRANSLATORS: this is the name of the internal panel */
 		output_name = _("Laptop LCD");
 	} else {
 		/* find the panel details */
-		g_object_get (priv->edid,
-			      "monitor-name", &name,
-			      "vendor-name", &vendor,
-			      NULL);
+		name = gcm_edid_get_monitor_name (priv->edid);
+		vendor = gcm_edid_get_vendor_name (priv->edid);
 	}
 
 	/* prepend vendor if available */
@@ -148,13 +144,9 @@ gcm_device_xrandr_get_output_name (GcmDeviceXrandr *device_xrandr, GnomeRROutput
 		g_string_assign (string, "Unknown Monitor");
 
 out:
-	/* find the best option */
-	g_object_get (priv->edid,
-		      "width", &width,
-		      "height", &height,
-		      NULL);
-
 	/* append size if available */
+	width = gcm_edid_get_width (priv->edid);
+	height = gcm_edid_get_height (priv->edid);
 	if (width != 0 && height != 0) {
 		gfloat diag;
 
@@ -165,8 +157,6 @@ out:
 		g_string_append_printf (string, " - %i\"", (guint) ((diag * 0.393700787f) + 0.5f));
 	}
 
-	g_free (name);
-	g_free (vendor);
 	return g_string_free (string, FALSE);
 }
 
@@ -177,10 +167,10 @@ static gchar *
 gcm_device_xrandr_get_id_for_xrandr_device (GcmDeviceXrandr *device_xrandr, GnomeRROutput *output)
 {
 	const gchar *output_name;
-	gchar *name = NULL;
-	gchar *vendor = NULL;
-	gchar *ascii = NULL;
-	gchar *serial = NULL;
+	const gchar *name;
+	const gchar *vendor;
+	const gchar *ascii;
+	const gchar *serial;
 	GString *string;
 	gboolean ret;
 	GcmDeviceXrandrPrivate *priv = device_xrandr->priv;
@@ -193,21 +183,17 @@ gcm_device_xrandr_get_id_for_xrandr_device (GcmDeviceXrandr *device_xrandr, Gnom
 	if (!ret)
 		goto out;
 
-	/* find the best option */
-	g_object_get (priv->edid,
-		      "monitor-name", &name,
-		      "vendor-name", &vendor,
-		      "ascii-string", &ascii,
-		      "serial-number", &serial,
-		      NULL);
-
 	/* append data if available */
+	vendor = gcm_edid_get_vendor_name (priv->edid);
 	if (vendor != NULL)
 		g_string_append_printf (string, "_%s", vendor);
+	name = gcm_edid_get_monitor_name (priv->edid);
 	if (name != NULL)
 		g_string_append_printf (string, "_%s", name);
+	ascii = gcm_edid_get_ascii_string (priv->edid);
 	if (ascii != NULL)
 		g_string_append_printf (string, "_%s", ascii);
+	serial = gcm_edid_get_serial_number (priv->edid);
 	if (serial != NULL)
 		g_string_append_printf (string, "_%s", serial);
 out:
@@ -222,11 +208,6 @@ out:
 
 	/* replace unsafe chars */
 	gcm_utils_alphanum_lcase (string->str);
-
-	g_free (name);
-	g_free (vendor);
-	g_free (ascii);
-	g_free (serial);
 	return g_string_free (string, FALSE);
 }
 
@@ -241,9 +222,9 @@ gcm_device_xrandr_set_from_output (GcmDevice *device, GnomeRROutput *output, GEr
 	gboolean ret = TRUE;
 	gboolean lcd_internal;
 	const gchar *output_name;
-	gchar *serial = NULL;
-	gchar *manufacturer = NULL;
-	gchar *model = NULL;
+	const gchar *serial;
+	const gchar *manufacturer;
+	const gchar *model;
 	const guint8 *data;
 	GcmDeviceXrandrPrivate *priv = GCM_DEVICE_XRANDR(device)->priv;
 
@@ -265,20 +246,15 @@ gcm_device_xrandr_set_from_output (GcmDevice *device, GnomeRROutput *output, GEr
 	egg_debug ("asking to add %s", id);
 
 	/* get data about the display */
-	g_object_get (priv->edid,
-		      "monitor-name", &model,
-		      "vendor-name", &manufacturer,
-		      "serial-number", &serial,
-		      NULL);
+	model = gcm_edid_get_monitor_name (priv->edid);
+	manufacturer = gcm_edid_get_vendor_name (priv->edid);
+	serial = gcm_edid_get_serial_number (priv->edid);
 
 	/* refine data if it's missing */
 	output_name = gnome_rr_output_get_name (output);
 	lcd_internal = gcm_utils_output_is_lcd_internal (output_name);
-	if (lcd_internal && model == NULL) {
-		g_object_get (priv->dmi,
-			      "version", &model,
-			      NULL);
-	}
+	if (lcd_internal && model == NULL)
+		model = gcm_dmi_get_version (priv->dmi);
 
 	/* add new device */
 	title = gcm_device_xrandr_get_output_name (GCM_DEVICE_XRANDR(device), output);
@@ -295,9 +271,6 @@ gcm_device_xrandr_set_from_output (GcmDevice *device, GnomeRROutput *output, GEr
 		      NULL);
 out:
 	g_free (id);
-	g_free (serial);
-	g_free (manufacturer);
-	g_free (model);
 	g_free (title);
 	return ret;
 }
diff --git a/src/gcm-dmi.c b/src/gcm-dmi.c
index 6740e0b..adaab3b 100644
--- a/src/gcm-dmi.c
+++ b/src/gcm-dmi.c
@@ -100,6 +100,59 @@ gcm_dmi_get_data (const gchar *filename)
 	return data;
 }
 
+
+/**
+ * gcm_dmi_get_name:
+ **/
+const gchar *
+gcm_dmi_get_name (GcmDmi *dmi)
+{
+	GcmDmiPrivate *priv = dmi->priv;
+	g_return_val_if_fail (GCM_IS_DMI (dmi), NULL);
+
+	if (priv->name == NULL)
+		priv->name = gcm_dmi_get_data ("/sys/class/dmi/id/product_name");
+	if (priv->name == NULL)
+		priv->name = gcm_dmi_get_data ("/sys/class/dmi/id/board_name");
+	return priv->name;
+}
+
+/**
+ * gcm_dmi_get_version:
+ **/
+const gchar *
+gcm_dmi_get_version (GcmDmi *dmi)
+{
+	GcmDmiPrivate *priv = dmi->priv;
+	g_return_val_if_fail (GCM_IS_DMI (dmi), NULL);
+
+	if (priv->version == NULL)
+		priv->version = gcm_dmi_get_data ("/sys/class/dmi/id/product_version");
+	if (priv->version == NULL)
+		priv->version = gcm_dmi_get_data ("/sys/class/dmi/id/chassis_version");
+	if (priv->version == NULL)
+		priv->version = gcm_dmi_get_data ("/sys/class/dmi/id/board_version");
+	return priv->version;
+}
+
+/**
+ * gcm_dmi_get_vendor:
+ **/
+const gchar *
+gcm_dmi_get_vendor (GcmDmi *dmi)
+{
+	GcmDmiPrivate *priv = dmi->priv;
+	g_return_val_if_fail (GCM_IS_DMI (dmi), NULL);
+
+	if (priv->vendor == NULL)
+		priv->vendor = gcm_dmi_get_data ("/sys/class/dmi/id/sys_vendor");
+	if (priv->vendor == NULL)
+		priv->vendor = gcm_dmi_get_data ("/sys/class/dmi/id/chassis_vendor");
+	if (priv->vendor == NULL)
+		priv->vendor = gcm_dmi_get_data ("/sys/class/dmi/id/board_vendor");
+	return priv->vendor;
+}
+
 /**
  * gcm_dmi_get_property:
  **/
@@ -107,33 +160,16 @@ static void
 gcm_dmi_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
 {
 	GcmDmi *dmi = GCM_DMI (object);
-	GcmDmiPrivate *priv = dmi->priv;
 
 	switch (prop_id) {
 	case PROP_NAME:
-		if (priv->name == NULL)
-			priv->name = gcm_dmi_get_data ("/sys/class/dmi/id/product_name");
-		if (priv->name == NULL)
-			priv->name = gcm_dmi_get_data ("/sys/class/dmi/id/board_name");
-		g_value_set_string (value, priv->name);
+		g_value_set_string (value, gcm_dmi_get_name (dmi));
 		break;
 	case PROP_VERSION:
-		if (priv->version == NULL)
-			priv->version = gcm_dmi_get_data ("/sys/class/dmi/id/product_version");
-		if (priv->version == NULL)
-			priv->version = gcm_dmi_get_data ("/sys/class/dmi/id/chassis_version");
-		if (priv->version == NULL)
-			priv->version = gcm_dmi_get_data ("/sys/class/dmi/id/board_version");
-		g_value_set_string (value, priv->version);
+		g_value_set_string (value, gcm_dmi_get_version (dmi));
 		break;
 	case PROP_VENDOR:
-		if (priv->vendor == NULL)
-			priv->vendor = gcm_dmi_get_data ("/sys/class/dmi/id/sys_vendor");
-		if (priv->vendor == NULL)
-			priv->vendor = gcm_dmi_get_data ("/sys/class/dmi/id/chassis_vendor");
-		if (priv->vendor == NULL)
-			priv->vendor = gcm_dmi_get_data ("/sys/class/dmi/id/board_vendor");
-		g_value_set_string (value, priv->vendor);
+		g_value_set_string (value, gcm_dmi_get_vendor (dmi));
 		break;
 	default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -248,9 +284,9 @@ void
 gcm_dmi_test (EggTest *test)
 {
 	GcmDmi *dmi;
-	gchar *name = NULL;
-	gchar *version = NULL;
-	gchar *vendor = NULL;
+	const gchar *name;
+	const gchar *version;
+	const gchar *vendor;
 
 	if (!egg_test_start (test, "GcmDmi"))
 		return;
@@ -260,29 +296,21 @@ gcm_dmi_test (EggTest *test)
 	dmi = gcm_dmi_new ();
 	egg_test_assert (test, dmi != NULL);
 
-	/* get data */
-	g_object_get (dmi,
-		      "name", &name,
-		      "version", &version,
-		      "vendor", &vendor,
-		      NULL);
-
 	/************************************************************/
 	egg_test_title (test, "got name: %s", name);
+	name = gcm_dmi_get_name (dmi);
 	egg_test_assert (test, name != NULL);
 
 	/************************************************************/
 	egg_test_title (test, "got version: %s", version);
+	version = gcm_dmi_get_version (dmi);
 	egg_test_assert (test, version != NULL);
 
 	/************************************************************/
 	egg_test_title (test, "got vendor: %s", vendor);
+	vendor = gcm_dmi_get_vendor (dmi);
 	egg_test_assert (test, vendor != NULL);
 
-	g_free (name);
-	g_free (version);
-	g_free (vendor);
-
 	g_object_unref (dmi);
 
 	egg_test_end (test);
diff --git a/src/gcm-dmi.h b/src/gcm-dmi.h
index 85d4ffb..f41be62 100644
--- a/src/gcm-dmi.h
+++ b/src/gcm-dmi.h
@@ -56,6 +56,9 @@ struct _GcmDmiClass
 
 GType		 gcm_dmi_get_type		  	(void);
 GcmDmi		*gcm_dmi_new				(void);
+const gchar	*gcm_dmi_get_name			(GcmDmi		*dmi);
+const gchar	*gcm_dmi_get_version			(GcmDmi		*dmi);
+const gchar	*gcm_dmi_get_vendor			(GcmDmi		*dmi);
 
 G_END_DECLS
 
diff --git a/src/gcm-edid.c b/src/gcm-edid.c
index 53f2286..1336047 100644
--- a/src/gcm-edid.c
+++ b/src/gcm-edid.c
@@ -92,6 +92,90 @@ G_DEFINE_TYPE (GcmEdid, gcm_edid, G_TYPE_OBJECT)
 
 
 /**
+ * gcm_edid_get_monitor_name:
+ **/
+const gchar *
+gcm_edid_get_monitor_name (GcmEdid *edid)
+{
+	g_return_val_if_fail (GCM_IS_EDID (edid), NULL);
+	return edid->priv->monitor_name;
+}
+
+/**
+ * gcm_edid_get_vendor_name:
+ **/
+const gchar *
+gcm_edid_get_vendor_name (GcmEdid *edid)
+{
+	GcmEdidPrivate *priv = edid->priv;
+	g_return_val_if_fail (GCM_IS_EDID (edid), NULL);
+
+	if (priv->vendor_name == NULL)
+		priv->vendor_name = gcm_tables_get_pnp_id (priv->tables, priv->pnp_id, NULL);
+	return priv->vendor_name;
+}
+
+/**
+ * gcm_edid_get_serial_number:
+ **/
+const gchar *
+gcm_edid_get_serial_number (GcmEdid *edid)
+{
+	g_return_val_if_fail (GCM_IS_EDID (edid), NULL);
+	return edid->priv->serial_number;
+}
+
+/**
+ * gcm_edid_get_ascii_string:
+ **/
+const gchar *
+gcm_edid_get_ascii_string (GcmEdid *edid)
+{
+	g_return_val_if_fail (GCM_IS_EDID (edid), NULL);
+	return edid->priv->ascii_string;
+}
+
+/**
+ * gcm_edid_get_pnp_id:
+ **/
+const gchar *
+gcm_edid_get_pnp_id (GcmEdid *edid)
+{
+	g_return_val_if_fail (GCM_IS_EDID (edid), NULL);
+	return edid->priv->pnp_id;
+}
+
+/**
+ * gcm_edid_get_width:
+ **/
+guint
+gcm_edid_get_width (GcmEdid *edid)
+{
+	g_return_val_if_fail (GCM_IS_EDID (edid), 0);
+	return edid->priv->width;
+}
+
+/**
+ * gcm_edid_get_height:
+ **/
+guint
+gcm_edid_get_height (GcmEdid *edid)
+{
+	g_return_val_if_fail (GCM_IS_EDID (edid), 0);
+	return edid->priv->height;
+}
+
+/**
+ * gcm_edid_get_gamma:
+ **/
+gfloat
+gcm_edid_get_gamma (GcmEdid *edid)
+{
+	g_return_val_if_fail (GCM_IS_EDID (edid), 0.0f);
+	return edid->priv->gamma;
+}
+
+/**
  * gcm_edid_reset:
  **/
 void
@@ -343,9 +427,7 @@ gcm_edid_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec
 		g_value_set_string (value, priv->monitor_name);
 		break;
 	case PROP_VENDOR_NAME:
-		if (priv->vendor_name == NULL)
-			priv->vendor_name = gcm_tables_get_pnp_id (priv->tables, priv->pnp_id, NULL);
-		g_value_set_string (value, priv->vendor_name);
+		g_value_set_string (value, gcm_edid_get_vendor_name (edid));
 		break;
 	case PROP_SERIAL_NUMBER:
 		g_value_set_string (value, priv->serial_number);
@@ -531,11 +613,11 @@ void
 gcm_edid_test_parse_edid_file (EggTest *test, GcmEdid *edid, const gchar *datafile, GcmEdidTestData *test_data)
 {
 	gchar *filename;
-	gchar *monitor_name;
-	gchar *vendor_name;
-	gchar *serial_number;
-	gchar *ascii_string;
-	gchar *pnp_id;
+	const gchar *monitor_name;
+	const gchar *vendor_name;
+	const gchar *serial_number;
+	const gchar *ascii_string;
+	const gchar *pnp_id;
 	gchar *data;
 	guint width;
 	guint height;
@@ -560,19 +642,9 @@ gcm_edid_test_parse_edid_file (EggTest *test, GcmEdid *edid, const gchar *datafi
 	else
 		egg_test_failed (test, "failed to parse: %s", error->message);
 
-	g_object_get (edid,
-		      "monitor-name", &monitor_name,
-		      "vendor-name", &vendor_name,
-		      "serial-number", &serial_number,
-		      "ascii-string", &ascii_string,
-		      "pnp-id", &pnp_id,
-		      "width", &width,
-		      "height", &height,
-		      "gamma", &gamma,
-		      NULL);
-
 	/************************************************************/
 	egg_test_title (test, "check monitor name for %s", datafile);
+	monitor_name = gcm_edid_get_monitor_name (edid);
 	if (g_strcmp0 (monitor_name, test_data->monitor_name) == 0)
 		egg_test_success (test, NULL);
 	else
@@ -580,6 +652,7 @@ gcm_edid_test_parse_edid_file (EggTest *test, GcmEdid *edid, const gchar *datafi
 
 	/************************************************************/
 	egg_test_title (test, "check vendor name for %s", datafile);
+	vendor_name = gcm_edid_get_vendor_name (edid);
 	if (g_strcmp0 (vendor_name, test_data->vendor_name) == 0)
 		egg_test_success (test, NULL);
 	else
@@ -587,6 +660,7 @@ gcm_edid_test_parse_edid_file (EggTest *test, GcmEdid *edid, const gchar *datafi
 
 	/************************************************************/
 	egg_test_title (test, "check serial number for %s", datafile);
+	serial_number = gcm_edid_get_serial_number (edid);
 	if (g_strcmp0 (serial_number, test_data->serial_number) == 0)
 		egg_test_success (test, NULL);
 	else
@@ -594,6 +668,7 @@ gcm_edid_test_parse_edid_file (EggTest *test, GcmEdid *edid, const gchar *datafi
 
 	/************************************************************/
 	egg_test_title (test, "check ascii string for %s", datafile);
+	ascii_string = gcm_edid_get_ascii_string (edid);
 	if (g_strcmp0 (ascii_string, test_data->ascii_string) == 0)
 		egg_test_success (test, NULL);
 	else
@@ -601,6 +676,7 @@ gcm_edid_test_parse_edid_file (EggTest *test, GcmEdid *edid, const gchar *datafi
 
 	/************************************************************/
 	egg_test_title (test, "check pnp id for %s", datafile);
+	pnp_id = gcm_edid_get_pnp_id (edid);
 	if (g_strcmp0 (pnp_id, test_data->pnp_id) == 0)
 		egg_test_success (test, NULL);
 	else
@@ -608,6 +684,7 @@ gcm_edid_test_parse_edid_file (EggTest *test, GcmEdid *edid, const gchar *datafi
 
 	/************************************************************/
 	egg_test_title (test, "check height for %s", datafile);
+	height = gcm_edid_get_height (edid);
 	if (height == test_data->height)
 		egg_test_success (test, NULL);
 	else
@@ -615,6 +692,7 @@ gcm_edid_test_parse_edid_file (EggTest *test, GcmEdid *edid, const gchar *datafi
 
 	/************************************************************/
 	egg_test_title (test, "check width for %s", datafile);
+	width = gcm_edid_get_width (edid);
 	if (width == test_data->width)
 		egg_test_success (test, NULL);
 	else
@@ -622,17 +700,12 @@ gcm_edid_test_parse_edid_file (EggTest *test, GcmEdid *edid, const gchar *datafi
 
 	/************************************************************/
 	egg_test_title (test, "check gamma for %s", datafile);
+	gamma = gcm_edid_get_gamma (edid);
 	if (gamma > (test_data->gamma - 0.01) && gamma < (test_data->gamma + 0.01))
 		egg_test_success (test, NULL);
 	else
 		egg_test_failed (test, "invalid value: %f, expecting: %f", gamma, test_data->gamma);
 
-	g_free (monitor_name);
-	g_free (vendor_name);
-	g_free (serial_number);
-	g_free (ascii_string);
-	g_free (pnp_id);
-	g_free (data);
 	g_free (filename);
 }
 
diff --git a/src/gcm-edid.h b/src/gcm-edid.h
index a61073d..c184a40 100644
--- a/src/gcm-edid.h
+++ b/src/gcm-edid.h
@@ -60,6 +60,14 @@ void		 gcm_edid_reset				(GcmEdid		*edid);
 gboolean	 gcm_edid_parse				(GcmEdid		*edid,
 							 const guint8		*data,
 							 GError			**error);
+const gchar	*gcm_edid_get_monitor_name		(GcmEdid		*edid);
+const gchar	*gcm_edid_get_vendor_name		(GcmEdid		*edid);
+const gchar	*gcm_edid_get_serial_number		(GcmEdid		*edid);
+const gchar	*gcm_edid_get_ascii_string		(GcmEdid		*edid);
+const gchar	*gcm_edid_get_pnp_id			(GcmEdid		*edid);
+guint		 gcm_edid_get_width			(GcmEdid		*edid);
+guint		 gcm_edid_get_height			(GcmEdid		*edid);
+gfloat		 gcm_edid_get_gamma			(GcmEdid		*edid);
 
 G_END_DECLS
 



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