windowing/windowserver/nga/CLIENT/RBUFFER.CPP
changeset 36 01a6848ebfd7
parent 0 5d03bc08d59c
equal deleted inserted replaced
0:5d03bc08d59c 36:01a6848ebfd7
     1 // Copyright (c) 1994-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 1994-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
    41 		iAutoFlush(ETrue),
    41 		iAutoFlush(ETrue),
    42 	#else
    42 	#else
    43 		iAutoFlush(EFalse),
    43 		iAutoFlush(EFalse),
    44 	#endif
    44 	#endif
    45 	iBuf(NULL,0,0), iNext(NULL), iPreviousHandle(0), iBufSize(0), iMaxBufSize(EMinBufferSize),
    45 	iBuf(NULL,0,0), iNext(NULL), iPreviousHandle(0), iBufSize(0), iMaxBufSize(EMinBufferSize),
       
    46 	#if defined(_DEBUG)
       
    47 	iAppendDataLength(0),
       
    48 	#endif
    46 	iDirectAcessCount(0), iInvalidBitmapArray(EFalse), iWindowSizeCache(NULL)
    49 	iDirectAcessCount(0), iInvalidBitmapArray(EFalse), iWindowSizeCache(NULL)
    47 	{
    50 	{
    48 	}
    51 	}
    49 
    52 
    50 TInt WsFbsDestroyCallBack(TAny* aBitmapHandle)
    53 TInt WsFbsDestroyCallBack(TAny* aBitmapHandle)
   268 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)
   269 	{
   272 	{
   270 	__ASSERT_DEBUG(((TUint32) aOpcode) < 0x8000, Assert(EW32AssertIllegalOpcode));
   273 	__ASSERT_DEBUG(((TUint32) aOpcode) < 0x8000, Assert(EW32AssertIllegalOpcode));
   271 	__ASSERT_DEBUG((aLength&0x3) == 0, Assert(EW32AssertOddLengthData));
   274 	__ASSERT_DEBUG((aLength&0x3) == 0, Assert(EW32AssertOddLengthData));
   272 	TInt xtra(0);
   275 	TInt xtra(0);
   273 	if (aLength2 > 0)
   276 	if (aLength2>0)
   274 		{
   277 		xtra = PadValue(aLength2);		// Round data upto a multiple of 4
   275 		xtra = 4 - (aLength2&0x3);		// Round data upto a multiple of 4
       
   276 		if (xtra==4)
       
   277 			{
       
   278 			xtra=0;
       
   279 			}
       
   280 		}
       
   281 
   278 
   282 	const TInt msgSize = aLength + aLength2 + xtra + static_cast<TInt>(sizeof(TWsCmdHeader));
   279 	const TInt msgSize = aLength + aLength2 + xtra + static_cast<TInt>(sizeof(TWsCmdHeader));
   283 	TInt available = iBuf.MaxLength() - iBuf.Length();
   280 	TInt available = iBuf.MaxLength() - iBuf.Length();
   284 	if (msgSize > available)
   281 	if (msgSize > available)
   285 		{
   282 		{
   323 
   320 
   324 	if (aLength)
   321 	if (aLength)
   325 		{
   322 		{
   326 		iBuf.Append((TUint8 *)aData, aLength);
   323 		iBuf.Append((TUint8 *)aData, aLength);
   327 		}
   324 		}
   328 	if (aLength2 > 0)
   325 	if (aLength2>0 && aData2!=NULL)
   329 		{
   326 		{
   330 		iBuf.Append((TUint8 *)aData2, aLength2);
   327 		iBuf.Append((TUint8 *)aData2, aLength2);
   331 		iBuf.AppendFill(0,xtra);
   328 		iBuf.AppendFill(0,xtra);
   332 		}
   329 		}
   333 
   330 #if defined(_DEBUG)
       
   331 	else if (aLength2>0 && aData2==NULL)
       
   332 		{
       
   333 		iAppendDataLength = aLength2;
       
   334 		}
       
   335 #endif
   334 	if (aFlush)
   336 	if (aFlush)
   335 		{
   337 		{
   336 		return Flush(aIpcArgs);
   338 		return Flush(aIpcArgs);
   337 		}
   339 		}
   338 	return KErrNone;
   340 	return KErrNone;
   341 void RWsBuffer::Write(TInt handle,TUint opcode)
   343 void RWsBuffer::Write(TInt handle,TUint opcode)
   342 	{
   344 	{
   343 	DoWrite(handle, opcode, iAutoFlush, NULL);
   345 	DoWrite(handle, opcode, iAutoFlush, NULL);
   344 	}
   346 	}
   345 
   347 
   346 void RWsBuffer::Write(TInt handle,TUint opcode,const TAny *pData, TInt length)
   348 /**
   347 	{
   349 Writes data sent in aData of length aLength1 for the specifed aOpcode
   348 	DoWrite(handle, opcode, iAutoFlush, NULL, pData, length);
   350 into wserv buffer. It also takes an TIpcArgs by which you can send additional 
   349 	}
   351 data. But one thing needs to be noted that if aIpcArgs has some content then 
   350 
   352 this function flushes the wserv buffer.
   351 void RWsBuffer::Write(TInt handle,TUint opcode,const TAny *pData, TInt length,const TAny *pData2, TInt length2)
   353 
   352 	{
   354 @param aHandle aHandle of class derived from MWsClientClass
   353 	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);
   354 	}
   428 	}
   355 
   429 
   356 TInt RWsBuffer::WriteReply(TInt handle,TUint opcode,const TIpcArgs* aIpcArgs)
   430 TInt RWsBuffer::WriteReply(TInt handle,TUint opcode,const TIpcArgs* aIpcArgs)
   357 	{
   431 	{
   358 	return DoWrite(handle, opcode, ETrue, aIpcArgs);
   432 	return DoWrite(handle, opcode, ETrue, aIpcArgs);