|
1 /* |
|
2 * Copyright (c) 2006-2008 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: Contains CNcdNodeUpgradeProxy class implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "ncdnodeupgradeproxy.h" |
|
20 #include "ncdnodemetadataproxy.h" |
|
21 #include "ncdnodemanagerproxy.h" |
|
22 #include "ncdnodeproxy.h" |
|
23 #include "ncdnodemanagerproxy.h" |
|
24 #include "catalogsclientserver.h" |
|
25 #include "ncdnodedependencyinfoimpl.h" |
|
26 #include "ncddependencyinfo.h" |
|
27 #include "ncdnodefunctionids.h" |
|
28 #include "ncdnodeclassids.h" |
|
29 #include "catalogsinterfaceidentifier.h" |
|
30 #include "ncdnodeidentifier.h" |
|
31 #include "catalogsutils.h" |
|
32 #include "catalogsdebug.h" |
|
33 #include "ncderrors.h" |
|
34 #include "ncdattributes.h" |
|
35 #include "ncdnodeupgradeimpl.h" // TUpgradeData |
|
36 |
|
37 |
|
38 // ======== PUBLIC MEMBER FUNCTIONS ======== |
|
39 |
|
40 CNcdNodeUpgradeProxy::CNcdNodeUpgradeProxy( |
|
41 MCatalogsClientServer& aSession, |
|
42 TInt aHandle, |
|
43 CNcdNodeMetadataProxy& aMetadata ) |
|
44 : CNcdInterfaceBaseProxy( aSession, aHandle, &aMetadata ), |
|
45 iNodeManager( aMetadata.Node().NodeManager() ), |
|
46 iUpgradeType( MNcdNodeUpgrade::EUpgradeNotAvailable ) |
|
47 { |
|
48 } |
|
49 |
|
50 |
|
51 void CNcdNodeUpgradeProxy::ConstructL() |
|
52 { |
|
53 // Register the interface |
|
54 MNcdNodeUpgrade* interface( this ); |
|
55 AddInterfaceL( |
|
56 CCatalogsInterfaceIdentifier::NewL( interface, this, MNcdNodeUpgrade::KInterfaceUid ) ); |
|
57 |
|
58 // Let the construction leave if we do not get the data from the server. |
|
59 InternalizeL(); |
|
60 } |
|
61 |
|
62 |
|
63 CNcdNodeUpgradeProxy* CNcdNodeUpgradeProxy::NewL( |
|
64 MCatalogsClientServer& aSession, |
|
65 TInt aHandle, |
|
66 CNcdNodeMetadataProxy& aMetadata ) |
|
67 { |
|
68 CNcdNodeUpgradeProxy* self = |
|
69 CNcdNodeUpgradeProxy::NewLC( aSession, aHandle, aMetadata ); |
|
70 CleanupStack::Pop( self ); |
|
71 return self; |
|
72 } |
|
73 |
|
74 CNcdNodeUpgradeProxy* CNcdNodeUpgradeProxy::NewLC( |
|
75 MCatalogsClientServer& aSession, |
|
76 TInt aHandle, |
|
77 CNcdNodeMetadataProxy& aMetadata ) |
|
78 { |
|
79 CNcdNodeUpgradeProxy* self = |
|
80 new( ELeave ) CNcdNodeUpgradeProxy( aSession, aHandle, aMetadata ); |
|
81 // Using PushL because the object does not have any references yet |
|
82 CleanupStack::PushL( self ); |
|
83 self->ConstructL(); |
|
84 return self; |
|
85 } |
|
86 |
|
87 |
|
88 CNcdNodeUpgradeProxy::~CNcdNodeUpgradeProxy() |
|
89 { |
|
90 // Remove interfaces implemented by this class from the interface list. |
|
91 // So, the interface list is up to date when this class object is deleted. |
|
92 RemoveInterface( MNcdNodeUpgrade::KInterfaceUid ); |
|
93 |
|
94 |
|
95 // Delete member variables here |
|
96 // Do not delete manager because |
|
97 // this object does not own it. |
|
98 |
|
99 // Casting is safe here because only this class creates the objects |
|
100 // that are inserted into the array. |
|
101 ResetAndDestroyWithCast<CNcdNodeDependencyInfo>( iUpgradeTargets ); |
|
102 |
|
103 delete iUpgradeData; |
|
104 } |
|
105 |
|
106 |
|
107 CNcdNodeManagerProxy& CNcdNodeUpgradeProxy::NodeManager() const |
|
108 { |
|
109 return iNodeManager; |
|
110 } |
|
111 |
|
112 |
|
113 void CNcdNodeUpgradeProxy::InternalizeL() |
|
114 { |
|
115 DLTRACEIN(("")); |
|
116 |
|
117 HBufC8* data( NULL ); |
|
118 |
|
119 // Because we do not know the exact size of the data, use |
|
120 // the alloc method, which creates the buffer of the right size |
|
121 // and sets the pointer to point to the created buffer. |
|
122 // Get all the data that is necessary to internalize this object |
|
123 // from the server side. |
|
124 TInt error( |
|
125 ClientServerSession(). |
|
126 SendSyncAlloc( NcdNodeFunctionIds::ENcdInternalize, |
|
127 KNullDesC8, |
|
128 data, |
|
129 Handle(), |
|
130 0 ) ); |
|
131 |
|
132 if ( error == KNcdErrorObsolete ) |
|
133 { |
|
134 DLINFO(("Upgrade was obsolete")); |
|
135 // Remove interfaces implemented by this class from the top parent interface list. |
|
136 // So, the interface list is up to date after this object is removed |
|
137 // from its top parent. |
|
138 RemoveInterface( MNcdNodeUpgrade::KInterfaceUid ); |
|
139 // Remove from the parent |
|
140 RemoveFromParent(); |
|
141 // Now update the interface for this object just in case somebody needs it. |
|
142 // Register the interface |
|
143 MNcdNodeUpgrade* interface( this ); |
|
144 AddInterfaceL( |
|
145 CCatalogsInterfaceIdentifier::NewL( interface, this, MNcdNodeUpgrade::KInterfaceUid ) ); |
|
146 |
|
147 } |
|
148 else if ( error == KErrNotFound ) |
|
149 { |
|
150 DLTRACE(("Upgrade not available anymore")); |
|
151 // Reset upgrade type so that the interface user knows that there's |
|
152 // no more upgrade available |
|
153 iUpgradeType = MNcdNodeUpgrade::EUpgradeNotAvailable; |
|
154 } |
|
155 |
|
156 // If error occurred during data transfer, leave here and forward the error. |
|
157 User::LeaveIfError( error ); |
|
158 |
|
159 if ( data == NULL ) |
|
160 { |
|
161 DLERROR(("")); |
|
162 User::Leave( KErrNotFound ); |
|
163 } |
|
164 |
|
165 CleanupStack::PushL( data ); |
|
166 |
|
167 // Read the data from the stream and insert it to the memeber variables |
|
168 RDesReadStream stream( *data ); |
|
169 CleanupClosePushL( stream ); |
|
170 |
|
171 InternalizeDataL( stream ); |
|
172 |
|
173 // Closes the stream |
|
174 CleanupStack::PopAndDestroy( &stream ); |
|
175 CleanupStack::PopAndDestroy( data ); |
|
176 |
|
177 DLTRACEOUT(("")); |
|
178 } |
|
179 |
|
180 |
|
181 // MNcdNodeUpgrade functions |
|
182 |
|
183 const TDesC& CNcdNodeUpgradeProxy::Name() const |
|
184 { |
|
185 // Even though we may have multiple possibilities in the array. |
|
186 // The API function only wants one. So choose the first one here. |
|
187 if ( iUpgradeTargets.Count() == 0 ) |
|
188 { |
|
189 return KNullDesC(); |
|
190 } |
|
191 |
|
192 return iUpgradeTargets[0]->Name(); |
|
193 } |
|
194 |
|
195 |
|
196 TUid CNcdNodeUpgradeProxy::Uid() const |
|
197 { |
|
198 DLTRACEIN(("")); |
|
199 |
|
200 // Upgrades some content, return uid for that content |
|
201 if ( iUpgradeData && |
|
202 iUpgradeData->AttributeType( CNcdNodeUpgrade::EUpgradeDataUid ) == |
|
203 CNcdAttributes::EAttributeTypeInt32 ) |
|
204 { |
|
205 DLTRACEOUT(("Return UID for content upgrade")) |
|
206 return TUid::Uid( iUpgradeData->AttributeInt32( |
|
207 CNcdNodeUpgrade::EUpgradeDataUid ) ); |
|
208 } |
|
209 |
|
210 // Even though we may have multiple possibilities in the array. |
|
211 // The API function only wants one. So choose the first one here. |
|
212 |
|
213 if ( iUpgradeTargets.Count() == 0 ) |
|
214 { |
|
215 return TUid::Null(); |
|
216 } |
|
217 |
|
218 |
|
219 return iUpgradeTargets[0]->Uid(); |
|
220 } |
|
221 |
|
222 |
|
223 const TDesC& CNcdNodeUpgradeProxy::Version() const |
|
224 { |
|
225 DLTRACEIN(("")); |
|
226 if ( iUpgradeData && |
|
227 iUpgradeData->AttributeType( CNcdNodeUpgrade::EUpgradeDataVersion ) == |
|
228 CNcdAttributes::EAttributeTypeString16 ) |
|
229 { |
|
230 DLTRACEOUT(("Return version for content upgrade")) |
|
231 return iUpgradeData->AttributeString16( |
|
232 CNcdNodeUpgrade::EUpgradeDataVersion ); |
|
233 } |
|
234 |
|
235 |
|
236 // Even though we may have multiple possibilities in the array. |
|
237 // The API function only wants one. So choose the first one here. |
|
238 |
|
239 if ( iUpgradeTargets.Count() == 0 ) |
|
240 { |
|
241 return KNullDesC(); |
|
242 } |
|
243 |
|
244 return iUpgradeTargets[0]->Version(); |
|
245 } |
|
246 |
|
247 |
|
248 MNcdNode* CNcdNodeUpgradeProxy::UpgradeableNodeL() const |
|
249 { |
|
250 DLTRACEIN(("")); |
|
251 |
|
252 // Even though we may have multiple possibilities in the array. |
|
253 // The API function only wants one. So choose the first one here. |
|
254 |
|
255 if ( iUpgradeTargets.Count() == 0 ) |
|
256 { |
|
257 return NULL; |
|
258 } |
|
259 |
|
260 return iUpgradeTargets[0]->DependencyNodeL(); |
|
261 } |
|
262 |
|
263 |
|
264 |
|
265 MNcdNodeUpgrade::TUpgradeType CNcdNodeUpgradeProxy::UpgradeType() const |
|
266 { |
|
267 return iUpgradeType; |
|
268 } |
|
269 |
|
270 |
|
271 // Other functions |
|
272 |
|
273 const RPointerArray<MNcdNodeDependencyInfo>& CNcdNodeUpgradeProxy::UpgradeTargets() const |
|
274 { |
|
275 return iUpgradeTargets; |
|
276 } |
|
277 |
|
278 |
|
279 void CNcdNodeUpgradeProxy::InternalizeDataL( RReadStream& aStream ) |
|
280 { |
|
281 DLTRACEIN(("")); |
|
282 |
|
283 // Use catalogsutils.h functions to internalize |
|
284 // memebervariables according to the data received |
|
285 // from the server. |
|
286 // Make sure that the variables are set here in the same |
|
287 // order as they are externalized in the server side. |
|
288 // Small mistake here messes up everything! |
|
289 |
|
290 // First read the class id. Because, it is the first thing in the stream. |
|
291 TInt classId( aStream.ReadInt32L() ); |
|
292 |
|
293 if ( classId != NcdNodeClassIds::ENcdNodeUpgradeClassId ) |
|
294 { |
|
295 // classId is not recognized |
|
296 DLERROR(("Class id was not recognized!")); |
|
297 // For testing purposes assert here |
|
298 DASSERT( EFalse ); |
|
299 |
|
300 // Otherwise leave is adequate |
|
301 User::Leave( KErrCorrupt ); |
|
302 } |
|
303 |
|
304 InternalizeUpgradeArrayL( aStream ); |
|
305 |
|
306 delete iUpgradeData; |
|
307 iUpgradeData = NULL; |
|
308 |
|
309 TBool upgradeDataExists = aStream.ReadInt8L(); |
|
310 if ( upgradeDataExists ) |
|
311 { |
|
312 iUpgradeData = CNcdAttributes::NewL( |
|
313 aStream, |
|
314 CNcdNodeUpgrade::EUpgradeDataInternal, |
|
315 0 ); |
|
316 } |
|
317 |
|
318 if ( !iUpgradeData && !iUpgradeTargets.Count() ) |
|
319 { |
|
320 DLERROR(("Corrupt data, leaving")); |
|
321 User::Leave( KErrCorrupt ); |
|
322 } |
|
323 |
|
324 RefreshUpgradeType(); |
|
325 DLTRACEOUT(("")); |
|
326 } |
|
327 |
|
328 |
|
329 void CNcdNodeUpgradeProxy::InternalizeUpgradeArrayL( RReadStream& aStream ) |
|
330 { |
|
331 DLTRACEIN(("")); |
|
332 |
|
333 // Casting is safe here because only this class creates the objects |
|
334 // that are inserted into the array. |
|
335 ResetAndDestroyWithCast<CNcdNodeDependencyInfo>( iUpgradeTargets ); |
|
336 |
|
337 // First get the node dependency information that is sent from the server |
|
338 // and then convert it to the proxy side dependency information object |
|
339 // that is inserted into the array. |
|
340 TInt count( aStream.ReadInt32L() ); |
|
341 CNcdDependencyInfo* upgradeInfo( NULL ); |
|
342 CNcdNodeDependencyInfo* info( NULL ); |
|
343 for( TInt i = 0; i < count; ++i ) |
|
344 { |
|
345 upgradeInfo = CNcdDependencyInfo::NewLC( aStream ); |
|
346 info = CNcdNodeDependencyInfo::NewLC( *upgradeInfo, NodeManager() ); |
|
347 iUpgradeTargets.AppendL( info ); |
|
348 // Ownership was transferred to the array |
|
349 CleanupStack::Pop( info ); |
|
350 CleanupStack::PopAndDestroy( upgradeInfo ); |
|
351 } |
|
352 |
|
353 // Second get the content dependency information |
|
354 count = aStream.ReadInt32L(); |
|
355 upgradeInfo = NULL; |
|
356 info = NULL; |
|
357 for( TInt i = 0; i < count; ++i ) |
|
358 { |
|
359 upgradeInfo = CNcdDependencyInfo::NewLC( aStream ); |
|
360 info = CNcdNodeDependencyInfo::NewLC( *upgradeInfo, NodeManager() ); |
|
361 iUpgradeTargets.AppendL( info ); |
|
362 CleanupStack::Pop( info ); |
|
363 CleanupStack::PopAndDestroy( upgradeInfo ); |
|
364 } |
|
365 |
|
366 DLTRACEOUT(("")); |
|
367 } |
|
368 |
|
369 |
|
370 void CNcdNodeUpgradeProxy::RefreshUpgradeType() |
|
371 { |
|
372 DLTRACEIN(("")); |
|
373 if ( iUpgradeData || |
|
374 !static_cast<CNcdNodeDependencyInfo*>( |
|
375 iUpgradeTargets[0] )->Identifier() ) |
|
376 { |
|
377 DLTRACE(("Upgrade content")); |
|
378 iUpgradeType = MNcdNodeUpgrade::EUpgradeContent; |
|
379 } |
|
380 else |
|
381 { |
|
382 DLTRACE(("Upgrade node")); |
|
383 iUpgradeType = MNcdNodeUpgrade::EUpgradeNode; |
|
384 } |
|
385 } |