os/kernelhwsrv/kerneltest/e32test/usbho/t_usbdi/src/UsbClientStateWatcher.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of the License "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // @file usbclientstatewatcher.cpp
    15 // @internalComponent
    16 // 
    17 //
    18 
    19 #include "UsbClientStateWatcher.h"
    20 #include <d32usbc.h>
    21 #include <e32test.h>
    22 #include <e32debug.h>
    23 
    24 extern RTest gtest;
    25 
    26 namespace NUnitTesting_USBDI
    27 	{
    28 
    29 CUsbClientStateWatcher* CUsbClientStateWatcher::NewL(RDevUsbcClient& aClientDriver,MUsbClientStateObserver& aStateObserver)
    30 	{
    31 	CUsbClientStateWatcher* self = new (ELeave) CUsbClientStateWatcher(aClientDriver,aStateObserver);
    32 	CleanupStack::PushL(self);
    33 	self->ConstructL();
    34 	CleanupStack::Pop(self);
    35 	return self;
    36 	}
    37 	
    38 	
    39 CUsbClientStateWatcher::CUsbClientStateWatcher(RDevUsbcClient& aClientDriver,MUsbClientStateObserver& aStateObserver)
    40 :	CActive(EPriorityUserInput),
    41 	iClientDriver(aClientDriver),
    42 	iStateObserver(aStateObserver)
    43 	{
    44 	CActiveScheduler::Add(this);
    45 	}
    46 
    47 
    48 CUsbClientStateWatcher::~CUsbClientStateWatcher()
    49 	{
    50 	LOG_FUNC
    51 	Cancel();
    52 	}
    53 	
    54 	
    55 void CUsbClientStateWatcher::ConstructL()
    56 	{
    57 	RDebug::Printf("<Client State Watcher> Watching state of device");
    58 	iClientDriver.AlternateDeviceStatusNotify(iStatus,iState);
    59 	SetActive();
    60 	}
    61 
    62 
    63 void CUsbClientStateWatcher::DoCancel()
    64 	{
    65 	// Cancel device status notification
    66 	iClientDriver.AlternateDeviceStatusNotifyCancel();	
    67 	}
    68 
    69 void CUsbClientStateWatcher::RunL()
    70 	{
    71 	// Retrieve the asynchronous completion code
    72 	TInt completionCode(iStatus.Int());
    73 	
    74 	if(iState & KUsbAlternateSetting)
    75 		{
    76 		// This is notification for alternate interface setting selected by the host
    77 		// so do nothing (Do not watch for these)
    78 		}
    79 	else
    80 		{
    81 		if(completionCode == KErrNone)
    82 			{
    83 			switch(iState)
    84 				{
    85 				case EUsbcDeviceStateUndefined:
    86 					RDebug::Printf("<Client State> Not attached");
    87 					break;
    88 				
    89 				case EUsbcDeviceStateAttached:
    90 					RDebug::Printf("<Client State> Attached to host but not powered");
    91 					break;
    92 					
    93 				case EUsbcDeviceStatePowered:
    94 					RDebug::Printf("<Client State> Attached and powered but no reset");
    95 					break;
    96 					
    97 				case EUsbcDeviceStateDefault:
    98 					RDebug::Printf("<Client State> Reset but not addressed");
    99 					break;
   100 					
   101 				case EUsbcDeviceStateAddress:
   102 					RDebug::Printf("<Client State> Addressed but not configured");
   103 					break;
   104 	 
   105 				case EUsbcDeviceStateConfigured:
   106 					RDebug::Printf("<Client State> Fully configured");
   107 					break;
   108 	 
   109 				case EUsbcDeviceStateSuspended:
   110 					RDebug::Printf("<Client State> Suspended");
   111 					break;
   112 					
   113 				case EUsbcNoState: //follow through
   114 				default:
   115 					RDebug::Printf("<Client State> Not specified");
   116 					break;
   117 				}
   118 			}
   119 		else
   120 			{
   121 			RDebug::Printf("<Client State> Notification error %d",completionCode);
   122 			}
   123 		
   124 		// Device state change
   125 		iStateObserver.StateChangeL(static_cast<TUsbcDeviceState>(iState),completionCode);		
   126 		}
   127 			
   128 	// Keep asking to be informed for status notifications
   129 	iClientDriver.AlternateDeviceStatusNotify(iStatus,iState);
   130 	SetActive();	
   131 	}
   132 	
   133 	
   134 TInt CUsbClientStateWatcher::RunError(TInt aError)
   135 	{
   136 	aError = KErrNone;
   137 	return aError;
   138 	}
   139 
   140 
   141 
   142 
   143 
   144 
   145 CAlternateInterfaceSelectionWatcher* CAlternateInterfaceSelectionWatcher::NewL(
   146 	RDevUsbcClient& aClientDriver,MAlternateSettingObserver& aObserver)
   147 	{
   148 	CAlternateInterfaceSelectionWatcher* self = new (ELeave) CAlternateInterfaceSelectionWatcher(aClientDriver,aObserver);
   149 	CleanupStack::PushL(self);
   150 	self->ConstructL();
   151 	CleanupStack::Pop(self);
   152 	return self;
   153 	}
   154 	
   155 	
   156 CAlternateInterfaceSelectionWatcher::CAlternateInterfaceSelectionWatcher(
   157 	RDevUsbcClient& aClientDriver,MAlternateSettingObserver& aObserver)
   158 :	CActive(EPriorityUserInput),
   159 	iClientDriver(aClientDriver),
   160 	iObserver(aObserver)
   161 	{
   162 	CActiveScheduler::Add(this);
   163 	}
   164 	
   165 	
   166 CAlternateInterfaceSelectionWatcher::~CAlternateInterfaceSelectionWatcher()
   167 	{
   168 	LOG_FUNC
   169 
   170 	Cancel();
   171 	}
   172 	
   173 	
   174 void CAlternateInterfaceSelectionWatcher::ConstructL()
   175 	{
   176 	LOG_FUNC
   177 
   178 	iClientDriver.AlternateDeviceStatusNotify(iStatus,iState);
   179 	SetActive();	
   180 	}
   181 
   182 
   183 void CAlternateInterfaceSelectionWatcher::DoCancel()
   184 	{
   185 	LOG_FUNC
   186 
   187 	iClientDriver.AlternateDeviceStatusNotifyCancel();
   188 	}
   189 	
   190 	
   191 void CAlternateInterfaceSelectionWatcher::RunL()
   192 	{
   193 	LOG_FUNC
   194 
   195 	TInt completionCode(iStatus.Int());
   196 	
   197 	if(iState & KUsbAlternateSetting)
   198 		{
   199 		iObserver.AlternateInterfaceSelectedL(iState & (~KUsbAlternateSetting));
   200 		}	
   201 	// Keep asking to be informed for status notifications
   202 	iClientDriver.AlternateDeviceStatusNotify(iStatus,iState);
   203 	SetActive();	
   204 	}
   205 
   206 
   207 TInt CAlternateInterfaceSelectionWatcher::RunError(TInt aError)
   208 	{
   209 	LOG_FUNC
   210 
   211 	return KErrNone;
   212 	}
   213 
   214 
   215 
   216 
   217 
   218 
   219 
   220 
   221 
   222 
   223 
   224 
   225 
   226 
   227 	}