00001 #ifndef _foobar2000_sdk_abort_callback_h_ 00002 #define _foobar2000_sdk_abort_callback_h_ 00003 00004 namespace foobar2000_io { 00005 00006 PFC_DECLARE_EXCEPTION(exception_aborted,pfc::exception,"User abort"); 00007 00008 #ifdef _WIN32 00009 typedef HANDLE abort_callback_event; 00010 #else 00011 #error PORTME 00012 #endif 00013 00016 class NOVTABLE abort_callback 00017 { 00018 public: 00020 virtual bool is_aborting() const = 0; 00021 00023 virtual abort_callback_event get_abort_event() const = 0; 00024 00026 void check() const; 00027 00029 inline void check_e() const {check();} 00030 00031 00033 void sleep(double p_timeout_seconds) const; 00035 bool sleep_ex(double p_timeout_seconds) const; 00036 protected: 00037 abort_callback() {} 00038 ~abort_callback() {} 00039 }; 00040 00041 00042 00044 class abort_callback_impl : public abort_callback { 00045 public: 00046 abort_callback_impl() : m_aborting(false) { 00047 m_event.create(true,false); 00048 } 00049 inline void abort() {set_state(true);} 00050 inline void reset() {set_state(false);} 00051 00052 void set_state(bool p_state) {m_aborting = p_state; m_event.set_state(p_state);} 00053 00054 bool is_aborting() const {return m_aborting;} 00055 00056 abort_callback_event get_abort_event() const {return m_event.get();} 00057 00058 private: 00059 abort_callback_impl(const abort_callback_impl &) {throw pfc::exception_not_implemented();} 00060 const abort_callback_impl & operator=(const abort_callback_impl&) {throw pfc::exception_not_implemented();} 00061 00062 volatile bool m_aborting; 00063 #ifdef WIN32 00064 win32_event m_event; 00065 #endif 00066 }; 00067 00069 typedef abort_callback_impl abort_callback_dummy; 00070 00071 } 00072 00073 using namespace foobar2000_io; 00074 00075 #endif //_foobar2000_sdk_abort_callback_h_
1.5.5