|
1 /* |
|
2 * Copyright (c) 2006 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 the License "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: CCVcxConnUtilWaitSch class definition file* |
|
15 */ |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 #include "vcxconnutilwaitsch.h" |
|
22 |
|
23 |
|
24 /** |
|
25 * CVcxConnUtilWait is used to wrap CActiveScheduler objects to be used |
|
26 * as "wait-type" context within videoconnutility. |
|
27 * Each CVcxConnUtilWait object has a wait type -id for whose |
|
28 * object maintans an array of CActiveScheduler objects' wait state. |
|
29 */ |
|
30 NONSHARABLE_CLASS( CVcxConnUtilWait ) : public CBase |
|
31 { |
|
32 public: |
|
33 |
|
34 /** |
|
35 * Destructor. |
|
36 */ |
|
37 ~CVcxConnUtilWait() |
|
38 { |
|
39 iWaitArray.ResetAndDestroy(); |
|
40 }; |
|
41 |
|
42 /** |
|
43 * Default constructor |
|
44 */ |
|
45 CVcxConnUtilWait( ) {}; |
|
46 |
|
47 /** |
|
48 * Wait type id |
|
49 */ |
|
50 TUint32 iType; |
|
51 |
|
52 /** |
|
53 * Flag to indicate wether CActiveScheduler maintained |
|
54 * by this object can really be released. In case flag is |
|
55 * false, CActiveScheduler -objects need to be put to wait |
|
56 * again right after their release. |
|
57 */ |
|
58 TBool iCanStop; |
|
59 |
|
60 /** |
|
61 * Array containing CActiveScheduler maintained |
|
62 * by this object |
|
63 */ |
|
64 RPointerArray < CActiveSchedulerWait > iWaitArray; |
|
65 }; |
|
66 |
|
67 |
|
68 // ----------------------------------------------------------------------------- |
|
69 // CVcxConnUtilWaitSch::CVcxConnUtilWaitSch() |
|
70 // ----------------------------------------------------------------------------- |
|
71 // |
|
72 CVcxConnUtilWaitSch::CVcxConnUtilWaitSch() |
|
73 { |
|
74 // No implementation required |
|
75 } |
|
76 |
|
77 // ----------------------------------------------------------------------------- |
|
78 // CVcxConnUtilWaitSch::~CVcxConnUtilWaitSch() |
|
79 // ----------------------------------------------------------------------------- |
|
80 // |
|
81 CVcxConnUtilWaitSch::~CVcxConnUtilWaitSch() |
|
82 { |
|
83 iWaits.ResetAndDestroy(); |
|
84 } |
|
85 |
|
86 // ----------------------------------------------------------------------------- |
|
87 // CVcxConnUtilWaitSch::NewLC() |
|
88 // ----------------------------------------------------------------------------- |
|
89 // |
|
90 CVcxConnUtilWaitSch* CVcxConnUtilWaitSch::NewLC() |
|
91 { |
|
92 CVcxConnUtilWaitSch* self = new (ELeave)CVcxConnUtilWaitSch(); |
|
93 CleanupStack::PushL(self); |
|
94 return self; |
|
95 } |
|
96 |
|
97 // ----------------------------------------------------------------------------- |
|
98 // CVcxConnUtilWaitSch::NewL() |
|
99 // ----------------------------------------------------------------------------- |
|
100 // |
|
101 CVcxConnUtilWaitSch* CVcxConnUtilWaitSch::NewL() |
|
102 { |
|
103 CVcxConnUtilWaitSch* self = CVcxConnUtilWaitSch::NewLC(); |
|
104 CleanupStack::Pop( self ); // self; |
|
105 return self; |
|
106 } |
|
107 |
|
108 // ----------------------------------------------------------------------------- |
|
109 // CVcxConnUtilWaitSch::WaitL() |
|
110 // ----------------------------------------------------------------------------- |
|
111 // |
|
112 void CVcxConnUtilWaitSch::WaitL( TUint32 aWaitId ) |
|
113 { |
|
114 CVcxConnUtilWait* wait = GetWaitL( aWaitId ); |
|
115 CActiveSchedulerWait* activeWait = GetActiveSWaitL( wait ); |
|
116 |
|
117 while( !wait->iCanStop ) |
|
118 { |
|
119 activeWait->Start(); |
|
120 } |
|
121 |
|
122 TInt index = wait->iWaitArray.FindL( activeWait ); |
|
123 if( index != KErrNotFound ) |
|
124 { |
|
125 wait->iWaitArray.Remove( index ); |
|
126 } |
|
127 delete activeWait; |
|
128 |
|
129 if( !wait->iWaitArray.Count() ) |
|
130 { |
|
131 index = iWaits.FindL( wait ); |
|
132 if( index != KErrNotFound ) |
|
133 { |
|
134 iWaits.Remove( index ); |
|
135 } |
|
136 delete wait; |
|
137 } |
|
138 } |
|
139 |
|
140 // ----------------------------------------------------------------------------- |
|
141 // CVcxConnUtilWaitSch::EndWait() |
|
142 // ----------------------------------------------------------------------------- |
|
143 // |
|
144 void CVcxConnUtilWaitSch::EndWait( TUint32 aWaitId ) |
|
145 { |
|
146 TInt waitCount( 0 ); |
|
147 TInt asWaitCount( 0 ); |
|
148 |
|
149 waitCount = iWaits.Count(); |
|
150 |
|
151 for( TInt i( 0 ); i < waitCount; ++i ) |
|
152 { |
|
153 iWaits[ i ]->iCanStop = ( aWaitId == iWaits[ i ]->iType ); |
|
154 |
|
155 asWaitCount = iWaits[ i ]->iWaitArray.Count(); |
|
156 |
|
157 for( TInt j( 0 ); j < asWaitCount; ++j ) |
|
158 { |
|
159 if( iWaits[ i ]->iWaitArray[ j ]->IsStarted() ) |
|
160 { |
|
161 iWaits[ i ]->iWaitArray[ j ]->AsyncStop(); |
|
162 } |
|
163 } |
|
164 } |
|
165 } |
|
166 |
|
167 // ----------------------------------------------------------------------------- |
|
168 // CVcxConnUtilWaitSch::GetWaitL() |
|
169 // ----------------------------------------------------------------------------- |
|
170 // |
|
171 CVcxConnUtilWait* CVcxConnUtilWaitSch::GetWaitL( TUint32 aID ) |
|
172 { |
|
173 CVcxConnUtilWait* wait( 0 ); |
|
174 TInt count( 0 ); |
|
175 count = iWaits.Count(); |
|
176 |
|
177 for( TInt i( 0 ); i < count; ++i ) |
|
178 { |
|
179 if( iWaits[ i ]->iType == aID ) |
|
180 { |
|
181 wait = iWaits[ i ]; |
|
182 break; |
|
183 } |
|
184 } |
|
185 if( !wait ) |
|
186 { |
|
187 wait = new (ELeave) CVcxConnUtilWait(); |
|
188 CleanupStack::PushL( wait ); |
|
189 wait->iType = aID; |
|
190 iWaits.AppendL( wait ); |
|
191 CleanupStack::Pop( wait ); |
|
192 } |
|
193 return wait; |
|
194 } |
|
195 |
|
196 // ----------------------------------------------------------------------------- |
|
197 // CVcxConnUtilWaitSch::GetActiveSWaitL() |
|
198 // ----------------------------------------------------------------------------- |
|
199 // |
|
200 CActiveSchedulerWait* CVcxConnUtilWaitSch::GetActiveSWaitL( CVcxConnUtilWait* aWait ) |
|
201 { |
|
202 CActiveSchedulerWait* item( 0 ); |
|
203 if( aWait ) |
|
204 { |
|
205 TInt count( aWait->iWaitArray.Count() ); |
|
206 for( TInt i( 0 ); i < count; i++ ) |
|
207 { |
|
208 if( !( aWait->iWaitArray[i]->IsStarted() ) ) |
|
209 { |
|
210 item = aWait->iWaitArray[i]; |
|
211 break; |
|
212 } |
|
213 } |
|
214 } |
|
215 if( !item ) |
|
216 { |
|
217 item = new ( ELeave) CActiveSchedulerWait; |
|
218 CleanupStack::PushL( item ); |
|
219 aWait->iWaitArray.AppendL( item ); |
|
220 CleanupStack::Pop( item ); |
|
221 } |
|
222 return item; |
|
223 } |
|
224 // End of file |
|
225 |