[Gnucash-changes] Chris Shoemaker's patch: Comments and tweaks for gnc-component-manager.

Derek Atkins warlord at cvs.gnucash.org
Sun Feb 13 18:00:02 EST 2005


Log Message:
-----------
Chris Shoemaker's patch: Comments and tweaks for gnc-component-manager.

	* gnc-component-manager tweaks
	  - Warn if we approach design limitation of component manager
	  - pass GUID as const in gnc_gui_get_entity_events, change
	    prototype, callers, and docs
	  - Clarify comments about receiving events after entity life-cycle

Tags:
----
gnucash-gnome2-dev

Modified Files:
--------------
    gnucash:
        ChangeLog
    gnucash/src/app-utils:
        gnc-component-manager.c
        gnc-component-manager.h
    gnucash/src/doc/design:
        component-manager.texinfo
    gnucash/src/gnome-utils:
        dialog-query-list.c

Revision Data
-------------
Index: ChangeLog
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/ChangeLog,v
retrieving revision 1.1487.2.169
retrieving revision 1.1487.2.170
diff -LChangeLog -LChangeLog -u -r1.1487.2.169 -r1.1487.2.170
--- ChangeLog
+++ ChangeLog
@@ -25,6 +25,13 @@
 	Chris Shoemaker's patch: Various comments and typo fixes.
 	* Comments and typo fixes
 
+	Chris Shoemaker's patch: Comments and tweaks for gnc-component-manager.
+	* gnc-component-manager tweaks
+	  - Warn if we approach design limitation of component manager
+	  - pass GUID as const in gnc_gui_get_entity_events, change
+	    prototype, callers, and docs
+	  - Clarify comments about receiving events after entity life-cycle
+
 2005-02-02  Derek Atkins  <derek at ihtfp.com>
 
 	Neil Williams' patch to clean up the test-book-merge:
Index: component-manager.texinfo
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/doc/design/component-manager.texinfo,v
retrieving revision 1.5
retrieving revision 1.5.6.1
diff -Lsrc/doc/design/component-manager.texinfo -Lsrc/doc/design/component-manager.texinfo -u -r1.5 -r1.5.6.1
--- src/doc/design/component-manager.texinfo
+++ src/doc/design/component-manager.texinfo
@@ -207,7 +207,7 @@
 
 There is a utility function for accessing the @var{changes} hash:
 
- at deftypefun {const EventInfo *} gnc_gui_get_entity_events (GHashTable * @var{changes}, GUID * @var{entity})
+ at deftypefun {const EventInfo *} gnc_gui_get_entity_events (GHashTable * @var{changes}, const GUID * @var{entity})
 Return the event info for the entity specified by @var{entity}. If there
 are no events for that entity, @code{NULL} is returned.
 @end deftypefun
Index: gnc-component-manager.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/app-utils/gnc-component-manager.c,v
retrieving revision 1.13.4.3
retrieving revision 1.13.4.4
diff -Lsrc/app-utils/gnc-component-manager.c -Lsrc/app-utils/gnc-component-manager.c -u -r1.13.4.3 -r1.13.4.4
--- src/app-utils/gnc-component-manager.c
+++ src/app-utils/gnc-component-manager.c
@@ -392,10 +392,17 @@
   /* look for a free handler id */
   component_id = next_component_id;
 
+  /* design warning: if we ever get 2^32-1 components, 
+     this loop is infinite.  Instead of fixing it, we'll just 
+     complain when (if) we get half way there (probably never).
+  */ 
   while (find_component (component_id))
     if (++component_id == NO_COMPONENT)
       component_id++;
 
+  if (component_id < 0) 
+    PERR("Amazing! Half way to running out of component_ids.");
+  
   /* found one, add the handler */
   ci = g_new0 (ComponentInfo, 1);
 
@@ -520,7 +527,7 @@
 }
 
 const EventInfo *
-gnc_gui_get_entity_events (GHashTable *changes, GUID *entity)
+gnc_gui_get_entity_events (GHashTable *changes, const GUID *entity)
 {
   if (!changes || !entity)
     return GNC_EVENT_NONE;
Index: gnc-component-manager.h
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/app-utils/gnc-component-manager.h,v
retrieving revision 1.5.4.1
retrieving revision 1.5.4.2
diff -Lsrc/app-utils/gnc-component-manager.h -Lsrc/app-utils/gnc-component-manager.h -u -r1.5.4.1 -r1.5.4.2
--- src/app-utils/gnc-component-manager.h
+++ src/app-utils/gnc-component-manager.h
@@ -46,8 +46,8 @@
  *          GUIDs to EventInfo structs describing which
  *          events have been received. Entities not in
  *          the hash have not generated any events.
- *          Entities which have been destroyed may not
- *          exist.
+ *          Entities which have been destroyed will be in 
+ *          the hash, but may not exist anymore.
  *
  *          Note since refreshes may not occur with every change,
  *          an entity may have all three change values.
@@ -60,6 +60,15 @@
  *                      entities used by the component may have
  *                      already been deleted. 'Refreshing' the
  *                      component may require closing the component.
+ * 
+ * Notes on dealing with destroyed entities: As stated above, entities
+ * in the changes GHashTable may no longer exist.  So how can you
+ * determine if this has happened?  Well, it's a good idea to check
+ * for the GNC_EVENT_DESTROY bit in the EventInfo structure.  Of
+ * course, that means you need the hash key (GUID) for the destroyed
+ * entity.  How are you going to get the GUID from the entity if the
+ * entity has already been destroyed?  You're not.  So, you have to
+ * save a COPY of the key (GUID) away beforehand.
  *
  * user_data: user_data supplied when component was registered.
  */
@@ -222,7 +231,7 @@
  *          if it is not found.
  */
 const EventInfo * gnc_gui_get_entity_events (GHashTable *changes,
-                                             GUID *entity);
+                                             const GUID *entity);
 
 /* gnc_gui_component_clear_watches
  *   Clear all watches for the component.
Index: dialog-query-list.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/gnome-utils/dialog-query-list.c,v
retrieving revision 1.3.2.2
retrieving revision 1.3.2.3
diff -Lsrc/gnome-utils/dialog-query-list.c -Lsrc/gnome-utils/dialog-query-list.c -u -r1.3.2.2 -r1.3.2.3
--- src/gnome-utils/dialog-query-list.c
+++ src/gnome-utils/dialog-query-list.c
@@ -140,7 +140,7 @@
   {
     for (node = dql->books; node; node = node->next)
     {
-      info = gnc_gui_get_entity_events (changes, (GUID*)(node->data));
+      info = gnc_gui_get_entity_events (changes, (const GUID*)(node->data));
       if (info && (info->event_mask & GNC_EVENT_DESTROY))
       {
 	gnc_close_gui_component (dql->component_id);


More information about the gnucash-changes mailing list