foobar2000 SDK  2015-01-14
Data Structures | Public Types | Public Member Functions | Private Attributes
callInMainThreadHelper

#include <main_thread_callback.h>

Data Structures

class  entry
 
class  entryVoid
 

Public Types

typedef pfc::rcptr_t< bool > killswitch_t
 

Public Member Functions

 callInMainThreadHelper ()
 
 ~callInMainThreadHelper ()
 
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 82 of file main_thread_callback.h.

Member Typedef Documentation

Definition at line 85 of file main_thread_callback.h.

Constructor & Destructor Documentation

callInMainThreadHelper::callInMainThreadHelper ( )
inline

Definition at line 123 of file main_thread_callback.h.

123  {
124  m_ks.new_t();
125  * m_ks = false;
126  }
void new_t()
Definition: rcptr.h:101
callInMainThreadHelper::~callInMainThreadHelper ( )
inline

Definition at line 131 of file main_thread_callback.h.

131  {
132  shutdown();
133  }

Member Function Documentation

template<typename host_t , typename arg_t >
void callInMainThreadHelper::add ( host_t *  host,
arg_t const &  arg 
)
inline

Definition at line 112 of file main_thread_callback.h.

112  {
113  add_( new service_impl_t< entry<host_t, arg_t> >( host, arg, m_ks ) );
114  }
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 116 of file main_thread_callback.h.

116  {
117  add_( new service_impl_t< entryVoid<host_t> >( host, m_ks ) );
118  }
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 119 of file main_thread_callback.h.

119  {
121  }
void main_thread_callback_add(main_thread_callback::ptr ptr)
void callInMainThreadHelper::shutdown ( )
inline

Definition at line 127 of file main_thread_callback.h.

127  {
128  PFC_ASSERT( core_api::is_main_thread() );
129  * m_ks = true;
130  }
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 136 of file main_thread_callback.h.


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