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