24
|
1 |
// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
2 |
// All rights reserved.
|
|
3 |
// This component and the accompanying materials are made available
|
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
|
5 |
// which accompanies this distribution, and is available
|
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
7 |
//
|
|
8 |
// Initial Contributors:
|
|
9 |
// Nokia Corporation - initial contribution.
|
|
10 |
//
|
|
11 |
// Contributors:
|
|
12 |
//
|
|
13 |
// Description:
|
|
14 |
// Contains the CThreadExec class declaration.
|
|
15 |
//
|
|
16 |
//
|
|
17 |
|
|
18 |
/**
|
|
19 |
@file
|
|
20 |
@internalTechnology
|
|
21 |
*/
|
|
22 |
|
|
23 |
#ifndef CTHREADEXEC_H
|
|
24 |
#define CTHREADEXEC_H
|
|
25 |
|
|
26 |
#include <e32base.h>
|
|
27 |
#include <etelmm.h>
|
|
28 |
|
|
29 |
|
|
30 |
class CThreadExec : public CBase
|
|
31 |
{
|
|
32 |
public:
|
|
33 |
class MFunctor
|
|
34 |
{
|
|
35 |
public:
|
|
36 |
virtual void ExecL() =0;
|
|
37 |
};
|
|
38 |
|
|
39 |
template<class C>
|
|
40 |
class TFunctor : public MFunctor
|
|
41 |
{
|
|
42 |
public:
|
|
43 |
typedef void (C::*TFnPtr)(void);
|
|
44 |
TFunctor(C* aObj, TFnPtr aFnPtr) :iObj(aObj), iFnPtr(aFnPtr) {};
|
|
45 |
virtual void ExecL() {(iObj->*iFnPtr)();}
|
|
46 |
protected:
|
|
47 |
C* iObj;
|
|
48 |
TFnPtr iFnPtr;
|
|
49 |
};
|
|
50 |
|
|
51 |
template<class C, typename P1>
|
|
52 |
class TFunctorP1 : public MFunctor
|
|
53 |
{
|
|
54 |
public:
|
|
55 |
typedef void (C::*TFnPtr)(P1);
|
|
56 |
TFunctorP1(C* aObj, TFnPtr aFnPtr, P1 aP1) :iObj(aObj),iFnPtr(aFnPtr),iP1(aP1) {};
|
|
57 |
virtual void ExecL() {(iObj->*iFnPtr)(iP1);}
|
|
58 |
protected:
|
|
59 |
C* iObj;
|
|
60 |
TFnPtr iFnPtr;
|
|
61 |
P1 iP1;
|
|
62 |
};
|
|
63 |
|
|
64 |
template<class C, typename P1 , typename P2>
|
|
65 |
class TFunctorP2 : public MFunctor
|
|
66 |
{
|
|
67 |
public:
|
|
68 |
typedef void (C::*TFnPtr)(P1, P2);
|
|
69 |
TFunctorP2(C* aObj, TFnPtr aFnPtr, P1 aP1, P2 aP2) :iObj(aObj),iFnPtr(aFnPtr),iP1(aP1),iP2(aP2) {};
|
|
70 |
virtual void ExecL() {(iObj->*iFnPtr)(iP1,iP2);}
|
|
71 |
protected:
|
|
72 |
C* iObj;
|
|
73 |
TFnPtr iFnPtr;
|
|
74 |
P1 iP1;
|
|
75 |
P2 iP2;
|
|
76 |
};
|
|
77 |
|
|
78 |
template<class C, typename P1 , typename P2, typename P3>
|
|
79 |
class TFunctorP3 : public MFunctor
|
|
80 |
{
|
|
81 |
public:
|
|
82 |
typedef void (C::*TFnPtr)(P1, P2, P3);
|
|
83 |
TFunctorP3(C* aObj, TFnPtr aFnPtr, P1 aP1, P2 aP2, P3 aP3) :iObj(aObj),iFnPtr(aFnPtr),iP1(aP1),iP2(aP2),iP3(aP3) {};
|
|
84 |
virtual void ExecL() {(iObj->*iFnPtr)(iP1,iP2,iP3);}
|
|
85 |
protected:
|
|
86 |
C* iObj;
|
|
87 |
TFnPtr iFnPtr;
|
|
88 |
P1 iP1;
|
|
89 |
P2 iP2;
|
|
90 |
P3 iP3;
|
|
91 |
};
|
|
92 |
|
|
93 |
template<class C, typename P1 , typename P2, typename P3, typename P4>
|
|
94 |
class TFunctorP4 : public MFunctor
|
|
95 |
{
|
|
96 |
public:
|
|
97 |
typedef void (C::*TFnPtr)(P1, P2, P3, P4);
|
|
98 |
TFunctorP4(C* aObj, TFnPtr aFnPtr, P1 aP1, P2 aP2, P3 aP3, P4 aP4) :iObj(aObj),iFnPtr(aFnPtr),iP1(aP1),iP2(aP2),iP3(aP3),iP4(aP4) {};
|
|
99 |
virtual void ExecL() {(iObj->*iFnPtr)(iP1,iP2,iP3,iP4);}
|
|
100 |
protected:
|
|
101 |
C* iObj;
|
|
102 |
TFnPtr iFnPtr;
|
|
103 |
P1 iP1;
|
|
104 |
P2 iP2;
|
|
105 |
P3 iP3;
|
|
106 |
P4 iP4;
|
|
107 |
};
|
|
108 |
|
|
109 |
template<class C, typename P1 , typename P2, typename P3, typename P4, typename P5>
|
|
110 |
class TFunctorP5 : public MFunctor
|
|
111 |
{
|
|
112 |
public:
|
|
113 |
typedef void (C::*TFnPtr)(P1, P2, P3, P4, P5);
|
|
114 |
TFunctorP5(C* aObj, TFnPtr aFnPtr, P1 aP1, P2 aP2, P3 aP3, P4 aP4, P5 aP5) : iObj(aObj),iFnPtr(aFnPtr),iP1(aP1),iP2(aP2),iP3(aP3),iP4(aP4),iP5(aP5) {};
|
|
115 |
virtual void ExecL() {(iObj->*iFnPtr)(iP1,iP2,iP3,iP4,iP5);}
|
|
116 |
protected:
|
|
117 |
C* iObj;
|
|
118 |
TFnPtr iFnPtr;
|
|
119 |
P1 iP1;
|
|
120 |
P2 iP2;
|
|
121 |
P3 iP3;
|
|
122 |
P4 iP4;
|
|
123 |
P5 iP5;
|
|
124 |
};
|
|
125 |
|
|
126 |
|
|
127 |
|
|
128 |
public:
|
|
129 |
static CThreadExec* NewL();
|
|
130 |
virtual ~CThreadExec();
|
|
131 |
|
|
132 |
public:
|
|
133 |
TInt Exec(MFunctor* aFunction);
|
|
134 |
void AsyncExec(MFunctor* aFunction);
|
|
135 |
|
|
136 |
private:
|
|
137 |
/**
|
|
138 |
Active object to execute a function in the thread the PhoneManager is created
|
|
139 |
*/
|
|
140 |
class CActiveFnExec: public CActive
|
|
141 |
{
|
|
142 |
public:
|
|
143 |
static CActiveFnExec* NewL(CThreadExec& aOwner);
|
|
144 |
public:
|
|
145 |
void Start();
|
|
146 |
void Exec();
|
|
147 |
public: // from CActive
|
|
148 |
void RunL();
|
|
149 |
void DoCancel();
|
|
150 |
private:
|
|
151 |
CActiveFnExec(CThreadExec& aOwner);
|
|
152 |
private:
|
|
153 |
CThreadExec& iOwner;
|
|
154 |
RThread iThread;
|
|
155 |
};
|
|
156 |
private:
|
|
157 |
CThreadExec();
|
|
158 |
void ConstructL();
|
|
159 |
|
|
160 |
private:
|
|
161 |
void DoExec();
|
|
162 |
|
|
163 |
private:
|
|
164 |
CActiveFnExec *iActiveFnExec;
|
|
165 |
MFunctor* iFunction;
|
|
166 |
RSemaphore iExecSemaphore;
|
|
167 |
TInt iLatestError;
|
|
168 |
TBool iNeedSignal;
|
|
169 |
};
|
|
170 |
|
|
171 |
#endif
|