usbmgmt/usbmgr/device/classdrivers/acm/classimplementation/ecacm/src/AcmWriter.cpp
branchRCL_3
changeset 15 f92a4f87e424
parent 0 c9bc50fca66e
child 16 012cc2ee6408
--- a/usbmgmt/usbmgr/device/classdrivers/acm/classimplementation/ecacm/src/AcmWriter.cpp	Thu Jul 15 20:42:20 2010 +0300
+++ b/usbmgmt/usbmgr/device/classdrivers/acm/classimplementation/ecacm/src/AcmWriter.cpp	Tue Aug 31 17:01:47 2010 +0300
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
+* Copyright (c) 1997-2010 Nokia Corporation and/or its subsidiary(-ies).
 * All rights reserved.
 * This component and the accompanying materials are made available
 * under the terms of "Eclipse Public License v1.0"
@@ -15,14 +15,13 @@
 *
 */
 
-#include <usb/usblogger.h>
 #include "AcmWriter.h"
 #include "AcmPort.h"
 #include "AcmPanic.h"
 #include "AcmUtils.h"
-
-#ifdef __FLOG_ACTIVE
-_LIT8(KLogComponent, "ECACM");
+#include "OstTraceDefinitions.h"
+#ifdef OST_TRACE_COMPILER_IN_USE
+#include "AcmWriterTraces.h"
 #endif
 
 CAcmWriter* CAcmWriter::NewL(CAcmPort& aPort, 
@@ -35,12 +34,12 @@
  * @return Ownership of a newly created CAcmWriter object
  */
 	{
-	LOG_STATIC_FUNC_ENTRY
-
+	OstTraceFunctionEntry0( CACMWRITER_NEWL_ENTRY );
 	CAcmWriter* self = new(ELeave) CAcmWriter(aPort, aBufSize);
 	CleanupStack::PushL(self);
 	self->ConstructL();
 	CLEANUPSTACK_POP(self);
+	OstTraceFunctionExit0( CACMWRITER_NEWL_EXIT );
 	return self;
 	}
 
@@ -49,11 +48,10 @@
  * Destructor.
  */
 	{
-	LOG_FUNC
-
+	OstTraceFunctionEntry0( CACMWRITER_CACMWRITER_DES_ENTRY );
 	WriteCancel();
-
 	delete iBuffer;
+	OstTraceFunctionExit0( CACMWRITER_CACMWRITER_DES_EXIT );
 	}
 
 void CAcmWriter::Write(const TAny* aClientBuffer, TUint aLength)
@@ -64,8 +62,8 @@
  * @param aLength Number of bytes to write
  */
 	{
-	LOGTEXT3(_L8("CAcmWriter::Write aClientBuffer=0x%08x, aLength=%d"), 
-		aClientBuffer, aLength);
+	OstTraceFunctionEntry0( CACMWRITER_WRITE_ENTRY );
+	OstTraceExt2( TRACE_NORMAL, CACMWRITER_WRITE, "CAcmWriter::Write;aClientBuffer=%p;aLength=%d", aClientBuffer, (TInt)aLength );
 
 	// Check we're open to requests and make a note of interesting data.
 	CheckNewRequest(aClientBuffer, aLength);
@@ -78,6 +76,7 @@
 	ReadDataFromClient();
 	// ...and write as much as we've got to the LDD
 	IssueWrite();
+	OstTraceFunctionExit0( CACMWRITER_WRITE_EXIT );
 	}
 
 void CAcmWriter::WriteCancel()
@@ -85,18 +84,18 @@
  * Cancel a write.
  */
 	{
-	LOG_FUNC
-
+	OstTraceFunctionEntry0( CACMWRITER_WRITECANCEL_ENTRY );
 	// Cancel any outstanding request on the LDD.
 	if ( iPort.Acm() )
 		{
-		LOGTEXT(_L8("\tiPort.Acm() exists- calling WriteCancel on it"));
+		OstTrace0( TRACE_NORMAL, CACMWRITER_WRITECANCEL, "CAcmWriter::WriteCancel;\tiPort.Acm() exists- calling WriteCancel on it" );
 		iPort.Acm()->WriteCancel();
 		}
 
 	// Reset our flag to say there's no current outstanding request. What's 
 	// already in our buffer can stay there.
 	iCurrentRequest.iClientPtr = NULL;
+	OstTraceFunctionExit0( CACMWRITER_WRITECANCEL_EXIT );
 	}
 
 void CAcmWriter::ResetBuffer()
@@ -104,15 +103,20 @@
  * Called by the port to clear the buffer.
  */
 	{
-	LOG_FUNC
-
+	OstTraceFunctionEntry0( CACMWRITER_RESETBUFFER_ENTRY );
 	// A request is outstanding- C32 should protect against this.
-	__ASSERT_DEBUG(!iCurrentRequest.iClientPtr, 
-		_USB_PANIC(KAcmPanicCat, EPanicInternalError));
 
+	if (iCurrentRequest.iClientPtr != NULL)
+		{
+		OstTrace1( TRACE_FATAL, CACMWRITER_RESETBUFFER, 
+										"CAcmWriter::ResetBuffer;EPanicInternalError=%d", 
+										(TInt)EPanicInternalError );
+		__ASSERT_DEBUG( EFalse, User::Panic(KAcmPanicCat, EPanicInternalError) );
+		}
 	// Don't have anything to do. There are no pointers to reset. This 
 	// function may in the future (if we support KConfigWriteBufferedComplete) 
 	// do work, so leave the above assertion in.
+	OstTraceFunctionExit0( CACMWRITER_RESETBUFFER_EXIT );
 	}
 
 TInt CAcmWriter::SetBufSize(TUint aSize)
@@ -123,13 +127,15 @@
  * @param aSize The required size of the buffer.
  */
 	{
-	LOG_FUNC
-	LOGTEXT2(_L8("\taSize=%d"), aSize);
+	OstTraceFunctionEntry0( CACMWRITER_SETBUFSIZE_ENTRY );
+	OstTrace1( TRACE_NORMAL, CACMWRITER_SETBUFSIZE, "CAcmWriter::SetBufSize;aSize=%d", (TInt)aSize );
 
 	if ( iCurrentRequest.iClientPtr )
 		{
 		// A request is outstanding. C32 does not protect us against this.
-		LOGTEXT(_L8("\t***a request is outstanding- returning KErrInUse"));
+		OstTrace0( TRACE_NORMAL, CACMWRITER_SETBUFSIZE_DUP1, 
+				"CAcmWriter::SetBufSize;\t***a request is outstanding- returning KErrInUse" );
+		OstTraceFunctionExit0( CACMWRITER_SETBUFSIZE_EXIT );
 		return KErrInUse;
 		}
 
@@ -137,7 +143,9 @@
 	HBufC8* newBuf = HBufC8::New(static_cast<TInt>(aSize));
 	if ( !newBuf )
 		{
-		LOGTEXT(_L8("\tfailed to create new buffer- returning KErrNoMemory"));
+		OstTrace0( TRACE_NORMAL, CACMWRITER_SETBUFSIZE_DUP2, 
+				"CAcmWriter::SetBufSize;\tfailed to create new buffer- returning KErrNoMemory" );
+		OstTraceFunctionExit0( CACMWRITER_SETBUFSIZE_EXIT_DUP1 );
 		return KErrNoMemory;
 		}
 	delete iBuffer;
@@ -145,6 +153,7 @@
 	iBuf.Set(iBuffer->Des());
 	iBufSize = aSize;
 
+	OstTraceFunctionExit0( CACMWRITER_SETBUFSIZE_EXIT_DUP2 );
 	return KErrNone;
 	}
 
@@ -160,6 +169,8 @@
 	iBuf(NULL,0,0),
 	iPort(aPort)
 	{
+	OstTraceFunctionEntry0( CACMWRITER_CACMWRITER_CONS_ENTRY );
+	OstTraceFunctionExit0( CACMWRITER_CACMWRITER_CONS_EXIT );
 	}
 
 void CAcmWriter::ConstructL()
@@ -167,9 +178,16 @@
  * 2nd-phase constructor. 
  */
 	{
+	OstTraceFunctionEntry0( CACMWRITER_CONSTRUCTL_ENTRY );
 	// Create the required buffer.
-	LOGTEXT(_L8("\tabout to create iBuffer"));
-	LEAVEIFERRORL(SetBufSize(iBufSize));
+	OstTrace0( TRACE_NORMAL, CACMWRITER_CONSTRUCTL, "CAcmWriter::ConstructL;\tabout to create iBuffer" );
+	TInt err = SetBufSize(iBufSize);
+	if (err < 0)
+		{
+		OstTrace1( TRACE_ERROR, CACMWRITER_CONSTRUCTL_DUP1, "CAcmWriter::ConstructL;err=%d", err );
+		User::Leave(err);
+		}
+	OstTraceFunctionExit0( CACMWRITER_CONSTRUCTL_EXIT );
 	}
 
 void CAcmWriter::WriteCompleted(TInt aError)
@@ -182,12 +200,12 @@
  * @param aError Error with which the write completed.
  */
 	{
-	LOG_FUNC
-	LOGTEXT2(_L8("\taError=%d"), aError);						   	
-
+	OstTraceFunctionEntry0( CACMWRITER_WRITECOMPLETED_ENTRY );
+	OstTrace1( TRACE_NORMAL, CACMWRITER_WRITECOMPLETED, "CAcmWriter::WriteCompleted;aError=%d", (TInt)aError );					   	
 	if(iLengthToGo == 0 || aError != KErrNone)
 		{
-		LOGTEXT2(_L8("\tcompleting request with %d"), aError);
+		OstTrace1( TRACE_NORMAL, CACMWRITER_WRITECOMPLETED_DUP1, 
+				"CAcmWriter::WriteCompleted;\tcompleting request with %d", aError );
 		CompleteRequest(aError);	
 		}
 	else
@@ -197,6 +215,7 @@
 		ReadDataFromClient();
 		IssueWrite();
 		}
+	OstTraceFunctionExit0( CACMWRITER_WRITECOMPLETED_EXIT );
 	}
 
 void CAcmWriter::ReadDataFromClient()
