|
1 /* |
|
2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Executes client specified callbacks in timely manner. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 #ifndef C_ICECALLBACKEXECUTER_H |
|
22 #define C_ICECALLBACKEXECUTER_H |
|
23 |
|
24 #include <e32base.h> |
|
25 #include "natfwinternaldefs.h" //UNIT_TEST |
|
26 |
|
27 /** |
|
28 * Encapsulates callback function. |
|
29 * |
|
30 * @lib icecandidatehandler.lib |
|
31 * @since S60 v3.2 |
|
32 */ |
|
33 class TIceCallBack |
|
34 { |
|
35 |
|
36 public: |
|
37 |
|
38 TIceCallBack( void ( *aFunction )( CBase& aObjectRef, TInt aData ), |
|
39 CBase& aObjectRef, TInt aData, |
|
40 const TTimeIntervalMicroSeconds32& aDelay ) |
|
41 : |
|
42 iFunction( aFunction ), |
|
43 iObjectRef( aObjectRef ), |
|
44 iData( aData ), |
|
45 iDelay( aDelay ) { }; |
|
46 |
|
47 /** |
|
48 * Calls encapsulated callback function with client specified parameters. |
|
49 * |
|
50 * @since S60 v3.2 |
|
51 */ |
|
52 void CallBack() const |
|
53 { |
|
54 if ( iFunction ) |
|
55 { |
|
56 (*iFunction)( iObjectRef, iData ); |
|
57 } |
|
58 } |
|
59 |
|
60 /** |
|
61 * Returns a wait time after which callback should be called. |
|
62 * |
|
63 * @since S60 v3.2 |
|
64 */ |
|
65 TTimeIntervalMicroSeconds32 Delay() const { return iDelay; } |
|
66 |
|
67 private: |
|
68 |
|
69 TIceCallBack(); |
|
70 |
|
71 public: |
|
72 |
|
73 /** |
|
74 * A pointer to the callback function. |
|
75 */ |
|
76 void ( *iFunction )( CBase& aObjectRef, TInt aData ); |
|
77 |
|
78 /** |
|
79 * A pointer that is passed to the callback function when |
|
80 * the function is called. |
|
81 */ |
|
82 CBase& iObjectRef; |
|
83 |
|
84 /** |
|
85 * A data that is passed to the callback function when |
|
86 * the function is called. |
|
87 */ |
|
88 TInt iData; |
|
89 |
|
90 /** |
|
91 * A delay after which callback is issued. |
|
92 */ |
|
93 TTimeIntervalMicroSeconds32 iDelay; |
|
94 }; |
|
95 |
|
96 |
|
97 /** |
|
98 * Executes client specified callbacks in timely manner. |
|
99 * |
|
100 * @lib icecandidatehandler.lib |
|
101 * @since S60 v3.2 |
|
102 */ |
|
103 class CIceCallBackExecuter : public CTimer |
|
104 { |
|
105 |
|
106 UNIT_TEST( UT_CIceCallBackExecuter ) |
|
107 |
|
108 public: |
|
109 |
|
110 /** |
|
111 * Two-phased constructor. |
|
112 * @param aPriority Active object priority |
|
113 */ |
|
114 static CIceCallBackExecuter* NewL( TInt aPriority ); |
|
115 |
|
116 /** |
|
117 * Two-phased constructor. |
|
118 * @param aPriority Active object priority |
|
119 */ |
|
120 static CIceCallBackExecuter* NewLC( TInt aPriority ); |
|
121 |
|
122 /** |
|
123 * Destructor. |
|
124 */ |
|
125 virtual ~CIceCallBackExecuter(); |
|
126 |
|
127 /** |
|
128 * Adds specified callback to the queue. Starts executing callbacks |
|
129 * if queue was empty. |
|
130 * |
|
131 * @since S60 v3.2 |
|
132 * @param aCallBack The callback to add to the queue |
|
133 */ |
|
134 void AddCallBackL( const TIceCallBack& aCallBack ); |
|
135 |
|
136 protected: |
|
137 |
|
138 void RunL(); |
|
139 |
|
140 void DoCancel(); |
|
141 |
|
142 private: |
|
143 |
|
144 CIceCallBackExecuter( TInt aPriority ); |
|
145 |
|
146 void ConstructL(); |
|
147 |
|
148 private: // data |
|
149 |
|
150 /** |
|
151 * Callback queue. |
|
152 */ |
|
153 RArray<TIceCallBack> iCallBacks; |
|
154 }; |
|
155 |
|
156 #endif // C_ICECALLBACKEXECUTER_H |