foobar2000 SDK  2015-08-03
Data Structures | Public Types | Public Member Functions | Private Attributes
callInMainThreadHelper

#include <main_thread_callback.h>

Data Structures

class  entry
 
class  entryFunc
 
class  entryVoid
 

Public Types

typedef std::function< void() > func_t
 
typedef pfc::rcptr_t< bool > killswitch_t
 

Public Member Functions

 callInMainThreadHelper ()
 
 ~callInMainThreadHelper ()
 
void add (func_t f)
 
template<typename host_t , typename arg_t >
void add (host_t *host, arg_t const &arg)
 
template<typename host_t >
void add (host_t *host)
 
void add_ (main_thread_callback::ptr cb)
 
void shutdown ()
 

Private Attributes

killswitch_t m_ks
 

Detailed Description

Helper class to call methods of your class (host class) in main thread with convenience.
Deals with the otherwise ugly scenario of your class becoming invalid while a method is queued.
Have this as a member of your class, then use m_mthelper.add( this, somearg ) ; to defer a call to this->inMainThread(somearg).
If your class becomes invalid before inMainThread is executed, the pending callback is discarded.
You can optionally call shutdown() to invalidate all pending callbacks early (in a destructor of your class - without waiting for callInMainThreadHelper destructor to do the job.
In order to let callInMainThreadHelper access your private methods, declare friend class callInMainThread.

Definition at line 84 of file main_thread_callback.h.

Member Typedef Documentation

typedef std::function< void () > callInMainThreadHelper::func_t

Definition at line 87 of file main_thread_callback.h.

Definition at line 89 of file main_thread_callback.h.

Constructor & Destructor Documentation

callInMainThreadHelper::callInMainThreadHelper ( )
inline

Definition at line 144 of file main_thread_callback.h.

144  {
145  m_ks.new_t();
146  * m_ks = false;
147  }
void new_t()
Definition: rcptr.h:101
callInMainThreadHelper::~callInMainThreadHelper ( )
inline

Definition at line 152 of file main_thread_callback.h.

152  {
153  shutdown();
154  }

Member Function Documentation

void callInMainThreadHelper::add ( func_t  f)
inline

Definition at line 128 of file main_thread_callback.h.

128  {
129  add_( new service_impl_t< entryFunc > ( f, m_ks ) );
130  }
void add_(main_thread_callback::ptr cb)
Template implementing reference-counting features of service_base. Intended for dynamic instantiation...
Definition: service_impl.h:4
template<typename host_t , typename arg_t >
void callInMainThreadHelper::add ( host_t *  host,
arg_t const &  arg 
)
inline

Definition at line 133 of file main_thread_callback.h.

133  {
134  add_( new service_impl_t< entry<host_t, arg_t> >( host, arg, m_ks ) );
135  }
void add_(main_thread_callback::ptr cb)
Template implementing reference-counting features of service_base. Intended for dynamic instantiation...
Definition: service_impl.h:4
template<typename host_t >
void callInMainThreadHelper::add ( host_t *  host)
inline

Definition at line 137 of file main_thread_callback.h.

137  {
138  add_( new service_impl_t< entryVoid<host_t> >( host, m_ks ) );
139  }
void add_(main_thread_callback::ptr cb)
Template implementing reference-counting features of service_base. Intended for dynamic instantiation...
Definition: service_impl.h:4
void callInMainThreadHelper::add_ ( main_thread_callback::ptr  cb)
inline

Definition at line 140 of file main_thread_callback.h.

140  {
142  }
void main_thread_callback_add(main_thread_callback::ptr ptr)
void callInMainThreadHelper::shutdown ( )
inline

Definition at line 148 of file main_thread_callback.h.

148  {
149  PFC_ASSERT( core_api::is_main_thread() );
150  * m_ks = true;
151  }
bool is_main_thread()
Returns true if calling thread is main app thread, false otherwise.

Field Documentation

killswitch_t callInMainThreadHelper::m_ks
private

Definition at line 157 of file main_thread_callback.h.


The documentation for this class was generated from the following file: