|
1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 |
|
17 |
|
18 // INCLUDE FILES |
|
19 #include <etelpckt.h> |
|
20 #include <pcktlist.h> |
|
21 #include "mbmstypes.h" |
|
22 #include "cmmmbmsmonitoredlist.h" |
|
23 #include <ctsy/tflogger.h> |
|
24 |
|
25 |
|
26 // ============================ MEMBER FUNCTIONS =============================== |
|
27 |
|
28 CMmMBMSMonitoredList::CMmMBMSMonitoredList() |
|
29 { |
|
30 } |
|
31 |
|
32 CMmMBMSMonitoredList* CMmMBMSMonitoredList::NewL( |
|
33 CMmPacketServiceTsy* aMmPacketService, |
|
34 TInt aMaxEntries ) |
|
35 { |
|
36 CMmMBMSMonitoredList* monitoredList = new ( ELeave ) CMmMBMSMonitoredList(); |
|
37 |
|
38 CleanupStack::PushL( monitoredList ); |
|
39 |
|
40 monitoredList->ConstructL(aMmPacketService, aMaxEntries); |
|
41 CleanupStack::Pop(); |
|
42 |
|
43 return monitoredList; |
|
44 } |
|
45 |
|
46 void CMmMBMSMonitoredList::ConstructL(CMmPacketServiceTsy* aMmPacketService, TInt aMaxEntries) |
|
47 { |
|
48 iMmPacketService = aMmPacketService; |
|
49 iServiceList = CPcktMbmsMonitoredServiceList::NewL(); |
|
50 iServiceList->SetMaxNumberEntries(aMaxEntries); |
|
51 } |
|
52 |
|
53 CMmMBMSMonitoredList::~CMmMBMSMonitoredList() |
|
54 { |
|
55 if(iServiceList != NULL) |
|
56 { |
|
57 delete iServiceList; |
|
58 iServiceList = NULL; |
|
59 } |
|
60 if(iMbmsMonitoredListData.iListOfChanges != NULL) |
|
61 { |
|
62 delete iMbmsMonitoredListData.iListOfChanges; |
|
63 iMbmsMonitoredListData.iListOfChanges = NULL; |
|
64 } |
|
65 } |
|
66 |
|
67 // --------------------------------------------------------------------------- |
|
68 // CMmMBMSMonitoredList::SaveReqUpdValues |
|
69 // Save changes to temp list |
|
70 // --------------------------------------------------------------------------- |
|
71 // |
|
72 TInt CMmMBMSMonitoredList::SaveUpdateValuesToTempL( |
|
73 TDes8* aList, |
|
74 TMbmsAction aAction ) |
|
75 { |
|
76 TInt ret( KErrNone ); |
|
77 |
|
78 iMbmsMonitoredListData.iActionType = aAction; |
|
79 iMbmsMonitoredListData.iServiceList = iServiceList; |
|
80 |
|
81 if(iMbmsMonitoredListData.iListOfChanges == NULL) |
|
82 { |
|
83 iMbmsMonitoredListData.iListOfChanges = CPcktMbmsMonitoredServiceList::NewL(); |
|
84 } |
|
85 |
|
86 if( aList == NULL ) |
|
87 { |
|
88 while( iMbmsMonitoredListData.iListOfChanges->Enumerate() > 0 ) |
|
89 { |
|
90 iMbmsMonitoredListData.iListOfChanges->DeleteEntryL(0); |
|
91 } |
|
92 } |
|
93 else |
|
94 { |
|
95 iMbmsMonitoredListData.iListOfChanges->RestoreL(*aList); |
|
96 |
|
97 if( ( EAddEntries == aAction ) || ( ERemoveEntries == aAction )) |
|
98 { |
|
99 RPacketService::TMbmsServiceAvailabilityV1 entry; |
|
100 TInt i = 0; |
|
101 while(i != iMbmsMonitoredListData.iListOfChanges->Enumerate() ) |
|
102 { |
|
103 entry = iMbmsMonitoredListData.iListOfChanges->GetEntryL(i); |
|
104 // check if entry already exists in service list |
|
105 if( ( ( EntryExistL( entry ) ) && ( EAddEntries == aAction )) || |
|
106 ( (!EntryExistL( entry ) ) && ( ERemoveEntries == aAction))) |
|
107 { |
|
108 iMbmsMonitoredListData.iListOfChanges->DeleteEntryL(i); |
|
109 } |
|
110 else |
|
111 { |
|
112 i++; |
|
113 } |
|
114 } |
|
115 if( 0 == iMbmsMonitoredListData.iListOfChanges->Enumerate()) |
|
116 { |
|
117 ret = KErrAlreadyExists; |
|
118 ResetTempListL(); |
|
119 } |
|
120 } |
|
121 } |
|
122 |
|
123 return ret; |
|
124 |
|
125 } |
|
126 |
|
127 // --------------------------------------------------------------------------- |
|
128 // CMmMBMSMonitoredList::PackData() |
|
129 // Pack data to send to the LTSY |
|
130 // --------------------------------------------------------------------------- |
|
131 // |
|
132 TInt CMmMBMSMonitoredList::PackDataL() |
|
133 { |
|
134 |
|
135 TInt ret( KErrNone ); |
|
136 |
|
137 CMmDataPackage dataPackage; |
|
138 switch( iMbmsMonitoredListData.iActionType ) |
|
139 { |
|
140 case ERemoveAllEntries: |
|
141 // pack data (old list + action) |
|
142 ResetTempListL(); |
|
143 //No break since we stll need to pack |
|
144 case EAddEntries: |
|
145 case ERemoveEntries: |
|
146 // Pack data (old list + change list + action) |
|
147 dataPackage.PackData( &iMbmsMonitoredListData ); |
|
148 ret = iMmPacketService->MessageManager()->HandleRequestL(EPacketUpdateMbmsMonitorServiceList, &dataPackage); |
|
149 break; |
|
150 default: |
|
151 ret = KErrNotSupported; |
|
152 break; |
|
153 } |
|
154 if( KErrNone != ret ) |
|
155 { |
|
156 ResetTempListL(); |
|
157 } |
|
158 |
|
159 return ret; |
|
160 } |
|
161 |
|
162 // --------------------------------------------------------------------------- |
|
163 // CMmMBMSMonitoredList::ProcessEntriesL |
|
164 // Packet Data specific functionality of CMmPacketContextTsy::ExtFunc |
|
165 // --------------------------------------------------------------------------- |
|
166 // |
|
167 TInt CMmMBMSMonitoredList::ProcessEntriesL( |
|
168 const CPcktMbmsMonitoredServiceList *aList, |
|
169 TMbmsAction aAction ) |
|
170 { |
|
171 TInt ret( KErrNone ); |
|
172 |
|
173 switch( aAction ) |
|
174 { |
|
175 case EAddEntries: |
|
176 ret = AddTempEntriesToCacheL( aList ); |
|
177 break; |
|
178 case ERemoveEntries: |
|
179 DeleteEntriesL( aList ); |
|
180 break; |
|
181 case ERemoveAllEntries: |
|
182 ClearListL( iServiceList ); |
|
183 break; |
|
184 default: |
|
185 ret = KErrNotSupported; |
|
186 break; |
|
187 } |
|
188 return ret; |
|
189 } |
|
190 |
|
191 // --------------------------------------------------------------------------- |
|
192 // CMmMBMSMonitoredList::AddEntries |
|
193 // Add new entry/entries into monitored service list |
|
194 // (other items were commented in a header). |
|
195 // --------------------------------------------------------------------------- |
|
196 // |
|
197 TInt CMmMBMSMonitoredList::AddEntriesL( const CPcktMbmsMonitoredServiceList *aList ) |
|
198 { |
|
199 // verify we dont cause overflow |
|
200 if(iServiceList->Enumerate() + aList->Enumerate() >= iServiceList->MaxNumberEntries() ) |
|
201 { |
|
202 return KErrOverflow; |
|
203 } |
|
204 TInt size = aList->Enumerate(); |
|
205 for( TInt i = 0; i < size; ++i) |
|
206 { |
|
207 if( EntryExistL( aList->GetEntryL(i) ) ) |
|
208 { |
|
209 return KErrAlreadyExists; |
|
210 } |
|
211 } |
|
212 for( TInt i = 0; i < size; ++i) |
|
213 { |
|
214 iServiceList->AddEntryL( aList->GetEntryL(i) ); |
|
215 } |
|
216 return KErrNone; |
|
217 } |
|
218 |
|
219 |
|
220 // --------------------------------------------------------------------------- |
|
221 // CMmMBMSMonitoredList::DeleteEntriesL |
|
222 // Remove entry/entries from monitored service list |
|
223 // (other items were commented in a header). |
|
224 // --------------------------------------------------------------------------- |
|
225 // |
|
226 void CMmMBMSMonitoredList::DeleteEntriesL( const CPcktMbmsMonitoredServiceList *aList ) |
|
227 { |
|
228 |
|
229 if( iMbmsMonitoredListData.iListOfChanges == NULL ) |
|
230 { |
|
231 return ; |
|
232 } |
|
233 // those entries should not be removed |
|
234 if( aList ) |
|
235 { |
|
236 // check if entries could not be added |
|
237 if( aList->Enumerate() > 0 ) |
|
238 { |
|
239 |
|
240 //iterate through failed entries vs. iMbmsMonitoredListData.iListOfChanges |
|
241 for( TInt i = 0; i < iMbmsMonitoredListData.iListOfChanges->Enumerate(); i++ ) |
|
242 { |
|
243 for(TInt j = 0; j < aList->Enumerate(); j++ ) |
|
244 { |
|
245 //if entry could not be removed -> remove it from temp list |
|
246 //if no match found. leave it into temp list |
|
247 if( iMbmsMonitoredListData.iListOfChanges->GetEntryL(i).iTmgi.GetServiceId() == aList->GetEntryL(j).iTmgi.GetServiceId() ) |
|
248 { |
|
249 iMbmsMonitoredListData.iListOfChanges->DeleteEntryL(i); |
|
250 j= aList->Enumerate(); |
|
251 i--; |
|
252 } |
|
253 } |
|
254 } |
|
255 } |
|
256 } |
|
257 |
|
258 // temp list is up-to-date |
|
259 // remove entries in temp list from the main list |
|
260 for( TInt i = 0; i < iMbmsMonitoredListData.iListOfChanges->Enumerate(); i++ ) |
|
261 { |
|
262 //iterate through temo list vs. main list |
|
263 for( TInt ii = 0; ii < iServiceList->Enumerate(); ) |
|
264 { |
|
265 //if entry could not be removed -> remove it from services list |
|
266 //if no match found. leave it into temp list |
|
267 if( iMbmsMonitoredListData.iListOfChanges->GetEntryL(i).iTmgi.GetServiceId() == |
|
268 iServiceList->GetEntryL(ii).iTmgi.GetServiceId()) |
|
269 { |
|
270 iServiceList->DeleteEntryL(ii); |
|
271 } |
|
272 else |
|
273 { |
|
274 ++ii; |
|
275 } |
|
276 } |
|
277 |
|
278 } |
|
279 } |
|
280 |
|
281 |
|
282 |
|
283 // --------------------------------------------------------------------------- |
|
284 // CMmMBMSMonitoredList::ClearListL |
|
285 // Clear given service list |
|
286 // (other items were commented in a header). |
|
287 // --------------------------------------------------------------------------- |
|
288 // |
|
289 void CMmMBMSMonitoredList::ClearListL( CPcktMbmsMonitoredServiceList *aList ) |
|
290 { |
|
291 |
|
292 while(aList->Enumerate() > 0 ) |
|
293 { |
|
294 aList->DeleteEntryL(0); |
|
295 } |
|
296 } |
|
297 |
|
298 // --------------------------------------------------------------------------- |
|
299 // CMmMBMSMonitoredList::EntryExistL |
|
300 // Clear given service list |
|
301 // (other items were commented in a header). |
|
302 // --------------------------------------------------------------------------- |
|
303 // |
|
304 TBool CMmMBMSMonitoredList::EntryExistL( const RPacketService::TMbmsServiceAvailabilityV1 &aEntry ) |
|
305 { |
|
306 |
|
307 for( TInt i = 0; i < iServiceList->Enumerate(); i++ ) |
|
308 { |
|
309 if( aEntry.iTmgi.GetServiceId() == iServiceList->GetEntryL(i).iTmgi.GetServiceId() ) |
|
310 { |
|
311 return ETrue; |
|
312 } |
|
313 } |
|
314 return EFalse; |
|
315 |
|
316 } |
|
317 |
|
318 // --------------------------------------------------------------------------- |
|
319 // CMmMBMSMonitoredList::NumberOfMonitoredList |
|
320 // This function returns the number of monitored service list. |
|
321 // --------------------------------------------------------------------------- |
|
322 // |
|
323 TInt CMmMBMSMonitoredList::NumberOfMonitoredList() |
|
324 { |
|
325 return iServiceList->Enumerate(); |
|
326 } |
|
327 |
|
328 // --------------------------------------------------------------------------- |
|
329 // CMmMBMSMonitoredList::SetServicesAvailabilityL |
|
330 // This function sets the availability status of the service list. |
|
331 // --------------------------------------------------------------------------- |
|
332 // |
|
333 void CMmMBMSMonitoredList::SetServicesAvailabilityL(CPcktMbmsMonitoredServiceList *aAvailableList) |
|
334 { |
|
335 if ( aAvailableList ) |
|
336 { |
|
337 #ifndef USING_CTSY_DISPATCHER |
|
338 //if the available list is empty (i.e. no services) then all entries in |
|
339 //the service list should be marked unavailable |
|
340 //the header says aAvailableList is "a list of services that should be set to available (the rest will be unavailable)" |
|
341 //this check prevents the the services being marked unavilable in the case the list is empty |
|
342 if (aAvailableList->Enumerate() > 0) |
|
343 #endif //USING_CTSY_DISPATCHER |
|
344 { |
|
345 RPacketService::TMbmsServiceAvailabilityV1 updEntry; |
|
346 RPacketService::TMbmsServiceAvailabilityV1 origEntry; |
|
347 |
|
348 //Set available status to EMbmsUnavailable |
|
349 for( TInt index1 = 0; index1 < iServiceList->Enumerate(); index1++ ) |
|
350 { |
|
351 origEntry = iServiceList->GetEntryL(index1); |
|
352 origEntry.iMbmsAvailabilityStatus = EMbmsUnavailable; |
|
353 iServiceList->ChangeEntryL(index1, origEntry); |
|
354 } |
|
355 |
|
356 // check throught the updated monitor list |
|
357 for( TInt index2 = 0; index2 < aAvailableList->Enumerate(); index2++ ) |
|
358 { |
|
359 updEntry = aAvailableList->GetEntryL(index2); |
|
360 |
|
361 // Seach same entry to original list |
|
362 for( TInt index3 = 0; index3 < iServiceList->Enumerate(); index3++ ) |
|
363 { |
|
364 origEntry = iServiceList->GetEntryL(index3); |
|
365 |
|
366 if (origEntry.iTmgi.GetServiceId() == updEntry.iTmgi.GetServiceId()) |
|
367 { |
|
368 // availability status is EMbmsAvailable |
|
369 origEntry.iMbmsAvailabilityStatus = EMbmsAvailable; |
|
370 iServiceList->ChangeEntryL(index3, origEntry); |
|
371 } |
|
372 } |
|
373 } |
|
374 } |
|
375 } |
|
376 } |
|
377 |
|
378 // --------------------------------------------------------------------------- |
|
379 // CMmMBMSMonitoredList::AddTempEntriesToCache |
|
380 // This function add the succesfully added monitor entries to main monitor service |
|
381 // list |
|
382 // --------------------------------------------------------------------------- |
|
383 // |
|
384 TInt CMmMBMSMonitoredList::AddTempEntriesToCacheL(const CPcktMbmsMonitoredServiceList* aFailedMonitorEntries) |
|
385 { |
|
386 |
|
387 if(iMbmsMonitoredListData.iListOfChanges == NULL) |
|
388 { |
|
389 return KErrNone; |
|
390 } |
|
391 // some entries could not be removed->update temp list for |
|
392 if( aFailedMonitorEntries ) |
|
393 { |
|
394 //iterate through failed entries vs. iMbmsMonitoredListData.iListOfChanges |
|
395 for(TInt j = 0; j < aFailedMonitorEntries->Enumerate(); j++ ) |
|
396 { |
|
397 for( TInt i = 0; i < iMbmsMonitoredListData.iListOfChanges->Enumerate(); i++ ) |
|
398 { |
|
399 //if entry could not be removed -> remove it from temp list |
|
400 //if no match found. leave it into temp list |
|
401 if( iMbmsMonitoredListData.iListOfChanges->GetEntryL(i).iTmgi.GetServiceId() == |
|
402 aFailedMonitorEntries->GetEntryL(j).iTmgi.GetServiceId() ) |
|
403 { |
|
404 //delete failed entry fom temp list before append them to main list |
|
405 iMbmsMonitoredListData.iListOfChanges->DeleteEntryL(i); |
|
406 i = iMbmsMonitoredListData.iListOfChanges->Enumerate(); |
|
407 } |
|
408 } |
|
409 } |
|
410 } |
|
411 |
|
412 if( iMbmsMonitoredListData.iListOfChanges->Enumerate() + iServiceList->Enumerate() >= |
|
413 iServiceList->MaxNumberEntries() ) |
|
414 { |
|
415 return KErrOverflow; |
|
416 } |
|
417 // temp list is up-to-date |
|
418 // temporary saved entries can be added to the main list |
|
419 for(TInt i=0;i < iMbmsMonitoredListData.iListOfChanges->Enumerate(); i++) |
|
420 { |
|
421 iServiceList->AddEntryL(iMbmsMonitoredListData.iListOfChanges->GetEntryL(i)); |
|
422 } |
|
423 ResetTempListL(); |
|
424 return KErrNone; |
|
425 } |
|
426 |
|
427 // --------------------------------------------------------------------------- |
|
428 // CMmMBMSMonitoredList::ResetTempListL |
|
429 // This function clears the temporary monitors service list e.g. in case of timeout |
|
430 // |
|
431 // --------------------------------------------------------------------------- |
|
432 // |
|
433 void CMmMBMSMonitoredList::ResetTempListL() |
|
434 { |
|
435 if(iMbmsMonitoredListData.iListOfChanges != NULL) |
|
436 { |
|
437 ClearListL(iMbmsMonitoredListData.iListOfChanges); |
|
438 delete iMbmsMonitoredListData.iListOfChanges; |
|
439 iMbmsMonitoredListData.iListOfChanges = NULL; |
|
440 } |
|
441 } |
|
442 |
|
443 |
|
444 // --------------------------------------------------------------------------- |
|
445 // CMmMBMSMonitoredList::ServiceList |
|
446 // This function return a pointer to the service list |
|
447 // |
|
448 // --------------------------------------------------------------------------- |
|
449 // |
|
450 CPcktMbmsMonitoredServiceList* CMmMBMSMonitoredList::ServiceList() |
|
451 { |
|
452 return iServiceList; |
|
453 } |
|
454 |
|
455 // End of File |
|
456 |