@@ -204,22 +223,28 @@
  * Read data from the client space into the internal buffer, prior to writing.
  */
 	{
-	LOG_FUNC
+	OstTraceFunctionEntry0( CACMWRITER_READDATAFROMCLIENT_ENTRY );
 	TPtr8 ptr((TUint8*)iBuf.Ptr(),
 			  0,
 			  Min(iBuf.MaxLength(), iLengthToGo));
 
 	TInt err = iPort.IPCRead(iCurrentRequest.iClientPtr,
 			ptr,
-			static_cast<TInt>(iOffsetIntoClientsMemory));	
-	LOGTEXT2(_L8("\tIPCRead = %d"), err);
+			static_cast<TInt>(iOffsetIntoClientsMemory));
+	OstTrace1( TRACE_NORMAL, CACMWRITER_READDATAFROMCLIENT, "CAcmWriter::ReadDataFromClient;\tIPCRead = %d", err );
+	
 	iBuf.SetLength(ptr.Length());
-	__ASSERT_DEBUG(!err, _USB_PANIC(KAcmPanicCat, EPanicInternalError));
-	
+	if (err != 0)
+		{
+		OstTrace1( TRACE_FATAL, CACMWRITER_READDATAFROMCLIENT_DUP1, 
+										"CAcmWriter::ReadDataFromClient;EPanicInternalError=%d", 
+										(TInt)EPanicInternalError );
+		__ASSERT_DEBUG( EFalse, User::Panic(KAcmPanicCat, EPanicInternalError) );
+		}
 	static_cast<void>(err);
