foobar2000 SDK  2015-08-03
abort_callback.h
Go to the documentation of this file.
1 #ifndef _foobar2000_sdk_abort_callback_h_
2 #define _foobar2000_sdk_abort_callback_h_
3 
4 namespace foobar2000_io {
5 
6 PFC_DECLARE_EXCEPTION(exception_aborted,pfc::exception,"User abort");
7 
9 
10 #ifdef check
11 #undef check
12 #endif
13 class NOVTABLE abort_callback
18 {
19 public:
21  virtual bool is_aborting() const = 0;
22 
23  inline bool is_set() const {return is_aborting();}
24 
27  virtual abort_callback_event get_abort_event() const = 0;
28 
29  inline abort_callback_event get_handle() const {return get_abort_event();}
30 
32  void check() const;
33 
35  inline void check_e() const {check();}
36 
37 
39  void sleep(double p_timeout_seconds) const;
41  bool sleep_ex(double p_timeout_seconds) const;
42 
43  bool waitForEvent( pfc::eventHandle_t evtHandle, double timeOut );
44  bool waitForEvent( pfc::event & evt, double timeOut ) {return waitForEvent( evt.get_handle(), timeOut ); }
45 protected:
48 };
49 
50 
51 
54 public:
55  abort_callback_impl() : m_aborting(false) {}
56  inline void abort() {set_state(true);}
57  inline void set() {set_state(true);}
58  inline void reset() {set_state(false);}
59 
60  void set_state(bool p_state) {m_aborting = p_state; m_event.set_state(p_state);}
61 
62  bool is_aborting() const {return m_aborting;}
63 
64  abort_callback_event get_abort_event() const {return m_event.get_handle();}
65 
66 private:
68  const abort_callback_impl & operator=(const abort_callback_impl&);
69 
70  volatile bool m_aborting;
72 };
73 
74 #ifdef _WIN32
75 class abort_callback_dummy : public abort_callback {
78 public:
79  bool is_aborting() const { return false; }
80 
81  abort_callback_event get_abort_event() const { return GetInfiniteWaitEvent();}
82 };
83 #else
84 
85 // FIX ME come up with a scheme to produce a persistent infinite wait filedescriptor on non Windows
86 // Could use /dev/null but still need to open it on upon object creation which defeats the purpose
88 
89 #endif
90 
91 }
95 
96 using namespace foobar2000_io;
97 
98 #define FB2K_PFCv2_ABORTER_SCOPE( abortObj ) \
99  (abortObj).check(); \
100  PP::waitableReadRef_t aborterRef = {(abortObj).get_abort_event()}; \
101  PP::aborter aborter_pfcv2( aborterRef ); \
102  PP::aborterScope l_aborterScope( aborter_pfcv2 );
103 
104 #endif //_foobar2000_sdk_abort_callback_h_
This class is used to signal underlying worker code whether user has decided to abort a potentially t...
foobar2000_io::abort_callback fb2k_event
foobar2000_io::abort_callback_impl fb2k_event_impl
bool waitForEvent(pfc::event &evt, double timeOut)
pfc::eventHandle_t abort_callback_event
Definition: abort_callback.h:8
Implementation of abort_callback interface.
abort_callback_impl abort_callback_dummy
HANDLE eventHandle_t
Definition: event.h:4
PFC_DECLARE_EXCEPTION(exception_aborted, pfc::exception,"User abort")
bool is_aborting() const
Returns whether user has requested the operation to be aborted.
Contains various I/O related structures and interfaces.
Definition: filetimetools.h:1
HANDLE get_handle() const
Definition: event.h:10
Dummy abort_callback that never gets aborted. Slightly more efficient than the regular one especiall...
abort_callback_event get_handle() const
foobar2000_io::abort_callback_event fb2k_event_handle
std::exception exception
Definition: primitives.h:193
void check_e() const
For compatibility with old code. Do not call.
HANDLE SHARED_EXPORT GetInfiniteWaitEvent()
bool is_aborting() const
Returns whether user has requested the operation to be aborted.
abort_callback_event get_abort_event() const
Retrieves event object that can be used with some OS calls. The even object becomes signaled when abo...
abort_callback_event get_abort_event() const
Retrieves event object that can be used with some OS calls. The even object becomes signaled when abo...