--- a/usbengines/usbotgwatcher/src/cusbhosteventnotificationobserver.cpp Tue Feb 02 00:52:37 2010 +0200
+++ b/usbengines/usbotgwatcher/src/cusbhosteventnotificationobserver.cpp Fri Mar 19 09:48:52 2010 +0200
@@ -1,20 +1,19 @@
/*
-* 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: Implementation
+ * 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: Implementation
+ *
+ */
#include <usbman.h>
@@ -41,8 +40,7 @@
//
void CUsbHostEventNotificationObserver::ConstructL()
{
-
- FLOG( _L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::ConstructL" ) );
+ LOG_FUNC
}
@@ -53,8 +51,7 @@
CUsbHostEventNotificationObserver* CUsbHostEventNotificationObserver::NewL(
RUsb* aUsb)
{
-
- FLOG( _L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::NewL" ) );
+ LOG_FUNC
CUsbHostEventNotificationObserver* self =
new (ELeave) CUsbHostEventNotificationObserver(aUsb);
@@ -70,8 +67,7 @@
//
CUsbHostEventNotificationObserver::~CUsbHostEventNotificationObserver()
{
-
- FLOG( _L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::~CUsbHostEventNotificationObserver" ) );
+ LOG_FUNC
Cancel();
@@ -84,11 +80,19 @@
// ---------------------------------------------------------------------------
//
void CUsbHostEventNotificationObserver::SubscribeL(
- MUsbHostEventNotificationObserver* aObserver)
+ MUsbHostEventNotificationObserver& aObserver)
{
- FLOG( _L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::SubscribeL" ) );
+ LOG_FUNC
- User::LeaveIfError(iObservers.Append(aObserver));
+ // check if the same observer already exist in a list
+ if (KErrNotFound != iObservers.Find(&aObserver))
+ {
+ LOG("Observer already exists" );
+ Panic( EObserverAlreadyExists);
+ return;
+ }
+
+ iObservers.AppendL(&aObserver);
if (KFirst == iObservers.Count()) // first item
{
@@ -103,30 +107,21 @@
// ---------------------------------------------------------------------------
//
void CUsbHostEventNotificationObserver::UnsubscribeL(
- MUsbHostEventNotificationObserver* aObserver)
+ MUsbHostEventNotificationObserver& aObserver)
{
- FLOG( _L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::UnsubscribeL" ) );
- if (0 == iObservers.Count()) // no items
+ LOG_FUNC
+
+ TInt i(iObservers.Find(&aObserver));
+ if (KErrNotFound == i)
{
- FLOG( _L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::UnsubscribeL No observers" ) );
+ LOG("Observer not found");
+ Panic( ECanNotFindHostEventNotificationObserver);
return;
}
-
- TInt i(0);
- while (i < iObservers.Count() && aObserver != iObservers[i])
- ++i;
- if (aObserver == iObservers[i]) // found
- {
- iObservers.Remove(i);
- }
- else
- {
- FLOG( _L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::UnsubscribeL CanNotFindIdPinObserver" ) );
- Panic(ECanNotFindIdPinObserver);
- }
+ iObservers.Remove(i);
- if (0 == iObservers.Count()) // no items
+ if (0 == iObservers.Count()) // no observers anymore
{
// cancel pending request
Cancel();
@@ -139,17 +134,19 @@
//
void CUsbHostEventNotificationObserver::RunL()
{
- FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::RunL iStatus = %d" ), iStatus.Int()));
+ LOG_FUNC
+
+ LOG1( "iStatus = %d", iStatus.Int());
- // if error occured, tell to Observers
- if(KErrNone != iStatus.Int())
+ // if error occured, tell to Observers
+ if (KErrNone != iStatus.Int())
+ {
+ for (TInt i(0); i < iObservers.Count(); ++i)
{
- for (TInt i(0); i < iObservers.Count(); ++i)
- {
- iObservers[i]->HostEventNotificationErrorL(iStatus.Int());
- }
- return;
+ iObservers[i]->HostEventNotificationErrorL(iStatus.Int());
}
+ return;
+ }
TDeviceEventInformation dei(iEventInfo);
@@ -157,20 +154,20 @@
iUsb->HostEventNotification(iStatus, iEventInfo);
SetActive();
- // Log the event
- FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::RunL iEventInfo.iDeviceId = %d" ), dei.iDeviceId));
- FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::RunL iEventInfo.iEventType = %d" ), dei.iEventType));
- FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::RunL iEventInfo.iError = %d" ), dei.iError));
- FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::RunL iEventInfo.iDriverLoadStatus = %d" ), dei.iDriverLoadStatus));
- FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::RunL iEventInfo.iVid = %d" ), dei.iVid));
- FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::RunL iEventInfo.iPid = %d" ), dei.iPid));
+ // Log the event
+ LOG1( "iEventInfo.iDeviceId = %d" , dei.iDeviceId);
+ LOG1( "iEventInfo.iEventType = %d" , dei.iEventType);
+ LOG1( "iEventInfo.iError = %d" , dei.iError);
+ LOG1( "iEventInfo.iDriverLoadStatus = %d" , dei.iDriverLoadStatus);
+ LOG1( "iEventInfo.iVid = %d" , dei.iVid);
+ LOG1( "iEventInfo.iPid = %d" , dei.iPid);
// then process property change
switch (dei.iEventType)
{
case EDeviceAttachment:
{
- FLOG( _L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::RunL DeviceAttachment" ) );
+ LOG("DeviceAttachment" );
for (TInt i(0); i < iObservers.Count(); ++i)
{
@@ -181,7 +178,7 @@
case EDeviceDetachment:
{
- FLOG( _L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::RunL DeviceDetachment" ) );
+ LOG( "DeviceDetachment" );
for (TInt i(0); i < iObservers.Count(); ++i)
{
@@ -196,7 +193,7 @@
{
case EDriverLoadSuccess:
{
- FLOG( _L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::RunL DriverLoadSuccess" ) );
+ LOG( "DriverLoadSuccess" );
for (TInt i(0); i < iObservers.Count(); ++i)
{
@@ -207,7 +204,7 @@
}
case EDriverLoadPartialSuccess:
{
- FLOG( _L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::RunL DriverLoadPartialSuccess" ) );
+ LOG( "DriverLoadPartialSuccess" );
for (TInt i(0); i < iObservers.Count(); ++i)
{
@@ -218,7 +215,7 @@
}
case EDriverLoadFailure:
{
- FLOG( _L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::RunL DriverLoadFailure" ) );
+ LOG( "DriverLoadFailure");
for (TInt i(0); i < iObservers.Count(); ++i)
{
@@ -228,8 +225,8 @@
}
default:
{
- FLOG( _L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::RunL DriverLoadFailure WrongDriverLoadStatus" ) );
- Panic(EWrongDriverLoadStatus);
+ LOG("WrongDriverLoadStatus" );
+ Panic( EWrongDriverLoadStatus);
}
}
break;
@@ -237,8 +234,8 @@
}
default:
{
- FLOG( _L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::RunL WrongHostEventNotification" ) );
- Panic(EWrongHostEventNotification);
+ LOG( "WrongHostEventNotification" );
+ Panic( EWrongHostEventNotification);
}
}
@@ -260,8 +257,9 @@
//
TInt CUsbHostEventNotificationObserver::RunError(TInt aError)
{
+ LOG_FUNC
- FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::RunError aError = %d" ), aError));
+ LOG1( "aError = %d" , aError);
// try to recover and continue
return KErrNone;