[geos-commits] r3672 - in trunk: capi include/geos/util src/util tests/unit/capi

svn_geos at osgeo.org svn_geos at osgeo.org
Thu Jun 7 08:11:08 PDT 2012


Author: strk
Date: 2012-06-07 08:11:06 -0700 (Thu, 07 Jun 2012)
New Revision: 3672

Modified:
   trunk/capi/geos_c.cpp
   trunk/capi/geos_c.h.in
   trunk/include/geos/util/Interrupt.h
   trunk/src/util/Interrupt.cpp
   trunk/tests/unit/capi/GEOSInterruptTest.cpp
Log:
Allow chaining interrupt callbacks, drop arg parameter

Modified: trunk/capi/geos_c.cpp
===================================================================
--- trunk/capi/geos_c.cpp	2012-06-07 15:10:18 UTC (rev 3671)
+++ trunk/capi/geos_c.cpp	2012-06-07 15:11:06 UTC (rev 3672)
@@ -115,10 +115,10 @@
     }
 }
 
-void
-GEOS_interruptRegisterCallback(GEOSInterruptCallback* cb, void *cbarg)
+GEOSInterruptCallback*
+GEOS_interruptRegisterCallback(GEOSInterruptCallback* cb)
 {
-  geos::util::Interrupt::registerCallback(cb, cbarg);
+  return geos::util::Interrupt::registerCallback(cb);
 }
 
 void

Modified: trunk/capi/geos_c.h.in
===================================================================
--- trunk/capi/geos_c.h.in	2012-06-07 15:10:18 UTC (rev 3671)
+++ trunk/capi/geos_c.h.in	2012-06-07 15:11:06 UTC (rev 3672)
@@ -155,8 +155,8 @@
  * The callback will be invoked _before_ checking for
  * interruption, so can be used to request it.
  */
-typedef void (GEOSInterruptCallback)(void *arg);
-extern void GEOS_DLL GEOS_interruptRegisterCallback(GEOSInterruptCallback* cb, void *cbarg);
+typedef void (GEOSInterruptCallback)();
+extern GEOSInterruptCallback GEOS_DLL *GEOS_interruptRegisterCallback(GEOSInterruptCallback* cb);
 /* Request safe interruption of operations */
 extern void GEOS_DLL GEOS_interruptRequest();
 /* Cancel a pending interruption request */

Modified: trunk/include/geos/util/Interrupt.h
===================================================================
--- trunk/include/geos/util/Interrupt.h	2012-06-07 15:10:18 UTC (rev 3671)
+++ trunk/include/geos/util/Interrupt.h	2012-06-07 15:11:06 UTC (rev 3672)
@@ -27,7 +27,7 @@
 
 public:
 
-  typedef void (Callback)(void *userdata);
+  typedef void (Callback)(void);
 
   /** 
    * Request interruption of operations
@@ -53,14 +53,18 @@
    * The callback can be used to call Interrupt::request()
    *
    */
-  static void registerCallback(Callback *cb, void *arg) { callback = cb; callback_arg = arg; }
+  static Callback* registerCallback(Callback *cb) {
+    Callback* prev = callback;
+    callback = cb;
+    return prev;
+  }
 
   /**
    * Invoke the callback, if any. Process pending interruption, if any.
    *
    */
   static void process() {
-    if ( callback ) (*callback)(callback_arg);
+    if ( callback ) (*callback)();
     if ( requested ) {
       requested = false;
       interrupt();
@@ -78,8 +82,6 @@
 
   static Callback *callback;
 
-  static void *callback_arg;
-
 };
 
 

Modified: trunk/src/util/Interrupt.cpp
===================================================================
--- trunk/src/util/Interrupt.cpp	2012-06-07 15:10:18 UTC (rev 3671)
+++ trunk/src/util/Interrupt.cpp	2012-06-07 15:11:06 UTC (rev 3672)
@@ -32,7 +32,6 @@
 
 bool Interrupt::requested = false;
 Interrupt::Callback *Interrupt::callback = 0;
-void *Interrupt::callback_arg = 0;
 
 } // namespace geos::util
 } // namespace geos

