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 00024 virtual abort_callback_event get_abort_event() const = 0; 00025 00027 void check() const; 00028 00030 inline void check_e() const {check();} 00031 00032 00034 void sleep(double p_timeout_seconds) const; 00036 bool sleep_ex(double p_timeout_seconds) const; 00037 protected: 00038 abort_callback() {} 00039 ~abort_callback() {} 00040 }; 00041 00042 00043 00045 class abort_callback_impl : public abort_callback { 00046 public: 00047 abort_callback_impl() : m_aborting(false) { 00048 m_event.create(true,false); 00049 } 00050 inline void abort() {set_state(true);} 00051 inline void reset() {set_state(false);} 00052 00053 void set_state(bool p_state) {m_aborting = p_state; m_event.set_state(p_state);} 00054 00055 bool is_aborting() const {return m_aborting;} 00056 00057 abort_callback_event get_abort_event() const {return m_event.get();} 00058 00059 private: 00060 abort_callback_impl(const abort_callback_impl &) {throw pfc::exception_not_implemented();} 00061 const abort_callback_impl & operator=(const abort_callback_impl&) {throw pfc::exception_not_implemented();} 00062 00063 volatile bool m_aborting; 00064 #ifdef WIN32 00065 win32_event m_event; 00066 #endif 00067 }; 00068 00070 typedef abort_callback_impl abort_callback_dummy; 00071 00072 } 00073 00074 using namespace foobar2000_io; 00075 00076 #endif //_foobar2000_sdk_abort_callback_h_
1.5.5