/*
* Copyright (c) 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: Base classes for Usb notifier wrapper
*
*/
#include "cusbnotifmanager.h"
#include "cusbnotenotifier.h"
#include "debug.h"
#include "panic.h"
// ======== MEMBER FUNCTIONS ========
// ---------------------------------------------------------------------------
// C++ constructor
// ---------------------------------------------------------------------------
//
CUsbNoteNotifier::CUsbNoteNotifier(RNotifier& aNotifier,
CUsbNotifManager* aNotifManager, TUid aCat, TUint aNotifId) :
CUsbNotifier(aNotifManager, aCat, aNotifId),
iNotifier(aNotifier)
{
FLOG( _L( "[USBOTGWATCHER]\tCUsbNoteNotifier::CUsbNoteNotifier" ) );
}
// ---------------------------------------------------------------------------
// Second-phase constructor
// ---------------------------------------------------------------------------
//
void CUsbNoteNotifier::ConstructL()
{
FLOG( _L( "[USBOTGWATCHER]\tCUsbNoteNotifier::ConstructL" ) );
iNotifierActive = new(ELeave)CUsbNoteNotifier::CNotifierActive(iNotifier, this);
}
// ---------------------------------------------------------------------------
// Destructor
// ---------------------------------------------------------------------------
//
CUsbNoteNotifier::~CUsbNoteNotifier()
{
FLOG( _L( "[USBOTGWATCHER]\tCUsbNoteNotifier::~CUsbNoteNotifier" ) );
delete iNotifierActive;
}
// ---------------------------------------------------------------------------
// From base class CUsbNotifier
// ---------------------------------------------------------------------------
//
void CUsbNoteNotifier::ShowL()
{
FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbNoteNotifier::ShowL aCat = 0x%X aNotifId = 0x%X" ), iCat, iNotifId));
iNotifierActive->StartL();
}
// ---------------------------------------------------------------------------
// From base class CUsbNotifier
// ---------------------------------------------------------------------------
//
void CUsbNoteNotifier::Close()
{
FLOG( _L( "[USBOTGWATCHER]\tCUsbNoteNotifier::Close" ) );
}
// ======== MEMBER FUNCTIONS ========
// ---------------------------------------------------------------------------
// C++ default constructor
// ---------------------------------------------------------------------------
//
CUsbNoteNotifier::CNotifierActive::CNotifierActive(RNotifier& aNotifier,
CUsbNoteNotifier* aUsbNoteNotifier) :
CUsbNoteNotifier::CNotifierActive::CActive(EPriorityStandard),
iUsbNoteNotifier(aUsbNoteNotifier),
iNotifier(aNotifier),
iRes(0)
{
CActiveScheduler::Add(this);
}
// ---------------------------------------------------------------------------
// Destructor
// ---------------------------------------------------------------------------
//
CUsbNoteNotifier::CNotifierActive::~CNotifierActive()
{
Cancel();
}
// ---------------------------------------------------------------------------
// Start to show the notifier
// ---------------------------------------------------------------------------
//
void CUsbNoteNotifier::CNotifierActive::StartL()
{
FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbNoteNotifier::CNotifierActive::ShowL aCat = 0x%X aNotifId = 0x%X" ),
iUsbNoteNotifier->iCat, iUsbNoteNotifier->iNotifId));
if (IsActive())
{
Panic(ENotifierIsActiveAlready);
return;
}
TPckgBuf<TInt> pckg;
pckg() = iUsbNoteNotifier->iNotifId;
iNotifier.StartNotifierAndGetResponse(iStatus, iUsbNoteNotifier->iCat, pckg, iRes);
SetActive();
}
// ---------------------------------------------------------------------------
// From base class CActive
// ---------------------------------------------------------------------------
//
void CUsbNoteNotifier::CNotifierActive::RunL()
{
FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCCUsbNoteNotifier::CNotifierActive::RunL iStatus = %d" ), iStatus.Int()));
// if error occured, deal with it in RunError
User::LeaveIfError(iStatus.Int());
iNotifier.CancelNotifier(iUsbNoteNotifier->iCat);
// report to owner that show is over
iUsbNoteNotifier->iNotifManager->NotifierShowCompletedL(iUsbNoteNotifier, KErrNone, iRes());
}
// ---------------------------------------------------------------------------
// From base class CActive
// ---------------------------------------------------------------------------
//
void CUsbNoteNotifier::CNotifierActive::DoCancel()
{
FLOG( _L( "[USBOTGWATCHER]\tCUsbNoteNotifier::CNotifierActive::DoCancel" ) );
iNotifier.CancelNotifier(iUsbNoteNotifier->iCat);
}
// ---------------------------------------------------------------------------
// From base class CActive
// ---------------------------------------------------------------------------
//
TInt CUsbNoteNotifier::CNotifierActive::RunError(TInt aError)
{
FTRACE( FPrint(_L("[USBOTGWATCHER]\tCUsbNoteNotifier::CNotifierActive::RunError aError = %d" ), aError));
iNotifier.CancelNotifier(iUsbNoteNotifier->iCat);
// try to continue
return KErrNone;
}
// End of file