-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
319 changed files
with
52,234 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
SDK/ | ||
Release/ | ||
Debug/ | ||
src/Release/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include "foobar2000.h" | ||
|
||
void abort_callback::check() const { | ||
if (is_aborting()) throw exception_aborted(); | ||
} | ||
|
||
void abort_callback::sleep(double p_timeout_seconds) const { | ||
if (!sleep_ex(p_timeout_seconds)) throw exception_aborted(); | ||
} | ||
|
||
bool abort_callback::sleep_ex(double p_timeout_seconds) const { | ||
// return true IF NOT SET (timeout), false if set | ||
return !pfc::event::g_wait_for(get_abort_event(),p_timeout_seconds); | ||
} | ||
|
||
bool abort_callback::waitForEvent( pfc::eventHandle_t evtHandle, double timeOut ) { | ||
int status = pfc::event::g_twoEventWait( this->get_abort_event(), evtHandle, timeOut ); | ||
switch(status) { | ||
case 1: throw exception_aborted(); | ||
case 2: return true; | ||
case 0: return false; | ||
default: uBugCheck(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
#ifndef _foobar2000_sdk_abort_callback_h_ | ||
#define _foobar2000_sdk_abort_callback_h_ | ||
|
||
namespace foobar2000_io { | ||
|
||
PFC_DECLARE_EXCEPTION(exception_aborted,pfc::exception,"User abort"); | ||
|
||
typedef pfc::eventHandle_t abort_callback_event; | ||
|
||
#ifdef check | ||
#undef check | ||
#endif | ||
//! This class is used to signal underlying worker code whether user has decided to abort a potentially time-consuming operation. \n | ||
//! It is commonly required by all filesystem related or decoding-related operations. \n | ||
//! Code that receives an abort_callback object should periodically check it and abort any operations being performed if it is signaled, typically throwing exception_aborted. \n | ||
//! See abort_callback_impl for an implementation. | ||
class NOVTABLE abort_callback | ||
{ | ||
public: | ||
//! Returns whether user has requested the operation to be aborted. | ||
virtual bool is_aborting() const = 0; | ||
|
||
inline bool is_set() const {return is_aborting();} | ||
|
||
//! Retrieves event object that can be used with some OS calls. The even object becomes signaled when abort is triggered. On win32, this is equivalent to win32 event handle (see: CreateEvent). \n | ||
//! You must not close this handle or call any methods that change this handle's state (SetEvent() or ResetEvent()), you can only wait for it. | ||
virtual abort_callback_event get_abort_event() const = 0; | ||
|
||
inline abort_callback_event get_handle() const {return get_abort_event();} | ||
|
||
//! Checks if user has requested the operation to be aborted, and throws exception_aborted if so. | ||
void check() const; | ||
|
||
//! For compatibility with old code. Do not call. | ||
inline void check_e() const {check();} | ||
|
||
|
||
//! Sleeps p_timeout_seconds or less when aborted, throws exception_aborted on abort. | ||
void sleep(double p_timeout_seconds) const; | ||
//! Sleeps p_timeout_seconds or less when aborted, returns true when execution should continue, false when not. | ||
bool sleep_ex(double p_timeout_seconds) const; | ||
|
||
bool waitForEvent( pfc::eventHandle_t evtHandle, double timeOut ); | ||
bool waitForEvent( pfc::event & evt, double timeOut ) {return waitForEvent( evt.get_handle(), timeOut ); } | ||
protected: | ||
abort_callback() {} | ||
~abort_callback() {} | ||
}; | ||
|
||
|
||
|
||
//! Implementation of abort_callback interface. | ||
class abort_callback_impl : public abort_callback { | ||
public: | ||
abort_callback_impl() : m_aborting(false) {} | ||
inline void abort() {set_state(true);} | ||
inline void set() {set_state(true);} | ||
inline void reset() {set_state(false);} | ||
|
||
void set_state(bool p_state) {m_aborting = p_state; m_event.set_state(p_state);} | ||
|
||
bool is_aborting() const {return m_aborting;} | ||
|
||
abort_callback_event get_abort_event() const {return m_event.get_handle();} | ||
|
||
private: | ||
abort_callback_impl(const abort_callback_impl &); | ||
const abort_callback_impl & operator=(const abort_callback_impl&); | ||
|
||
volatile bool m_aborting; | ||
pfc::event m_event; | ||
}; | ||
|
||
#ifdef _WIN32 | ||
//! Dummy abort_callback that never gets aborted. \n | ||
//! Slightly more efficient than the regular one especially when you need to regularly create temporary instances of it. | ||
class abort_callback_dummy : public abort_callback { | ||
public: | ||
bool is_aborting() const { return false; } | ||
|
||
abort_callback_event get_abort_event() const { return GetInfiniteWaitEvent();} | ||
}; | ||
#else | ||
|
||
// FIX ME come up with a scheme to produce a persistent infinite wait filedescriptor on non Windows | ||
// Could use /dev/null but still need to open it on upon object creation which defeats the purpose | ||
typedef abort_callback_impl abort_callback_dummy; | ||
|
||
#endif | ||
|
||
} | ||
typedef foobar2000_io::abort_callback_event fb2k_event_handle; | ||
typedef foobar2000_io::abort_callback fb2k_event; | ||
typedef foobar2000_io::abort_callback_impl fb2k_event_impl; | ||
|
||
using namespace foobar2000_io; | ||
|
||
#define FB2K_PFCv2_ABORTER_SCOPE( abortObj ) \ | ||
(abortObj).check(); \ | ||
PP::waitableReadRef_t aborterRef = {(abortObj).get_abort_event()}; \ | ||
PP::aborter aborter_pfcv2( aborterRef ); \ | ||
PP::aborterScope l_aborterScope( aborter_pfcv2 ); | ||
|
||
#endif //_foobar2000_sdk_abort_callback_h_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#include "foobar2000.h" | ||
|
||
|
||
t_uint32 advconfig_entry::get_preferences_flags_() { | ||
{ | ||
advconfig_entry_string_v2::ptr ex; | ||
if (service_query_t(ex)) return ex->get_preferences_flags(); | ||
} | ||
{ | ||
advconfig_entry_checkbox_v2::ptr ex; | ||
if (service_query_t(ex)) return ex->get_preferences_flags(); | ||
} | ||
return 0; | ||
} | ||
|
||
bool advconfig_entry_checkbox::get_default_state_() { | ||
{ | ||
advconfig_entry_checkbox_v2::ptr ex; | ||
if (service_query_t(ex)) return ex->get_default_state(); | ||
} | ||
|
||
bool backup = get_state(); | ||
reset(); | ||
bool rv = get_state(); | ||
set_state(backup); | ||
return rv; | ||
} | ||
|
||
void advconfig_entry_string::get_default_state_(pfc::string_base & out) { | ||
{ | ||
advconfig_entry_string_v2::ptr ex; | ||
if (service_query_t(ex)) {ex->get_default_state(out); return;} | ||
} | ||
pfc::string8 backup; | ||
get_state(backup); | ||
reset(); | ||
get_state(out); | ||
set_state(backup); | ||
} |
Oops, something went wrong.