-
 	// Increase our pointer (into the client's space) of already-read data.
 	iOffsetIntoClientsMemory += iBuf.Length();
+	OstTraceFunctionExit0( CACMWRITER_READDATAFROMCLIENT_EXIT );
 	}
 
 
@@ -234,26 +259,38 @@
  * @param aLength Length to write.
  */
 	{
-	LOG_FUNC
-
-	__ASSERT_DEBUG(aLength <= static_cast<TUint>(KMaxTInt), 
-		_USB_PANIC(KAcmPanicCat, EPanicInternalError));
-
+	OstTraceFunctionEntry0( CACMWRITER_CHECKNEWREQUEST_ENTRY );
+	
+	if (aLength > static_cast<TUint>(KMaxTInt))
+		{
+		OstTrace1( TRACE_FATAL, CACMWRITER_CHECKNEWREQUEST, 
+										"CAcmWriter::CheckNewRequest;aLength > static_cast<TUint>(KMaxTInt), EPanicInternalError=%d", 
+										(TInt)EPanicInternalError );
+		__ASSERT_DEBUG( EFalse, User::Panic(KAcmPanicCat, EPanicInternalError) );
+		}
 	// Check we have no outstanding request already.
 	if ( iCurrentRequest.iClientPtr )
 		{
-		_USB_PANIC(KAcmPanicCat, EPanicInternalError);
+		OstTrace1( TRACE_FATAL, CACMWRITER_CHECKNEWREQUEST_DUP1, 
+										"CAcmWriter::CheckNewRequest;iCurrentRequest.iClientPtr != NULL, EPanicInternalError=%d", 
+										(TInt)EPanicInternalError );
+		__ASSERT_DEBUG( EFalse, User::Panic(KAcmPanicCat, EPanicInternalError) );
 		}
 	// Sanity check on what C32 gave us.
-	__ASSERT_DEBUG(aClientBuffer, 
-		_USB_PANIC(KAcmPanicCat, EPanicInternalError));
-
+	if (aClientBuffer == NULL)
+		{
+		OstTrace1( TRACE_FATAL, CACMWRITER_CHECKNEWREQUEST_DUP2, 
+										"CAcmWriter::CheckNewRequest;aClientBuffer == NULL, EPanicInternalError=%d", 
+										(TInt)EPanicInternalError );
+		__ASSERT_DEBUG( EFalse, User::Panic(KAcmPanicCat, EPanicInternalError) );
+		}
 	// Make a note of interesting data.
 	iCurrentRequest.iLength = aLength;
 	iCurrentRequest.iClientPtr = aClientBuffer;
 	
 	iLengthToGo = aLength;
 	iOffsetIntoClientsMemory = 0;
+	OstTraceFunctionExit0( CACMWRITER_CHECKNEWREQUEST_EXIT );
 	}
 
 void CAcmWriter::CompleteRequest(TInt aError)
