[Aptitude-svn-commit] r4140 - in branches/aptitude-0.3/aptitude: . src/vscreen

Daniel Burrows dburrows at costa.debian.org
Tue Sep 20 22:33:31 UTC 2005


Author: dburrows
Date: Tue Sep 20 22:33:25 2005
New Revision: 4140

Modified:
   branches/aptitude-0.3/aptitude/ChangeLog
   branches/aptitude-0.3/aptitude/src/vscreen/vscreen.cc
   branches/aptitude-0.3/aptitude/src/vscreen/vscreen.h
Log:
Add a safe wrapper that converts sigc++ slots into vscreen events.  This is
particularly important for timeouts, since timeouts are posted from the
main thread (hence manipulating slots from them is safe) but may not run
immediately (hence you can have problems if the target object is deleted
in the meantime).


Modified: branches/aptitude-0.3/aptitude/ChangeLog
==============================================================================
--- branches/aptitude-0.3/aptitude/ChangeLog	(original)
+++ branches/aptitude-0.3/aptitude/ChangeLog	Tue Sep 20 22:33:25 2005
@@ -1,5 +1,10 @@
 2005-09-20  Daniel Burrows  <dburrows at debian.org>
 
+	* src/vscreen/vscreen.cc, src/vscreen/vscreen.h:
+
+	  Add a slot_event that wraps a sigc++ slot in a safe
+	  vscreen_event wrapper.
+
 	* src/vscreen/vs_tree.cc:
 
 	  Be robust in the face of a totally empty tree (one with a NULL

Modified: branches/aptitude-0.3/aptitude/src/vscreen/vscreen.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/vscreen/vscreen.cc	(original)
+++ branches/aptitude-0.3/aptitude/src/vscreen/vscreen.cc	Tue Sep 20 22:33:25 2005
@@ -102,6 +102,11 @@
 {
 }
 
+void slot_event::dispatch()
+{
+  the_slot();
+}
+
 static vs_widget_ref toplevel = NULL;
 // The widget which is displayed as the root of everything
 

Modified: branches/aptitude-0.3/aptitude/src/vscreen/vscreen.h
==============================================================================
--- branches/aptitude-0.3/aptitude/src/vscreen/vscreen.h	(original)
+++ branches/aptitude-0.3/aptitude/src/vscreen/vscreen.h	Tue Sep 20 22:33:25 2005
@@ -41,6 +41,27 @@
   virtual ~vscreen_event();
 };
 
+/** An event based on sigc++ slots.  This is important because it can
+ *  avoid some timing issues that occur when an object is destroyed
+ *  before its callback triggers.  However, you cannot construct one
+ *  of these threadsafely unless you are EXTREMELY careful, because it
+ *  involves a slot copy; as with other sigc++ stuff, I recommend that
+ *  you only create these in the 'main thread'.  (of course, passing
+ *  around pointers to the resulting object is just fine, as long as
+ *  the final invocation is also in the main thread)
+ */
+class slot_event : public vscreen_event
+{
+  sigc::slot0<void> the_slot;
+public:
+  slot_event(const sigc::slot0<void> &_the_slot)
+    : the_slot(_the_slot)
+  {
+  }
+
+  void dispatch();
+};
+
 class vscreen_widget;
 
 void vscreen_init();



More information about the Aptitude-svn-commit mailing list