|
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 CNcdNodeContentInfoProxy class implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "ncdnodecontentinfoproxy.h" |
|
20 #include "ncdnodemetadataproxy.h" |
|
21 #include "ncdoperationimpl.h" |
|
22 #include "catalogsclientserver.h" |
|
23 #include "ncdnodeidentifier.h" |
|
24 #include "ncdnodefunctionids.h" |
|
25 #include "ncdnodeclassids.h" |
|
26 #include "catalogsinterfaceidentifier.h" |
|
27 #include "catalogsutils.h" |
|
28 #include "catalogsdebug.h" |
|
29 #include "ncderrors.h" |
|
30 |
|
31 |
|
32 // ======== PUBLIC MEMBER FUNCTIONS ======== |
|
33 |
|
34 CNcdNodeContentInfoProxy::CNcdNodeContentInfoProxy( |
|
35 MCatalogsClientServer& aSession, |
|
36 TInt aHandle, |
|
37 CNcdNodeMetadataProxy& aMetadata ) |
|
38 : CNcdInterfaceBaseProxy( aSession, aHandle, &aMetadata ) |
|
39 { |
|
40 } |
|
41 |
|
42 |
|
43 void CNcdNodeContentInfoProxy::ConstructL() |
|
44 { |
|
45 DLTRACEIN(("")); |
|
46 // Register the interface |
|
47 MNcdNodeContentInfo* interface( this ); |
|
48 AddInterfaceL( |
|
49 CCatalogsInterfaceIdentifier::NewL( interface, this, MNcdNodeContentInfo::KInterfaceUid ) ); |
|
50 |
|
51 InternalizeL(); |
|
52 } |
|
53 |
|
54 |
|
55 CNcdNodeContentInfoProxy* CNcdNodeContentInfoProxy::NewL( |
|
56 MCatalogsClientServer& aSession, |
|
57 TInt aHandle, |
|
58 CNcdNodeMetadataProxy& aMetadata ) |
|
59 { |
|
60 CNcdNodeContentInfoProxy* self = |
|
61 CNcdNodeContentInfoProxy::NewLC( aSession, aHandle, aMetadata ); |
|
62 CleanupStack::Pop( self ); |
|
63 return self; |
|
64 } |
|
65 |
|
66 CNcdNodeContentInfoProxy* CNcdNodeContentInfoProxy::NewLC( |
|
67 MCatalogsClientServer& aSession, |
|
68 TInt aHandle, |
|
69 CNcdNodeMetadataProxy& aMetadata ) |
|
70 { |
|
71 CNcdNodeContentInfoProxy* self = |
|
72 new( ELeave ) CNcdNodeContentInfoProxy( aSession, aHandle, aMetadata ); |
|
73 // Using PushL because the object does not have any references yet |
|
74 CleanupStack::PushL( self ); |
|
75 self->ConstructL(); |
|
76 return self; |
|
77 } |
|
78 |
|
79 |
|
80 CNcdNodeContentInfoProxy::~CNcdNodeContentInfoProxy() |
|
81 { |
|
82 DLTRACEIN(("")); |
|
83 // Remove interfaces implemented by this class from the interface list. |
|
84 // So, the interface list is up to date when this class object is deleted. |
|
85 RemoveInterface( MNcdNodeContentInfo::KInterfaceUid ); |
|
86 |
|
87 delete iMimeType; |
|
88 iMimeType = NULL; |
|
89 |
|
90 delete iVersion; |
|
91 iVersion = NULL; |
|
92 } |
|
93 |
|
94 |
|
95 void CNcdNodeContentInfoProxy::InternalizeL() |
|
96 { |
|
97 DLTRACEIN(("")); |
|
98 |
|
99 HBufC8* data( NULL ); |
|
100 |
|
101 // Because we do not know the exact size of the data, use |
|
102 // the alloc method, which creates the buffer of the right size |
|
103 // and sets the pointer to point to the created buffer. |
|
104 // Get all the data that is necessary to internalize this object |
|
105 // from the server side. |
|
106 TInt error( |
|
107 ClientServerSession(). |
|
108 SendSyncAlloc( NcdNodeFunctionIds::ENcdInternalize, |
|
109 KNullDesC8, |
|
110 data, |
|
111 Handle(), |
|
112 0 ) ); |
|
113 |
|
114 if ( error == KNcdErrorObsolete ) |
|
115 { |
|
116 DLINFO(("Content info was obsolete")); |
|
117 // Remove interfaces implemented by this class from the top parent interface list. |
|
118 // So, the interface list is up to date after this object is removed |
|
119 // from its top parent. |
|
120 RemoveInterface( MNcdNodeContentInfo::KInterfaceUid ); |
|
121 // Remove from the parent |
|
122 RemoveFromParent(); |
|
123 // Now update the interface for this object just in case somebody needs it. |
|
124 // Register the interface |
|
125 MNcdNodeContentInfo* interface( this ); |
|
126 AddInterfaceL( |
|
127 CCatalogsInterfaceIdentifier::NewL( interface, this, MNcdNodeContentInfo::KInterfaceUid ) ); |
|
128 } |
|
129 |
|
130 // If error occurred during data transfer, leave here and forward the error. |
|
131 User::LeaveIfError( error ); |
|
132 |
|
133 if ( data == NULL ) |
|
134 { |
|
135 DLERROR(("")); |
|
136 User::Leave( KErrNotFound ); |
|
137 } |
|
138 |
|
139 CleanupStack::PushL( data ); |
|
140 |
|
141 // Read the data from the stream and insert it to the memeber variables |
|
142 RDesReadStream stream( *data ); |
|
143 CleanupClosePushL( stream ); |
|
144 |
|
145 InternalizeDataL( stream ); |
|
146 |
|
147 // Closes the stream |
|
148 CleanupStack::PopAndDestroy( &stream ); |
|
149 CleanupStack::PopAndDestroy( data ); |
|
150 |
|
151 DLTRACEOUT(("")); |
|
152 } |
|
153 |
|
154 |
|
155 // MNcdNodeContentInfo functions |
|
156 |
|
157 TUint CNcdNodeContentInfoProxy::Purpose() const |
|
158 { |
|
159 DLTRACEIN(( "iPurpose: %u", iPurpose )); |
|
160 return iPurpose; |
|
161 } |
|
162 |
|
163 const TDesC& CNcdNodeContentInfoProxy::MimeType() const |
|
164 { |
|
165 DASSERT( iMimeType ); |
|
166 return *iMimeType; |
|
167 } |
|
168 |
|
169 TUid CNcdNodeContentInfoProxy::Uid() const |
|
170 { |
|
171 return iUid; |
|
172 } |
|
173 |
|
174 const TDesC& CNcdNodeContentInfoProxy::Version() const |
|
175 { |
|
176 DASSERT( iVersion ); |
|
177 return *iVersion; |
|
178 } |
|
179 |
|
180 TInt CNcdNodeContentInfoProxy::Size() const |
|
181 { |
|
182 return iSize; |
|
183 } |
|
184 |
|
185 |
|
186 // Other functions |
|
187 |
|
188 void CNcdNodeContentInfoProxy::InternalizeDataL( RReadStream& aStream ) |
|
189 { |
|
190 DLTRACEIN(("")); |
|
191 |
|
192 // First read the class id. Because, it is the first thing in the stream. |
|
193 TInt classId( aStream.ReadInt32L() ); |
|
194 |
|
195 if ( classId != NcdNodeClassIds::ENcdNodeContentInfoClassId ) |
|
196 { |
|
197 // classId is not recognized |
|
198 DLERROR(("Class id was not recognized!")); |
|
199 // For testing purposes assert here |
|
200 DASSERT( EFalse ); |
|
201 |
|
202 // Otherwise leave is adequate |
|
203 User::Leave( KErrCorrupt ); |
|
204 } |
|
205 |
|
206 iPurpose = aStream.ReadUint16L(); |
|
207 DLINFO(( "Purpose: %u", iPurpose )); |
|
208 |
|
209 InternalizeDesL( iMimeType, aStream ); |
|
210 DLINFO(( _L("Mime: %S"), iMimeType )); |
|
211 |
|
212 iUid.iUid = aStream.ReadInt32L(); |
|
213 DLINFO(( "Uid: %x", iUid.iUid )); |
|
214 |
|
215 InternalizeDesL( iVersion, aStream ); |
|
216 DLINFO(( _L("Version: %S"), iVersion )); |
|
217 |
|
218 iSize = aStream.ReadInt32L(); |
|
219 DLINFO(( _L("Size: %d"), iSize )); |
|
220 |
|
221 DLTRACEOUT(("")); |
|
222 } |