[tracker/binary-log-2: 18/44] Use an enum not hardcoded values for journal data formats



commit 0f408c61d1263a7fd5d693ab49698ef254e3cecd
Author: Martyn Russell <martyn lanedo com>
Date:   Tue Jan 5 16:02:37 2010 +0000

    Use an enum not hardcoded values for journal data formats

 src/libtracker-db/tracker-db-journal.c |   33 +++++++++++++++++++++++--------
 1 files changed, 24 insertions(+), 9 deletions(-)
---
diff --git a/src/libtracker-db/tracker-db-journal.c b/src/libtracker-db/tracker-db-journal.c
index fb2e6dc..6d425be 100644
--- a/src/libtracker-db/tracker-db-journal.c
+++ b/src/libtracker-db/tracker-db-journal.c
@@ -41,6 +41,20 @@
 #define JOURNAL_FILENAME  "tracker-store.journal"
 #define MIN_BLOCK_SIZE    1024
 
+/*
+ * data_format:
+ * #... 0000 0000 (total size is 4 bytes)
+ *            ||`- resource insert (all other bits must be 0 if 1)
+ *            |`-- object type (1 = id, 0 = cstring)
+ *            `--- operation type (0 = insert, 1 = delete)
+ */
+
+enum {
+	DATA_FORMAT_RESOURCE_INSERT  = 1 << 0,
+	DATA_FORMAT_OBJECT_ID        = 1 << 1,
+	DATA_FORMAT_OPERATION_DELETE = 1 << 2
+};
+
 static struct {
 	gchar *filename;
 	GMappedFile *file;
@@ -316,7 +330,8 @@ tracker_db_journal_append_delete_statement (guint32      s_id,
 	g_return_val_if_fail (writer.journal > 0, FALSE);
 
 	o_len = strlen (object);
-	data_format = 0x04;
+	data_format = DATA_FORMAT_OPERATION_DELETE;
+
 	size = (sizeof (guint32) * 3) + o_len + 1;
 
 	cur_block_maybe_expand (size);
@@ -342,7 +357,7 @@ tracker_db_journal_append_delete_statement_id (guint32 s_id,
 
 	g_return_val_if_fail (writer.journal > 0, FALSE);
 
-	data_format = 0x06;
+	data_format = DATA_FORMAT_OPERATION_DELETE | DATA_FORMAT_OBJECT_ID;
 	size = sizeof (guint32) * 4;
 
 	cur_block_maybe_expand (size);
@@ -396,7 +411,7 @@ tracker_db_journal_append_insert_statement_id (guint32 s_id,
 
 	g_return_val_if_fail (writer.journal > 0, FALSE);
 
-	data_format = 0x02;
+	data_format = DATA_FORMAT_OBJECT_ID;
 	size = sizeof (guint32) * 4;
 
 	cur_block_maybe_expand (size);
@@ -423,7 +438,7 @@ tracker_db_journal_append_resource (guint32      s_id,
 	g_return_val_if_fail (writer.journal > 0, FALSE);
 
 	o_len = strlen (uri);
-	data_format = 0x01;
+	data_format = DATA_FORMAT_RESOURCE_INSERT;
 	size = (sizeof (guint32) * 2) + o_len + 1;
 
 	cur_block_maybe_expand (size);
@@ -683,7 +698,7 @@ tracker_db_journal_reader_next (GError **error)
 		data_format = read_uint32 (reader.current);
 		reader.current += 4;
 
-		if (data_format == 1) {
+		if (data_format == DATA_FORMAT_RESOURCE_INSERT) {
 			reader.type = TRACKER_DB_JOURNAL_RESOURCE;
 
 			if (reader.end - reader.current < sizeof (guint32) + 1) {
@@ -716,14 +731,14 @@ tracker_db_journal_reader_next (GError **error)
 			reader.uri = reader.current;
 			reader.current += str_length + 1;
 		} else {
-			if (data_format & 4) {
-				if (data_format & 2) {
+			if (data_format & DATA_FORMAT_OPERATION_DELETE) {
+				if (data_format & DATA_FORMAT_OBJECT_ID) {
 					reader.type = TRACKER_DB_JOURNAL_DELETE_STATEMENT_ID;
 				} else {
 					reader.type = TRACKER_DB_JOURNAL_DELETE_STATEMENT;
 				}
 			} else {
-				if (data_format & 2) {
+				if (data_format & DATA_FORMAT_OBJECT_ID) {
 					reader.type = TRACKER_DB_JOURNAL_INSERT_STATEMENT_ID;
 				} else {
 					reader.type = TRACKER_DB_JOURNAL_INSERT_STATEMENT;
@@ -744,7 +759,7 @@ tracker_db_journal_reader_next (GError **error)
 			reader.p_id = read_uint32 (reader.current);
 			reader.current += 4;
 
-			if (data_format & 2) {
+			if (data_format & DATA_FORMAT_OBJECT_ID) {
 				if (reader.end - reader.current < sizeof (guint32)) {
 					/* damaged journal entry */
 					g_set_error (error, TRACKER_DB_JOURNAL_ERROR, 0, 



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