author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 14 Sep 2010 20:58:58 +0300 | |
branch | RCL_3 |
changeset 35 | 3321d3e205b6 |
parent 34 | 5456b4e8b3a8 |
permissions | -rw-r--r-- |
34 | 1 |
/* |
2 |
* Copyright (c) 2005-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: Transaction factory implementation |
|
15 |
* |
|
16 |
*/ |
|
17 |
||
18 |
||
19 |
#include "transactionfactoryimpl.h" |
|
20 |
||
21 |
#include "transaction.h" |
|
22 |
#include "texttransactionelement.h" |
|
23 |
#include "databuffertransactionelement.h" |
|
24 |
#include "imagetransactionelement.h" |
|
25 |
#include "emptycontenttransactionelement.h" |
|
26 |
#include "newstickertransactionelement.h" |
|
27 |
#include "aixmluiconstants.h" |
|
28 |
||
29 |
using namespace AiXmlUiController; |
|
30 |
||
31 |
// ============================ MEMBER FUNCTIONS =============================== |
|
32 |
||
33 |
CTransactionFactoryImpl::CTransactionFactoryImpl( |
|
34 |
AiUtility::CContentPriorityMap& aContentPriorityMap, |
|
35 |
CCssPropertyMap& aPropertyMap ) |
|
36 |
: iAvailableTransactions( CTransaction::FactoryLinkOffset() ), |
|
37 |
iReservedTransactions( CTransaction::FactoryLinkOffset() ), |
|
38 |
iAvailableElements( CTransactionElement::FactoryLinkOffset() ), |
|
39 |
iReservedElements( CTransactionElement::FactoryLinkOffset() ), |
|
40 |
iContentPriorityMap( aContentPriorityMap ), |
|
41 |
iPropertyMap( aPropertyMap ) |
|
42 |
{ |
|
43 |
} |
|
44 |
||
45 |
CTransactionFactoryImpl* CTransactionFactoryImpl::NewL( |
|
46 |
AiUtility::CContentPriorityMap& aContentPriorityMap, |
|
47 |
CCssPropertyMap& aPropertyMap ) |
|
48 |
{ |
|
49 |
CTransactionFactoryImpl* self = |
|
50 |
new( ELeave ) CTransactionFactoryImpl( aContentPriorityMap, |
|
51 |
aPropertyMap ); |
|
52 |
return self; |
|
53 |
} |
|
35
3321d3e205b6
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
34
diff
changeset
|
54 |
|
3321d3e205b6
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
34
diff
changeset
|
55 |
RAiPolicyElementArray& CTransactionFactoryImpl::PolicyArray() |
3321d3e205b6
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
34
diff
changeset
|
56 |
{ |
3321d3e205b6
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
34
diff
changeset
|
57 |
return iPolicyArray; |
3321d3e205b6
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
34
diff
changeset
|
58 |
} |
3321d3e205b6
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
34
diff
changeset
|
59 |
|
3321d3e205b6
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
34
diff
changeset
|
60 |
void CTransactionFactoryImpl::ResetPolicyArray() |
3321d3e205b6
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
34
diff
changeset
|
61 |
{ |
3321d3e205b6
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
34
diff
changeset
|
62 |
iPolicyArray.Reset(); |
3321d3e205b6
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
34
diff
changeset
|
63 |
} |
34 | 64 |
|
65 |
CTransactionFactoryImpl::~CTransactionFactoryImpl() |
|
66 |
{ |
|
67 |
// Delete transaction objects |
|
68 |
DeleteTransactionList( iAvailableTransactions ); |
|
69 |
DeleteTransactionList( iReservedTransactions ); |
|
70 |
||
71 |
// Delete transaction elements |
|
72 |
DeleteElementList( iAvailableElements ); |
|
73 |
DeleteElementList( iReservedElements ); |
|
35
3321d3e205b6
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
34
diff
changeset
|
74 |
|
3321d3e205b6
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
34
diff
changeset
|
75 |
ResetPolicyArray(); |
34 | 76 |
} |
77 |
||
78 |
MTransaction* CTransactionFactoryImpl::CreateTransactionL( TInt aTxId ) |
|
79 |
{ |
|
80 |
CTransaction* tr = NULL; |
|
81 |
||
82 |
if ( iAvailableTransactions.IsEmpty() ) // No free transactions |
|
83 |
{ |
|
84 |
tr = CTransaction::NewL(); |
|
85 |
} |
|
86 |
else |
|
87 |
{ |
|
88 |
// Take first available transaction and remove from queue |
|
89 |
tr = iAvailableTransactions.First(); |
|
90 |
iAvailableTransactions.Remove( *tr ); |
|
91 |
} |
|
92 |
||
93 |
// Initialize with id |
|
94 |
tr->Initialize(aTxId); |
|
95 |
||
96 |
// Reserve |
|
97 |
iReservedTransactions.AddFirst( *tr ); |
|
98 |
||
99 |
return tr; |
|
100 |
} |
|
101 |
||
102 |
void CTransactionFactoryImpl::ReleaseTransaction( MTransaction* aTransaction ) |
|
103 |
{ |
|
104 |
CTransaction* tr = dynamic_cast< CTransaction* >( aTransaction ); |
|
105 |
if ( tr ) |
|
106 |
{ |
|
107 |
// Reset transaction for reuse |
|
108 |
tr->Reset( *this ); |
|
109 |
||
110 |
// Deque from reserved list |
|
111 |
iReservedTransactions.Remove( *tr ); |
|
112 |
||
113 |
// Enque to available list |
|
114 |
iAvailableTransactions.AddFirst( *tr ); |
|
115 |
} |
|
116 |
} |
|
117 |
||
118 |
MTransactionElement* CTransactionFactoryImpl::CreateTextTransactionElementL( |
|
119 |
CXnNodeAppIf& aTarget, |
|
120 |
const TDesC& aText, |
|
121 |
TInt aPriority ) |
|
122 |
{ |
|
123 |
// Instantiate new element |
|
124 |
CTextTransactionElement* element = NewInstanceL< CTextTransactionElement >(); |
|
125 |
||
126 |
CleanupStack::PushL( element ); |
|
127 |
||
128 |
// Initialize element |
|
129 |
element->InitializeL( aTarget, aText ); |
|
130 |
||
131 |
CleanupStack::Pop( element ); |
|
132 |
||
133 |
// Reserve |
|
134 |
iReservedElements.AddLast( *element ); |
|
135 |
||
136 |
// Set content priority |
|
137 |
element->SetContentPriority( aPriority ); |
|
138 |
||
139 |
return element; |
|
140 |
} |
|
141 |
||
142 |
MTransactionElement* |
|
143 |
CTransactionFactoryImpl::CreateDataBufferTransactionElementL( |
|
144 |
CXnNodeAppIf& aTarget, |
|
145 |
const TDesC8& aData, |
|
146 |
TInt aPriority ) |
|
147 |
{ |
|
148 |
// Instantiate element |
|
149 |
CDataBufferTransactionElement* element = NewInstanceL< CDataBufferTransactionElement >(); |
|
150 |
CleanupStack::PushL( element ); |
|
151 |
||
152 |
// Initialize |
|
153 |
element->InitializeL( aTarget, aData ); |
|
154 |
CleanupStack::Pop( element ); |
|
155 |
||
156 |
// Reserve |
|
157 |
iReservedElements.AddLast( *element ); |
|
158 |
||
159 |
// Set content priority |
|
160 |
element->SetContentPriority( aPriority ); |
|
161 |
||
162 |
return element; |
|
163 |
} |
|
164 |
||
165 |
MTransactionElement* |
|
166 |
CTransactionFactoryImpl::CreateDataBufferTransactionElementL( |
|
167 |
CXnNodeAppIf& aTarget, |
|
168 |
const TDesC8& aData, |
|
169 |
TInt aPriority, |
|
170 |
const TDesC& aCid, |
|
171 |
TInt aIndex ) |
|
172 |
{ |
|
173 |
// Instantiate element |
|
174 |
CDataBufferTransactionElement* element = NewInstanceL< CDataBufferTransactionElement >(); |
|
175 |
CleanupStack::PushL( element ); |
|
176 |
||
177 |
// Initialize |
|
178 |
element->InitializeL( aTarget, aData, aCid, aIndex ); |
|
179 |
CleanupStack::Pop( element ); |
|
180 |
||
181 |
// Reserve |
|
182 |
iReservedElements.AddLast( *element ); |
|
183 |
||
184 |
// Set content priority |
|
185 |
element->SetContentPriority( aPriority ); |
|
186 |
||
187 |
return element; |
|
188 |
} |
|
189 |
||
190 |
MTransactionElement* |
|
191 |
CTransactionFactoryImpl::CreateEmptyContentTransactionElementL( |
|
192 |
CXnNodeAppIf& aTarget, |
|
193 |
TInt aIndex) |
|
194 |
{ |
|
195 |
// Instantiate |
|
196 |
CEmptyContentTransactionElement* element = NewInstanceL< CEmptyContentTransactionElement >(); |
|
197 |
||
198 |
CleanupStack::PushL( element ); |
|
199 |
||
200 |
// Initialize |
|
201 |
element->InitializeL( aTarget, aIndex ); |
|
202 |
||
203 |
CleanupStack::Pop( element ); |
|
204 |
||
205 |
// Reserve |
|
206 |
iReservedElements.AddLast( *element ); |
|
207 |
||
208 |
return element; |
|
209 |
} |
|
210 |
||
211 |
MTransactionElement* CTransactionFactoryImpl::CreateImageTransactionElementL( CXnNodeAppIf& aTarget, |
|
212 |
CGulIcon* aIcon, |
|
213 |
TInt aPriority ) |
|
214 |
{ |
|
215 |
// Instantiate |
|
216 |
CImageTransactionElement* element = NewInstanceL< CImageTransactionElement >(); |
|
217 |
||
218 |
CleanupStack::PushL( element ); |
|
219 |
||
220 |
// Initialize |
|
221 |
element->InitializeL( aTarget, aIcon ); |
|
222 |
||
223 |
CleanupStack::Pop( element ); |
|
224 |
||
225 |
// Reserve |
|
226 |
iReservedElements.AddLast( *element ); |
|
227 |
||
228 |
// Set priority |
|
229 |
element->SetContentPriority( aPriority ); |
|
230 |
||
231 |
return element; |
|
232 |
} |
|
233 |
||
234 |
MTransactionElement* CTransactionFactoryImpl::CreateImageTransactionElementL( |
|
235 |
CXnNodeAppIf& aTarget, |
|
236 |
RFile& aFile, |
|
237 |
TInt aPriority ) |
|
238 |
{ |
|
239 |
// Instantiate |
|
240 |
CImageTransactionElement* element = NewInstanceL< CImageTransactionElement >(); |
|
241 |
||
242 |
CleanupStack::PushL( element ); |
|
243 |
||
244 |
// Initialize |
|
245 |
element->InitializeL( aTarget, aFile ); |
|
246 |
||
247 |
CleanupStack::Pop( element ); |
|
248 |
||
249 |
// Reserve |
|
250 |
iReservedElements.AddLast( *element ); |
|
251 |
||
252 |
// Set priority |
|
253 |
element->SetContentPriority( aPriority ); |
|
254 |
||
255 |
return element; |
|
256 |
} |
|
257 |
||
258 |
MTransactionElement* CTransactionFactoryImpl::CreateNewsTickerTransactionElementL( |
|
259 |
CXnNodeAppIf& aTarget, |
|
260 |
const TDesC& aText, |
|
261 |
TInt aPriority, |
|
262 |
TInt aIndex ) |
|
263 |
{ |
|
264 |
// Instantiate new element |
|
265 |
CNewsTickerTransactionElement* element = NewInstanceL< CNewsTickerTransactionElement >(); |
|
266 |
||
267 |
CleanupStack::PushL( element ); |
|
268 |
||
269 |
// Initialize element |
|
270 |
element->InitializeL( aTarget, aText, aIndex ); |
|
271 |
||
272 |
CleanupStack::Pop( element ); |
|
273 |
||
274 |
// Reserve |
|
275 |
iReservedElements.AddLast( *element ); |
|
276 |
||
277 |
// Set content priority |
|
278 |
element->SetContentPriority( aPriority ); |
|
279 |
||
280 |
return element; |
|
281 |
} |
|
282 |
||
283 |
void CTransactionFactoryImpl::ReleaseTransactionElement( MTransactionElement* aElement) |
|
284 |
{ |
|
285 |
CTransactionElement* element = dynamic_cast< CTransactionElement* >( aElement ); |
|
286 |
||
287 |
if ( element ) |
|
288 |
{ |
|
289 |
// Reset element |
|
290 |
element->Reset(); |
|
291 |
||
292 |
// Move element from reserved list to available |
|
293 |
iReservedElements.Remove( *element ); |
|
294 |
iAvailableElements.AddFirst( *element ); |
|
295 |
} |
|
296 |
} |
|
297 |
||
298 |
TBool CTransactionFactoryImpl::IsSupported( CXnNodeAppIf& aTarget, const TDesC8& aContentType ) |
|
299 |
{ |
|
300 |
// Check if target node and content type is supported |
|
301 |
if ( aContentType == KContentTypeText ) |
|
302 |
{ |
|
303 |
return CTextTransactionElement::IsSupported( aTarget ) || CNewsTickerTransactionElement::IsSupported( aTarget ); |
|
304 |
} |
|
305 |
else if ( aContentType == KContentTypeBitmap ) |
|
306 |
{ |
|
307 |
return CImageTransactionElement::IsSupported( aTarget ); |
|
308 |
} |
|
309 |
else |
|
310 |
{ |
|
311 |
return CDataBufferTransactionElement::IsSupported( aTarget, aContentType ); |
|
312 |
} |
|
313 |
} |
|
314 |
||
315 |
template< class T > T* CTransactionFactoryImpl::NewInstanceL() |
|
316 |
{ |
|
317 |
T* instance = NULL; |
|
318 |
||
319 |
// Iterate list of transaction elements |
|
320 |
TSglQueIter< CTransactionElement > iter( iAvailableElements ); |
|
321 |
iter.SetToFirst(); |
|
322 |
||
323 |
while ( iter ) |
|
324 |
{ |
|
325 |
instance = dynamic_cast< T* >( iter++ ); // NULL if not T* |
|
326 |
||
327 |
if ( instance ) |
|
328 |
{ |
|
329 |
// Deque first instance of class T and quit |
|
330 |
iAvailableElements.Remove( *instance ); |
|
331 |
return instance; |
|
332 |
} |
|
333 |
} |
|
334 |
||
335 |
// Not found from list. Instantiate |
|
336 |
instance = T::NewL(iContentPriorityMap); |
|
337 |
instance->SetCssPropertyMap( &iPropertyMap ); |
|
338 |
||
339 |
return instance; |
|
340 |
} |
|
341 |
||
342 |
void CTransactionFactoryImpl::DeleteTransactionList( TSglQue< CTransaction >& aList ) |
|
343 |
{ |
|
344 |
TSglQueIter< CTransaction > trIter( aList ); |
|
345 |
trIter.SetToFirst(); |
|
346 |
||
347 |
while (trIter) |
|
348 |
{ |
|
349 |
// Get first transaction and remove it from the list |
|
350 |
CTransaction* first = trIter++; |
|
351 |
aList.Remove( *first ); |
|
352 |
||
353 |
// Delete |
|
354 |
first->Reset( *this ); |
|
355 |
delete first; |
|
356 |
} |
|
357 |
} |
|
358 |
||
359 |
void CTransactionFactoryImpl::DeleteElementList( TSglQue< CTransactionElement >& aList ) |
|
360 |
{ |
|
361 |
TSglQueIter< CTransactionElement > iter( aList ); |
|
362 |
iter.SetToFirst(); |
|
363 |
||
364 |
while ( iter ) |
|
365 |
{ |
|
366 |
CTransactionElement* element = iter++; |
|
367 |
aList.Remove( *element ); |
|
368 |
||
369 |
delete element; |
|
370 |
} |
|
371 |
} |
|
372 |
||
373 |
// End of File |