r2093 - in trunk/src/target/OM-2007/openmoko-libs: . libmokojournal/src

thomas at sita.openmoko.org thomas at sita.openmoko.org
Tue May 29 16:59:22 CEST 2007


Author: thomas
Date: 2007-05-29 16:59:21 +0200 (Tue, 29 May 2007)
New Revision: 2093

Modified:
   trunk/src/target/OM-2007/openmoko-libs/ChangeLog
   trunk/src/target/OM-2007/openmoko-libs/libmokojournal/src/moko-journal.c
   trunk/src/target/OM-2007/openmoko-libs/libmokojournal/src/moko-journal.h
Log:
Patch by: Neil J Patel <njp at o-hand.com>

* libmokojournal/src/moko-journal.c: (moko_journal_open_default),
(moko_journal_close), (moko_journal_remove_entry_at),
(moko_journal_remove_entry_by_uid),
(moko_journal_write_to_storage), (on_entries_added_cb):
* libmokojournal/src/moko-journal.h:

      - Adds ability to set callbacks for being notified when entrys 
        are added & removed from the journal.
      - Callbacks are called only when ecal updates, they are not 
        called for _add_entry or _remove_entry, as these are not
        persistent until write_to_storage is called. 


Modified: trunk/src/target/OM-2007/openmoko-libs/ChangeLog
===================================================================
--- trunk/src/target/OM-2007/openmoko-libs/ChangeLog	2007-05-29 14:23:50 UTC (rev 2092)
+++ trunk/src/target/OM-2007/openmoko-libs/ChangeLog	2007-05-29 14:59:21 UTC (rev 2093)
@@ -1,3 +1,19 @@
+2007-05-29  Thomas Wood  <thomas at openedhand.com>
+
+	Patch by: Neil J Patel <njp at o-hand.com>
+
+	* libmokojournal/src/moko-journal.c: (moko_journal_open_default),
+	(moko_journal_close), (moko_journal_remove_entry_at),
+	(moko_journal_remove_entry_by_uid),
+	(moko_journal_write_to_storage), (on_entries_added_cb):
+	* libmokojournal/src/moko-journal.h:
+
+        - Adds ability to set callbacks for being notified when entrys 
+          are added & removed from the journal.
+        - Callbacks are called only when ecal updates, they are not 
+          called for _add_entry or _remove_entry, as these are not
+          persistent until write_to_storage is called. 
+
 2007-05-22  Michael Lauer <mickey at openmoko.org>
 
 	* libmokogsmd/moko-gsmd-connection.h: Add prototype for PIN request signal

Modified: trunk/src/target/OM-2007/openmoko-libs/libmokojournal/src/moko-journal.c
===================================================================
--- trunk/src/target/OM-2007/openmoko-libs/libmokojournal/src/moko-journal.c	2007-05-29 14:23:50 UTC (rev 2092)
+++ trunk/src/target/OM-2007/openmoko-libs/libmokojournal/src/moko-journal.c	2007-05-29 14:59:21 UTC (rev 2093)
@@ -35,6 +35,13 @@
   ECalView *ecal_view ;
   GList *entries_to_delete ;
   GArray *entries ;
+  
+  /* Callbacks */
+  MokoJournalEntryAddedFunc added_func ;
+  gpointer added_data ;
+
+  MokoJournalEntryRemovedFunc removed_func ;
+  gpointer removed_data ;  
 };
 
 struct _MokoJournalVoiceInfo
@@ -145,6 +152,24 @@
                                    MokoJournal *a_journal) ;
 
 
