File: Asynchronous_Object.h

package info (click to toggle)
kwave 0.7.2-5
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 9,048 kB
  • ctags: 4,906
  • sloc: cpp: 31,275; ansic: 13,111; sh: 9,511; perl: 2,724; makefile: 786; asm: 145
file content (119 lines) | stat: -rw-r--r-- 3,419 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/**
 * \file  mt/Asynchronous_Object.h
 * \brief Template classes for making methods asynchronously callable 
 *
 * Thanks to Carlos O'Ryan (coryan@cs.wustl.edu) for elucidating
 * the Daemon_Adapter pattern on which this is closely based.
 *
 * \author  Oliver M. Kellogg <Oliver.Kellogg@vs.dasa.de>
 * \author  Thomas Eschenbacher
 * \date    12.08.1998, Oct. 1998
 *
 * \par NOTE:
 *      this code is taken from the following news article 
 *      (found by www.dejanews.com):
 
 \verbatim
  ----------------------------------------------------------------------------
  Author: Oliver M. Kellogg <Oliver.Kellogg@vs.dasa.de>
  Date:   1998/08/12
  Forums: comp.soft-sys.ace
  ----------------------------------------------------------------------------
  Subject: Re: [ace-users] Handing non-static methods into ACE_Thread::spawn()
  From: ace-users@cs.wustl.edu
  Date: 1998/08/12
  Newsgroups: comp.soft-sys.ace

 \endverbatim

 */

/**
 * \class    Asynchronous_Object
 * \brief    Template classes for making methods asynchronously callable
 */

#ifndef _ASYNCHRONOUS_OBJECT_H_
#define _ASYNCHRONOUS_OBJECT_H_

#include "config.h"
#include "mt/Thread.h"

template <class T>class Asynchronous_Object: public Thread
{
    Q_OBJECT
public:
    typedef void (T::*PTMF) (void);

    /**
     * Constructor.
     * @param object pointer to the object that should be made
     *               asynchronously called
     * @param method pointer to a method within the object, will be made
     *               the thread's active function
     */
    Asynchronous_Object (T* object, PTMF method)
	:Thread(), o_(object), m_(method)
    {};

    /*! Wrapper function to execute the object's method as a thread */
    void run() { (o_->*m_) (); }
    
private:
    T* o_;          /*!< pointer to the object */
    PTMF m_;        /*!< pointer to the member function within the object */
};

template <class T, class Arg1>
class Asynchronous_Object_with_1_arg : public Thread
{
public:
    typedef void (T::*PTMF) (Arg1);
    Asynchronous_Object_with_1_arg (T* o, PTMF m, Arg1 a1)
    : Thread(), o_ (o), m_ (m), a1_(a1)
    {};
    void run() { (o_->*m_) (a1_); }
private:
    T* o_;
    PTMF m_;
    Arg1 a1_;
};

//template <class T, class Arg1, class Arg2>
//class Asynchronous_Object_with_2_args : public Daemon {
//public:
//    typedef void (T::*PTMF) (Arg1, Arg2);
//    Asynchronous_Object_with_2_args (T* o, PTMF m, Arg1 a1, Arg2 a2,
//                                           bool respawn = false,
//					   bool standalone = false)
//    : Daemon(respawn, standalone), o_ (o), m_ (m), a1_(a1), a2_(a2)
//    {};
//    void execute () { (o_->*m_) (a1_, a2_); }
//private:
//    T* o_;
//    PTMF m_;
//    Arg1 a1_;
//    Arg2 a2_;
//};
//
//template <class T, class Arg1, class Arg2, class Arg3>
//class Asynchronous_Object_with_3_args : public Daemon {
//public:
//    typedef void (T::*PTMF) (Arg1, Arg2, Arg3);
//    Asynchronous_Object_with_3_args (T* o, PTMF m, Arg1 a1, Arg2 a2, Arg3 a3,
//                                           bool respawn = false,
//					   bool standalone = false)
//    : Daemon(respawn, standalone), o_ (o), m_ (m), a1_(a1), a2_(a2), a3_(a3)
//    { };
//    void execute () { (o_->*m_) (a1_, a2_, a3_); }
//private:
//    T* o_;
//    PTMF m_;
//    Arg1 a1_;
//    Arg2 a2_;
//    Arg3 a3_;
//};

#endif /* _ASYNCHRONOUS_OBJECT_H_ */

/* end of mt/Asynchronous_Object.h */