|
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 CNcdNodeDependencyProxy class implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "ncdnodedependencyproxy.h" |
|
20 #include "ncdnodemetadataproxy.h" |
|
21 #include "ncdnodemanagerproxy.h" |
|
22 #include "ncdnodeproxy.h" |
|
23 #include "ncdnodedependencyinfoimpl.h" |
|
24 #include "ncddependencyinfo.h" |
|
25 #include "ncdoperationimpl.h" |
|
26 #include "ncddownloadoperationproxy.h" |
|
27 #include "ncdnodemanagerproxy.h" |
|
28 #include "catalogsclientserver.h" |
|
29 #include "ncdnodeidentifier.h" |
|
30 #include "ncdnodefunctionids.h" |
|
31 #include "ncdnodeclassids.h" |
|
32 #include "catalogsinterfaceidentifier.h" |
|
33 #include "ncdnodeidentifier.h" |
|
34 #include "catalogsutils.h" |
|
35 #include "catalogsdebug.h" |
|
36 #include "ncderrors.h" |
|
37 |
|
38 |
|
39 // ======== PUBLIC MEMBER FUNCTIONS ======== |
|
40 |
|
41 CNcdNodeDependencyProxy::CNcdNodeDependencyProxy( |
|
42 MCatalogsClientServer& aSession, |
|
43 TInt aHandle, |
|
44 CNcdNodeMetadataProxy& aMetadata ) |
|
45 : CNcdInterfaceBaseProxy( aSession, aHandle, &aMetadata ), |
|
46 iNodeManager( aMetadata.Node().NodeManager() ) |
|
47 { |
|
48 } |
|
49 |
|
50 |
|
51 void CNcdNodeDependencyProxy::ConstructL() |
|
52 { |
|
53 // Register the interface |
|
54 MNcdNodeDependency* interface( this ); |
|
55 AddInterfaceL( |
|
56 CCatalogsInterfaceIdentifier::NewL( interface, this, MNcdNodeDependency::KInterfaceUid ) ); |
|
57 |
|
58 // Let the construction leave if we do not get the data from the server. |
|
59 InternalizeL(); |
|
60 } |
|
61 |
|
62 |
|
63 CNcdNodeDependencyProxy* CNcdNodeDependencyProxy::NewL( |
|
64 MCatalogsClientServer& aSession, |
|
65 TInt aHandle, |
|
66 CNcdNodeMetadataProxy& aMetadata ) |
|
67 { |
|
68 CNcdNodeDependencyProxy* self = |
|
69 CNcdNodeDependencyProxy::NewLC( aSession, aHandle, aMetadata ); |
|
70 CleanupStack::Pop( self ); |
|
71 return self; |
|
72 } |
|
73 |
|
74 CNcdNodeDependencyProxy* CNcdNodeDependencyProxy::NewLC( |
|
75 MCatalogsClientServer& aSession, |
|
76 TInt aHandle, |
|
77 CNcdNodeMetadataProxy& aMetadata ) |
|
78 { |
|
79 CNcdNodeDependencyProxy* self = |
|
80 new( ELeave ) CNcdNodeDependencyProxy( 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 CNcdNodeDependencyProxy::~CNcdNodeDependencyProxy() |
|
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( MNcdNodeDependency::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>( iDependencyTargets ); |
|
102 } |
|
103 |
|
104 |
|
105 CNcdNodeManagerProxy& CNcdNodeDependencyProxy::NodeManager() const |
|
106 { |
|
107 return iNodeManager; |
|
108 } |
|
109 |
|
110 |
|
111 void CNcdNodeDependencyProxy::InternalizeL() |
|
112 { |
|
113 DLTRACEIN(("")); |
|
114 |
|
115 HBufC8* data( NULL ); |
|
116 |
|
117 // Because we do not know the exact size of the data, use |
|
118 // the alloc method, which creates the buffer of the right size |
|
119 // and sets the pointer to point to the created buffer. |
|
120 // Get all the data that is necessary to internalize this object |
|
121 // from the server side. |
|
122 TInt error( |
|
123 ClientServerSession(). |
|
124 SendSyncAlloc( NcdNodeFunctionIds::ENcdInternalize, |
|
125 KNullDesC8, |
|
126 data, |
|
127 Handle(), |
|
128 0 ) ); |
|
129 |
|
130 if ( error == KNcdErrorObsolete ) |
|
131 { |
|
132 DLINFO(("Dependency was obsolete")); |
|
133 // Remove interfaces implemented by this class from the top parent interface list. |
|
134 // So, the interface list is up to date after this object is removed |
|
135 // from its top parent. |
|
136 RemoveInterface( MNcdNodeDependency::KInterfaceUid ); |
|
137 // Remove from the parent |
|
138 RemoveFromParent(); |
|
139 // Now update the interface for this object just in case somebody needs it. |
|
140 // Register the interface |
|
141 MNcdNodeDependency* interface( this ); |
|
142 AddInterfaceL( |
|
143 CCatalogsInterfaceIdentifier::NewL( interface, this, MNcdNodeDependency::KInterfaceUid ) ); |
|
144 } |
|
145 |
|
146 // If error occurred during data transfer, leave here and forward the error. |
|
147 User::LeaveIfError( error ); |
|
148 |
|
149 if ( data == NULL ) |
|
150 { |
|
151 DLERROR(("")); |
|
152 User::Leave( KErrNotFound ); |
|
153 } |
|
154 |
|
155 CleanupStack::PushL( data ); |
|
156 |
|
157 // Read the data from the stream and insert it to the memeber variables |
|
158 RDesReadStream stream( *data ); |
|
159 CleanupClosePushL( stream ); |
|
160 |
|
161 InternalizeDataL( stream ); |
|
162 |
|
163 // Closes the stream |
|
164 CleanupStack::PopAndDestroy( &stream ); |
|
165 CleanupStack::PopAndDestroy( data ); |
|
166 |
|
167 DLTRACEOUT(("")); |
|
168 } |
|
169 |
|
170 |
|
171 // MNcdNodeDependency functions |
|
172 |
|
173 const RPointerArray<MNcdNodeDependencyInfo>& CNcdNodeDependencyProxy::DependencyInfos() const |
|
174 { |
|
175 DLTRACEIN(("")); |
|
176 return iDependencyTargets; |
|
177 } |
|
178 |
|
179 |
|
180 |
|
181 TNcdDependencyState CNcdNodeDependencyProxy::State() const |
|
182 { |
|
183 DLTRACEIN(("")); |
|
184 TNcdDependencyState totalState = ENcdDependencyInstalled; |
|
185 for ( TInt i = 0; i < iDependencyTargets.Count(); ++i ) |
|
186 { |
|
187 if ( iDependencyTargets[i]->State() < totalState ) |
|
188 { |
|
189 DLTRACE(("Downgrading state from %d to %d", |
|
190 totalState, iDependencyTargets[i]->State() )); |
|
191 totalState = iDependencyTargets[i]->State(); |
|
192 } |
|
193 } |
|
194 DLTRACEOUT(("Total state: %d", totalState )); |
|
195 return totalState; |
|
196 } |
|
197 |
|
198 |
|
199 // Other functions |
|
200 |
|
201 void CNcdNodeDependencyProxy::InternalizeDataL( RReadStream& aStream ) |
|
202 { |
|
203 DLTRACEIN(("")); |
|
204 |
|
205 // Use catalogsutils.h functions to internalize |
|
206 // memebervariables according to the data received |
|
207 // from the server. |
|
208 // Make sure that the variables are set here in the same |
|
209 // order as they are externalized in the server side. |
|
210 // Small mistake here messes up everything! |
|
211 |
|
212 // First read the class id. Because, it is the first thing in the stream. |
|
213 TInt classId( aStream.ReadInt32L() ); |
|
214 |
|
215 if ( classId != NcdNodeClassIds::ENcdNodeDependencyClassId ) |
|
216 { |
|
217 // classId is not recognized |
|
218 DLERROR(("Class id was not recognized!")); |
|
219 // For testing purposes assert here |
|
220 DASSERT( EFalse ); |
|
221 |
|
222 // Otherwise leave is adequate |
|
223 User::Leave( KErrCorrupt ); |
|
224 } |
|
225 |
|
226 InternalizeDependencyArrayL( aStream ); |
|
227 |
|
228 DLTRACEOUT(("")); |
|
229 } |
|
230 |
|
231 |
|
232 void CNcdNodeDependencyProxy::InternalizeDependencyArrayL( RReadStream& aStream ) |
|
233 { |
|
234 DLTRACEIN(("")); |
|
235 |
|
236 // Casting is safe here because only this class creates the objects |
|
237 // that are inserted into the array. |
|
238 ResetAndDestroyWithCast<CNcdNodeDependencyInfo>( iDependencyTargets ); |
|
239 |
|
240 // First get the node dependency information that is sent from the server |
|
241 // and then convert it to the proxy side dependency information object |
|
242 // that is inserted into the array. |
|
243 TInt count( aStream.ReadInt32L() ); |
|
244 CNcdDependencyInfo* dependencyInfo( NULL ); |
|
245 CNcdNodeDependencyInfo* info( NULL ); |
|
246 for( TInt i = 0; i < count; ++i ) |
|
247 { |
|
248 dependencyInfo = CNcdDependencyInfo::NewLC( aStream ); |
|
249 info = CNcdNodeDependencyInfo::NewLC( *dependencyInfo, NodeManager() ); |
|
250 iDependencyTargets.AppendL( info ); |
|
251 // Ownership was transferred to the array |
|
252 CleanupStack::Pop( info ); |
|
253 CleanupStack::PopAndDestroy( dependencyInfo ); |
|
254 } |
|
255 |
|
256 // Second get the content dependency information |
|
257 count = aStream.ReadInt32L(); |
|
258 dependencyInfo = NULL; |
|
259 info = NULL; |
|
260 for( TInt i = 0; i < count; ++i ) |
|
261 { |
|
262 dependencyInfo = CNcdDependencyInfo::NewLC( aStream ); |
|
263 info = CNcdNodeDependencyInfo::NewLC( *dependencyInfo, NodeManager() ); |
|
264 iDependencyTargets.AppendL( info ); |
|
265 CleanupStack::Pop( info ); |
|
266 CleanupStack::PopAndDestroy( dependencyInfo ); |
|
267 } |
|
268 |
|
269 DLTRACEOUT(("")); |
|
270 } |