[gnome-color-manager] Add gcm_edid_get_checksum() to get the EDID checksum



commit daf137949104adbdfd9a4b4fc084e1ea10ba4a60
Author: Richard Hughes <richard hughsie com>
Date:   Wed Jun 16 15:02:55 2010 +0100

    Add gcm_edid_get_checksum() to get the EDID checksum

 src/gcm-edid.c      |   31 +++++++++++++++++++++++++++++++
 src/gcm-edid.h      |    1 +
 src/gcm-self-test.c |    4 ++++
 3 files changed, 36 insertions(+), 0 deletions(-)
---
diff --git a/src/gcm-edid.c b/src/gcm-edid.c
index fa89e5c..99b430a 100644
--- a/src/gcm-edid.c
+++ b/src/gcm-edid.c
@@ -54,6 +54,7 @@ struct _GcmEdidPrivate
 	gchar				*vendor_name;
 	gchar				*serial_number;
 	gchar				*eisa_id;
+	gchar				*checksum;
 	gchar				*pnp_id;
 	guint				 width;
 	guint				 height;
@@ -67,6 +68,7 @@ enum {
 	PROP_VENDOR_NAME,
 	PROP_SERIAL_NUMBER,
 	PROP_EISA_ID,
+	PROP_CHECKSUM,
 	PROP_GAMMA,
 	PROP_PNP_ID,
 	PROP_WIDTH,
@@ -136,6 +138,16 @@ gcm_edid_get_eisa_id (GcmEdid *edid)
 }
 
 /**
+ * gcm_edid_get_checksum:
+ **/
+const gchar *
+gcm_edid_get_checksum (GcmEdid *edid)
+{
+	g_return_val_if_fail (GCM_IS_EDID (edid), NULL);
+	return edid->priv->checksum;
+}
+
+/**
  * gcm_edid_get_pnp_id:
  **/
 const gchar *
@@ -190,6 +202,7 @@ gcm_edid_reset (GcmEdid *edid)
 	g_free (priv->vendor_name);
 	g_free (priv->serial_number);
 	g_free (priv->eisa_id);
+	g_free (priv->checksum);
 
 	/* do not deallocate, just blank */
 	priv->pnp_id[0] = '\0';
@@ -199,6 +212,7 @@ gcm_edid_reset (GcmEdid *edid)
 	priv->vendor_name = NULL;
 	priv->serial_number = NULL;
 	priv->eisa_id = NULL;
+	priv->checksum = NULL;
 	priv->width = 0;
 	priv->height = 0;
 	priv->gamma = 0.0f;
@@ -405,10 +419,14 @@ gcm_edid_parse (GcmEdid *edid, const guint8 *data, GError **error)
 	if (extension_blocks > 0)
 		egg_warning ("%i extension blocks to parse", extension_blocks);
 
+	/* calculate checksum */
+	priv->checksum = g_compute_checksum_for_data (G_CHECKSUM_MD5, data, 0x6c);
+
 	/* print what we've got */
 	egg_debug ("monitor name: %s", priv->monitor_name);
 	egg_debug ("serial number: %s", priv->serial_number);
 	egg_debug ("ascii string: %s", priv->eisa_id);
+	egg_debug ("checksum: %s", priv->checksum);
 out:
 	return ret;
 }
@@ -435,6 +453,9 @@ gcm_edid_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec
 	case PROP_EISA_ID:
 		g_value_set_string (value, priv->eisa_id);
 		break;
+	case PROP_CHECKSUM:
+		g_value_set_string (value, priv->checksum);
+		break;
 	case PROP_GAMMA:
 		g_value_set_float (value, priv->gamma);
 		break;
@@ -511,6 +532,14 @@ gcm_edid_class_init (GcmEdidClass *klass)
 	g_object_class_install_property (object_class, PROP_EISA_ID, pspec);
 
 	/**
+	 * GcmEdid:checksum:
+	 */
+	pspec = g_param_spec_string ("checksum", NULL, NULL,
+				     NULL,
+				     G_PARAM_READABLE);
+	g_object_class_install_property (object_class, PROP_CHECKSUM, pspec);
+
+	/**
 	 * GcmEdid:gamma:
 	 */
 	pspec = g_param_spec_float ("gamma", NULL, NULL,
@@ -556,6 +585,7 @@ gcm_edid_init (GcmEdid *edid)
 	edid->priv->vendor_name = NULL;
 	edid->priv->serial_number = NULL;
 	edid->priv->eisa_id = NULL;
+	edid->priv->checksum = NULL;
 	edid->priv->tables = gcm_tables_new ();
 	edid->priv->pnp_id = g_new0 (gchar, 4);
 }
@@ -573,6 +603,7 @@ gcm_edid_finalize (GObject *object)
 	g_free (priv->vendor_name);
 	g_free (priv->serial_number);
 	g_free (priv->eisa_id);
+	g_free (priv->checksum);
 	g_free (priv->pnp_id);
 	g_object_unref (priv->tables);
 
diff --git a/src/gcm-edid.h b/src/gcm-edid.h
index 76ae336..35423ce 100644
--- a/src/gcm-edid.h
+++ b/src/gcm-edid.h
@@ -64,6 +64,7 @@ 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_eisa_id			(GcmEdid		*edid);
+const gchar	*gcm_edid_get_checksum			(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);
diff --git a/src/gcm-self-test.c b/src/gcm-self-test.c
index 9383963..24f1ae1 100644
--- a/src/gcm-self-test.c
+++ b/src/gcm-self-test.c
@@ -502,6 +502,7 @@ typedef struct {
 	const gchar *vendor_name;
 	const gchar *serial_number;
 	const gchar *eisa_id;
+	const gchar *checksum;
 	const gchar *pnp_id;
 	guint width;
 	guint height;
@@ -530,6 +531,7 @@ gcm_test_edid_test_parse_edid_file (GcmEdid *edid, const gchar *datafile, GcmEdi
 	g_assert_cmpstr (gcm_edid_get_vendor_name (edid), ==, test_data->vendor_name);
 	g_assert_cmpstr (gcm_edid_get_serial_number (edid), ==, test_data->serial_number);
 	g_assert_cmpstr (gcm_edid_get_eisa_id (edid), ==, test_data->eisa_id);
+	g_assert_cmpstr (gcm_edid_get_checksum (edid), ==, test_data->checksum);
 	g_assert_cmpstr (gcm_edid_get_pnp_id (edid), ==, test_data->pnp_id);
 	g_assert_cmpint (gcm_edid_get_height (edid), ==, test_data->height);
 	g_assert_cmpint (gcm_edid_get_width (edid), ==, test_data->width);
@@ -555,6 +557,7 @@ gcm_test_edid_func (void)
 	test_data.vendor_name = "Goldstar Company Ltd";
 	test_data.serial_number = "34398";
 	test_data.eisa_id = NULL;
+	test_data.checksum = "80b7dda4c74b06366abb8fa23e71d645";
 	test_data.pnp_id = "GSM";
 	test_data.height = 30;
 	test_data.width = 47;
@@ -566,6 +569,7 @@ gcm_test_edid_func (void)
 	test_data.vendor_name = "IBM France";
 	test_data.serial_number = NULL;
 	test_data.eisa_id = "LTN154P2-L05";
+	test_data.checksum = "c585d9e80adc65c54f0a52597e850f83";
 	test_data.pnp_id = "IBM";
 	test_data.height = 21;
 	test_data.width = 33;



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