usbmgmt/usbmgr/device/classdrivers/acm/classimplementation/ecacm/src/CdcInterfaceBase.cpp
branchRCL_3
changeset 16 012cc2ee6408
parent 15 f92a4f87e424
equal deleted inserted replaced
15:f92a4f87e424 16:012cc2ee6408
     1 /*
     1 /*
     2 * Copyright (c) 1997-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 #include <e32std.h>
    18 #include <e32std.h>
    19 #include "CdcInterfaceBase.h"
    19 #include "CdcInterfaceBase.h"
    20 #include "OstTraceDefinitions.h"
    20 #include <usb/usblogger.h>
    21 #ifdef OST_TRACE_COMPILER_IN_USE
    21 
    22 #include "CdcInterfaceBaseTraces.h"
    22 #ifdef __FLOG_ACTIVE
       
    23 _LIT8(KLogComponent, "ECACM");
    23 #endif
    24 #endif
    24 
       
    25 
    25 
    26 CCdcInterfaceBase::CCdcInterfaceBase(const TDesC16& aIfcName)
    26 CCdcInterfaceBase::CCdcInterfaceBase(const TDesC16& aIfcName)
    27 /**
    27 /**
    28  * Constructor.
    28  * Constructor.
    29  *
    29  *
    30  * @param aIfcName The name of the interface.
    30  * @param aIfcName The name of the interface.
    31  */
    31  */
    32 	{
    32 	{
    33 	OstTraceFunctionEntry0( CCDCINTERFACEBASE_CCDCINTERFACEBASE_CONS_ENTRY );
       
    34 	iIfcName.Set(aIfcName);
    33 	iIfcName.Set(aIfcName);
    35 	OstTraceFunctionExit0( CCDCINTERFACEBASE_CCDCINTERFACEBASE_CONS_EXIT );
       
    36 	}
    34 	}
    37 
    35 
    38 void CCdcInterfaceBase::BaseConstructL()
    36 void CCdcInterfaceBase::BaseConstructL()
    39 /**
    37 /**
    40  * Construct the object
    38  * Construct the object
    41  * This call registers the object with the USB device driver
    39  * This call registers the object with the USB device driver
    42  */
    40  */
    43 	{
    41 	{
    44 	OstTraceFunctionEntry0( CCDCINTERFACEBASE_BASECONSTRUCTL_ENTRY );
    42 	LOGTEXT(_L8("\tcalling RDevUsbcClient::Open"));
    45 	OstTrace0( TRACE_NORMAL, CCDCINTERFACEBASE_BASECONSTRUCTL, "CCdcInterfaceBase::BaseConstructL;\tcalling RDevUsbcClient::Open" );
       
    46 	// 0 is assumed to mean ep0
    43 	// 0 is assumed to mean ep0
    47 	TInt ret = iLdd.Open(0); 
    44 	TInt ret = iLdd.Open(0); 
    48 	if ( ret )
    45 	if ( ret )
    49 		{		
    46 		{
    50 		OstTrace1( TRACE_NORMAL, CCDCINTERFACEBASE_BASECONSTRUCTL_DUP1, 
    47 		LOGTEXT2(_L8("\tRDevUsbcClient::Open = %d"), ret);
    51 					"CCdcInterfaceBase::BaseConstructL;\tRDevUsbcClient::Open = %d", ret );
    48 		LEAVEIFERRORL(ret); 
    52 		if (ret < 0)
       
    53 			{
       
    54 			User::Leave(ret);
       
    55 			}
       
    56 		}
    49 		}
    57 
    50 
    58 	ret = SetUpInterface();
    51 	ret = SetUpInterface();
    59 	if ( ret )
    52 	if ( ret )
    60 		{
    53 		{
    61 		OstTrace1( TRACE_NORMAL, CCDCINTERFACEBASE_BASECONSTRUCTL_DUP2, 
    54 		LOGTEXT2(_L8("\tSetUpInterface = %d"), ret);
    62 					"CCdcInterfaceBase::BaseConstructL;\tSetUpInterface = %d", ret );
    55 		LEAVEIFERRORL(ret);
    63 		if (ret < 0)
       
    64 			{
       
    65 			User::Leave(ret);
       
    66 			}
       
    67 		}
    56 		}
    68 	OstTraceFunctionExit0( CCDCINTERFACEBASE_BASECONSTRUCTL_EXIT );
       
    69 	}
    57 	}
    70 
    58 
    71 CCdcInterfaceBase::~CCdcInterfaceBase()
    59 CCdcInterfaceBase::~CCdcInterfaceBase()
    72 /**
    60 /**
    73  * Destructor.
    61  * Destructor.
    74  */
    62  */
    75 	{
    63 	{
    76 	OstTraceFunctionEntry0( CCDCINTERFACEBASE_CCDCINTERFACEBASE_DES_ENTRY );
    64 	LOG_FUNC
       
    65 
    77 	if ( iLdd.Handle() )
    66 	if ( iLdd.Handle() )
    78 		{
    67 		{
    79 		OstTrace0( TRACE_NORMAL, CCDCINTERFACEBASE_CCDCINTERFACEBASE_DES, 
    68 		LOGTEXT(_L8("\tLDD handle exists"));
    80 				"CCdcInterfaceBase::~CCdcInterfaceBase;\tLDD handle exists" );
    69 
    81 		// Don't bother calling ReleaseInterface- the base driver spec says 
    70 		// Don't bother calling ReleaseInterface- the base driver spec says 
    82 		// that Close does it for us.
    71 		// that Close does it for us.
    83 		OstTrace0( TRACE_NORMAL, CCDCINTERFACEBASE_CCDCINTERFACEBASE_DES_DUP1, 
    72 
    84 				"CCdcInterfaceBase::~CCdcInterfaceBase;\tclosing LDD session" );
    73 		LOGTEXT(_L8("\tclosing LDD session"));
    85 		iLdd.Close();
    74 		iLdd.Close();
    86 		}
    75 		}
    87 	OstTraceFunctionExit0( CCDCINTERFACEBASE_CCDCINTERFACEBASE_DES_EXIT );
       
    88 	}
    76 	}
    89 
    77 
    90 TInt CCdcInterfaceBase::GetInterfaceNumber(TUint8& aIntNumber)
    78 TInt CCdcInterfaceBase::GetInterfaceNumber(TUint8& aIntNumber)
    91 /**
    79 /**
    92  * Get my interface number
    80  * Get my interface number
    93  *
    81  *
    94  * @param aIntNumber My interface number
    82  * @param aIntNumber My interface number
    95  * @return Error.
    83  * @return Error.
    96  */
    84  */
    97 	{
    85 	{
    98 	OstTraceFunctionEntry0( CCDCINTERFACEBASE_GETINTERFACENUMBER_ENTRY );
    86 	LOG_FUNC
       
    87 
    99 	TInt interfaceSize = 0;
    88 	TInt interfaceSize = 0;
       
    89 
   100 	// 0 means the main interface in the LDD API
    90 	// 0 means the main interface in the LDD API
   101 	TInt res = iLdd.GetInterfaceDescriptorSize(0, interfaceSize);
    91 	TInt res = iLdd.GetInterfaceDescriptorSize(0, interfaceSize);
   102 
    92 
   103 	if ( res )
    93 	if ( res )
   104 		{
    94 		{
   105 		OstTrace1( TRACE_NORMAL, CCDCINTERFACEBASE_GETINTERFACENUMBER, 
    95 		LOGTEXT2(_L8("\t***GetInterfaceDescriptorSize()=%d"), res);
   106 				"CCdcInterfaceBase::GetInterfaceNumber;\t***GetInterfaceDescriptorSize()=%d", res );
       
   107 		OstTraceFunctionExit0( CCDCINTERFACEBASE_GETINTERFACENUMBER_EXIT );
       
   108 		return res;
    96 		return res;
   109 		}
    97 		}
   110 
    98 
   111 	HBufC8* interfaceBuf = HBufC8::New(interfaceSize);
    99 	HBufC8* interfaceBuf = HBufC8::New(interfaceSize);
   112 	if ( !interfaceBuf )
   100 	if ( !interfaceBuf )
   113 		{
   101 		{
   114 		OstTrace0( TRACE_NORMAL, CCDCINTERFACEBASE_GETINTERFACENUMBER_DUP1, 
   102 		LOGTEXT(_L8("\t***failed to create interfaceBuf- "
   115 				"CCdcInterfaceBase::GetInterfaceNumber;\t***failed to create interfaceBuf-returning KErrNoMemory" );
   103 			"returning KErrNoMemory"));
   116 		OstTraceFunctionExit0( CCDCINTERFACEBASE_GETINTERFACENUMBER_EXIT_DUP1 );
       
   117 		return KErrNoMemory;
   104 		return KErrNoMemory;
   118 		}
   105 		}
   119 
   106 
   120 	TPtr8 interfacePtr = interfaceBuf->Des();
   107 	TPtr8 interfacePtr = interfaceBuf->Des();
   121 	interfacePtr.SetLength(0);
   108 	interfacePtr.SetLength(0);
   123 	res = iLdd.GetInterfaceDescriptor(0, interfacePtr); 
   110 	res = iLdd.GetInterfaceDescriptor(0, interfacePtr); 
   124 
   111 
   125 	if ( res )
   112 	if ( res )
   126 		{
   113 		{
   127 		delete interfaceBuf;
   114 		delete interfaceBuf;
   128 		OstTrace1( TRACE_NORMAL, CCDCINTERFACEBASE_GETINTERFACENUMBER_DUP2, "CCdcInterfaceBase::GetInterfaceNumber;res=%d", res );
   115 		LOGTEXT2(_L8("\t***GetInterfaceDescriptor()=%d"), res);
   129 		OstTraceFunctionExit0( CCDCINTERFACEBASE_GETINTERFACENUMBER_EXIT_DUP2 );
       
   130 		return res;
   116 		return res;
   131 		}
   117 		}
   132 
   118 
   133 	OstTrace1( TRACE_NORMAL, CCDCINTERFACEBASE_GETINTERFACENUMBER_DUP3, 
   119 #ifdef __FLOG_ACTIVE
   134 			"CCdcInterfaceBase::GetInterfaceNumber;\t***interface length = %d", interfacePtr.Length() );
   120 	LOGTEXT2(_L8("\t***interface length = %d"), interfacePtr.Length());
   135 	for ( TInt i = 0 ; i < interfacePtr.Length() ; i++ )
   121 	for ( TInt i = 0 ; i < interfacePtr.Length() ; i++ )
   136 		{
   122 		{
   137 		OstTraceExt1( TRACE_NORMAL, CCDCINTERFACEBASE_GETINTERFACENUMBER_DUP4, 
   123 		LOGTEXT2(_L8("\t***** %x"),interfacePtr[i]);
   138 				"\t***** %hhx", interfacePtr[i] );
       
   139 		}
   124 		}
       
   125 #endif
   140 
   126 
   141 	const TUint8* buffer = reinterpret_cast<const TUint8*>(interfacePtr.Ptr());
   127 	const TUint8* buffer = reinterpret_cast<const TUint8*>(interfacePtr.Ptr());
   142 	// 2 is where the interface number is, according to the LDD API
   128 	// 2 is where the interface number is, according to the LDD API
   143 	aIntNumber = buffer[2]; 
   129 	aIntNumber = buffer[2]; 
   144 	OstTrace1( TRACE_NORMAL, CCDCINTERFACEBASE_GETINTERFACENUMBER_DUP5, 
   130 
   145 			"CCdcInterfaceBase::GetInterfaceNumber;\tinterface number = %d", (TInt)aIntNumber );
   131 	LOGTEXT2(_L8("\tinterface number = %d"), aIntNumber);
   146 	
   132 
   147 	delete interfaceBuf;
   133 	delete interfaceBuf;
   148 	OstTraceFunctionExit0( CCDCINTERFACEBASE_GETINTERFACENUMBER_EXIT_DUP3 );
   134 
   149 	return KErrNone;
   135 	return KErrNone;
   150 	}
   136 	}
   151 
   137 
   152 //
   138 //
   153 // End of file
   139 // End of file