usbmgmt/usbmgr/device/classdrivers/acm/classimplementation/ecacm/src/linkstatenotifier.cpp
changeset 0 c9bc50fca66e
child 15 f92a4f87e424
equal deleted inserted replaced
-1:000000000000 0:c9bc50fca66e
       
     1 /*
       
     2 * Copyright (c) 2006-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 *
       
    16 */
       
    17 
       
    18 #include <e32base.h>
       
    19 #include <d32usbc.h>
       
    20 #include <usb/usblogger.h>
       
    21 #include "AcmPanic.h"
       
    22 #include "linkstatenotifier.h"
       
    23 
       
    24 #ifdef __FLOG_ACTIVE
       
    25 _LIT8(KLogComponent, "ECACM");
       
    26 #endif
       
    27 
       
    28 CLinkStateNotifier* CLinkStateNotifier::NewL(MLinkStateObserver& aParent, RDevUsbcClient& aUsb)
       
    29 	{
       
    30 	LOG_STATIC_FUNC_ENTRY
       
    31 	
       
    32 	CLinkStateNotifier* self = new (ELeave) CLinkStateNotifier(aParent, aUsb);
       
    33 	return self;
       
    34 	}
       
    35 
       
    36 
       
    37 CLinkStateNotifier::CLinkStateNotifier(MLinkStateObserver& aParent, RDevUsbcClient& aUsb)
       
    38 	 : CActive(EPriorityStandard),
       
    39 	   iParent(aParent), iUsb(aUsb)
       
    40 	{
       
    41 	LOG_FUNC
       
    42 	
       
    43 	CActiveScheduler::Add(this);
       
    44 	}
       
    45 
       
    46 
       
    47 
       
    48 /**
       
    49 CObexUsbHandler destructor.
       
    50 */
       
    51 CLinkStateNotifier::~CLinkStateNotifier()
       
    52 	{
       
    53 	LOG_FUNC
       
    54 	Cancel();
       
    55 	}
       
    56 
       
    57 
       
    58 /**
       
    59 Standard active object error function.
       
    60 
       
    61 @return	KErrNone because currently nothing should cause this to be called.
       
    62 */
       
    63 TInt CLinkStateNotifier::RunError(TInt /*aError*/)
       
    64 	{
       
    65 	return KErrNone;
       
    66 	}
       
    67 
       
    68 
       
    69 /**
       
    70 This function will be called upon a change in the state of the device
       
    71 (as set up in AcceptL).
       
    72 */
       
    73 void CLinkStateNotifier::RunL()
       
    74 	{
       
    75 	LOGTEXT2(_L8("CObexUsbHandler::RunL called state=0x%X"), iUsbState);
       
    76 	
       
    77 	if (iStatus != KErrNone)
       
    78 		{
       
    79 		LOGTEXT2(_L8("CObexUsbHandler::RunL() - Error = %d"),iStatus.Int());
       
    80 		LinkDown();
       
    81 		iParent.MLSOStateChange(KDefaultMaxPacketTypeBulk);
       
    82 
       
    83 		return;
       
    84 		}
       
    85 
       
    86 	if (!(iUsbState & KUsbAlternateSetting))
       
    87 		{
       
    88 		TUsbcDeviceState deviceState = static_cast<TUsbcDeviceState>(iUsbState);
       
    89 
       
    90 		switch(deviceState)
       
    91 			{
       
    92 		case EUsbcDeviceStateUndefined:
       
    93 			LinkDown();
       
    94 			break;
       
    95 				
       
    96 		case EUsbcDeviceStateAttached:
       
    97 		case EUsbcDeviceStatePowered:
       
    98 		case EUsbcDeviceStateDefault:
       
    99 		case EUsbcDeviceStateAddress:
       
   100 		case EUsbcDeviceStateSuspended:
       
   101 			break;
       
   102 
       
   103 		case EUsbcDeviceStateConfigured:
       
   104 			LinkUp();
       
   105 			break;
       
   106 
       
   107 		default:
       
   108 			__ASSERT_DEBUG(false, _USB_PANIC(KAcmPanicCat, EPanicUnknownDeviceState));
       
   109 			break;
       
   110 			}
       
   111 		}
       
   112 
       
   113 	iParent.MLSOStateChange(iPacketSize || KDefaultMaxPacketTypeBulk);
       
   114 
       
   115 	// Await further notification of a state change.
       
   116 	iUsb.AlternateDeviceStatusNotify(iStatus, iUsbState);
       
   117 	SetActive();
       
   118 	}
       
   119 
       
   120 
       
   121 /**
       
   122 Standard active object cancellation function.
       
   123 */
       
   124 void CLinkStateNotifier::DoCancel()
       
   125 	{
       
   126 	LOG_FUNC
       
   127 
       
   128 	iUsb.AlternateDeviceStatusNotifyCancel();
       
   129 	}
       
   130 
       
   131 
       
   132 
       
   133 /**
       
   134 Accept an incoming connection.
       
   135 */
       
   136 void CLinkStateNotifier::Start()
       
   137 	{
       
   138 	LOG_FUNC
       
   139 	iUsb.AlternateDeviceStatusNotify(iStatus, iUsbState);
       
   140 	SetActive();
       
   141 	}
       
   142 
       
   143 
       
   144 void CLinkStateNotifier::LinkUp()
       
   145 	{
       
   146 	if (iUsb.CurrentlyUsingHighSpeed())
       
   147 		{
       
   148 		iPacketSize = KMaxPacketTypeBulkHS;
       
   149 		}
       
   150 	else
       
   151 		{
       
   152 		iPacketSize = KMaxPacketTypeBulkFS;
       
   153 		}
       
   154 	}
       
   155 
       
   156 
       
   157 void CLinkStateNotifier::LinkDown()
       
   158 	{
       
   159 	iPacketSize = 0;
       
   160 	}