|
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: Implementation of CatalogsBaseMessageImpl |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <e32std.h> |
|
20 #include <f32file.h> |
|
21 |
|
22 #include "catalogsbasemessageimpl.h" |
|
23 #include "catalogsclientserverserversession.h" |
|
24 #include "catalogsserverdefines.h" |
|
25 #include "catalogsdebug.h" |
|
26 |
|
27 |
|
28 const TInt KInputSlot = 2; |
|
29 const TInt KOutputSlot = 3; |
|
30 |
|
31 |
|
32 CCatalogsBaseMessageImpl::CCatalogsBaseMessageImpl( |
|
33 const RMessage2& aMessage, |
|
34 CCatalogsClientServerServerSession& aSession, |
|
35 TInt aHandle ) : |
|
36 iMessage( aMessage ), |
|
37 iSession( aSession ), |
|
38 iHandle( aHandle ), |
|
39 iSenderLost( EFalse ) |
|
40 { |
|
41 } |
|
42 |
|
43 void CCatalogsBaseMessageImpl::ConstructL() |
|
44 { |
|
45 DLTRACEIN(( "this: %x", this )); |
|
46 } |
|
47 |
|
48 |
|
49 CCatalogsBaseMessageImpl* CCatalogsBaseMessageImpl::NewL( |
|
50 const RMessage2& aMessage, |
|
51 CCatalogsClientServerServerSession& aSession, |
|
52 TInt aHandle ) |
|
53 { |
|
54 CCatalogsBaseMessageImpl* self = |
|
55 CCatalogsBaseMessageImpl::NewLC( aMessage, aSession, aHandle ); |
|
56 CleanupStack::Pop( self ); |
|
57 return self; |
|
58 } |
|
59 |
|
60 |
|
61 CCatalogsBaseMessageImpl* CCatalogsBaseMessageImpl::NewLC( |
|
62 const RMessage2& aMessage, |
|
63 CCatalogsClientServerServerSession& aSession, |
|
64 TInt aHandle ) |
|
65 { |
|
66 CCatalogsBaseMessageImpl* self = |
|
67 new( ELeave ) CCatalogsBaseMessageImpl( aMessage, aSession, aHandle ); |
|
68 CleanupStack::PushL( self ); |
|
69 self->ConstructL(); |
|
70 return self; |
|
71 } |
|
72 |
|
73 CCatalogsBaseMessageImpl::~CCatalogsBaseMessageImpl() |
|
74 { |
|
75 } |
|
76 |
|
77 TInt CCatalogsBaseMessageImpl::InputLength() const |
|
78 { |
|
79 return iMessage.GetDesLength( KInputSlot ); |
|
80 } |
|
81 |
|
82 TInt CCatalogsBaseMessageImpl::ReadInput( TDes8& aInputData ) const |
|
83 { |
|
84 return iMessage.Read( KInputSlot, aInputData ); |
|
85 } |
|
86 |
|
87 TInt CCatalogsBaseMessageImpl::ReadInput( TDes16& aInputData ) const |
|
88 { |
|
89 return iMessage.Read( KInputSlot, aInputData ); |
|
90 } |
|
91 |
|
92 TInt CCatalogsBaseMessageImpl::Handle() const |
|
93 { |
|
94 return iHandle; |
|
95 } |
|
96 |
|
97 void CCatalogsBaseMessageImpl::CompleteAndRelease( TInt aStatus ) const |
|
98 { |
|
99 DLTRACEIN(("TInt, handle: %d, this: %x", Handle(), this )); |
|
100 if ( iSenderLost ) |
|
101 { |
|
102 DLINFO(("Sender was lost, deleting message")); |
|
103 delete this; |
|
104 DLTRACEOUT(("")); |
|
105 return; |
|
106 } |
|
107 iMessage.Complete( aStatus ); |
|
108 delete this; |
|
109 DLTRACEOUT(("")); |
|
110 } |
|
111 |
|
112 void CCatalogsBaseMessageImpl::CompleteAndReleaseL( |
|
113 const TDesC8& aOutputData, |
|
114 TInt aStatus ) |
|
115 { |
|
116 DLTRACEIN(("TDesC8, TInt, handle: %d, this: %x", Handle(), this )); |
|
117 if ( iSenderLost ) |
|
118 { |
|
119 DLINFO(("Sender was lost, deleting message")); |
|
120 delete this; |
|
121 DLTRACEOUT(("")); |
|
122 return; |
|
123 } |
|
124 |
|
125 TInt clientDescLength( iMessage.GetDesMaxLengthL( KOutputSlot ) ); |
|
126 |
|
127 if ( clientDescLength < aOutputData.Length() ) |
|
128 { |
|
129 if( iMessage.Function() == ECatalogsExternalAllocMessage ) |
|
130 { |
|
131 TInt incompMsgHandle( iSession.WriteToLargerDesL( aOutputData, |
|
132 aStatus ) ); |
|
133 |
|
134 TBuf8<KCatalogsMinimumAllocSize> internalMsg( |
|
135 KCatalogsMinimumAllocLength ); |
|
136 |
|
137 internalMsg.Num( incompMsgHandle ); |
|
138 internalMsg.Append( KCatalogsTooSmallDescMsgElementDivider ); |
|
139 internalMsg.AppendNum( aOutputData.Length() ); |
|
140 |
|
141 TRAPD( error, iMessage.WriteL( KOutputSlot, internalMsg ) ); |
|
142 if ( error != KErrNone ) |
|
143 { |
|
144 iSession.RemoveIncompleteMessage( incompMsgHandle ); |
|
145 User::Leave( error ); |
|
146 } |
|
147 } |
|
148 iMessage.Complete( KCatalogsErrorTooSmallDescriptor ); |
|
149 } |
|
150 else |
|
151 { |
|
152 iMessage.WriteL( KOutputSlot, aOutputData ); |
|
153 iMessage.Complete( aStatus ); |
|
154 } |
|
155 |
|
156 delete this; |
|
157 DLTRACEOUT(("")); |
|
158 } |
|
159 |
|
160 void CCatalogsBaseMessageImpl::CompleteAndReleaseL( |
|
161 TInt aOutputData, |
|
162 TInt aStatus ) |
|
163 { |
|
164 DLTRACEIN(("TInt, TInt,handle: %d, this: %x", Handle(), this)); |
|
165 if ( iSenderLost ) |
|
166 { |
|
167 DLINFO(("Sender was lost, deleting message")); |
|
168 delete this; |
|
169 DLTRACEOUT(("")); |
|
170 return; |
|
171 } |
|
172 |
|
173 TPckgBuf<TInt> handleBuf( aOutputData ); |
|
174 iMessage.WriteL( KOutputSlot, handleBuf ); |
|
175 iMessage.Complete( aStatus ); |
|
176 delete this; |
|
177 DLTRACEOUT(("")); |
|
178 } |
|
179 |
|
180 void CCatalogsBaseMessageImpl::CompleteAndReleaseL( |
|
181 const TDesC16& aOutputData, |
|
182 TInt aStatus ) |
|
183 { |
|
184 DLTRACEIN(("TDesC16, TInt, handle: %d, this: %x", Handle(), this)); |
|
185 if ( iSenderLost ) |
|
186 { |
|
187 DLINFO(("Sender was lost, deleting message")); |
|
188 delete this; |
|
189 DLTRACEOUT(("")); |
|
190 return; |
|
191 } |
|
192 |
|
193 TInt clientDescLength( iMessage.GetDesMaxLengthL( 3 ) ); |
|
194 |
|
195 if ( clientDescLength < aOutputData.Length() ) |
|
196 { |
|
197 if( iMessage.Function() == ECatalogsExternalAllocMessage ) |
|
198 { |
|
199 TInt incompMsgHandle( iSession.WriteToLargerDesL( aOutputData, |
|
200 aStatus ) ); |
|
201 |
|
202 TBuf16<KCatalogsMinimumAllocSize> internalMsg( |
|
203 KCatalogsMinimumAllocLength ); |
|
204 |
|
205 internalMsg.Num( incompMsgHandle ); |
|
206 internalMsg.Append( KCatalogsTooSmallDescMsgElementDivider ); |
|
207 internalMsg.AppendNum( aOutputData.Length() ); |
|
208 |
|
209 TRAPD( error, iMessage.WriteL( KOutputSlot, internalMsg ) ); |
|
210 if ( error != KErrNone ) |
|
211 { |
|
212 iSession.RemoveIncompleteMessage( incompMsgHandle ); |
|
213 User::Leave( error ); |
|
214 } |
|
215 } |
|
216 |
|
217 iMessage.Complete( KCatalogsErrorTooSmallDescriptor ); |
|
218 } |
|
219 else |
|
220 { |
|
221 iMessage.WriteL( KOutputSlot, aOutputData ); |
|
222 iMessage.Complete( aStatus ); |
|
223 } |
|
224 |
|
225 delete this; |
|
226 DLTRACEOUT(("")); |
|
227 } |
|
228 |
|
229 |
|
230 // --------------------------------------------------------------------------- |
|
231 // Completes the message |
|
232 // --------------------------------------------------------------------------- |
|
233 // |
|
234 void CCatalogsBaseMessageImpl::CompleteAndReleaseL( RFs& /*aFs*/, |
|
235 RFile& aFile ) |
|
236 { |
|
237 DLTRACEIN(("RFs, RFile,handle: %d, this: %x", Handle(), this)); |
|
238 if ( iSenderLost ) |
|
239 { |
|
240 DLINFO(("Sender was lost, deleting message")); |
|
241 delete this; |
|
242 DLTRACEOUT(("")); |
|
243 return; |
|
244 } |
|
245 |
|
246 //DLTRACE(("Sharing the file session")); |
|
247 //User::LeaveIfError( aFs.ShareProtected() ); |
|
248 |
|
249 DLTRACE(("TransferToClient, completes the message if successful")); |
|
250 aFile.TransferToClient( iMessage, KOutputSlot ); |
|
251 DLTRACE(("Transferred")); |
|
252 // The message should be complete |
|
253 /** |
|
254 * How to handle errors? |
|
255 */ |
|
256 DASSERT( iMessage.IsNull() ); |
|
257 |
|
258 delete this; |
|
259 DLTRACEOUT(("")); |
|
260 |
|
261 } |
|
262 |
|
263 |
|
264 void CCatalogsBaseMessageImpl::Release() |
|
265 { |
|
266 DLTRACEIN(( "this: %x", this )); |
|
267 delete this; |
|
268 } |
|
269 |
|
270 TBool CCatalogsBaseMessageImpl::CheckSecurityPolicy( const TSecurityPolicy& aSecurityPolicy ) |
|
271 { |
|
272 return aSecurityPolicy.CheckPolicy( iMessage ); |
|
273 } |
|
274 |
|
275 MCatalogsSession& CCatalogsBaseMessageImpl::Session() const |
|
276 { |
|
277 return iSession; |
|
278 } |
|
279 |
|
280 TBool CCatalogsBaseMessageImpl::CounterPartLost( |
|
281 const MCatalogsSession& aSession ) |
|
282 { |
|
283 DLTRACEIN(("")); |
|
284 // We compare the pointers |
|
285 if ( &iSession == &aSession ) |
|
286 { |
|
287 DLINFO(("Sender was lost")); |
|
288 iSenderLost = ETrue; |
|
289 return ETrue; |
|
290 } |
|
291 return EFalse; |
|
292 } |