@@ -264,13 +301,17 @@
  * @param aError The error code to complete with.
  */
 	{
-	LOGTEXT2(_L8("CAcmWriter::CompleteRequest aError=%d"), aError);
-
+	OstTraceFunctionEntry0( CACMWRITER_COMPLETEREQUEST_ENTRY );
+	OstTrace1( TRACE_NORMAL, CACMWRITER_COMPLETEREQUEST, 
+			"CAcmWriter::CompleteRequest;CAcmWriter::CompleteRequest aError=%d", (TInt)aError );
+	
 	// Set our flag to say that we no longer have an outstanding request.
 	iCurrentRequest.iClientPtr = NULL;
-
-	LOGTEXT2(_L8("\tcalling WriteCompleted with %d"), aError);
+	OstTrace1( TRACE_NORMAL, CACMWRITER_COMPLETEREQUEST_DUP1, 
+			"CAcmWriter::CompleteRequest;\tcalling WriteCompleted with %d", aError );
+	
 	iPort.WriteCompleted(aError);
+	OstTraceFunctionExit0( CACMWRITER_COMPLETEREQUEST_EXIT );
 	}
 
 void CAcmWriter::IssueWrite()
@@ -279,11 +320,15 @@
  * entire load of buffered data in one go.
  */
 	{
-	LOG_FUNC
-
-	LOGTEXT2(_L8("\tissuing Write of %d bytes"), iBuf.Length());
-	__ASSERT_DEBUG(iPort.Acm(), 
-		_USB_PANIC(KAcmPanicCat, EPanicInternalError));
+	OstTraceFunctionEntry0( CACMWRITER_ISSUEWRITE_ENTRY );
+	
+	OstTrace1( TRACE_NORMAL, CACMWRITER_ISSUEWRITE, "CAcmWriter::IssueWrite;\tissuing Write of %d bytes", (TInt)(iBuf.Length()) );
+	if (iPort.Acm() == NULL)
+		{
+		OstTrace1( TRACE_FATAL, CACMWRITER_ISSUEWRITE_DUP1, 
+					"CAcmWriter::IssueWrite;EPanicInternalError=%d", (TInt)EPanicInternalError);
+		__ASSERT_DEBUG( EFalse, User::Panic(KAcmPanicCat, EPanicInternalError) );
+		}
 	iPort.Acm()->Write(*this, 
 		iBuf, 
 		iBuf.Length());
@@ -296,11 +341,14 @@
 	// This is not expected to occur but the test is in here just to be safe.
 	if(iBuf.Length() == 0 && iCurrentRequest.Length() != 0 && iLengthToGo != 0)
 		{
-		_USB_PANIC(KAcmPanicCat, EPanicInternalError);
+		OstTrace1( TRACE_FATAL, CACMWRITER_ISSUEWRITE_DUP2, 
+					"CAcmWriter::IssueWrite;EPanicInternalError=%d", (TInt)EPanicInternalError);
+		__ASSERT_DEBUG( EFalse, User::Panic(KAcmPanicCat, EPanicInternalError) );
 		}
 #endif
 	// Update our counter of remaining data to write. 
 	iLengthToGo -= iBuf.Length();
+	OstTraceFunctionExit0( CACMWRITER_ISSUEWRITE_EXIT );
 	}
 
 //