|
1 /* |
|
2 * Copyright (c) 2004 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: Multiple bearers |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <sysutil.h> |
|
22 |
|
23 #include "nsmlroam.h" |
|
24 |
|
25 |
|
26 // -------------------------------- |
|
27 // CNSmlRoamTable::NewLC( RDbNamedDatabase& aDatabase ) |
|
28 // Creates new instance of the CNSmlRoamTable |
|
29 // -------------------------------- |
|
30 // |
|
31 EXPORT_C CNSmlRoamTable* CNSmlRoamTable::NewLC( RDbNamedDatabase& aDatabase ) |
|
32 { |
|
33 CNSmlRoamTable* self = new ( ELeave ) CNSmlRoamTable( aDatabase ); |
|
34 CleanupStack::PushL(self); |
|
35 self->ConstructL(); |
|
36 return self; |
|
37 } |
|
38 |
|
39 // -------------------------------- |
|
40 // CNSmlRoamTable::NewL( RDbNamedDatabase& aDatabase ) |
|
41 // Creates new instance of the CNSmlRoamTable |
|
42 // -------------------------------- |
|
43 // |
|
44 EXPORT_C CNSmlRoamTable* CNSmlRoamTable::NewL(RDbNamedDatabase& aDatabase) |
|
45 { |
|
46 CNSmlRoamTable* self = NewLC( aDatabase ); |
|
47 CleanupStack::Pop(); |
|
48 return self; |
|
49 } |
|
50 |
|
51 // -------------------------------- |
|
52 // CNSmlRoamTable::ConstructL() |
|
53 // Second constructor |
|
54 // -------------------------------- |
|
55 // |
|
56 void CNSmlRoamTable::ConstructL() |
|
57 { |
|
58 RDbTable dbTable; |
|
59 CleanupClosePushL( dbTable ); |
|
60 |
|
61 TInt result = dbTable.Open(iDatabase, KTable); |
|
62 |
|
63 if (result != KErrNone) |
|
64 { |
|
65 User::LeaveIfError( iDatabase.Execute( KSQLCreateTable ) ); |
|
66 User::LeaveIfError( iDatabase.Execute( KSQLCreateIndex ) ); |
|
67 User::LeaveIfError( dbTable.Open(iDatabase, KTable) ); |
|
68 } |
|
69 |
|
70 iColSet = dbTable.ColSetL(); |
|
71 |
|
72 CleanupStack::PopAndDestroy(); //dbTable |
|
73 |
|
74 } |
|
75 |
|
76 // -------------------------------- |
|
77 // CNSmlRoamTable::CNSmlRoamTable(RDbNamedDatabase& aDatabase) |
|
78 // Constructor |
|
79 // -------------------------------- |
|
80 // |
|
81 CNSmlRoamTable::CNSmlRoamTable(RDbNamedDatabase& aDatabase) |
|
82 : iDatabase(aDatabase) |
|
83 { |
|
84 } |
|
85 |
|
86 // -------------------------------- |
|
87 // CNSmlRoamTable::~CNSmlRoamTable() |
|
88 // Destructor |
|
89 // -------------------------------- |
|
90 // |
|
91 EXPORT_C CNSmlRoamTable::~CNSmlRoamTable() |
|
92 { |
|
93 delete iColSet; |
|
94 } |
|
95 |
|
96 // -------------------------------- |
|
97 // CNSmlRoamTable::PutItemsL( TInt aProfileId, CNSmlIAPArray* aItems ) |
|
98 // Put items from array to table for profile id |
|
99 // -------------------------------- |
|
100 // |
|
101 EXPORT_C void CNSmlRoamTable::PutItemsL( TInt aProfileId, CNSmlIAPArray* aItems ) |
|
102 { |
|
103 TInt count(0); |
|
104 |
|
105 RDbView view; |
|
106 CleanupClosePushL( view ); |
|
107 |
|
108 CNSmlRoamItem item; |
|
109 |
|
110 User::LeaveIfNull( aItems ); |
|
111 |
|
112 if (! IsNewItemL(view, aProfileId)) |
|
113 { |
|
114 count = view.CountL(); |
|
115 |
|
116 if ( count > aItems->Count() ) |
|
117 { |
|
118 RemoveAllByIdL(aProfileId); |
|
119 } |
|
120 } |
|
121 |
|
122 for (TInt i = 0; i < aItems->Count(); i++) |
|
123 { |
|
124 item.iProfileId= aProfileId; |
|
125 item.iPriority = i; |
|
126 item.iIAPId = aItems->At(i); |
|
127 HandleItemL( item ); |
|
128 } |
|
129 |
|
130 CleanupStack::PopAndDestroy(); //view |
|
131 } |
|
132 |
|
133 // -------------------------------- |
|
134 // CNSmlRoamTable::GetItemsForIdL( TInt aProfileId ) |
|
135 // Return array of IAPs for profile id |
|
136 // -------------------------------- |
|
137 // |
|
138 EXPORT_C CNSmlIAPArray* CNSmlRoamTable::GetItemsForIdL( TInt aProfileId ) |
|
139 { |
|
140 RDbView view; |
|
141 CleanupClosePushL( view ); |
|
142 |
|
143 CNSmlIAPArray* array = new (ELeave) CArrayFixFlat<TUint32>(4); |
|
144 CleanupStack::PushL( array ); |
|
145 |
|
146 IsNewItemL(view, aProfileId); |
|
147 |
|
148 view.FirstL(); |
|
149 |
|
150 while (view.AtRow()) |
|
151 { |
|
152 view.GetL(); |
|
153 array->AppendL( view.ColUint32( iColSet->ColNo( KColIapId ) )); |
|
154 view.NextL(); |
|
155 } |
|
156 |
|
157 CleanupStack::Pop(); //array |
|
158 CleanupStack::PopAndDestroy(); //view |
|
159 return array; |
|
160 } |
|
161 |
|
162 // -------------------------------- |
|
163 // CNSmlRoamTable::GetItemIAPL( TInt aProfileId, TInt aPriority ) |
|
164 // Return IAP for profile id and priority |
|
165 // -------------------------------- |
|
166 // |
|
167 EXPORT_C TUint32 CNSmlRoamTable::GetItemIAPL( TInt aProfileId, TInt aPriority ) |
|
168 { |
|
169 RDbView view; |
|
170 CleanupClosePushL(view); |
|
171 |
|
172 TUint32 uint(0); |
|
173 TBuf<KNSmlMaxSQLLength> sqlBuf; |
|
174 sqlBuf.Format( KSQLSelectUint, aProfileId, aPriority ); |
|
175 |
|
176 view.Prepare(iDatabase, TDbQuery( sqlBuf )); |
|
177 view.EvaluateAll(); |
|
178 |
|
179 if ( view.IsEmptyL() ) |
|
180 { |
|
181 User::Leave( KErrNotFound ); |
|
182 } |
|
183 |
|
184 view.FirstL(); |
|
185 view.GetL(); |
|
186 |
|
187 uint = view.ColUint( iColSet->ColNo( KColIapId )); |
|
188 |
|
189 CleanupStack::PopAndDestroy(); //view |
|
190 |
|
191 return uint; |
|
192 } |
|
193 |
|
194 // -------------------------------- |
|
195 // CNSmlRoamTable::RemoveAllByIdL( TInt aProfileId ) |
|
196 // Removes all IAPs for profile id |
|
197 // -------------------------------- |
|
198 // |
|
199 EXPORT_C void CNSmlRoamTable::RemoveAllByIdL( TInt aProfileId ) |
|
200 { |
|
201 TBuf<KNSmlMaxSQLLength> sqlBuf; |
|
202 sqlBuf.Format(KSQLDeleteForId, aProfileId); |
|
203 |
|
204 TInt res( iDatabase.Execute( sqlBuf ) ); |
|
205 User::LeaveIfError( res ); |
|
206 #ifdef __MODULETEST |
|
207 test.iDeleted = res; |
|
208 #endif |
|
209 } |
|
210 |
|
211 // -------------------------------- |
|
212 // CNSmlRoamTable::AddItemL( CNSmlRoamItem& aItem ) |
|
213 // Adds item to IAP table |
|
214 // -------------------------------- |
|
215 // |
|
216 void CNSmlRoamTable::AddItemL( CNSmlRoamItem& aItem ) |
|
217 { |
|
218 |
|
219 RFs fs; |
|
220 User::LeaveIfError( fs.Connect() ); |
|
221 CleanupClosePushL(fs); |
|
222 |
|
223 if (SysUtil::FFSSpaceBelowCriticalLevelL(&fs, 12)) |
|
224 { |
|
225 User::Leave( KErrDiskFull ); |
|
226 } |
|
227 |
|
228 CleanupStack::PopAndDestroy(); //fs |
|
229 |
|
230 TBuf<KNSmlMaxSQLLength> sqlBuf; |
|
231 sqlBuf.Format( KSQLInsertQuery, aItem.iProfileId, aItem.iIAPId, aItem.iPriority ); |
|
232 |
|
233 RDbView view; |
|
234 CleanupClosePushL( view ); |
|
235 |
|
236 view.Prepare(iDatabase, TDbQuery(KSQLMatchQuery2), RDbView::EInsertOnly); |
|
237 view.InsertL(); |
|
238 view.SetColL( iColSet->ColNo( KColProfileId ), aItem.iProfileId ); |
|
239 view.SetColL( iColSet->ColNo( KColPriority ), aItem.iPriority ); |
|
240 view.SetColL( iColSet->ColNo( KColIapId ), aItem.iIAPId ); |
|
241 view.PutL(); |
|
242 |
|
243 CleanupStack::PopAndDestroy(); //view |
|
244 |
|
245 #ifdef __MODULETEST |
|
246 test.iAdded++; |
|
247 #endif |
|
248 } |
|
249 |
|
250 // -------------------------------- |
|
251 // CNSmlRoamTable::UpdateItemL(RDbView& aView, CNSmlRoamItem& aItem ) |
|
252 // Updates item in the IAP table |
|
253 // -------------------------------- |
|
254 // |
|
255 void CNSmlRoamTable::UpdateItemL(RDbView& aView, CNSmlRoamItem& aItem ) |
|
256 { |
|
257 |
|
258 aView.FirstL(); |
|
259 aView.UpdateL(); |
|
260 |
|
261 aView.SetColL( iColSet->ColNo( KColProfileId ), aItem.iProfileId ); |
|
262 aView.SetColL( iColSet->ColNo( KColPriority ), aItem.iPriority ); |
|
263 aView.SetColL( iColSet->ColNo( KColIapId ), aItem.iIAPId ); |
|
264 |
|
265 aView.PutL(); |
|
266 |
|
267 #ifdef __MODULETEST |
|
268 test.iUpdated++; |
|
269 #endif |
|
270 } |
|
271 |
|
272 // -------------------------------- |
|
273 // CNSmlRoamTable::HandleItemL( CNSmlRoamItem& aItem ) |
|
274 // Handles item addition or update |
|
275 // -------------------------------- |
|
276 // |
|
277 void CNSmlRoamTable::HandleItemL( CNSmlRoamItem& aItem ) |
|
278 { |
|
279 RDbView view; |
|
280 CleanupClosePushL( view); |
|
281 |
|
282 if (IsNewItemL(view, aItem)) |
|
283 { |
|
284 CleanupStack::PopAndDestroy(); //view |
|
285 AddItemL(aItem); |
|
286 } |
|
287 else |
|
288 { |
|
289 UpdateItemL(view, aItem); |
|
290 CleanupStack::PopAndDestroy(); //aView |
|
291 } |
|
292 |
|
293 } |
|
294 |
|
295 // -------------------------------- |
|
296 // CNSmlRoamTable::IsNewItemL( RDbView& aView, TInt aProfileId) |
|
297 // Checks if whether profile has IAPs |
|
298 // -------------------------------- |
|
299 // |
|
300 TBool CNSmlRoamTable::IsNewItemL( RDbView& aView, TInt aProfileId) |
|
301 { |
|
302 TBuf<KNSmlMaxSQLLength> sqlBuf; |
|
303 sqlBuf.Format(KSQLMultiQuery, aProfileId); |
|
304 |
|
305 aView.Prepare(iDatabase, TDbQuery( sqlBuf )); |
|
306 aView.EvaluateAll(); |
|
307 return aView.IsEmptyL(); |
|
308 } |
|
309 |
|
310 // -------------------------------- |
|
311 // CNSmlRoamTable::IsNewItemL( RDbView& aView, CNSmlRoamItem& aItem) |
|
312 // Checks if whether IAP is new for profile id and priority |
|
313 // -------------------------------- |
|
314 // |
|
315 TBool CNSmlRoamTable::IsNewItemL( RDbView& aView, CNSmlRoamItem& aItem) |
|
316 { |
|
317 TBuf<KNSmlMaxSQLLength> sqlBuf; |
|
318 sqlBuf.Format( KSQLSelectUint, aItem.iProfileId, aItem.iPriority ); |
|
319 |
|
320 aView.Prepare(iDatabase, TDbQuery( sqlBuf )); |
|
321 aView.EvaluateAll(); |
|
322 return aView.IsEmptyL(); |
|
323 } |
|
324 |
|
325 #ifdef __MODULETEST |
|
326 EXPORT_C CTestClass* CNSmlRoamTable::Test() |
|
327 { |
|
328 return &test; |
|
329 } |
|
330 #endif |
|
331 |
|
332 |
|
333 // End of File |