|
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: Implements CNcdNodeDisclaimer class |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "ncdnodedisclaimer.h" |
|
20 #include "catalogssession.h" |
|
21 #include "catalogsbasemessage.h" |
|
22 #include "ncdnodefunctionids.h" |
|
23 #include "catalogsconstants.h" |
|
24 #include "ncd_pp_dataentity.h" |
|
25 #include "ncd_cp_query.h" |
|
26 #include "ncdstring.h" |
|
27 #include "catalogsutils.h" |
|
28 #include "catalogsdebug.h" |
|
29 #include "ncderrors.h" |
|
30 |
|
31 |
|
32 CNcdNodeDisclaimer::CNcdNodeDisclaimer( NcdNodeClassIds::TNcdNodeClassId aClassId ) |
|
33 : CNcdCommunicable(), |
|
34 iClassId( aClassId ) |
|
35 { |
|
36 } |
|
37 |
|
38 void CNcdNodeDisclaimer::ConstructL() |
|
39 { |
|
40 // These values has to be set. |
|
41 iTitle = KNullDesC().AllocL(); |
|
42 iBodyText = KNullDesC().AllocL(); |
|
43 } |
|
44 |
|
45 void CNcdNodeDisclaimer::ConstructL( const CNcdNodeDisclaimer& aDisclaimer ) |
|
46 { |
|
47 iClassId = aDisclaimer.iClassId; |
|
48 iMessage = NULL; |
|
49 |
|
50 AssignDesL( iTitle, *aDisclaimer.iTitle ); |
|
51 AssignDesL( iBodyText, *aDisclaimer.iBodyText ); |
|
52 |
|
53 iOptional = aDisclaimer.iOptional; |
|
54 iSemantics = aDisclaimer.iSemantics; |
|
55 } |
|
56 |
|
57 |
|
58 CNcdNodeDisclaimer* CNcdNodeDisclaimer::NewL() |
|
59 { |
|
60 CNcdNodeDisclaimer* self = |
|
61 CNcdNodeDisclaimer::NewLC(); |
|
62 CleanupStack::Pop( self ); |
|
63 return self; |
|
64 } |
|
65 |
|
66 CNcdNodeDisclaimer* CNcdNodeDisclaimer::NewLC() |
|
67 { |
|
68 CNcdNodeDisclaimer* self = |
|
69 new( ELeave ) CNcdNodeDisclaimer( |
|
70 NcdNodeClassIds::ENcdNodeDisclaimerClassId ); |
|
71 CleanupClosePushL( *self ); |
|
72 self->ConstructL(); |
|
73 return self; |
|
74 } |
|
75 |
|
76 CNcdNodeDisclaimer* CNcdNodeDisclaimer::NewL( const CNcdNodeDisclaimer& aDisclaimer ) |
|
77 { |
|
78 CNcdNodeDisclaimer* self = NewLC( aDisclaimer ); |
|
79 CleanupStack::Pop( self ); |
|
80 return self; |
|
81 } |
|
82 |
|
83 |
|
84 CNcdNodeDisclaimer* CNcdNodeDisclaimer::NewLC( const CNcdNodeDisclaimer& aDisclaimer ) |
|
85 { |
|
86 CNcdNodeDisclaimer* self = new( ELeave ) CNcdNodeDisclaimer( |
|
87 NcdNodeClassIds::ENcdNodeDisclaimerClassId ); |
|
88 CleanupClosePushL( *self ); |
|
89 self->ConstructL( aDisclaimer ); |
|
90 return self; |
|
91 } |
|
92 |
|
93 |
|
94 CNcdNodeDisclaimer::~CNcdNodeDisclaimer() |
|
95 { |
|
96 DLTRACEIN(("")); |
|
97 |
|
98 // Delete member variables here |
|
99 |
|
100 delete iTitle; |
|
101 iTitle = NULL; |
|
102 |
|
103 delete iBodyText; |
|
104 iBodyText = NULL; |
|
105 |
|
106 DLTRACEOUT(("")); |
|
107 } |
|
108 |
|
109 |
|
110 // Internalization from the protocol |
|
111 |
|
112 void CNcdNodeDisclaimer::InternalizeL( const MNcdConfigurationProtocolQuery& aData ) |
|
113 { |
|
114 DLTRACEIN(("")); |
|
115 |
|
116 // First create the new values |
|
117 |
|
118 HBufC* tmpTitle = aData.Title().Data().AllocLC(); |
|
119 HBufC* tmpBodyText = aData.BodyText().Data().AllocLC(); |
|
120 |
|
121 // Now, that we are sure we have correctly created new values and the |
|
122 // code cannot leave here, set the tmp values to the member variables. |
|
123 |
|
124 delete iBodyText; |
|
125 iBodyText = tmpBodyText; |
|
126 CleanupStack::Pop( tmpBodyText ); |
|
127 |
|
128 delete iTitle; |
|
129 iTitle = tmpTitle; |
|
130 CleanupStack::Pop( tmpTitle ); |
|
131 |
|
132 iOptional = aData.Optional(); |
|
133 iSemantics = aData.Semantics(); |
|
134 |
|
135 DLTRACEOUT(("")); |
|
136 } |
|
137 |
|
138 |
|
139 // Internalization from and externalization to the database |
|
140 |
|
141 void CNcdNodeDisclaimer::ExternalizeL( RWriteStream& aStream ) |
|
142 { |
|
143 DLTRACEIN(("")); |
|
144 |
|
145 // Set all the membervariable values to the stream. So, |
|
146 // that the stream may be used later to create a new |
|
147 // object. |
|
148 |
|
149 // First insert data that the creator of this class object will use to |
|
150 // create this class object. Class id informs what class object |
|
151 // will be created. |
|
152 |
|
153 aStream.WriteInt32L( iClassId ); |
|
154 |
|
155 |
|
156 // Write the data that will be used when internalize function |
|
157 // is called. catalogsutils.h contains good internalize and |
|
158 // externalize functions. |
|
159 // Make sure that this matches to the order that is used |
|
160 // when this stream is internalized. |
|
161 |
|
162 ExternalizeDesL( *iTitle, aStream ); |
|
163 ExternalizeDesL( *iBodyText, aStream ); |
|
164 aStream.WriteInt32L( iOptional ); |
|
165 aStream.WriteInt32L( iSemantics ); |
|
166 |
|
167 DLTRACEOUT(("")); |
|
168 } |
|
169 |
|
170 |
|
171 void CNcdNodeDisclaimer::InternalizeL( RReadStream& aStream ) |
|
172 { |
|
173 DLTRACEIN(("")); |
|
174 |
|
175 // Read the class id out from the stream since it's not read |
|
176 // anywhere else |
|
177 aStream.ReadInt32L(); |
|
178 |
|
179 // Take data to the temporary variables |
|
180 |
|
181 HBufC* tmpTitle( NULL ); |
|
182 HBufC* tmpBodyText( NULL ); |
|
183 |
|
184 InternalizeDesL( tmpTitle, aStream ); |
|
185 CleanupStack::PushL( tmpTitle ); |
|
186 |
|
187 InternalizeDesL( tmpBodyText, aStream ); |
|
188 CleanupStack::PushL( tmpBodyText ); |
|
189 |
|
190 TBool tmpOptional = aStream.ReadInt32L(); |
|
191 |
|
192 // We can be sure that enumerations can be converted to integer values. |
|
193 MNcdQuery::TSemantics tmpSemantics = |
|
194 static_cast<MNcdQuery::TSemantics>(aStream.ReadInt32L()); |
|
195 |
|
196 // Because there was enough memory and this function will not |
|
197 // leave anymore, we may safely insert new values into the |
|
198 // member variables. |
|
199 |
|
200 delete iBodyText; |
|
201 iBodyText = tmpBodyText; |
|
202 CleanupStack::Pop( tmpBodyText ); |
|
203 |
|
204 delete iTitle; |
|
205 iTitle = tmpTitle; |
|
206 CleanupStack::Pop( tmpTitle ); |
|
207 |
|
208 iOptional = tmpOptional; |
|
209 iSemantics = tmpSemantics; |
|
210 |
|
211 |
|
212 DLTRACEOUT(("")); |
|
213 } |
|
214 |
|
215 |
|
216 void CNcdNodeDisclaimer::ReceiveMessage( MCatalogsBaseMessage* aMessage, |
|
217 TInt aFunctionNumber ) |
|
218 { |
|
219 DLTRACEIN(("")); |
|
220 |
|
221 DASSERT( aMessage ); |
|
222 |
|
223 // Now, we can be sure that rest of the time iMessage exists. |
|
224 // This member variable is set for the CounterPartLost function. |
|
225 iMessage = aMessage; |
|
226 |
|
227 TInt trapError( KErrNone ); |
|
228 |
|
229 // Check which function is called by the proxy side object. |
|
230 // Function number are located in ncdnodefunctinoids.h file. |
|
231 switch( aFunctionNumber ) |
|
232 { |
|
233 case NcdNodeFunctionIds::ENcdInternalize: |
|
234 // Internalize the proxy side according to the data |
|
235 // of this object. |
|
236 TRAP( trapError, InternalizeRequestL( *aMessage ) ); |
|
237 break; |
|
238 |
|
239 case NcdNodeFunctionIds::ENcdRelease: |
|
240 // The proxy does not want to use this object anymore. |
|
241 // So, release the handle from the session. |
|
242 ReleaseRequest( *aMessage ); |
|
243 break; |
|
244 |
|
245 default: |
|
246 DLERROR(("Unidentified function request")); |
|
247 DASSERT( EFalse ); |
|
248 break; |
|
249 } |
|
250 |
|
251 if ( trapError != KErrNone ) |
|
252 { |
|
253 // Because something went wrong, the complete has not been |
|
254 // yet called for the message. |
|
255 // So, inform the client about the error if the |
|
256 // message is still available. |
|
257 aMessage->CompleteAndRelease( trapError ); |
|
258 } |
|
259 |
|
260 // Because the message should not be used after this, set it NULL. |
|
261 // So, CounterPartLost function will know that no messages are |
|
262 // waiting the response at the moment. |
|
263 iMessage = NULL; |
|
264 |
|
265 DLTRACEOUT(("")); |
|
266 } |
|
267 |
|
268 void CNcdNodeDisclaimer::CounterPartLost( const MCatalogsSession& aSession ) |
|
269 { |
|
270 // This function may be called whenever -- when the message is waiting |
|
271 // response or when the message does not exist. |
|
272 // iMessage may be NULL here, because in the end of the |
|
273 // ReceiveMessage it is set to NULL. The life time of the message |
|
274 // ends shortly after CompleteAndRelease is called. |
|
275 if ( iMessage != NULL ) |
|
276 { |
|
277 iMessage->CounterPartLost( aSession ); |
|
278 } |
|
279 } |
|
280 |
|
281 |
|
282 void CNcdNodeDisclaimer::InternalizeRequestL( MCatalogsBaseMessage& aMessage ) |
|
283 { |
|
284 DLTRACEIN(("")); |
|
285 |
|
286 CBufBase* buf = CBufFlat::NewL( KBufExpandSize ); |
|
287 CleanupStack::PushL( buf ); |
|
288 |
|
289 RBufWriteStream stream( *buf ); |
|
290 CleanupClosePushL( stream ); |
|
291 |
|
292 |
|
293 // Include all the necessary node data to the stream |
|
294 ExternalizeDataForRequestL( stream ); |
|
295 |
|
296 |
|
297 // Commits data to the stream when closing. |
|
298 CleanupStack::PopAndDestroy( &stream ); |
|
299 |
|
300 |
|
301 // If this leaves, ReceiveMessge will complete the message. |
|
302 // NOTE: that here we expect that the buffer contains at least |
|
303 // some data. So, make sure taht ExternalizeDataForRequestL inserts |
|
304 // something to the buffer. |
|
305 aMessage.CompleteAndReleaseL( buf->Ptr( 0 ), KErrNone ); |
|
306 |
|
307 |
|
308 DLTRACE(("Deleting the buf")); |
|
309 CleanupStack::PopAndDestroy( buf ); |
|
310 |
|
311 DLTRACEOUT(("")); |
|
312 } |
|
313 |
|
314 |
|
315 void CNcdNodeDisclaimer::ExternalizeDataForRequestL( RWriteStream& aStream ) |
|
316 { |
|
317 DLTRACEIN(("")); |
|
318 |
|
319 if ( IsObsolete() ) |
|
320 { |
|
321 DLINFO(("Set as obsolete. This means that server has removed the object.")); |
|
322 User::Leave( KNcdErrorObsolete ); |
|
323 } |
|
324 |
|
325 ExternalizeL( aStream ); |
|
326 |
|
327 DLTRACEOUT(("")); |
|
328 } |
|
329 |
|
330 void CNcdNodeDisclaimer::ReleaseRequest( MCatalogsBaseMessage& aMessage ) const |
|
331 { |
|
332 DLTRACEIN(("")); |
|
333 |
|
334 // Decrease the reference count for this object. |
|
335 // When the reference count reaches zero, this object will be destroyed |
|
336 // and removed from the session. |
|
337 MCatalogsSession& requestSession( aMessage.Session() ); |
|
338 TInt handle( aMessage.Handle() ); |
|
339 |
|
340 // Send complete information back to proxy. |
|
341 aMessage.CompleteAndRelease( KErrNone ); |
|
342 |
|
343 // Remove this object from the session. |
|
344 requestSession.RemoveObject( handle ); |
|
345 |
|
346 DLTRACEOUT(("")); |
|
347 } |
|
348 |
|
349 |