foobar2000 SDK  2015-08-03
CallForwarder.h
Go to the documentation of this file.
1 namespace CF {
2  template<typename obj_t, typename arg_t> class _inMainThread : public main_thread_callback {
3  public:
4  _inMainThread(obj_t const & obj, const arg_t & arg) : m_obj(obj), m_arg(arg) {}
5 
6  void callback_run() {
7  if (m_obj.IsValid()) callInMainThread::callThis(&*m_obj, m_arg);
8  }
9  private:
10  obj_t m_obj;
11  arg_t m_arg;
12  };
13 
14  template<typename TWhat> class CallForwarder {
15  public:
16  CallForwarder(TWhat * ptr) { m_ptr.new_t(ptr); }
17 
18  void Orphan() {*m_ptr = NULL;}
19  bool IsValid() const { return *m_ptr != NULL; }
20  bool IsEmpty() const { return !IsValid(); }
21 
22  TWhat * operator->() const {
23  PFC_ASSERT( IsValid() );
24  return *m_ptr;
25  }
26 
27  TWhat & operator*() const {
28  PFC_ASSERT( IsValid() );
29  return **m_ptr;
30  }
31 
32  template<typename arg_t>
33  void callInMainThread(const arg_t & arg) {
35  }
36  private:
38  };
39 
40  template<typename TWhat> class CallForwarderMaster : public CallForwarder<TWhat> {
41  public:
42  CallForwarderMaster(TWhat * ptr) : CallForwarder<TWhat>(ptr) {}
43  ~CallForwarderMaster() { this->Orphan(); }
44 
45  PFC_CLASS_NOT_COPYABLE(CallForwarderMaster, CallForwarderMaster<TWhat>);
46  };
47 
48 }
void callback_run()
Gets called from main app thread. See main_thread_callback_manager description for more info...
Definition: CallForwarder.h:6
Template implementing reference-counting features of service_base. Intended for dynamic instantiation...
Definition: service_impl.h:4
static void callThis(host_t *host, param_t &param)
void main_thread_callback_add(main_thread_callback::ptr ptr)
TWhat & operator*() const
Definition: CallForwarder.h:27
_inMainThread(obj_t const &obj, const arg_t &arg)
Definition: CallForwarder.h:4
void callInMainThread(const arg_t &arg)
Definition: CallForwarder.h:33
pfc::rcptr_t< TWhat * > m_ptr
Definition: CallForwarder.h:37
CallForwarderMaster(TWhat *ptr)
Definition: CallForwarder.h:42
TWhat * operator->() const
Definition: CallForwarder.h:22
bool IsValid() const
Definition: CallForwarder.h:19
bool IsEmpty() const
Definition: CallForwarder.h:20
CallForwarder(TWhat *ptr)
Definition: CallForwarder.h:16
Callback object class for main_thread_callback_manager service.