|
1 /* |
|
2 * Copyright (c) 2006 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: Implementation of RCmConnectionMethodExt |
|
15 * |
|
16 */ |
|
17 |
|
18 // INCLUDES |
|
19 #include "cmmanagerimpl.h" |
|
20 #include <cmdestinationext.h> |
|
21 #include <cmpluginbase.h> |
|
22 #include <cmconnectionmethodext.h> |
|
23 #include "cmdestinationimpl.h" |
|
24 |
|
25 using namespace CMManager; |
|
26 // ======== MEMBER FUNCTIONS ======== |
|
27 |
|
28 // ----------------------------------------------------------------------------- |
|
29 // RCmConnectionMethodExt::RCmConnectionMethodExt() |
|
30 // ----------------------------------------------------------------------------- |
|
31 // |
|
32 EXPORT_C RCmConnectionMethodExt::RCmConnectionMethodExt( |
|
33 const RCmConnectionMethodExt& aItem) |
|
34 : iImplementation( aItem.iImplementation ) |
|
35 { |
|
36 iImplementation->IncrementRefCounter(); |
|
37 } |
|
38 |
|
39 |
|
40 // ----------------------------------------------------------------------------- |
|
41 // RCmConnectionMethodExt::Close() |
|
42 // ----------------------------------------------------------------------------- |
|
43 // |
|
44 EXPORT_C void RCmConnectionMethodExt::Close() |
|
45 { |
|
46 if( !iImplementation ) |
|
47 { |
|
48 return; |
|
49 } |
|
50 |
|
51 TRAP_IGNORE( iImplementation->CmMgr().RemoveCMFromPoolL(iImplementation) ); |
|
52 iImplementation = NULL; |
|
53 } |
|
54 |
|
55 |
|
56 // ----------------------------------------------------------------------------- |
|
57 // RCmConnectionMethodExt::CreateCopyL() |
|
58 // ----------------------------------------------------------------------------- |
|
59 // |
|
60 EXPORT_C RCmConnectionMethodExt RCmConnectionMethodExt::CreateCopyL() |
|
61 { |
|
62 if (!iImplementation) |
|
63 { |
|
64 User::Leave(KErrBadHandle); |
|
65 } |
|
66 |
|
67 RCmConnectionMethodExt cm; |
|
68 |
|
69 cm.iImplementation = iImplementation->CreateCopyL(); |
|
70 |
|
71 cm.iImplementation->CmMgr().InsertConnectionMethodL(cm.iImplementation); |
|
72 |
|
73 return cm; |
|
74 } |
|
75 |
|
76 |
|
77 // ----------------------------------------------------------------------------- |
|
78 // RCmConnectionMethodExt::GetIntAttributeL() |
|
79 // ----------------------------------------------------------------------------- |
|
80 // |
|
81 EXPORT_C TUint32 |
|
82 RCmConnectionMethodExt::GetIntAttributeL( TUint32 aAttribute ) const |
|
83 { |
|
84 if (!iImplementation) |
|
85 { |
|
86 User::Leave(KErrBadHandle); |
|
87 } |
|
88 |
|
89 return iImplementation->GetIntAttributeL( aAttribute ); |
|
90 } |
|
91 |
|
92 // ----------------------------------------------------------------------------- |
|
93 // RCmConnectionMethodExt::GetBoolAttributeL() |
|
94 // ----------------------------------------------------------------------------- |
|
95 // |
|
96 EXPORT_C TBool |
|
97 RCmConnectionMethodExt::GetBoolAttributeL( TUint32 aAttribute ) const |
|
98 { |
|
99 if (!iImplementation) |
|
100 { |
|
101 User::Leave(KErrBadHandle); |
|
102 } |
|
103 |
|
104 |
|
105 return iImplementation->GetBoolAttributeL( aAttribute ); |
|
106 } |
|
107 |
|
108 // ----------------------------------------------------------------------------- |
|
109 // RCmConnectionMethodExt::GetStringAttributeL() |
|
110 // ----------------------------------------------------------------------------- |
|
111 // |
|
112 EXPORT_C HBufC* |
|
113 RCmConnectionMethodExt::GetStringAttributeL( TUint32 aAttribute ) const |
|
114 { |
|
115 if (!iImplementation) |
|
116 { |
|
117 User::Leave(KErrBadHandle); |
|
118 } |
|
119 |
|
120 |
|
121 return iImplementation->GetStringAttributeL( aAttribute ); |
|
122 } |
|
123 |
|
124 // ----------------------------------------------------------------------------- |
|
125 // RCmConnectionMethodExt::GetString8AttributeL() |
|
126 // ----------------------------------------------------------------------------- |
|
127 // |
|
128 EXPORT_C HBufC8* |
|
129 RCmConnectionMethodExt::GetString8AttributeL( TUint32 aAttribute ) const |
|
130 { |
|
131 if (!iImplementation) |
|
132 { |
|
133 User::Leave(KErrBadHandle); |
|
134 } |
|
135 |
|
136 return iImplementation->GetString8AttributeL( aAttribute ); |
|
137 } |
|
138 |
|
139 // ----------------------------------------------------------------------------- |
|
140 // RCmConnectionMethodExt::SetIntAttributeL() |
|
141 // ----------------------------------------------------------------------------- |
|
142 // |
|
143 EXPORT_C void RCmConnectionMethodExt::SetIntAttributeL( TUint32 aAttribute, |
|
144 TUint32 aValue ) |
|
145 { |
|
146 if (!iImplementation) |
|
147 { |
|
148 User::Leave(KErrBadHandle); |
|
149 } |
|
150 |
|
151 if( iImplementation->GetBoolAttributeL( ECmProtected ) ) |
|
152 { |
|
153 // Only clients with NetworkControl capability can modify |
|
154 // protection setting! |
|
155 CCmManagerImpl::HasCapabilityL( ECapabilityNetworkControl ); |
|
156 } |
|
157 |
|
158 iImplementation->SetIntAttributeL( aAttribute, aValue ); |
|
159 } |
|
160 |
|
161 // ----------------------------------------------------------------------------- |
|
162 // RCmConnectionMethodExt::SetBoolAttributeL() |
|
163 // ----------------------------------------------------------------------------- |
|
164 // |
|
165 EXPORT_C void RCmConnectionMethodExt::SetBoolAttributeL( TUint32 aAttribute, |
|
166 TBool aValue ) |
|
167 { |
|
168 if (!iImplementation) |
|
169 { |
|
170 User::Leave(KErrBadHandle); |
|
171 } |
|
172 |
|
173 if( iImplementation->GetBoolAttributeL( ECmProtected ) ) |
|
174 { |
|
175 // Only clients with NetworkControl capability can modify |
|
176 // protection setting! |
|
177 CCmManagerImpl::HasCapabilityL( ECapabilityNetworkControl ); |
|
178 } |
|
179 |
|
180 iImplementation->SetBoolAttributeL( aAttribute, aValue ); |
|
181 } |
|
182 |
|
183 // ----------------------------------------------------------------------------- |
|
184 // RCmConnectionMethodExt::SetStringAttributeL() |
|
185 // ----------------------------------------------------------------------------- |
|
186 // |
|
187 EXPORT_C void |
|
188 RCmConnectionMethodExt::SetStringAttributeL( TUint32 aAttribute, |
|
189 const TDesC16& aValue ) |
|
190 { |
|
191 if (!iImplementation) |
|
192 { |
|
193 User::Leave(KErrBadHandle); |
|
194 } |
|
195 |
|
196 if( iImplementation->GetBoolAttributeL( ECmProtected ) ) |
|
197 { |
|
198 // Only clients with NetworkControl capability can modify |
|
199 // protection setting! |
|
200 CCmManagerImpl::HasCapabilityL( ECapabilityNetworkControl ); |
|
201 } |
|
202 |
|
203 iImplementation->SetStringAttributeL( aAttribute, aValue ); |
|
204 } |
|
205 |
|
206 // ----------------------------------------------------------------------------- |
|
207 // RCmConnectionMethodExt::SetString8AttributeL() |
|
208 // ----------------------------------------------------------------------------- |
|
209 // |
|
210 EXPORT_C void |
|
211 RCmConnectionMethodExt::SetString8AttributeL( TUint32 aAttribute, |
|
212 const TDesC8& aValue ) |
|
213 { |
|
214 if (!iImplementation) |
|
215 { |
|
216 User::Leave(KErrBadHandle); |
|
217 } |
|
218 |
|
219 if( iImplementation->GetBoolAttributeL( ECmProtected ) ) |
|
220 { |
|
221 // Only clients with NetworkControl capability can modify |
|
222 // protection setting! |
|
223 CCmManagerImpl::HasCapabilityL( ECapabilityNetworkControl ); |
|
224 } |
|
225 |
|
226 iImplementation->SetString8AttributeL( aAttribute, aValue ); |
|
227 } |
|
228 |
|
229 // ----------------------------------------------------------------------------- |
|
230 // RCmConnectionMethodExt::UpdateL() |
|
231 // ----------------------------------------------------------------------------- |
|
232 // |
|
233 EXPORT_C void RCmConnectionMethodExt::UpdateL() |
|
234 { |
|
235 if (!iImplementation) |
|
236 { |
|
237 User::Leave(KErrBadHandle); |
|
238 } |
|
239 |
|
240 iImplementation->UpdateL(); |
|
241 } |
|
242 |
|
243 // ----------------------------------------------------------------------------- |
|
244 // RCmConnectionMethodExt::DeleteL() |
|
245 // ----------------------------------------------------------------------------- |
|
246 // |
|
247 EXPORT_C TBool RCmConnectionMethodExt::DeleteL() |
|
248 { |
|
249 if (!iImplementation) |
|
250 { |
|
251 User::Leave(KErrBadHandle); |
|
252 } |
|
253 |
|
254 if( iImplementation->GetBoolAttributeL( ECmProtected ) ) |
|
255 { |
|
256 // Only clients with NetworkControl capability can delete |
|
257 // this destination |
|
258 CCmManagerImpl::HasCapabilityL( ECapabilityNetworkControl ); |
|
259 } |
|
260 |
|
261 // Check it's not connected |
|
262 if ( iImplementation->GetBoolAttributeL( ECmConnected ) ) |
|
263 { |
|
264 User::Leave( KErrInUse ); |
|
265 } |
|
266 |
|
267 // Check it's not referenced by Virtual CM |
|
268 if( iImplementation->GetBoolAttributeL( ECmIsLinked ) ) |
|
269 { |
|
270 User::Leave( KErrLocked ); |
|
271 } |
|
272 |
|
273 // Check that it's not the last CM in a destination which is |
|
274 // referenced by Virtual CM |
|
275 CCmDestinationImpl* destImpl = iImplementation->ParentDestination(); |
|
276 TUint32 destId ( 0 ); |
|
277 TUint32 count( 0 ); |
|
278 |
|
279 if ( destImpl ) |
|
280 { |
|
281 destId = destImpl->Id(); |
|
282 count = destImpl->ConnectionMethodCount(); |
|
283 } |
|
284 delete destImpl; |
|
285 destImpl = NULL; |
|
286 |
|
287 if ( count == 1 ) |
|
288 { |
|
289 // The IAP is in destination and it's the last one |
|
290 // for each IAP in CM manager |
|
291 // 1. check if it is virtual |
|
292 // if not => goto 1. |
|
293 // if yes: |
|
294 // 2. check if it links to the destination of this CM |
|
295 // if yes => carryOn = EFalse, ERROR |
|
296 // if not: carryOn = ETrue |
|
297 TBool carryOn = ETrue; |
|
298 |
|
299 CommsDat::CMDBRecordSet<CommsDat::CCDIAPRecord>* iaps = iImplementation->CmMgr().AllIapsL(); |
|
300 CleanupStack::PushL( iaps ); |
|
301 |
|
302 // for each IAP in CM manager |
|
303 for ( TInt i = KCmInitIndex; carryOn && i < iaps->iRecords.Count(); ++i ) |
|
304 { |
|
305 CommsDat::CCDIAPRecord* rec = (*iaps)[i]; |
|
306 TUint32 bearerType = 0; |
|
307 |
|
308 TRAP_IGNORE( bearerType = iImplementation->CmMgr().BearerTypeFromIapRecordL( rec ) ); |
|
309 if ( !bearerType ) |
|
310 { |
|
311 continue; |
|
312 } |
|
313 |
|
314 // check if it is virtual |
|
315 if ( iImplementation->CmMgr().GetBearerInfoBoolL( bearerType, ECmVirtual ) ) |
|
316 { |
|
317 // check if it links to the current destination |
|
318 CCmPluginBase* plugin = NULL; |
|
319 TRAP_IGNORE( plugin = iImplementation->CmMgr().GetConnectionMethodL( rec->RecordId() ) ); |
|
320 |
|
321 if ( !plugin ) |
|
322 { |
|
323 continue; |
|
324 } |
|
325 |
|
326 if ( plugin->IsLinkedToSnap( destId ) ) |
|
327 { |
|
328 // the CM links to this destination, deletion not allowed |
|
329 carryOn = EFalse; |
|
330 } |
|
331 |
|
332 delete plugin; |
|
333 } |
|
334 } |
|
335 |
|
336 CleanupStack::PopAndDestroy( iaps ); |
|
337 |
|
338 if ( !carryOn ) |
|
339 { |
|
340 User::Leave( KErrLocked ); |
|
341 } |
|
342 } |
|
343 |
|
344 // ETrue = delete it. It doesn't matter how many referencies there are. |
|
345 TBool deleteRes = iImplementation->DeleteL( ETrue ); |
|
346 if( deleteRes ) |
|
347 { |
|
348 CCmDestinationImpl* dest = iImplementation->ParentDestination(); |
|
349 if( dest ) |
|
350 { |
|
351 CCmPluginBase* connMethod = new (ELeave) |
|
352 CCmPluginBase(iImplementation); |
|
353 CleanupStack::PushL( connMethod ); |
|
354 dest->ConnectionMethodDeletedL( *connMethod ); |
|
355 CleanupStack::PopAndDestroy(connMethod);//deletes iImplementation |
|
356 iImplementation = NULL; |
|
357 } |
|
358 delete dest; |
|
359 } |
|
360 |
|
361 return deleteRes; |
|
362 } |
|
363 |
|
364 // ----------------------------------------------------------------------------- |
|
365 // RCmConnectionMethod::Destination() |
|
366 // ----------------------------------------------------------------------------- |
|
367 // |
|
368 EXPORT_C RCmDestinationExt RCmConnectionMethodExt::DestinationL() const |
|
369 { |
|
370 if (!iImplementation) |
|
371 { |
|
372 User::Leave(KErrBadHandle); |
|
373 } |
|
374 if (!iImplementation->Destination()) |
|
375 { |
|
376 User::Leave(KErrNotSupported); |
|
377 } |
|
378 |
|
379 RCmDestinationExt dest; |
|
380 dest.iDestinatonData = |
|
381 iImplementation->Destination()->GetData(); |
|
382 dest.iDestinatonData->IncrementRefCounter(); |
|
383 return dest; |
|
384 } |
|
385 // -------------------------------------------------------------------------- |
|
386 // RCmConnectionMethod::RCmConnectionMethod |
|
387 // -------------------------------------------------------------------------- |
|
388 // |
|
389 EXPORT_C RCmConnectionMethodExt::RCmConnectionMethodExt() |
|
390 : iImplementation( NULL ) |
|
391 { |
|
392 } |
|
393 |
|
394 // ----------------------------------------------------------------------------- |
|
395 // RCmConnectionMethodExt::~RCmConnectionMethodExt() |
|
396 // ----------------------------------------------------------------------------- |
|
397 // |
|
398 EXPORT_C RCmConnectionMethodExt::~RCmConnectionMethodExt() |
|
399 { |
|
400 Close(); |
|
401 } |
|
402 |
|
403 // ----------------------------------------------------------------------------- |
|
404 // RCmConnectionMethod::operator=() |
|
405 // ----------------------------------------------------------------------------- |
|
406 // |
|
407 EXPORT_C RCmConnectionMethodExt& RCmConnectionMethodExt::operator=( |
|
408 const RCmConnectionMethodExt& aConnMethod) |
|
409 { |
|
410 if (this != &aConnMethod) |
|
411 { |
|
412 Close(); |
|
413 iImplementation = aConnMethod.iImplementation; |
|
414 iImplementation->IncrementRefCounter(); |
|
415 } |
|
416 return *this; |
|
417 } |
|
418 |
|
419 // -------------------------------------------------------------------------- |
|
420 // RCmConnectionMethod::operator== |
|
421 // -------------------------------------------------------------------------- |
|
422 // |
|
423 EXPORT_C TBool RCmConnectionMethodExt::operator==( |
|
424 RCmConnectionMethodExt& aConnMethod ) const |
|
425 { |
|
426 return ( iImplementation == aConnMethod.iImplementation ); |
|
427 }; |
|
428 |
|
429 |
|
430 // -------------------------------------------------------------------------- |
|
431 // RCmConnectionMethod::operator!= |
|
432 // -------------------------------------------------------------------------- |
|
433 // |
|
434 EXPORT_C TBool RCmConnectionMethodExt::operator!=( |
|
435 RCmConnectionMethodExt& aConnMethod ) const |
|
436 { |
|
437 return !( iImplementation == aConnMethod.iImplementation ); |
|
438 }; |