279 TInt RWsBuffer::DoWrite(TInt aHandle, TUint aOpcode, TBool aFlush, const TIpcArgs* aIpcArgs, const TAny* aData, TInt aLength, const TAny* aData2, TInt aLength2) |
271 TInt RWsBuffer::DoWrite(TInt aHandle, TUint aOpcode, TBool aFlush, const TIpcArgs* aIpcArgs, const TAny* aData, TInt aLength, const TAny* aData2, TInt aLength2) |
280 { |
272 { |
281 __ASSERT_DEBUG(((TUint32) aOpcode) < 0x8000, Assert(EW32AssertIllegalOpcode)); |
273 __ASSERT_DEBUG(((TUint32) aOpcode) < 0x8000, Assert(EW32AssertIllegalOpcode)); |
282 __ASSERT_DEBUG((aLength&0x3) == 0, Assert(EW32AssertOddLengthData)); |
274 __ASSERT_DEBUG((aLength&0x3) == 0, Assert(EW32AssertOddLengthData)); |
283 TInt xtra(0); |
275 TInt xtra(0); |
284 if (aLength2 > 0) |
276 if (aLength2>0) |
285 { |
277 xtra = PadValue(aLength2); // Round data upto a multiple of 4 |
286 xtra = 4 - (aLength2&0x3); // Round data upto a multiple of 4 |
|
287 if (xtra==4) |
|
288 { |
|
289 xtra=0; |
|
290 } |
|
291 } |
|
292 |
278 |
293 const TInt msgSize = aLength + aLength2 + xtra + static_cast<TInt>(sizeof(TWsCmdHeader)); |
279 const TInt msgSize = aLength + aLength2 + xtra + static_cast<TInt>(sizeof(TWsCmdHeader)); |
294 TInt available = iBuf.MaxLength() - iBuf.Length(); |
280 TInt available = iBuf.MaxLength() - iBuf.Length(); |
295 if (msgSize > available) |
281 if (msgSize > available) |
296 { |
282 { |
352 void RWsBuffer::Write(TInt handle,TUint opcode) |
343 void RWsBuffer::Write(TInt handle,TUint opcode) |
353 { |
344 { |
354 DoWrite(handle, opcode, iAutoFlush, NULL); |
345 DoWrite(handle, opcode, iAutoFlush, NULL); |
355 } |
346 } |
356 |
347 |
357 void RWsBuffer::Write(TInt handle,TUint opcode,const TAny *pData, TInt length) |
348 /** |
358 { |
349 Writes data sent in aData of length aLength1 for the specifed aOpcode |
359 DoWrite(handle, opcode, iAutoFlush, NULL, pData, length); |
350 into wserv buffer. It also takes an TIpcArgs by which you can send additional |
360 } |
351 data. But one thing needs to be noted that if aIpcArgs has some content then |
361 |
352 this function flushes the wserv buffer. |
362 void RWsBuffer::Write(TInt handle,TUint opcode,const TAny *pData, TInt length,const TAny *pData2, TInt length2) |
353 |
363 { |
354 @param aHandle aHandle of class derived from MWsClientClass |
364 DoWrite(handle, opcode, iAutoFlush, NULL, pData, length, pData2, length2); |
355 @param aOpcode Opcode for the current command |
|
356 @param aData Data to be added to the buffer |
|
357 @param aLength Length of the data to be added to buffer |
|
358 @param aIpcArgs Additional data sent from client to server. It has default argument NULL. |
|
359 And if some data is sent in aIpcArgs, it flushes wserv buffer |
|
360 */ |
|
361 void RWsBuffer::Write(TInt aHandle, TUint aOpcode, const TAny *aData, TInt aLength, const TIpcArgs* aIpcArgs/*=NULL*/) |
|
362 { |
|
363 TBool flush = (aIpcArgs != NULL ? ETrue : iAutoFlush); // If aIpcArgs contains data then we do explicit flush |
|
364 DoWrite(aHandle, aOpcode, flush, aIpcArgs, aData, aLength); |
|
365 } |
|
366 |
|
367 /** |
|
368 Writes data sent in aData and aData2 of lengths aLength1 and aLength2 |
|
369 for the specifed aOpcode into wserv buffer. It also takes an TIpcArgs by which |
|
370 you can send additional data. But one thing needs to be noted that if aIpcArgs |
|
371 has some content then this function flushes the wserv buffer. |
|
372 |
|
373 @param aHandle Handle of class derived from MWsClientClass |
|
374 @param aOpcode Opcode for the current command |
|
375 @param aData Data to be added to the buffer |
|
376 @param aLength Length of the data to be added to buffer |
|
377 @param aData2 second Data to be added to the buffer |
|
378 @param aLength2 Length of the second data to be added to buffer |
|
379 @param aIpcArgs Additional data sent from client to server. It has default argument NULL. |
|
380 And if some data is sent in aIpcArgs, it flushes wserv buffer |
|
381 */ |
|
382 void RWsBuffer::Write(TInt aHandle, TUint aOpcode, const TAny *aData, TInt aLength, const TAny *aData2, TInt aLength2, const TIpcArgs* aIpcArgs/*=NULL*/) |
|
383 { |
|
384 __ASSERT_DEBUG(!((aIpcArgs != NULL) && (aLength2 > 0 && aData2 == NULL)), Assert(EW32AssertBufferLogic)); |
|
385 TBool flush = iAutoFlush; |
|
386 if (aLength2 > 0 && aData2 == NULL) |
|
387 { |
|
388 flush = EFalse; // if just length2 is sent then we should not flush |
|
389 } |
|
390 else if (aIpcArgs != NULL) |
|
391 { |
|
392 flush = ETrue; // If aIpcArgs contains data then we do explicit flush |
|
393 } |
|
394 DoWrite(aHandle, aOpcode, flush, aIpcArgs, aData, aLength, aData2, aLength2); |
|
395 } |
|
396 |
|
397 /** |
|
398 Appends data directly to wserv buffer for the current command. So this function |
|
399 should be used after adding the current command. |
|
400 |
|
401 @param aData Data to be added to the buffer |
|
402 @param aLength Length of the data to be added to buffer. Make sure that its length |
|
403 is less than availabe buffer. |
|
404 @param aFinished EFalse, adds data to buffer and disables flushing even if auto flush is on, |
|
405 basically this notfies that more data is pending to be added. |
|
406 ETrue, adds data to buffer and resume normal service for flushing |
|
407 ie. Signals that this is the last bit of data to be added |
|
408 |
|
409 Note: When data is added using this API, it pads out buffer to multiple of 4 bytes |
|
410 */ |
|
411 void RWsBuffer::AppendData(const TAny *aData,TInt aLength,TBool aFinished) |
|
412 { |
|
413 __ASSERT_ALWAYS(iBuf.MaxLength()-iBuf.Length()>=PaddedValue(aLength),Assert(EW32AssertBufferLogic)); |
|
414 #if defined(_DEBUG) |
|
415 // Check if this function is called only after setting iAppendDataLength |
|
416 __ASSERT_DEBUG(iAppendDataLength > 0, Assert(EW32AssertBufferLogic)); |
|
417 // Check if length passed in is less then iAppendDataLength |
|
418 __ASSERT_DEBUG(iAppendDataLength >= aLength, Assert(EW32AssertBufferLogic)); |
|
419 if (aFinished) |
|
420 iAppendDataLength = 0; |
|
421 else |
|
422 iAppendDataLength -= aLength; |
|
423 #endif |
|
424 iBuf.Append((TUint8*)(aData),aLength); |
|
425 iBuf.AppendFill(0,PadValue(iBuf.Length())); // Padout out buffer to multiple of 4 bytes |
|
426 if (aFinished && iAutoFlush) |
|
427 Flush(NULL); |
365 } |
428 } |
366 |
429 |
367 TInt RWsBuffer::WriteReply(TInt handle,TUint opcode,const TIpcArgs* aIpcArgs) |
430 TInt RWsBuffer::WriteReply(TInt handle,TUint opcode,const TIpcArgs* aIpcArgs) |
368 { |
431 { |
369 return DoWrite(handle, opcode, ETrue, aIpcArgs); |
432 return DoWrite(handle, opcode, ETrue, aIpcArgs); |