+static void
+notify_entry_added (MokoJournal *a_journal, MokoJournalEntry *entry)
+{
+  if (a_journal->added_func == NULL)
+    return;
+  
+  a_journal->added_func (a_journal, entry, a_journal->added_data);
+}
+
+static void
+notify_entry_removed (MokoJournal *a_journal, MokoJournalEntry *entry)
+{
+  if (a_journal->removed_func == NULL)
+    return;
+  
+  a_journal->removed_func (a_journal, entry, a_journal->removed_data);
+}
+
 static const gchar*
 entry_type_to_string (enum MokoJournalEntryType a_type)
 {
@@ -915,6 +940,48 @@
 }
 
 /**
+ * moko_journal_set_entry_added_callback:
+ * @journal: the current instance of journal
+ * @func: the function that will be called when an entry is added or NULL.
+ * @data: the data you would like to pass to the callback or NULL.
+ * This will replace the current callback.
+ *
+ * Add a callback to the journal to ne notified when an entry is added.
+ *
+ * Return value: 
+ */
+void moko_journal_set_entry_added_callback (MokoJournal *a_journal,  
+                                            MokoJournalEntryAddedFunc func,
+                                            gpointer data)
+{
+  g_return_if_fail (a_journal) ;
+  
+  a_journal->added_func = func;
+  a_journal->added_data = data;
+}
+
+/**
+ * moko_journal_set_entry_removed_callback:
+ * @journal: the current instance of journal
+ * @func: the function that will be called when an entry is removed or NULL.
+ * @data: the data you would like to pass to the callback or NULL. 
+ * This will replace the current callback.
+ *
+ * Add a callback to the journal to ne notified when an entry is removed.
+ *
+ * Return value: 
+ */
+void moko_journal_set_entry_removed_callback (MokoJournal *a_journal,  
+                                              MokoJournalEntryRemovedFunc func,
+                                              gpointer data)
+{
+  g_return_if_fail (a_journal) ;
+  
+  a_journal->removed_func = func;
+  a_journal->removed_data = data;
+}
+
+/**
  * moko_journal_add_entry:
  * @journal: the current instance of journal
  * @entry: the new entry to add to the journal. The journal is responsible
@@ -1047,6 +1114,7 @@
     entry = g_array_index (a_journal->entries, MokoJournalEntry*, i) ;
     if (entry && entry->uid && !strcmp (entry->uid, a_uid))
     {
+      notify_entry_removed (a_journal, entry);
       return moko_journal_remove_entry_at (a_journal, i) ;
     }
   }
@@ -1266,6 +1334,7 @@
       continue ;
     }
     moko_journal_add_entry (a_journal, entry) ;
+    notify_entry_added (a_journal, entry);
     entry = NULL ;
   }
 }

Modified: trunk/src/target/OM-2007/openmoko-libs/libmokojournal/src/moko-journal.h
===================================================================
--- trunk/src/target/OM-2007/openmoko-libs/libmokojournal/src/moko-journal.h	2007-05-29 14:23:50 UTC (rev 2092)
+++ trunk/src/target/OM-2007/openmoko-libs/libmokojournal/src/moko-journal.h	2007-05-29 14:59:21 UTC (rev 2093)
@@ -77,6 +77,17 @@
   gushort cid ;
 } MokoGSMLocation ;
 
+/* The 'entry added' callback function */
+typedef void (*MokoJournalEntryAddedFunc) (MokoJournal *journal, 
+                                           MokoJournalEntry *entry,
+                                           gpointer user_data);
+
+/* The 'entry added' callback function */
+typedef void (*MokoJournalEntryRemovedFunc) (MokoJournal *journal, 
+                                             const MokoJournalEntry *entry,
+                                             gpointer user_data);
+
+
 /*<journal management>*/
 /**
  * moko_journal_open_default:
@@ -97,6 +108,37 @@
 void moko_journal_close (MokoJournal *journal) ;
 
 /**
+ * moko_journal_set_entry_added_callback:
+ * @journal: the current instance of journal
+ * @func: the function that will be called when an entry is added or NULL.
+ * @data: the data you would like to pass to the callback or NULL.
+ * This will replace the current callback.
+ *
+ * Add a callback to the journal to ne notified when an entry is added.
+ *
+ * Return value: 
+ */
+void moko_journal_set_entry_added_callback (MokoJournal *journal,  
+                                            MokoJournalEntryAddedFunc func,
+                                            gpointer data) ;
+
+/**
+ * moko_journal_set_entry_removed_callback:
+ * @journal: the current instance of journal
+ * @func: the function that will be called when an entry is removed or NULL.
+ * @data: the data you would like to pass to the callback or NULL. 
+ * This will replace the current callback.
+ *
+ * Add a callback to the journal to ne notified when an entry is removed.
+ *
+ * Return value: 
+ */
+void moko_journal_set_entry_removed_callback (MokoJournal *journal,  
+                                              MokoJournalEntryRemovedFunc func,
+                                              gpointer data) ;
+
+
+/**
  * moko_journal_add_entry:
  * @journal: the current instance of journal
  * @entry: the new entry to add to the journal. Must be non NULL.





More information about the commitlog mailing list