usbmgmt/usbmgr/usbman/server/SRC/CUsbDeviceStateWatcher.cpp
changeset 0 c9bc50fca66e
child 15 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 * Talks directly to the USB Logical Device Driver (LDD) and 
       
    16 * watches any state changes
       
    17 *
       
    18 */
       
    19 
       
    20 /**
       
    21  @file
       
    22 */
       
    23 
       
    24 #include <usb/usblogger.h>
       
    25 #include "CUsbScheduler.h"
       
    26 #include "CUsbDeviceStateWatcher.h"
       
    27 #include "CUsbDevice.h"
       
    28 
       
    29 #ifdef __FLOG_ACTIVE
       
    30 _LIT8(KLogComponent, "USBSVR");
       
    31 #endif
       
    32 
       
    33 /**
       
    34  * The CUsbDeviceStateWatcher::NewL method
       
    35  *
       
    36  * Constructs a new CUsbDeviceStateWatcher object
       
    37  *
       
    38  * @internalComponent
       
    39  * @param	aOwner	The device that owns the state watcher
       
    40  * @param	aLdd	A reference to the USB Logical Device Driver
       
    41  *
       
    42  * @return	A new CUsbDeviceStateWatcher object
       
    43  */
       
    44 CUsbDeviceStateWatcher* CUsbDeviceStateWatcher::NewL(CUsbDevice& aOwner, RDevUsbcClient& aLdd)
       
    45 	{
       
    46 	LOG_STATIC_FUNC_ENTRY
       
    47 
       
    48 	CUsbDeviceStateWatcher* r = new (ELeave) CUsbDeviceStateWatcher(aOwner, aLdd);
       
    49 	return r;
       
    50 	}
       
    51 
       
    52 
       
    53 /**
       
    54  * The CUsbDeviceStateWatcher::~CUsbDeviceStateWatcher method
       
    55  *
       
    56  * Destructor
       
    57  *
       
    58  * @internalComponent
       
    59  */
       
    60 CUsbDeviceStateWatcher::~CUsbDeviceStateWatcher()
       
    61 	{
       
    62 	LOGTEXT2(_L8(">CUsbDeviceStateWatcher::~CUsbDeviceStateWatcher (0x%08x)"), (TUint32) this);
       
    63 	Cancel();
       
    64 	}
       
    65 
       
    66 
       
    67 /**
       
    68  * The CUsbDeviceStateWatcher::CUsbDeviceStateWatcher method
       
    69  *
       
    70  * Constructor
       
    71  *
       
    72  * @param	aOwner	The device that owns the state watcher
       
    73  * @param	aLdd	A reference to the USB Logical Device Driver
       
    74  */
       
    75 CUsbDeviceStateWatcher::CUsbDeviceStateWatcher(CUsbDevice& aOwner, RDevUsbcClient& aLdd)
       
    76 	: CActive(CActive::EPriorityStandard), iOwner(aOwner), iLdd(aLdd)
       
    77 	{
       
    78 	CActiveScheduler::Add(this);
       
    79 	}
       
    80 
       
    81 /**
       
    82  * Called when the USB device changes its state.
       
    83  */
       
    84 void CUsbDeviceStateWatcher::RunL()
       
    85 	{
       
    86 	if (iStatus.Int() != KErrNone)
       
    87 		{
       
    88 		LOGTEXT2(_L8("CUsbDeviceStateWatcher::RunL() - Error = %d"), iStatus.Int());
       
    89 		return;
       
    90 		}
       
    91 
       
    92 	LOGTEXT2(_L8("CUsbDeviceStateWatcher::RunL() - State Changed to %d"), iState);
       
    93 
       
    94 	if (!(iState & KUsbAlternateSetting))
       
    95 		iOwner.SetDeviceState((TUsbcDeviceState) iState);
       
    96 
       
    97 	LOGTEXT(_L8("CUsbDeviceStateWatcher::RunL() - About to call DeviceStatusNotify"));
       
    98 	iLdd.AlternateDeviceStatusNotify(iStatus, iState);
       
    99 	SetActive();
       
   100 	LOGTEXT(_L8("CUsbDeviceStateWatcher::RunL() - Called DeviceStatusNotify"));
       
   101 	}
       
   102 
       
   103 
       
   104 /**
       
   105  * Automatically called when the state watcher is cancelled.
       
   106  */
       
   107 void CUsbDeviceStateWatcher::DoCancel()
       
   108 	{
       
   109 	LOG_FUNC
       
   110 	iLdd.AlternateDeviceStatusNotifyCancel();
       
   111 	}
       
   112 
       
   113 
       
   114 /**
       
   115  * Instructs the state watcher to start watching.
       
   116  */
       
   117 void CUsbDeviceStateWatcher::Start()
       
   118 	{
       
   119 	LOG_FUNC
       
   120 	iLdd.AlternateDeviceStatusNotify(iStatus, iState);
       
   121 	SetActive();
       
   122 	}