--- a/usbengines/usbotgwatcher/src/cusbmessagenotificationobserver.cpp Tue Feb 02 00:52:37 2010 +0200
+++ b/usbengines/usbotgwatcher/src/cusbmessagenotificationobserver.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>
#include <d32usbdi_errors.h>
@@ -22,7 +21,7 @@
#include "cusbmessagenotificationobserver.h"
-#include "definitions.h"
+#include "definitions.h"
#include "debug.h"
#include "panic.h"
@@ -42,8 +41,7 @@
//
void CUsbMessageNotificationObserver::ConstructL()
{
-
- FLOG( _L( "[USBOTGWATCHER]\tCUsbMessageNotificationObserver::ConstructL" ) );
+ LOG_FUNC
}
@@ -54,8 +52,7 @@
CUsbMessageNotificationObserver* CUsbMessageNotificationObserver::NewL(
RUsb* aUsb)
{
-
- FLOG( _L( "[USBOTGWATCHER]\tCUsbMessageNotificationObserver::NewL" ) );
+ LOG_FUNC
CUsbMessageNotificationObserver* self =
new (ELeave) CUsbMessageNotificationObserver(aUsb);
@@ -71,8 +68,7 @@
//
CUsbMessageNotificationObserver::~CUsbMessageNotificationObserver()
{
-
- FLOG( _L( "[USBOTGWATCHER]\tCUsbMessageNotificationObserver::~CUsbMessageNotificationObserver" ) );
+ LOG_FUNC
Cancel();
@@ -85,11 +81,18 @@
// ---------------------------------------------------------------------------
//
void CUsbMessageNotificationObserver::SubscribeL(
- MUsbMessageNotificationObserver* aObserver)
+ MUsbMessageNotificationObserver& aObserver)
{
- FLOG( _L( "[USBOTGWATCHER]\tCUsbMessageNotificationObserver::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,29 +106,19 @@
// ---------------------------------------------------------------------------
//
void CUsbMessageNotificationObserver::UnsubscribeL(
- MUsbMessageNotificationObserver* aObserver)
+ MUsbMessageNotificationObserver& aObserver)
{
- FLOG( _L( "[USBOTGWATCHER]\tCUsbMessageNotificationObserver::UnsubscribeL" ) );
+ LOG_FUNC
- if (0 == iObservers.Count()) // no items
- {
- FLOG( _L( "[USBOTGWATCHER]\tCUsbMessageNotificationObserver::UnsubscribeL No observers" ) );
- return;
- }
-
- TInt i(0);
- while (i < iObservers.Count() && aObserver != iObservers[i])
- ++i;
+ TInt i(iObservers.Find(&aObserver));
+ if (KErrNotFound == i)
+ {
+ LOG("Observer not found" )
+ Panic( ECanNotFindMessageNotificationObserver);
+ return;
+ }
- if (aObserver == iObservers[i]) // found
- {
- iObservers.Remove(i);
- }
- else
- {
- FLOG( _L( "[USBOTGWATCHER]\tCUsbMessageNotificationObserver::UnsubscribeL CanNotFindMessageNotificationObserver" ) );
- Panic(ECanNotFindMessageNotificationObserver);
- }
+ iObservers.Remove(i);
if (0 == iObservers.Count()) // no items
{
@@ -140,13 +133,16 @@
//
void CUsbMessageNotificationObserver::RunL()
{
+ // Log the event
+ LOG1( "Message notification observer iMessage = %d" , iMessage);
+
// if error occured, tell to Observers
- if(KErrNone != iStatus.Int())
+ if (KErrNone != iStatus.Int())
{
for (TInt i(0); i < iObservers.Count(); ++i)
- {
- iObservers[i]->MessageNotificationErrorL(iStatus.Int());
- }
+ {
+ iObservers[i]->MessageNotificationErrorL(iStatus.Int());
+ }
return;
}
@@ -156,15 +152,12 @@
iUsb->MessageNotification(iStatus, iMessage);
SetActive();
- // Log the event
- FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbMessageNotificationObserver::RunL iMessage = %d" ), message));
-
// then process property change
switch (message)
{
case KErrUsbBadHubPosition:
{
- FLOG( _L( "[USBOTGWATCHER]\tCUsbMessageNotificationObserver::RunL HubBadPosition" ) );
+ LOG("HubBadPosition" );
for (TInt i(0); i < iObservers.Count(); ++i)
{
@@ -174,7 +167,7 @@
}
case KErrUsbOtgVbusError:
{
- FLOG( _L( "[USBOTGWATCHER]\tCUsbMessageNotificationObserver::RunL VBusError" ) );
+ LOG( "VBusError");
for (TInt i(0); i < iObservers.Count(); ++i)
{
@@ -184,7 +177,7 @@
}
case KUsbMessageSrpReceived:
{
- FLOG( _L( "[USBOTGWATCHER]\tCUsbMessageNotificationObserver::RunL SRP received" ) );
+ LOG("SRP received" );
for (TInt i(0); i < iObservers.Count(); ++i)
{
@@ -194,7 +187,7 @@
}
case KUsbMessageRequestSession:
{
- FLOG( _L( "[USBOTGWATCHER]\tCUsbMessageNotificationObserver::RunL Session Requested" ) );
+ LOG("Session requested" );
for (TInt i(0); i < iObservers.Count(); ++i)
{
@@ -205,6 +198,7 @@
// notify states with other messages
default:
{
+
for (TInt i(0); i < iObservers.Count(); ++i)
{
iObservers[i]->MessageNotificationReceivedL(message);
@@ -231,8 +225,9 @@
//
TInt CUsbMessageNotificationObserver::RunError(TInt aError)
{
+ LOG_FUNC
- FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbMessageNotificationObserver::RunError aError = %d" ), aError));
+ LOG1( "aError = %d" , aError);
// try to recover and continue
return KErrNone;