Modified: trunk/tests/unit/capi/GEOSInterruptTest.cpp
===================================================================
--- trunk/tests/unit/capi/GEOSInterruptTest.cpp	2012-06-07 15:10:18 UTC (rev 3671)
+++ trunk/tests/unit/capi/GEOSInterruptTest.cpp	2012-06-07 15:11:06 UTC (rev 3672)
@@ -19,8 +19,8 @@
     // Common data used in test cases.
     struct test_capiinterrupt_data
     {
-        static int alloc_count;
-        static int dealloc_count;
+        static int numcalls;
+        static GEOSInterruptCallback* nextcb;
 
         static void notice(const char *fmt, ...)
         {
@@ -42,21 +42,21 @@
         {
         }
 
-        static void interruptNow(void *)
+        static void interruptNow()
         {
           GEOS_interruptRequest();
         }
 
-        static void countCalls(void *arg)
+        static void countCalls()
         {
-          int* numcalls = reinterpret_cast<int*>(arg);
-          ++(*numcalls);
+          ++numcalls;
+          if ( nextcb ) (*nextcb)();
         }
 
     };
 
-    int test_capiinterrupt_data::alloc_count = 0;
-    int test_capiinterrupt_data::dealloc_count = 0;
+    int test_capiinterrupt_data::numcalls = 0;
+    GEOSInterruptCallback* test_capiinterrupt_data::nextcb = 0;
 
     typedef test_group<test_capiinterrupt_data> group;
     typedef group::object object;
@@ -72,11 +72,11 @@
     template<>
     void object::test<1>()
     {
-        int numcalls = 0;
+        numcalls = 0;
 
         initGEOS(notice, notice);
 
-        GEOS_interruptRegisterCallback(countCalls, &numcalls);
+        GEOS_interruptRegisterCallback(countCalls);
 
         ensure_equals(numcalls, 0);
 
@@ -93,7 +93,7 @@
         GEOSGeom_destroy(geom1);
         GEOSGeom_destroy(geom2);
 
-        GEOS_interruptRegisterCallback(0, 0); /* unregister */
+        GEOS_interruptRegisterCallback(0); /* unregister */
 
 
         finishGEOS();
@@ -104,9 +104,9 @@
     template<>
     void object::test<2>()
     {
-        int numcalls = 0;
+        numcalls = 0;
 
-        GEOS_interruptRegisterCallback(countCalls, &numcalls);
+        GEOS_interruptRegisterCallback(countCalls);
 
         initGEOS(notice, notice);
 
@@ -125,9 +125,8 @@
         GEOSGeom_destroy(geom1);
         GEOSGeom_destroy(geom2);
 
-        GEOS_interruptRegisterCallback(0, 0); /* unregister (shouldn't be needed) */
+        GEOS_interruptRegisterCallback(0); 
 
-
         finishGEOS();
     }
 
@@ -142,11 +141,10 @@
 
         ensure("GEOSGeomFromWKT failed", 0 != geom1);
 
-        GEOS_interruptRegisterCallback(interruptNow, 0); 
-        bool interrupted = false;
+        GEOS_interruptRegisterCallback(interruptNow); 
         GEOSGeometry *geom2 = GEOSBuffer(geom1, 1, 8);
         ensure("GEOSBuffer wasn't interrupted", 0 == geom2);
-        GEOS_interruptRegisterCallback(0, 0);  /* unregister */
+        GEOS_interruptRegisterCallback(0);  /* unregister */
 
         // TODO: check the actual exception ? (sent to notice() callback)
 
@@ -155,6 +153,32 @@
         finishGEOS();
     }
 
+    /// Test chaining interrupt callbacks
+    template<>
+    template<>
+    void object::test<4>()
+    {
+        numcalls = 0;
 
+        initGEOS(notice, notice);
+
+        GEOSGeometry *geom1 = GEOSGeomFromWKT("LINESTRING(0 0, 1 0)");
+
+        ensure("GEOSGeomFromWKT failed", 0 != geom1);
+
+        GEOS_interruptRegisterCallback(interruptNow); 
+        nextcb = GEOS_interruptRegisterCallback(countCalls); 
+        GEOSGeometry *geom2 = GEOSBuffer(geom1, 1, 8);
+        ensure("GEOSBuffer wasn't interrupted", 0 == geom2);
+        ensure_equals(numcalls, 1);
+        GEOS_interruptRegisterCallback(0);  /* unregister */
+        nextcb = 0;
+
+        GEOSGeom_destroy(geom1);
+
+        finishGEOS();
+    }
+
+
 } // namespace tut
 



More information about the geos-commits mailing list