|
1 /* |
|
2 * Copyright (c) 2009-2010 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: |
|
15 * Implementation of the bearer priority array cache. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #include <datamobilitycommsdattypes.h> |
|
21 #include <cmmanagerdef.h> |
|
22 |
|
23 #include "cmmbearerprioritycache.h" |
|
24 #include "cmmbearerpriority.h" |
|
25 #include "cmmtransactionhandler.h" |
|
26 |
|
27 #include "OstTraceDefinitions.h" |
|
28 #ifdef OST_TRACE_COMPILER_IN_USE |
|
29 #include "cmmbearerprioritycacheTraces.h" |
|
30 #endif |
|
31 |
|
32 |
|
33 // --------------------------------------------------------------------------- |
|
34 // Two phased construction. |
|
35 // --------------------------------------------------------------------------- |
|
36 // |
|
37 CCmmBearerPriorityCache* CCmmBearerPriorityCache::NewL( |
|
38 CCmmTransactionHandler* aTrans, |
|
39 CommsDat::TMDBElementId aBearerPriorityTableId ) |
|
40 { |
|
41 OstTraceFunctionEntry0( CCMMBEARERPRIORITYCACHE_NEWL_ENTRY ); |
|
42 |
|
43 CCmmBearerPriorityCache* self = |
|
44 CCmmBearerPriorityCache::NewLC( aTrans, aBearerPriorityTableId ); |
|
45 CleanupStack::Pop( self ); |
|
46 |
|
47 OstTraceFunctionExit0( CCMMBEARERPRIORITYCACHE_NEWL_EXIT ); |
|
48 return self; |
|
49 } |
|
50 |
|
51 // --------------------------------------------------------------------------- |
|
52 // Two phased construction. |
|
53 // --------------------------------------------------------------------------- |
|
54 // |
|
55 CCmmBearerPriorityCache* CCmmBearerPriorityCache::NewLC( |
|
56 CCmmTransactionHandler* aTrans, |
|
57 CommsDat::TMDBElementId aBearerPriorityTableId ) |
|
58 { |
|
59 OstTraceFunctionEntry0( CCMMBEARERPRIORITYCACHE_NEWLC_ENTRY ); |
|
60 |
|
61 CCmmBearerPriorityCache* self = |
|
62 new( ELeave ) CCmmBearerPriorityCache( aTrans, aBearerPriorityTableId ); |
|
63 CleanupStack::PushL( self ); |
|
64 self->ConstructL(); |
|
65 |
|
66 OstTraceFunctionExit0( CCMMBEARERPRIORITYCACHE_NEWLC_EXIT ); |
|
67 return self; |
|
68 } |
|
69 |
|
70 // --------------------------------------------------------------------------- |
|
71 // Destructor. |
|
72 // --------------------------------------------------------------------------- |
|
73 // |
|
74 CCmmBearerPriorityCache::~CCmmBearerPriorityCache() |
|
75 { |
|
76 OstTraceFunctionEntry0( CCMMBEARERPRIORITYCACHE_CCMMBEARERPRIORITYCACHE_ENTRY ); |
|
77 iArray.ResetAndDestroy(); |
|
78 OstTraceFunctionExit0( CCMMBEARERPRIORITYCACHE_CCMMBEARERPRIORITYCACHE_EXIT ); |
|
79 } |
|
80 |
|
81 // --------------------------------------------------------------------------- |
|
82 // Constructor. |
|
83 // --------------------------------------------------------------------------- |
|
84 // |
|
85 CCmmBearerPriorityCache::CCmmBearerPriorityCache( |
|
86 CCmmTransactionHandler* aTrans, |
|
87 CommsDat::TMDBElementId aBearerPriorityTableId ) |
|
88 : |
|
89 iTrans( aTrans ), |
|
90 iArray(), |
|
91 iBearerPriorityTableId( aBearerPriorityTableId ) |
|
92 { |
|
93 OstTraceFunctionEntry0( DUP1_CCMMBEARERPRIORITYCACHE_CCMMBEARERPRIORITYCACHE_ENTRY ); |
|
94 OstTraceFunctionExit0( DUP1_CCMMBEARERPRIORITYCACHE_CCMMBEARERPRIORITYCACHE_EXIT ); |
|
95 } |
|
96 |
|
97 // --------------------------------------------------------------------------- |
|
98 // Second phase constructor. |
|
99 // --------------------------------------------------------------------------- |
|
100 // |
|
101 void CCmmBearerPriorityCache::ConstructL() |
|
102 { |
|
103 OstTraceFunctionEntry0( CCMMBEARERPRIORITYCACHE_CONSTRUCTL_ENTRY ); |
|
104 |
|
105 // Read initial bearer priority array from commsdat. |
|
106 ReadL(); |
|
107 |
|
108 OstTraceFunctionExit0( CCMMBEARERPRIORITYCACHE_CONSTRUCTL_EXIT ); |
|
109 } |
|
110 |
|
111 // --------------------------------------------------------------------------- |
|
112 // Updates the bearer priority array with the contents of aArray. |
|
113 // --------------------------------------------------------------------------- |
|
114 // |
|
115 void CCmmBearerPriorityCache::UpdateL( const RPointerArray<CCmmBearerPriority>& aArray ) |
|
116 { |
|
117 OstTraceFunctionEntry0( CCMMBEARERPRIORITYCACHE_UPDATEL_ENTRY ); |
|
118 |
|
119 iTrans->OpenTransactionLC(); |
|
120 |
|
121 CommsDat::CMDBRecordSet<CCDGlobalBearerTypePriorizationRecord>* bpRS = |
|
122 new( ELeave ) CommsDat::CMDBRecordSet<CCDGlobalBearerTypePriorizationRecord>( |
|
123 iBearerPriorityTableId ); |
|
124 CleanupStack::PushL( bpRS ); |
|
125 |
|
126 // Delete the old records. |
|
127 TRAP_IGNORE( bpRS->LoadL( iTrans->Session() ) ); |
|
128 for ( TInt i = 0; i < bpRS->iRecords.Count(); i++ ) |
|
129 { |
|
130 bpRS->iRecords[i]->DeleteL( iTrans->Session() ); |
|
131 } |
|
132 CleanupStack::PopAndDestroy( bpRS ); |
|
133 bpRS = NULL; |
|
134 |
|
135 iArray.ResetAndDestroy(); |
|
136 |
|
137 // Add new content. |
|
138 const TInt count( aArray.Count() ); |
|
139 for ( TInt i = 0; i < count; i++ ) |
|
140 { |
|
141 if ( aArray[i]->ServiceType() && aArray[i]->ServiceType()->Length() > 0 ) |
|
142 { |
|
143 CCDGlobalBearerTypePriorizationRecord* bpRcd = |
|
144 new( ELeave ) CCDGlobalBearerTypePriorizationRecord( |
|
145 iBearerPriorityTableId ); |
|
146 CleanupStack::PushL( bpRcd ); |
|
147 |
|
148 HBufC* serviceType = aArray[i]->ServiceType()->AllocLC(); |
|
149 TUint priority = aArray[i]->Priority(); |
|
150 TUint uiPriority = aArray[i]->UiPriority(); |
|
151 |
|
152 bpRcd->SetRecordId( KCDNewRecordRequest ); |
|
153 bpRcd->iServiceType.SetL( *serviceType ); |
|
154 bpRcd->iPriority.SetL( priority ); |
|
155 bpRcd->iUIPriority.SetL( uiPriority ); |
|
156 bpRcd->StoreL( iTrans->Session() ); |
|
157 |
|
158 TPtrC tempServiceType( serviceType->Des() ); |
|
159 CCmmBearerPriority* item = CCmmBearerPriority::NewLC( |
|
160 tempServiceType, |
|
161 priority, |
|
162 uiPriority ); |
|
163 iArray.AppendL( item ); // Ownership transferred. |
|
164 CleanupStack::Pop( item ); |
|
165 CleanupStack::PopAndDestroy( serviceType ); |
|
166 CleanupStack::PopAndDestroy( bpRcd ); |
|
167 } |
|
168 } |
|
169 iTrans->CommitTransactionL(); |
|
170 |
|
171 OstTraceFunctionExit0( CCMMBEARERPRIORITYCACHE_UPDATEL_EXIT ); |
|
172 } |
|
173 |
|
174 // --------------------------------------------------------------------------- |
|
175 // CopyL() |
|
176 // --------------------------------------------------------------------------- |
|
177 // |
|
178 void CCmmBearerPriorityCache::CopyL( RPointerArray<CCmmBearerPriority>& aArray ) const |
|
179 { |
|
180 OstTraceFunctionEntry0( CCMMBEARERPRIORITYCACHE_COPYL_ENTRY ); |
|
181 |
|
182 const TInt count( iArray.Count() ); |
|
183 for ( TInt i = 0; i < count; i++ ) |
|
184 { |
|
185 if ( iArray[i]->ServiceType() ) |
|
186 { |
|
187 TPtrC tempServiceType( iArray[i]->ServiceType()->Des() ); |
|
188 if ( tempServiceType.Length() > 0 ) |
|
189 { |
|
190 CCmmBearerPriority* item = CCmmBearerPriority::NewLC( |
|
191 tempServiceType, |
|
192 iArray[i]->Priority(), |
|
193 iArray[i]->UiPriority() ); |
|
194 aArray.AppendL( item ); |
|
195 CleanupStack::Pop( item ); |
|
196 } |
|
197 } |
|
198 } |
|
199 |
|
200 OstTraceFunctionExit0( CCMMBEARERPRIORITYCACHE_COPYL_EXIT ); |
|
201 } |
|
202 |
|
203 // --------------------------------------------------------------------------- |
|
204 // Get the priority value for a service type from the bearer priority cache. |
|
205 // --------------------------------------------------------------------------- |
|
206 // |
|
207 TUint CCmmBearerPriorityCache::GetPriority( const TDesC& aServiceType ) const |
|
208 { |
|
209 TUint priority = CMManager::KDataMobilitySelectionPolicyPriorityWildCard; |
|
210 |
|
211 if ( aServiceType.Length() > 0 ) |
|
212 { |
|
213 for ( TInt i = 0; i < iArray.Count(); i++ ) |
|
214 { |
|
215 if ( iArray[i]->ServiceType()->Compare( aServiceType ) == 0 ) |
|
216 { |
|
217 priority = iArray[i]->Priority(); |
|
218 break; |
|
219 } |
|
220 } |
|
221 } |
|
222 |
|
223 return priority; |
|
224 } |
|
225 |
|
226 // --------------------------------------------------------------------------- |
|
227 // Reads the bearer priority array from CommsDat. |
|
228 // --------------------------------------------------------------------------- |
|
229 // |
|
230 void CCmmBearerPriorityCache::ReadL() |
|
231 { |
|
232 OstTraceFunctionEntry0( CCMMBEARERPRIORITYCACHE_READL_ENTRY ); |
|
233 |
|
234 CommsDat::CMDBRecordSet<CCDGlobalBearerTypePriorizationRecord>* bpRS = |
|
235 new( ELeave ) CommsDat::CMDBRecordSet<CCDGlobalBearerTypePriorizationRecord>( |
|
236 iBearerPriorityTableId ); |
|
237 CleanupStack::PushL( bpRS ); |
|
238 |
|
239 CCDGlobalBearerTypePriorizationRecord* bpRcd = |
|
240 new( ELeave ) CCDGlobalBearerTypePriorizationRecord( |
|
241 iBearerPriorityTableId ); |
|
242 CleanupStack::PushL( bpRcd ); |
|
243 |
|
244 TRAP_IGNORE( bpRS->LoadL( iTrans->Session() ) ); |
|
245 |
|
246 // Read every record and store to cache. |
|
247 const TInt bpCount = bpRS->iRecords.Count(); |
|
248 for ( TInt i = 0; i < bpCount; i++ ) |
|
249 { |
|
250 bpRcd->SetElementId( bpRS->iRecords[i]->ElementId() ); |
|
251 bpRcd->LoadL( iTrans->Session() ); |
|
252 |
|
253 if ( !bpRcd->iServiceType.IsNull() ) |
|
254 { |
|
255 TPtrC serviceType( bpRcd->iServiceType ); |
|
256 TUint priority = bpRcd->iPriority; |
|
257 TUint uiPriority = bpRcd->iUIPriority; |
|
258 |
|
259 if ( serviceType.Length() > 0 ) |
|
260 { |
|
261 CCmmBearerPriority* item = CCmmBearerPriority::NewLC( |
|
262 serviceType, |
|
263 priority, |
|
264 uiPriority ); |
|
265 iArray.AppendL( item ); |
|
266 CleanupStack::Pop( item ); |
|
267 } |
|
268 } |
|
269 } |
|
270 CleanupStack::PopAndDestroy( bpRcd ); |
|
271 CleanupStack::PopAndDestroy( bpRS ); |
|
272 |
|
273 OstTraceFunctionExit0( CCMMBEARERPRIORITYCACHE_READL_EXIT ); |
|
274 } |
|
275 |
|
276 // End of file |