|
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: Contains CNcdNodeDownloadProxy class implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "ncdnodedownloadproxy.h" |
|
20 #include "ncdnodemetadataproxy.h" |
|
21 #include "ncdnodeproxy.h" |
|
22 #include "ncdoperationimpl.h" |
|
23 #include "ncddownloadoperationproxy.h" |
|
24 #include "ncdoperationmanagerproxy.h" |
|
25 #include "ncdoperationdatatypes.h" |
|
26 #include "catalogsclientserver.h" |
|
27 #include "ncdnodeidentifier.h" |
|
28 #include "ncdnodefunctionids.h" |
|
29 #include "ncdnodeclassids.h" |
|
30 #include "catalogsinterfaceidentifier.h" |
|
31 #include "catalogsutils.h" |
|
32 #include "catalogsdebug.h" |
|
33 |
|
34 |
|
35 // ======== PUBLIC MEMBER FUNCTIONS ======== |
|
36 |
|
37 CNcdNodeDownloadProxy::CNcdNodeDownloadProxy( |
|
38 MCatalogsClientServer& aSession, |
|
39 TInt aHandle, |
|
40 CNcdNodeMetadataProxy& aMetadata ) |
|
41 : CNcdInterfaceBaseProxy( aSession, aHandle, &aMetadata ), |
|
42 iMetadata( aMetadata ) |
|
43 { |
|
44 } |
|
45 |
|
46 |
|
47 void CNcdNodeDownloadProxy::ConstructL() |
|
48 { |
|
49 // Register the interface |
|
50 MNcdNodeDownload* interface( this ); |
|
51 AddInterfaceL( |
|
52 CCatalogsInterfaceIdentifier::NewL( interface, this, MNcdNodeDownload::KInterfaceUid ) ); |
|
53 |
|
54 InternalizeL(); |
|
55 } |
|
56 |
|
57 |
|
58 CNcdNodeDownloadProxy* CNcdNodeDownloadProxy::NewL( |
|
59 MCatalogsClientServer& aSession, |
|
60 TInt aHandle, |
|
61 CNcdNodeMetadataProxy& aMetadata ) |
|
62 { |
|
63 CNcdNodeDownloadProxy* self = |
|
64 CNcdNodeDownloadProxy::NewLC( aSession, aHandle, aMetadata ); |
|
65 CleanupStack::Pop( self ); |
|
66 return self; |
|
67 } |
|
68 |
|
69 CNcdNodeDownloadProxy* CNcdNodeDownloadProxy::NewLC( |
|
70 MCatalogsClientServer& aSession, |
|
71 TInt aHandle, |
|
72 CNcdNodeMetadataProxy& aMetadata ) |
|
73 { |
|
74 CNcdNodeDownloadProxy* self = |
|
75 new( ELeave ) CNcdNodeDownloadProxy( aSession, aHandle, aMetadata ); |
|
76 // Using PushL because the object does not have any references yet |
|
77 CleanupStack::PushL( self ); |
|
78 self->ConstructL(); |
|
79 return self; |
|
80 } |
|
81 |
|
82 |
|
83 CNcdNodeDownloadProxy::~CNcdNodeDownloadProxy() |
|
84 { |
|
85 DLTRACEIN(("")); |
|
86 // Remove interfaces implemented by this class from the interface list. |
|
87 // So, the interface list is up to date when this class object is deleted. |
|
88 RemoveInterface( MNcdNodeDownload::KInterfaceUid ); |
|
89 |
|
90 // Delete member variables here |
|
91 // Do not delete node and operation manager because |
|
92 // this object does not own them. |
|
93 } |
|
94 |
|
95 |
|
96 CNcdNodeMetadataProxy& CNcdNodeDownloadProxy::Metadata() const |
|
97 { |
|
98 return iMetadata; |
|
99 } |
|
100 |
|
101 |
|
102 void CNcdNodeDownloadProxy::InternalizeL() |
|
103 { |
|
104 DLTRACEIN(("")); |
|
105 |
|
106 HBufC8* data( NULL ); |
|
107 |
|
108 // Because we do not know the exact size of the data, use |
|
109 // the alloc method, which creates the buffer of the right size |
|
110 // and sets the pointer to point to the created buffer. |
|
111 // Get all the data that is necessary to internalize this object |
|
112 // from the server side. |
|
113 User::LeaveIfError( |
|
114 ClientServerSession(). |
|
115 SendSyncAlloc( NcdNodeFunctionIds::ENcdInternalize, |
|
116 KNullDesC8, |
|
117 data, |
|
118 Handle(), |
|
119 0 ) ); |
|
120 |
|
121 if ( data == NULL ) |
|
122 { |
|
123 DLERROR(("")); |
|
124 User::Leave( KErrNotFound ); |
|
125 } |
|
126 |
|
127 CleanupStack::PushL( data ); |
|
128 |
|
129 // Read the data from the stream and insert it to the memeber variables |
|
130 RDesReadStream stream( *data ); |
|
131 CleanupClosePushL( stream ); |
|
132 |
|
133 InternalizeDataL( stream ); |
|
134 |
|
135 // Closes the stream |
|
136 CleanupStack::PopAndDestroy( &stream ); |
|
137 CleanupStack::PopAndDestroy( data ); |
|
138 |
|
139 DLTRACEOUT(("")); |
|
140 } |
|
141 |
|
142 |
|
143 // MNcdNodeDownload functions |
|
144 |
|
145 TBool CNcdNodeDownloadProxy::IsDownloadedL() const |
|
146 { |
|
147 DLTRACEIN(("")); |
|
148 if ( !iIsDownloaded ) |
|
149 { |
|
150 DLTRACEOUT(("iIsDownloaded == EFalse")); |
|
151 return EFalse; |
|
152 } |
|
153 |
|
154 TInt filesExist = 0; |
|
155 // Internalize so that the server checks whether the files exist or not |
|
156 User::LeaveIfError( |
|
157 ClientServerSession(). |
|
158 SendSync( NcdNodeFunctionIds::ENcdFilesExist, |
|
159 KNullDesC8, |
|
160 filesExist, |
|
161 Handle() ) ); |
|
162 |
|
163 DLTRACEOUT(("isDownloaded status from server: %d", filesExist )); |
|
164 return filesExist; |
|
165 } |
|
166 |
|
167 |
|
168 MNcdDownloadOperation* CNcdNodeDownloadProxy::DownloadContentL( |
|
169 MNcdDownloadOperationObserver& aObserver ) |
|
170 { |
|
171 DLTRACEIN(("")); |
|
172 |
|
173 CNcdDownloadOperationProxy* operation( NULL ); |
|
174 |
|
175 // What is the data id here? Is KNullDesC ok? |
|
176 operation = |
|
177 Metadata().Node(). |
|
178 OperationManager(). |
|
179 CreateDownloadOperationL( ENcdContentDownload, |
|
180 Metadata().Node(), |
|
181 KNullDesC, |
|
182 &aObserver ); |
|
183 |
|
184 // It is enought that the observer is informed |
|
185 // when the file operation is ready. So, no need to add |
|
186 // node or this class object to be observers. |
|
187 |
|
188 // No need to increase the operation ref count here because |
|
189 // it should be initially one. |
|
190 |
|
191 DLTRACEOUT(("Operation %x", |
|
192 static_cast<MCatalogsBase*>( operation ) )); |
|
193 |
|
194 return operation; |
|
195 } |
|
196 |
|
197 |
|
198 // Other functions |
|
199 |
|
200 void CNcdNodeDownloadProxy::InternalizeDataL( RReadStream& aStream ) |
|
201 { |
|
202 DLTRACEIN(("")); |
|
203 |
|
204 // Use catalogsutils.h functions to internalize |
|
205 // memebervariables according to the data received |
|
206 // from the server. |
|
207 // Make sure that the variables are set here in the same |
|
208 // order as they are externalized in the server side. |
|
209 // Small mistake here messes up everything! |
|
210 |
|
211 // First read the class id. Because, it is the first thing in the stream. |
|
212 TInt classId( aStream.ReadInt32L() ); |
|
213 |
|
214 if ( classId != NcdNodeClassIds::ENcdNodeDownloadClassId ) |
|
215 { |
|
216 // classId is not recognized |
|
217 DLERROR(("Class id was not recognized!")); |
|
218 // For testing purposes assert here |
|
219 DASSERT( EFalse ); |
|
220 |
|
221 // Otherwise leave is adequate |
|
222 User::Leave( KErrCorrupt ); |
|
223 } |
|
224 |
|
225 |
|
226 iIsDownloaded = aStream.ReadInt32L(); |
|
227 |
|
228 DLTRACEOUT(("")); |
|
229 } |