usbmgmt/usbmgr/usbman/chargingplugin/src/idpinwatcher.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Tue, 31 Aug 2010 17:01:47 +0300
branchRCL_3
changeset 15 f92a4f87e424
parent 0 c9bc50fca66e
child 16 012cc2ee6408
permissions -rw-r--r--
Revision: 201033 Kit: 201035

/*
* Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description:
* Talks directly to the USB Logical Device Driver (LDD) and 
* watches any state changes
*
*/

/**
 @file
*/

#include "idpinwatcher.h"
#include <usb/usbshared.h>

CIdPinWatcher* CIdPinWatcher::NewL(MOtgPropertiesObserver* aObserver)
	{
	CIdPinWatcher* self = new(ELeave) CIdPinWatcher(aObserver);
	CleanupStack::PushL(self);
	self->ConstructL();
	CleanupStack::Pop(self);
	return self;
	}

CIdPinWatcher::~CIdPinWatcher()
	{
	Cancel();
	iIdPinProp.Close();
	}

CIdPinWatcher::CIdPinWatcher(MOtgPropertiesObserver* aObserver)
	: CActive(EPriorityStandard)
	, iObserver(aObserver), iIdPinValue(EFalse)
	{
	CActiveScheduler::Add(this);
	}

void CIdPinWatcher::ConstructL()
	{
#ifdef __CHARGING_PLUGIN_TEST_CODE__
    const TInt8 KPropertyOffsetForChargingTest = 100;
    User::LeaveIfError(iIdPinProp.Attach(KUidUsbManCategory, KUsbOtgIdPinPresentProperty + KPropertyOffsetForChargingTest));
#else
    User::LeaveIfError(iIdPinProp.Attach(KUidUsbManCategory, KUsbOtgIdPinPresentProperty));
#endif
    
	iIdPinProp.Subscribe(iStatus);
	SetActive();

	TInt err = iIdPinProp.Get(iIdPinValue);
	if (KErrNone != err)
		{
		iIdPinValue = EFalse;
		}
	}

void CIdPinWatcher::DoCancel()
	{
	iIdPinProp.Cancel();
	}

void CIdPinWatcher::RunL()
	{
	iIdPinProp.Subscribe(iStatus);
	SetActive();

	TInt err = iIdPinProp.Get(iIdPinValue);
	if (KErrNone == err)
		{
		iObserver->MpsoIdPinStateChanged(iIdPinValue);
		}
	else
		{
		iIdPinValue = EFalse;
		}
	}

TInt CIdPinWatcher::IdPinValue() const
	{
	return iIdPinValue;
	}