|
1 /* |
|
2 * Copyright (c) 2004 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: Messenger Object. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 |
|
21 #include "CPhSrvMessengerObject.h" |
|
22 #include "CPhSrvSubSessionBase.h" |
|
23 #include "CPhSrvSession.h" // Phone server session. |
|
24 #include "PhSrvDebugInfo.h" |
|
25 |
|
26 |
|
27 // CONSTANTS |
|
28 |
|
29 // Null ID. |
|
30 const TUint KPhSrvNullId = 0; |
|
31 |
|
32 // The minimum Default message size. |
|
33 const TInt KPhSrvMinDefSize = 1; |
|
34 |
|
35 |
|
36 // ============================ MEMBER FUNCTIONS =============================== |
|
37 |
|
38 |
|
39 // ----------------------------------------------------------------------------- |
|
40 // CPhSrvMessengerObject::CPhSrvMessengerObject |
|
41 // |
|
42 // Constructor. |
|
43 // ----------------------------------------------------------------------------- |
|
44 // |
|
45 CPhSrvMessengerObject::CPhSrvMessengerObject( |
|
46 CPhSrvSubSessionBase& aSubSession ) |
|
47 : iSubSession( aSubSession ) |
|
48 { |
|
49 } |
|
50 |
|
51 |
|
52 // ----------------------------------------------------------------------------- |
|
53 // CPhSrvMessengerObject::~CPhSrvMessengerObject |
|
54 // |
|
55 // Destructor. |
|
56 // ----------------------------------------------------------------------------- |
|
57 // |
|
58 CPhSrvMessengerObject::~CPhSrvMessengerObject() |
|
59 { |
|
60 } |
|
61 |
|
62 |
|
63 // ----------------------------------------------------------------------------- |
|
64 // CPhSrvMessengerObject::ConstructL |
|
65 // |
|
66 // Symbian 2nd phase constructor can leave. |
|
67 // ----------------------------------------------------------------------------- |
|
68 // |
|
69 void CPhSrvMessengerObject::ConstructL( |
|
70 const TPhCltMessengerParameters& aParameters ) |
|
71 { |
|
72 TInt size = aParameters.iDefaultMessageSize; |
|
73 if( size < KPhSrvMinDefSize ) |
|
74 { |
|
75 // Default message size must be at least KPhSrvMinDefSize. |
|
76 User::Leave( KErrArgument ); |
|
77 } |
|
78 |
|
79 iParameters.iCategoryUid = aParameters.iCategoryUid; |
|
80 iParameters.iDefaultMessageSize = size; |
|
81 } |
|
82 |
|
83 |
|
84 // ----------------------------------------------------------------------------- |
|
85 // CPhSrvMessengerObject::NewLC |
|
86 // |
|
87 // Static Symbian OS two-phase constructor. Return an instance |
|
88 // and leave it on the cleanup stack. |
|
89 // ----------------------------------------------------------------------------- |
|
90 // |
|
91 CPhSrvMessengerObject* CPhSrvMessengerObject::NewLC( |
|
92 CPhSrvSubSessionBase& aSubSession, |
|
93 const TPhCltMessengerParameters& aParameters ) |
|
94 { |
|
95 CPhSrvMessengerObject* self = new( ELeave ) CPhSrvMessengerObject( |
|
96 aSubSession ); |
|
97 |
|
98 CleanupStack::PushL( self ); |
|
99 self->ConstructL( aParameters ); |
|
100 |
|
101 return self; |
|
102 } |
|
103 |
|
104 |
|
105 // ----------------------------------------------------------------------------- |
|
106 // CPhSrvMessengerObject::InformOfMessengerRequest |
|
107 // |
|
108 // Complete a client request which will indicate the result |
|
109 // of attempting to perform a request. |
|
110 // ----------------------------------------------------------------------------- |
|
111 // |
|
112 void CPhSrvMessengerObject::InformOfMessengerRequest( |
|
113 const TPhCltPhoneResults aResultOfAttemptingRequest, |
|
114 const TPhCltMessengerCommand aRequest ) |
|
115 { |
|
116 // Complete the client's pending request, indicating |
|
117 // the result of the messenger request attempt. |
|
118 if ( aRequest == EPhCltMesCommandSend ) |
|
119 { |
|
120 // Send command. |
|
121 if ( iParameters.iSendDataValid ) |
|
122 { |
|
123 iParameters.iSendStatus.Complete( aResultOfAttemptingRequest ); |
|
124 iParameters.iSendDataValid = EFalse; |
|
125 } |
|
126 } |
|
127 else if ( aRequest == EPhCltMesCommandReceive ) |
|
128 { |
|
129 // Receive command. |
|
130 if ( iParameters.iReceiveDataValid ) |
|
131 { |
|
132 iParameters.iReceiveMessage.Complete( aResultOfAttemptingRequest ); |
|
133 iParameters.iReceiveDataValid = EFalse; |
|
134 } |
|
135 } |
|
136 else |
|
137 { |
|
138 // Should never happen! |
|
139 } |
|
140 } |
|
141 |
|
142 |
|
143 // ----------------------------------------------------------------------------- |
|
144 // CPhSrvMessengerObject::SubSessionHandle |
|
145 // |
|
146 // Return the handle of the subsession that initiated the |
|
147 // original messenger request. |
|
148 // ----------------------------------------------------------------------------- |
|
149 // |
|
150 TInt CPhSrvMessengerObject::SubSessionHandle() const |
|
151 { |
|
152 return iSubSession.SubSessionUniqueHandle(); |
|
153 } |
|
154 |
|
155 |
|
156 // ----------------------------------------------------------------------------- |
|
157 // CPhSrvMessengerObject::SetActive |
|
158 // |
|
159 // Set the request active. |
|
160 // ----------------------------------------------------------------------------- |
|
161 // |
|
162 void CPhSrvMessengerObject::SetActive( |
|
163 const TPhCltMessengerParameters& aParameters, |
|
164 const RMessage2& aMessage, |
|
165 const TUint aSentDataId ) |
|
166 { |
|
167 TPhCltMessengerCommand request = aParameters.iMessengerCommand; |
|
168 |
|
169 switch( request ) |
|
170 { |
|
171 case EPhCltMesCommandSend: |
|
172 { |
|
173 // Set the Send data parameters. |
|
174 iParameters.iSendStatus = aMessage; |
|
175 iParameters.iSendDataValid = ETrue; |
|
176 iParameters.iSentDataId = aSentDataId; |
|
177 iParameters.iSendPayloadLength = aParameters.iSendPayloadLength; |
|
178 break; |
|
179 } |
|
180 case EPhCltMesCommandReceive: |
|
181 { |
|
182 // Set the Receive parameters. |
|
183 iParameters.iReceiveMessage = aMessage; |
|
184 |
|
185 iParameters.iReceiveBufferMaxSize = |
|
186 aParameters.iReceiveBufferMaxSize; |
|
187 |
|
188 iParameters.iReceiveDataValid = ETrue; |
|
189 |
|
190 // Receive called, so Skip can not be active. |
|
191 iParameters.iSkipNextMessage = EFalse; |
|
192 iParameters.iSkippedSentDataId = KPhSrvNullId; |
|
193 break; |
|
194 } |
|
195 case EPhCltMesCommandSkip: |
|
196 { |
|
197 iParameters.iSkipNextMessage = ETrue; |
|
198 break; |
|
199 } |
|
200 |
|
201 default: |
|
202 // Should never happen! |
|
203 break; |
|
204 } |
|
205 } |
|
206 |
|
207 |
|
208 // ----------------------------------------------------------------------------- |
|
209 // CPhSrvMessengerObject::IsRequestActive |
|
210 // |
|
211 // Check if there is already active request. |
|
212 // ----------------------------------------------------------------------------- |
|
213 // |
|
214 TBool CPhSrvMessengerObject::IsRequestActive( |
|
215 const TPhCltMessengerCommand aRequest ) const |
|
216 { |
|
217 TBool isRequestActive = EFalse; |
|
218 |
|
219 switch( aRequest ) |
|
220 { |
|
221 case EPhCltMesCommandSend: |
|
222 { |
|
223 isRequestActive = iParameters.iSendDataValid; |
|
224 break; |
|
225 } |
|
226 case EPhCltMesCommandReceive: |
|
227 { |
|
228 isRequestActive = iParameters.iReceiveDataValid; |
|
229 break; |
|
230 } |
|
231 case EPhCltMesCommandSkip: |
|
232 { |
|
233 isRequestActive = iParameters.iSkipNextMessage; |
|
234 break; |
|
235 } |
|
236 |
|
237 default: |
|
238 // Should never happen! |
|
239 break; |
|
240 } |
|
241 return isRequestActive; |
|
242 } |
|
243 |
|
244 |
|
245 // ----------------------------------------------------------------------------- |
|
246 // CPhSrvMessengerObject::IsReadyToReceive |
|
247 // |
|
248 // Check whether this object is ready to receive or not. |
|
249 // If Receive is active but the length of the buffer |
|
250 // ----------------------------------------------------------------------------- |
|
251 // |
|
252 TBool CPhSrvMessengerObject::IsReadyToReceive( |
|
253 const TDesC8& aSentMessage, |
|
254 const TUint aSentDataId ) |
|
255 { |
|
256 TBool ret = EFalse; |
|
257 const TInt sendDataLength = aSentMessage.Length(); |
|
258 |
|
259 ret = IsMessageSkipped( aSentDataId ); |
|
260 |
|
261 // If the message is not skipped, handle it here. |
|
262 if ( !ret ) |
|
263 { |
|
264 // If receive data is valid, then we can be ready to receive. |
|
265 if( iParameters.iReceiveDataValid ) |
|
266 { |
|
267 // If the sent message does not fit to receive buffer, then complete |
|
268 // Receive to indicate that bigger buffer is needed. |
|
269 if ( sendDataLength > |
|
270 iParameters.iReceiveBufferMaxSize ) |
|
271 { |
|
272 CompleteReceive( aSentMessage, aSentDataId ); |
|
273 } |
|
274 else |
|
275 { |
|
276 // Object can receive the sent message. |
|
277 ret = ETrue; |
|
278 } |
|
279 } |
|
280 } |
|
281 return ret; |
|
282 } |
|
283 |
|
284 |
|
285 // ----------------------------------------------------------------------------- |
|
286 // CPhSrvMessengerObject::CompleteReceive |
|
287 // |
|
288 // Complete the receive request. |
|
289 // ----------------------------------------------------------------------------- |
|
290 // |
|
291 TInt CPhSrvMessengerObject::CompleteReceive( |
|
292 const TDesC8& aSentMessage, |
|
293 const TUint aSentDataId ) |
|
294 { |
|
295 _DPRINT( 4, "PhSrv.MesObj.CompleteReceive START" ); // debug print |
|
296 |
|
297 TBool ret = IsMessageSkipped( aSentDataId ); |
|
298 TInt err = KErrNotReady; |
|
299 |
|
300 // If message is skipped, then we do not complete the request. |
|
301 if( ret ) |
|
302 { |
|
303 err = KErrNone; |
|
304 } |
|
305 |
|
306 // If err is not KErrNone, then receive is handled. |
|
307 if ( err != KErrNone ) |
|
308 { |
|
309 // If request is not active, then it can not be completed, and |
|
310 // something has gone wrong. However, recover (do nothing). |
|
311 if ( iParameters.iReceiveDataValid ) |
|
312 { |
|
313 // Receive request active, it is handled. |
|
314 |
|
315 _DPRINT( 4, "PhSrv.MesObj.CompleteReceive WRITE1" ); // debug print |
|
316 |
|
317 const TInt recBufMaxSize = |
|
318 iParameters.iReceiveBufferMaxSize; |
|
319 |
|
320 // Write the whole sent message or the beginnig of it to client data |
|
321 // area, i.e ensure that receive message buffer is not overflowed. |
|
322 iSubSession.Write( |
|
323 iParameters.iReceiveMessage, |
|
324 1, |
|
325 aSentMessage.Left( recBufMaxSize ) ); |
|
326 |
|
327 TInt length = aSentMessage.Length(); |
|
328 TPckgC < TInt > intPckg( length ); |
|
329 |
|
330 _DPRINT( 4, "PhSrv.MesObj.CompleteReceive WRITE2" ); // debug print |
|
331 |
|
332 // Write the length information to user side. |
|
333 iSubSession.Write( |
|
334 iParameters.iReceiveMessage, |
|
335 2, |
|
336 intPckg ); |
|
337 |
|
338 // If whole sent message was written to receive buffer, then |
|
339 // completion was successful. |
|
340 if ( length <= recBufMaxSize ) |
|
341 { |
|
342 err = KErrNone; |
|
343 } |
|
344 else |
|
345 { |
|
346 // The receive was not completed fully. |
|
347 iParameters.iSkippedSentDataId = aSentDataId; |
|
348 } |
|
349 |
|
350 _DPRINT( 4, "PhSrv.MesObj.CompleteReceive COMPLETE" ); // debug print |
|
351 |
|
352 // Complete the receive request. |
|
353 if ( !iParameters.iReceiveMessage.IsNull() ) |
|
354 { |
|
355 iParameters.iReceiveMessage.Complete( KErrNone ); |
|
356 } |
|
357 iParameters.iReceiveDataValid = EFalse; |
|
358 } |
|
359 } |
|
360 |
|
361 _DPRINT( 4, "PhSrv.MesObj.CompleteReceive END" ); // debug print |
|
362 |
|
363 return err; |
|
364 } |
|
365 |
|
366 |
|
367 // ----------------------------------------------------------------------------- |
|
368 // CPhSrvMessengerObject::GetSendDataLength |
|
369 // |
|
370 // Get the Send data. |
|
371 // ----------------------------------------------------------------------------- |
|
372 // |
|
373 TInt CPhSrvMessengerObject::GetSendDataLength() |
|
374 { |
|
375 return iParameters.iSendPayloadLength; |
|
376 } |
|
377 |
|
378 |
|
379 // ----------------------------------------------------------------------------- |
|
380 // CPhSrvMessengerObject::GetSendData |
|
381 // |
|
382 // Get the Send data. |
|
383 // ----------------------------------------------------------------------------- |
|
384 // |
|
385 void CPhSrvMessengerObject::GetSendData( TDes8& aDes ) const |
|
386 { |
|
387 // Read the Send data information from user side. |
|
388 // Do not leave, but will panic if pointer not valid descriptor. |
|
389 iSubSession.Read( |
|
390 iParameters.iSendStatus, |
|
391 1, |
|
392 aDes ); |
|
393 } |
|
394 |
|
395 |
|
396 // ----------------------------------------------------------------------------- |
|
397 // CPhSrvMessengerObject::GetUid |
|
398 // |
|
399 // Get the Uid. |
|
400 // ----------------------------------------------------------------------------- |
|
401 // |
|
402 const TUid& CPhSrvMessengerObject::GetUid() const |
|
403 { |
|
404 return iParameters.iCategoryUid; |
|
405 } |
|
406 |
|
407 |
|
408 // ----------------------------------------------------------------------------- |
|
409 // CPhSrvMessengerObject::SentDataId |
|
410 // |
|
411 // Get the sent data ID. |
|
412 // ----------------------------------------------------------------------------- |
|
413 // |
|
414 TUint CPhSrvMessengerObject::SentDataId() |
|
415 { |
|
416 return iParameters.iSentDataId; |
|
417 } |
|
418 |
|
419 |
|
420 |
|
421 // ----------------------------------------------------------------------------- |
|
422 // CPhSrvMessengerObject::IsMessageSkipped |
|
423 // |
|
424 // Return information whether the message is skipped or not. |
|
425 // ----------------------------------------------------------------------------- |
|
426 // |
|
427 TBool CPhSrvMessengerObject::IsMessageSkipped( |
|
428 const TUint aSentDataId ) |
|
429 { |
|
430 TBool ret = EFalse; // By default message is not skipped. |
|
431 |
|
432 // If Skip is active, then everything is OK. |
|
433 if ( iParameters.iSkipNextMessage ) |
|
434 { |
|
435 // If the sent data is the same as that it was earlier, then it is |
|
436 // skipped. If the sent message is not the same, then it is not skipped. |
|
437 if ( iParameters.iSkippedSentDataId == aSentDataId ) |
|
438 { |
|
439 // This message is skipped. |
|
440 ret = ETrue; |
|
441 } |
|
442 else |
|
443 { |
|
444 // This message is not skipped. |
|
445 iParameters.iSkipNextMessage = EFalse; |
|
446 iParameters.iSkippedSentDataId = KPhSrvNullId; // Set to not valid. |
|
447 } |
|
448 } |
|
449 return ret; |
|
450 } |
|
451 |
|
452 |
|
453 // End of File |