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



commit a6abc57419cf406ee495307b9367365113f231ce
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 f318590..5bb775d 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;
@@ -314,7 +328,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);
@@ -340,7 +355,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);
@@ -394,7 +409,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);
@@ -421,7 +436,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);
@@ -681,7 +696,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) {
@@ -714,14 +729,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;
@@ -742,7 +757,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]