usbmgmt/usbmgrtest/usbmsapp/usbms_stub/src/usbms_stub.cpp
changeset 0 c9bc50fca66e
child 25 4ddb65515edd
child 42 f92a4f87e424
equal deleted inserted replaced
-1:000000000000 0:c9bc50fca66e
       
     1 /*
       
     2 * Copyright (c) 1997-2009 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:
       
    15 * Adheres to the UsbMan USB Class Controller API and talks to C32
       
    16 * to manage the stub3.CSY that is used to provide a virtual
       
    17 * serial port service to clients
       
    18 *
       
    19 */
       
    20 
       
    21 /**
       
    22  @file
       
    23 */
       
    24 
       
    25 #include "usbms_stub.h"
       
    26 #include <usb_std.h>
       
    27 #include <es_ini.h>
       
    28 #include <d32usbc.h>
       
    29 
       
    30 #include "UsbmanInternalConstants.h"
       
    31 
       
    32 #define _USB_PANIC(CAT, CODE)	User::Panic(CAT, CODE) 
       
    33 
       
    34 // Panic category 
       
    35 _LIT( Kstub3CcPanicCategory, "UsbstubCc" );
       
    36 
       
    37 
       
    38 /**
       
    39  * Panic codes for the USB stub3 Class Controller.
       
    40  */
       
    41 enum Tstub3CcPanic
       
    42 	{
       
    43 	/** Class called while in an illegal state */
       
    44 	EBadApiCall = 0,
       
    45 	/** Asynchronous function called (not needed, as all requests complete synchronously) */
       
    46 	EUnusedFunction = 1,
       
    47 	/** Error reading ini file. */
       
    48 	EPanicBadIniFile = 2,		
       
    49 	/** Bad value for the iNumberOfstub3Functions member.*/
       
    50 	EPanicBadNumberOfstub3Functions = 3,
       
    51 	
       
    52 	EPanicUnexpectedStatus,
       
    53 	EPanicUnexpectedState
       
    54 
       
    55 	};
       
    56 	
       
    57 
       
    58 /**
       
    59  * Constructs a CUsbstub3ClassController object
       
    60  *
       
    61  * @param	aOwner	USB Device that owns and manages the class
       
    62  *
       
    63  * @return	A new CUsbstub3ClassController object
       
    64  */
       
    65 CUsbstub3ClassController* CUsbstub3ClassController::NewL(
       
    66 	MUsbClassControllerNotify& aOwner)
       
    67 	{
       
    68 	CUsbstub3ClassController* r = new (ELeave) CUsbstub3ClassController(aOwner);
       
    69 	CleanupStack::PushL(r);
       
    70 	r->ConstructL();
       
    71 	CleanupStack::Pop();
       
    72 	return r;
       
    73 	}
       
    74 
       
    75 /**
       
    76  * Destructor
       
    77  */
       
    78 CUsbstub3ClassController::~CUsbstub3ClassController()
       
    79 	{
       
    80 	Cancel();
       
    81 
       
    82 	iTimer.Close();
       
    83 
       
    84 #ifndef __WINS__	
       
    85 //	iLdd.Close();
       
    86 #endif
       
    87 
       
    88 	}
       
    89 
       
    90 
       
    91 
       
    92 /**
       
    93  * Constructor.
       
    94  *
       
    95  * @param	aOwner	USB Device that owns and manages the class
       
    96  */
       
    97 CUsbstub3ClassController::CUsbstub3ClassController(
       
    98 	MUsbClassControllerNotify& aOwner)
       
    99 	: CUsbClassControllerPlugIn(aOwner, Kstub3StartupPriority),
       
   100 	iStartDelay(Kstub3CCDefaultDelay),
       
   101 	iStopDelay(Kstub3CCDefaultDelay),
       
   102 	iFailToStart(EFalse),
       
   103 	iFailToStop(EFalse)	
       
   104 
       
   105 	{
       
   106 	iTimer.CreateLocal();
       
   107 	}
       
   108 
       
   109 
       
   110 
       
   111 /**
       
   112  * 2nd Phase Construction.
       
   113  */
       
   114 void CUsbstub3ClassController::ConstructL()
       
   115 	{
       
   116 	}
       
   117 
       
   118 /**
       
   119  * Called by UsbMan when it wants to start the USB stub3 class. This always
       
   120  * completes immediately.
       
   121  *
       
   122  * @param aStatus The caller's request status, filled in with an error code
       
   123  */
       
   124 void CUsbstub3ClassController::Start(TRequestStatus& aStatus)
       
   125 	{
       
   126 
       
   127 	aStatus = KRequestPending;
       
   128 	iReportStatus = &aStatus;
       
   129 	//If we are already started then just complete the request.
       
   130 	if (iState == EUsbServiceStarted)
       
   131 		{
       
   132 		User::RequestComplete(iReportStatus, KErrNone);
       
   133 		return;
       
   134 		}
       
   135 
       
   136 	if (iFailToStart)
       
   137 		{
       
   138 		User::RequestComplete(iReportStatus, KErrGeneral);
       
   139 		return;
       
   140 		}
       
   141 	
       
   142 	iState = EUsbServiceStarting;
       
   143 
       
   144 	iTimer.After(iStatus, iStartDelay*1000);  //convert from usec to msec
       
   145 	SetActive();
       
   146 	}
       
   147 
       
   148 /**
       
   149  * Called by UsbMan when it wants to stop the USB stub3 class.
       
   150  *
       
   151  * @param aStatus The caller's request status: always set to KErrNone
       
   152  */
       
   153 void CUsbstub3ClassController::Stop(TRequestStatus& aStatus)
       
   154 	{
       
   155 
       
   156 	aStatus = KRequestPending;
       
   157 	iReportStatus = &aStatus;
       
   158 	//If we are already idle then just complete the request.
       
   159 	if (iState == EUsbServiceIdle)
       
   160 		{
       
   161 		User::RequestComplete(iReportStatus, KErrNone);
       
   162 		return;
       
   163 		}
       
   164 
       
   165 	if (iFailToStop)
       
   166 		{
       
   167 		User::RequestComplete(iReportStatus, KErrGeneral);
       
   168 		return;
       
   169 		}
       
   170 
       
   171 	iState = EUsbServiceStopping;
       
   172 
       
   173 	
       
   174 	iTimer.After(iStatus, iStopDelay*1000);  //convert from usec to msec
       
   175 	SetActive();
       
   176 	}
       
   177 
       
   178 /**
       
   179  * Gets information about the descriptor which this class provides.
       
   180  *
       
   181  * @param aDescriptorInfo Descriptor info structure filled in by this function
       
   182  */
       
   183 void CUsbstub3ClassController::GetDescriptorInfo(TUsbDescriptor& aDescriptorInfo) const
       
   184 	{
       
   185 
       
   186 	aDescriptorInfo.iLength = Kstub3DescriptorLength;
       
   187 	aDescriptorInfo.iNumInterfaces = Kstub3NumberOfInterfacesPerstub3Function;
       
   188 	}
       
   189 
       
   190 
       
   191 /**
       
   192  * Standard active object RunL. 
       
   193  */
       
   194 void CUsbstub3ClassController::RunL()
       
   195 	{
       
   196 
       
   197 	__ASSERT_DEBUG( iStatus == KErrNone, _USB_PANIC(Kstub3CcPanicCategory, EPanicUnexpectedStatus) );
       
   198 	switch (iState)
       
   199 		{
       
   200 		case EUsbServiceStarting:
       
   201 			iState = EUsbServiceStarted;
       
   202 			break;
       
   203 		case EUsbServiceStopping:
       
   204 			iState = EUsbServiceIdle;
       
   205 			break;
       
   206 		default:	
       
   207 			_USB_PANIC(Kstub3CcPanicCategory, EPanicUnexpectedState);
       
   208 		}
       
   209 	*iReportStatus = KErrNone;	
       
   210 	User::RequestComplete(iReportStatus, iStatus.Int());	
       
   211 	}
       
   212 
       
   213 /**
       
   214  * Standard active object cancellation function. Never called because this
       
   215  * class has no asynchronous requests.
       
   216  */
       
   217 void CUsbstub3ClassController::DoCancel()
       
   218 	{
       
   219 
       
   220 	if (IsActive())
       
   221 		{
       
   222 		iTimer.Cancel();	
       
   223 		}
       
   224 	switch (iState)
       
   225 	{
       
   226 		case EUsbServiceStarting:
       
   227 			iState = EUsbServiceIdle;
       
   228 			break;
       
   229 		case EUsbServiceStopping:
       
   230 			iState = EUsbServiceStarted;
       
   231 			break;
       
   232 		default:	
       
   233 			_USB_PANIC(Kstub3CcPanicCategory, EPanicUnexpectedState);
       
   234 	}
       
   235 	*iReportStatus = KErrNone;		
       
   236 	User::RequestComplete(iReportStatus, KErrCancel);	
       
   237 	}
       
   238 
       
   239 /**
       
   240  * Standard active object error function. Never called because this class has
       
   241  * no asynchronous requests, and hence its RunL is never called.
       
   242  *
       
   243  * @param aError The error code (unused)
       
   244  * @return Always KErrNone to avoid an active scheduler panic
       
   245  */
       
   246 TInt CUsbstub3ClassController::RunError(TInt /*aError*/)
       
   247 	{
       
   248 	__ASSERT_DEBUG( EFalse, _USB_PANIC(Kstub3CcPanicCategory, EUnusedFunction) );
       
   249 	return KErrNone;
       
   250 	}
       
   251 
       
   252 TInt CUsbstub3ClassController::SetUpInterface()
       
   253 /**
       
   254  * Set up the interface for use. This involves finding a "Interrupt IN" 
       
   255  * endpoint and, if found, configuring the interface.
       
   256  */
       
   257 	{
       
   258 return 0;
       
   259 	}
       
   260 
       
   261 	
       
   262 //
       
   263 // End of file