|
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 |
|
53 return self; |
|
54 } |
|
55 |
|
56 CTransactionFactoryImpl::~CTransactionFactoryImpl() |
|
57 { |
|
58 // Delete transaction objects |
|
59 DeleteTransactionList( iAvailableTransactions ); |
|
60 DeleteTransactionList( iReservedTransactions ); |
|
61 |
|
62 // Delete transaction elements |
|
63 DeleteElementList( iAvailableElements ); |
|
64 DeleteElementList( iReservedElements ); |
|
65 } |
|
66 |
|
67 MTransaction* CTransactionFactoryImpl::CreateTransactionL( TInt aTxId ) |
|
68 { |
|
69 CTransaction* tr = NULL; |
|
70 |
|
71 if ( iAvailableTransactions.IsEmpty() ) // No free transactions |
|
72 { |
|
73 tr = CTransaction::NewL(); |
|
74 } |
|
75 else |
|
76 { |
|
77 // Take first available transaction and remove from queue |
|
78 tr = iAvailableTransactions.First(); |
|
79 iAvailableTransactions.Remove( *tr ); |
|
80 } |
|
81 |
|
82 // Initialize with id |
|
83 tr->Initialize(aTxId); |
|
84 |
|
85 // Reserve |
|
86 iReservedTransactions.AddFirst( *tr ); |
|
87 |
|
88 return tr; |
|
89 } |
|
90 |
|
91 void CTransactionFactoryImpl::ReleaseTransaction( MTransaction* aTransaction ) |
|
92 { |
|
93 CTransaction* tr = dynamic_cast< CTransaction* >( aTransaction ); |
|
94 if ( tr ) |
|
95 { |
|
96 // Reset transaction for reuse |
|
97 tr->Reset( *this ); |
|
98 |
|
99 // Deque from reserved list |
|
100 iReservedTransactions.Remove( *tr ); |
|
101 |
|
102 // Enque to available list |
|
103 iAvailableTransactions.AddFirst( *tr ); |
|
104 } |
|
105 } |
|
106 |
|
107 MTransactionElement* CTransactionFactoryImpl::CreateTextTransactionElementL( |
|
108 CXnNodeAppIf& aTarget, |
|
109 const TDesC& aText, |
|
110 TInt aPriority ) |
|
111 { |
|
112 // Instantiate new element |
|
113 CTextTransactionElement* element = NewInstanceL< CTextTransactionElement >(); |
|
114 |
|
115 CleanupStack::PushL( element ); |
|
116 |
|
117 // Initialize element |
|
118 element->InitializeL( aTarget, aText ); |
|
119 |
|
120 CleanupStack::Pop( element ); |
|
121 |
|
122 // Reserve |
|
123 iReservedElements.AddLast( *element ); |
|
124 |
|
125 // Set content priority |
|
126 element->SetContentPriority( aPriority ); |
|
127 |
|
128 return element; |
|
129 } |
|
130 |
|
131 MTransactionElement* |
|
132 CTransactionFactoryImpl::CreateDataBufferTransactionElementL( |
|
133 CXnNodeAppIf& aTarget, |
|
134 const TDesC8& aData, |
|
135 TInt aPriority ) |
|
136 { |
|
137 // Instantiate element |
|
138 CDataBufferTransactionElement* element = NewInstanceL< CDataBufferTransactionElement >(); |
|
139 CleanupStack::PushL( element ); |
|
140 |
|
141 // Initialize |
|
142 element->InitializeL( aTarget, aData ); |
|
143 CleanupStack::Pop( element ); |
|
144 |
|
145 // Reserve |
|
146 iReservedElements.AddLast( *element ); |
|
147 |
|
148 // Set content priority |
|
149 element->SetContentPriority( aPriority ); |
|
150 |
|
151 return element; |
|
152 } |
|
153 |
|
154 MTransactionElement* |
|
155 CTransactionFactoryImpl::CreateEmptyContentTransactionElementL( |
|
156 CXnNodeAppIf& aTarget, |
|
157 TInt aIndex) |
|
158 { |
|
159 // Instantiate |
|
160 CEmptyContentTransactionElement* element = NewInstanceL< CEmptyContentTransactionElement >(); |
|
161 |
|
162 CleanupStack::PushL( element ); |
|
163 |
|
164 // Initialize |
|
165 element->InitializeL( aTarget, aIndex ); |
|
166 |
|
167 CleanupStack::Pop( element ); |
|
168 |
|
169 // Reserve |
|
170 iReservedElements.AddLast( *element ); |
|
171 |
|
172 return element; |
|
173 } |
|
174 |
|
175 MTransactionElement* CTransactionFactoryImpl::CreateImageTransactionElementL( CXnNodeAppIf& aTarget, |
|
176 CGulIcon* aIcon, |
|
177 TInt aPriority ) |
|
178 { |
|
179 // Instantiate |
|
180 CImageTransactionElement* element = NewInstanceL< CImageTransactionElement >(); |
|
181 |
|
182 CleanupStack::PushL( element ); |
|
183 |
|
184 // Initialize |
|
185 element->InitializeL( aTarget, aIcon ); |
|
186 |
|
187 CleanupStack::Pop( element ); |
|
188 |
|
189 // Reserve |
|
190 iReservedElements.AddLast( *element ); |
|
191 |
|
192 // Set priority |
|
193 element->SetContentPriority( aPriority ); |
|
194 |
|
195 return element; |
|
196 } |
|
197 |
|
198 MTransactionElement* CTransactionFactoryImpl::CreateImageTransactionElementL( |
|
199 CXnNodeAppIf& aTarget, |
|
200 RFile& aFile, |
|
201 TInt aPriority ) |
|
202 { |
|
203 // Instantiate |
|
204 CImageTransactionElement* element = NewInstanceL< CImageTransactionElement >(); |
|
205 |
|
206 CleanupStack::PushL( element ); |
|
207 |
|
208 // Initialize |
|
209 element->InitializeL( aTarget, aFile ); |
|
210 |
|
211 CleanupStack::Pop( element ); |
|
212 |
|
213 // Reserve |
|
214 iReservedElements.AddLast( *element ); |
|
215 |
|
216 // Set priority |
|
217 element->SetContentPriority( aPriority ); |
|
218 |
|
219 return element; |
|
220 } |
|
221 |
|
222 MTransactionElement* CTransactionFactoryImpl::CreateNewsTickerTransactionElementL( |
|
223 CXnNodeAppIf& aTarget, |
|
224 const TDesC& aText, |
|
225 TInt aPriority, |
|
226 TInt aIndex ) |
|
227 { |
|
228 // Instantiate new element |
|
229 CNewsTickerTransactionElement* element = NewInstanceL< CNewsTickerTransactionElement >(); |
|
230 |
|
231 CleanupStack::PushL( element ); |
|
232 |
|
233 // Initialize element |
|
234 element->InitializeL( aTarget, aText, aIndex ); |
|
235 |
|
236 CleanupStack::Pop( element ); |
|
237 |
|
238 // Reserve |
|
239 iReservedElements.AddLast( *element ); |
|
240 |
|
241 // Set content priority |
|
242 element->SetContentPriority( aPriority ); |
|
243 |
|
244 return element; |
|
245 } |
|
246 |
|
247 void CTransactionFactoryImpl::ReleaseTransactionElement( MTransactionElement* aElement) |
|
248 { |
|
249 CTransactionElement* element = dynamic_cast< CTransactionElement* >( aElement ); |
|
250 |
|
251 if ( element ) |
|
252 { |
|
253 // Reset element |
|
254 element->Reset(); |
|
255 |
|
256 // Move element from reserved list to available |
|
257 iReservedElements.Remove( *element ); |
|
258 iAvailableElements.AddFirst( *element ); |
|
259 } |
|
260 } |
|
261 |
|
262 TBool CTransactionFactoryImpl::IsSupported( CXnNodeAppIf& aTarget, const TDesC8& aContentType ) |
|
263 { |
|
264 // Check if target node and content type is supported |
|
265 if ( aContentType == KContentTypeText ) |
|
266 { |
|
267 return CTextTransactionElement::IsSupported( aTarget ) || CNewsTickerTransactionElement::IsSupported( aTarget ); |
|
268 } |
|
269 else if ( aContentType == KContentTypeBitmap ) |
|
270 { |
|
271 return CImageTransactionElement::IsSupported( aTarget ); |
|
272 } |
|
273 else |
|
274 { |
|
275 return CDataBufferTransactionElement::IsSupported( aTarget, aContentType ); |
|
276 } |
|
277 } |
|
278 |
|
279 template< class T > T* CTransactionFactoryImpl::NewInstanceL() |
|
280 { |
|
281 T* instance = NULL; |
|
282 |
|
283 // Iterate list of transaction elements |
|
284 TSglQueIter< CTransactionElement > iter( iAvailableElements ); |
|
285 iter.SetToFirst(); |
|
286 |
|
287 while ( iter ) |
|
288 { |
|
289 instance = dynamic_cast< T* >( iter++ ); // NULL if not T* |
|
290 |
|
291 if ( instance ) |
|
292 { |
|
293 // Deque first instance of class T and quit |
|
294 iAvailableElements.Remove( *instance ); |
|
295 return instance; |
|
296 } |
|
297 } |
|
298 |
|
299 // Not found from list. Instantiate |
|
300 instance = T::NewL(iContentPriorityMap); |
|
301 instance->SetCssPropertyMap( &iPropertyMap ); |
|
302 |
|
303 return instance; |
|
304 } |
|
305 |
|
306 void CTransactionFactoryImpl::DeleteTransactionList( TSglQue< CTransaction >& aList ) |
|
307 { |
|
308 TSglQueIter< CTransaction > trIter( aList ); |
|
309 trIter.SetToFirst(); |
|
310 |
|
311 while (trIter) |
|
312 { |
|
313 // Get first transaction and remove it from the list |
|
314 CTransaction* first = trIter++; |
|
315 aList.Remove( *first ); |
|
316 |
|
317 // Delete |
|
318 first->Reset( *this ); |
|
319 delete first; |
|
320 } |
|
321 } |
|
322 |
|
323 void CTransactionFactoryImpl::DeleteElementList( TSglQue< CTransactionElement >& aList ) |
|
324 { |
|
325 TSglQueIter< CTransactionElement > iter( aList ); |
|
326 iter.SetToFirst(); |
|
327 |
|
328 while ( iter ) |
|
329 { |
|
330 CTransactionElement* element = iter++; |
|
331 aList.Remove( *element ); |
|
332 |
|
333 delete element; |
|
334 } |
|
335 } |
|
336 |
|
337 // End of File |