usbengines/usbotgwatcher/src/cusbbusactivityobserver.cpp
changeset 25 8c311f9acc5e
parent 0 1e05558e2206
child 26 0ae0f29418cd
--- a/usbengines/usbotgwatcher/src/cusbbusactivityobserver.cpp	Tue Feb 02 00:52:37 2010 +0200
+++ b/usbengines/usbotgwatcher/src/cusbbusactivityobserver.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 CUsbBusActivityObserver::ConstructL()
     {
-
-        FLOG( _L( "[USBOTGWATCHER]\tCUsbBusActivityObserver::ConstructL" ) );
+    LOG_FUNC
 
     User::LeaveIfError(iBusActivity.Attach(KUidUsbManCategory,
             KUsbOtgConnectionIdleProperty));
@@ -54,8 +52,7 @@
 //
 CUsbBusActivityObserver* CUsbBusActivityObserver::NewL()
     {
-
-        FLOG( _L( "[USBOTGWATCHER]\tCUsbBusActivityObserver::NewL" ) );
+    LOG_FUNC
 
     CUsbBusActivityObserver* self = new (ELeave) CUsbBusActivityObserver();
     CleanupStack::PushL(self);
@@ -71,8 +68,7 @@
 CUsbBusActivityObserver::~CUsbBusActivityObserver()
 
     {
-
-        FLOG( _L( "[USBOTGWATCHER]\tCUsbBusActivityObserver::~CUsbBusActivityObserver" ) );
+    LOG_FUNC
 
     Cancel();
 
@@ -89,20 +85,16 @@
 CUsbBusActivityObserver::TBusActivity CUsbBusActivityObserver::BusActivity()
     {
 
-        FLOG( _L( "[USBOTGWATCHER]\tCUsbBusActivityObserver::BusActivity" ) );
-
     TInt val(0);
 
     TInt err = iBusActivity.Get(val);
 
     if (KErrNone != err)
         {
-            FLOG( _L( "[USBOTGWATCHER]\tCUsbBusActivityObserver::BusActivity CanNotGetBusActivityProperty" ) );
-        Panic(ECanNotGetBusActivityProperty);
+        LOG("ECanNotGetBusActivityProperty" );
+        Panic( ECanNotGetBusActivityProperty);
         }
 
-        FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbBusActivityObserver::State = %d" ), val ));
-
     return (0 == val ? EBusActive : EBusIdle);
 
     }
@@ -111,11 +103,18 @@
 // 
 // ---------------------------------------------------------------------------
 //
-void CUsbBusActivityObserver::SubscribeL(MUsbBusActivityObserver* aObserver)
+void CUsbBusActivityObserver::SubscribeL(MUsbBusActivityObserver& aObserver)
     {
-        FLOG( _L( "[USBOTGWATCHER]\tCUsbBusActivityObserver::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
         {
@@ -129,31 +128,21 @@
 // 
 // ---------------------------------------------------------------------------
 //
-void CUsbBusActivityObserver::UnsubscribeL(MUsbBusActivityObserver* aObserver)
+void CUsbBusActivityObserver::UnsubscribeL(MUsbBusActivityObserver& aObserver)
     {
-        FLOG( _L( "[USBOTGWATCHER]\tCUsbBusActivityObserver::UnsubscribeL" ) );
+    LOG_FUNC
 
-    if (0 == iObservers.Count()) // no items
+    TInt i(iObservers.Find(&aObserver));
+    if (KErrNotFound == i)
         {
-        FLOG( _L( "[USBOTGWATCHER]\tCUsbBusActivityObserver::UnsubscribeL No observers" ) );
+        LOG( "Observer not found" );
+        Panic( ECanNotFindBusActivityObserver);
         return;
         }
-        
-    TInt i(0);
-    while (i < iObservers.Count() && aObserver != iObservers[i])
-        ++i;
 
-    if (aObserver == iObservers[i]) // found
-        {
-        iObservers.Remove(i);
-        }
-    else
-        {
-            FLOG( _L( "[USBOTGWATCHER]\tCUsbBusActivityObserver::UnsubscribeL CanNotFindBusActivityObserver " ) );
-        Panic(ECanNotFindBusActivityObserver);
-        }
+    iObservers.Remove(i);
 
-    if (0 == iObservers.Count()) // no items
+    if (0 == iObservers.Count()) // no observers anymore
         {
         // cancel pending request
         Cancel();
@@ -166,15 +155,17 @@
 //
 void CUsbBusActivityObserver::RunL()
     {
-        FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbBusActivityObserver::RunL iStatus = %d" ), iStatus.Int()));
+    LOG_FUNC
+
+    LOG1( "iStatus = %d" , iStatus.Int());
 
     // if error occured, inform observers
-    if(KErrNone != iStatus.Int())
+    if (KErrNone != iStatus.Int())
         {
         for (TInt i(0); i < iObservers.Count(); ++i)
-                    {
-                    iObservers[i]->BusActivityErrorL(iStatus.Int());
-                    }
+            {
+            iObservers[i]->BusActivityErrorL(iStatus.Int());
+            }
         }
 
     // re-issue request first
@@ -188,7 +179,7 @@
         {
         case EBusIdle:
             {
-                FLOG( _L( "[USBOTGWATCHER]\tCUsbBusActivityObserver::RunL BusIdle" ) );
+            LOG("BusIdle");
 
             for (TInt i(0); i < iObservers.Count(); ++i)
                 {
@@ -199,7 +190,7 @@
 
         case EBusActive:
             {
-                FLOG( _L( "[USBOTGWATCHER]\tCUsbBusActivityObserver::RunL BusActive" ) );
+            LOG("BusActive");
 
             for (TInt i(0); i < iObservers.Count(); ++i)
                 {
@@ -210,8 +201,8 @@
 
         default:
             {
-                FLOG( _L( "[USBOTGWATCHER]\tCUsbBusActivityObserver::RunL BusActive WrongBusState" ) );
-            Panic(EWrongBusState);
+            LOG("WrongBusState" );
+            Panic( EWrongBusState);
             }
         }
 
@@ -232,9 +223,10 @@
 //
 TInt CUsbBusActivityObserver::RunError(TInt aError)
     {
+    LOG_FUNC
 
-    FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbBusActivityObserver::RunError aError = %d" ), aError));
-                  
+    LOG1( "aError = %d", aError );
+
     // try to continue	
     return KErrNone;