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



commit c7d9ee1680d8ae70287cc02bcc8067fb4c74e65f
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 66f7e38..fa4dfb1 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;
@@ -315,7 +329,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);
@@ -341,7 +356,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);
@@ -395,7 +410,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);
@@ -422,7 +437,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);
@@ -682,7 +697,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) {
@@ -715,14 +730,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;
@@ -743,7 +758,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]