--- a/usbengines/usbotgwatcher/src/cusbvbusobserver.cpp Tue Feb 02 00:52:37 2010 +0200
+++ b/usbengines/usbotgwatcher/src/cusbvbusobserver.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 <usbotgdefs.h>
@@ -40,8 +39,7 @@
//
void CUsbVBusObserver::ConstructL()
{
-
- FLOG( _L( "[USBOTGWATCHER]\tCUsbVBusObserver::ConstructL" ) );
+ LOG_FUNC
User::LeaveIfError(iVBus.Attach(KUidUsbManCategory,
KUsbOtgVBusPoweredProperty));
@@ -54,8 +52,7 @@
//
CUsbVBusObserver* CUsbVBusObserver::NewL()
{
-
- FLOG( _L( "[USBOTGWATCHER]\tCUsbVBusObserver::NewL" ) );
+ LOG_FUNC
CUsbVBusObserver* self = new (ELeave) CUsbVBusObserver();
CleanupStack::PushL(self);
@@ -70,8 +67,7 @@
//
CUsbVBusObserver::~CUsbVBusObserver()
{
-
- FLOG( _L( "[USBOTGWATCHER]\tCUsbVBusObserver::~CUsbVBusObserver" ) );
+ LOG_FUNC
Cancel();
@@ -85,24 +81,19 @@
//
// ---------------------------------------------------------------------------
//
-CUsbVBusObserver::TState CUsbVBusObserver::VBus() /* not const, because for some reason RProperty::Get is not const! */
+CUsbVBusObserver::TState CUsbVBusObserver::VBus() /* not const, because for some reason RProperty::Get is not const */
{
- FLOG( _L( "[USBOTGWATCHER]\tCUsbVBusObserver::VBus" ) );
-
TInt val(0);
TInt err = iVBus.Get(val);
if (KErrNone != err)
{
- FLOG( _L( "[USBOTGWATCHER]\tCUsbVBusObserver::VBus CanNotGetVBusProperty" ) );
- Panic(ECanNotGetVBusProperty);
+ LOG("CanNotGetVBusProperty" )
+ Panic( ECanNotGetVBusProperty);
}
- FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbVBusObserver::VBus = %d" ), val ));
-
- // not found in docs clear definition of this property. Verification is needed
return (0 == val ? EVBusDown : EVBusUp);
}
@@ -110,13 +101,19 @@
//
// ---------------------------------------------------------------------------
//
-void CUsbVBusObserver::SubscribeL(MUsbVBusObserver* aObserver)
+void CUsbVBusObserver::SubscribeL(MUsbVBusObserver& aObserver)
{
- FLOG( _L( "[USBOTGWATCHER]\tCUsbVBusObserver::SubscribeL" ) );
+ LOG_FUNC
- User::LeaveIfError(iObservers.Append(aObserver));
-
- FLOG( _L( "[USBOTGWATCHER]\tCUsbVBusObserver::SubscribeL Observer appended." ) );
+ // 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
{
@@ -129,39 +126,24 @@
//
// ---------------------------------------------------------------------------
//
-void CUsbVBusObserver::UnsubscribeL(MUsbVBusObserver* aObserver)
+void CUsbVBusObserver::UnsubscribeL(MUsbVBusObserver& aObserver)
{
- FLOG( _L( "[USBOTGWATCHER]\tCUsbVBusObserver::UnsubscribeL" ) );
-
- if (0 == iObservers.Count()) // no items
+ LOG_FUNC
+
+ TInt i(iObservers.Find(&aObserver));
+ if (KErrNotFound == i)
{
- FLOG( _L( "[USBOTGWATCHER]\tCUsbVBusObserver::UnsubscribeL No observers" ) );
+ LOG("Observer not found" );
+ Panic( ECanNotFindVBusObserver);
return;
}
-
- TInt i(0);
- while (i < iObservers.Count() && aObserver != iObservers[i])
- {
- ++i;
- FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbVBusObserver::UnsubscribeL i = %d" ), i ));
- }
- if (aObserver == iObservers[i]) // found
- {
- FLOG( _L( "[USBOTGWATCHER]\tCUsbVBusObserver::UnsubscribeL Removing item" ) );
- iObservers.Remove(i);
- }
- else
- {
- FLOG( _L( "[USBOTGWATCHER]\tCUsbVBusObserver::UnsubscribeL CanNotFindVBusObserver" ) );
- Panic(ECanNotFindVBusObserver);
- }
-
+ iObservers.Remove(i);
+
if (0 == iObservers.Count()) // no observers anymore
{
// cancel pending request, if any
Cancel();
- return;
}
}
@@ -171,17 +153,19 @@
//
void CUsbVBusObserver::RunL()
{
- FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbVBusObserver::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]->VBusObserverErrorL(iStatus.Int());
- }
- return;
+ iObservers[i]->VBusObserverErrorL(iStatus.Int());
}
+ return;
+ }
// re-issue request first
iVBus.Subscribe(iStatus);
@@ -195,7 +179,7 @@
{
case EVBusUp:
{
- FLOG(_L( "[USBOTGWATCHER]\tCUsbVBusObserver::RunL VBus UP"));
+ LOG("VBus UP");
for (TInt i(0); i < iObservers.Count(); ++i)
{
@@ -207,7 +191,7 @@
case EVBusDown:
{
- FLOG(_L( "[USBOTGWATCHER]\tCUsbVBusObserver::RunL VBus DOWN"));
+ LOG("VBus DOWN");
for (TInt i(0); i < iObservers.Count(); ++i)
{
@@ -219,7 +203,8 @@
default:
{
- Panic(EWrongVBusState);
+ LOG("WrongVBusState");
+ Panic( EWrongVBusState);
}
}
@@ -240,8 +225,9 @@
//
TInt CUsbVBusObserver::RunError(TInt aError)
{
+ LOG_FUNC
- FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbVBusObserver::RunError aError = %d" ), aError));
+ LOG1( "aError = %d" , aError);
// try to continue
return KErrNone;