1 /********************************************************************** 2 * 3 * GEOS - Geometry Engine Open Source 4 * http://geos.osgeo.org 5 * 6 * Copyright (C) 2012 Sandro Santilli <strk@kbt.io> 7 * 8 * This is free software; you can redistribute and/or modify it under 9 * the terms of the GNU Lesser General Public Licence as published 10 * by the Free Software Foundation. 11 * See the COPYING file for more information. 12 * 13 **********************************************************************/ 14 15 #ifndef GEOS_UTIL_INTERRUPT_H 16 #define GEOS_UTIL_INTERRUPT_H 17 18 #include <geos/export.h> 19 20 namespace geos { 21 namespace util { // geos::util 22 23 #define GEOS_CHECK_FOR_INTERRUPTS() geos::util::Interrupt::process() 24 25 /** \brief Used to manage interruption requests and callbacks. */ 26 class GEOS_DLL Interrupt { 27 28 public: 29 30 typedef void (Callback)(void); 31 32 /** 33 * Request interruption of operations 34 * 35 * Operations will be terminated by a GEOSInterrupt 36 * exception at first occasion. 37 */ 38 static void request(); 39 40 /** Cancel a pending interruption request */ 41 static void cancel(); 42 43 /** Check if an interruption request is pending */ 44 static bool check(); 45 46 /** \brief 47 * Register a callback that will be invoked 48 * before checking for interruption requests. 49 * 50 * NOTE that interruption request checking may happen 51 * frequently so any callback would better be quick. 52 * 53 * The callback can be used to call Interrupt::request() 54 * 55 */ 56 static Callback* registerCallback(Callback* cb); 57 58 /** 59 * Invoke the callback, if any. Process pending interruption, if any. 60 * 61 */ 62 static void process(); 63 64 /* Perform the actual interruption (simply throw an exception) */ 65 static void interrupt(); 66 67 }; 68 69 70 } // namespace geos::util 71 } // namespace geos 72 73 74 #endif // GEOS_UTIL_INTERRUPT_H 75