usbmgmt/usbmgr/usbman/chargingplugin/src/otgstatewatcher.cpp
changeset 0 c9bc50fca66e
child 15 f92a4f87e424
equal deleted inserted replaced
-1:000000000000 0:c9bc50fca66e
       
     1 /*
       
     2 * Copyright (c) 2008-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 "otgstatewatcher.h"
       
    25 
       
    26 COtgStateWatcher* COtgStateWatcher::NewL(MOtgPropertiesObserver* aObserver)
       
    27 	{
       
    28 	COtgStateWatcher* self = new(ELeave) COtgStateWatcher(aObserver);
       
    29 	CleanupStack::PushL(self);
       
    30 	self->ConstructL();
       
    31 	CleanupStack::Pop(self);
       
    32 	return self;
       
    33 	}
       
    34 
       
    35 COtgStateWatcher::~COtgStateWatcher()
       
    36 	{
       
    37 	Cancel();
       
    38 	iOtgStateProp.Close();
       
    39 	}
       
    40 
       
    41 COtgStateWatcher::COtgStateWatcher(MOtgPropertiesObserver* aObserver)
       
    42 	: CActive(EPriorityStandard)
       
    43 	, iObserver(aObserver)
       
    44 	, iOtgState(EUsbOtgStateReset)
       
    45 	{
       
    46 	CActiveScheduler::Add(this);
       
    47 	}
       
    48 
       
    49 void COtgStateWatcher::ConstructL()
       
    50 	{
       
    51 	User::LeaveIfError(iOtgStateProp.Attach(KUidUsbManCategory, KUsbOtgStateProperty));
       
    52 	iOtgStateProp.Subscribe(iStatus);
       
    53 	SetActive();
       
    54 
       
    55 	TInt err = iOtgStateProp.Get((TInt&)iOtgState);
       
    56 	if (KErrNone != err)
       
    57 		{
       
    58 		iOtgState = EUsbOtgStateBPeripheral;
       
    59 		}
       
    60 	}
       
    61 
       
    62 void COtgStateWatcher::DoCancel()
       
    63 	{
       
    64 	iOtgStateProp.Cancel();
       
    65 	}
       
    66 
       
    67 void COtgStateWatcher::RunL()
       
    68 	{
       
    69 	iOtgStateProp.Subscribe(iStatus);
       
    70 	SetActive();
       
    71 
       
    72 	TInt err = iOtgStateProp.Get((TInt&)iOtgState);
       
    73 	if (KErrNone != err)
       
    74 		{
       
    75 		iOtgState = EUsbOtgStateBPeripheral;
       
    76 		}
       
    77 	iObserver->MpsoOtgStateChangedL(iOtgState);
       
    78 	}
       
    79 
       
    80 TUsbOtgState COtgStateWatcher::OtgState() const
       
    81 	{
       
    82 	return iOtgState;
       
    83 	}