usbengines/usbotgwatcher/src/cusbidpinobserver.cpp
branchRCL_3
changeset 20 a15c582fbf97
parent 13 7068aba64af5
child 21 ff9df6630274
equal deleted inserted replaced
13:7068aba64af5 20:a15c582fbf97
     1 /*
     1 /*
     2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
     2  * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3  * All rights reserved.
     4 * This component and the accompanying materials are made available
     4  * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5  * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6  * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 *
     8  *
     9 * Initial Contributors:
     9  * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    10  * Nokia Corporation - initial contribution.
    11 *
    11  *
    12 * Contributors:
    12  * Contributors:
    13 *
    13  *
    14 * Description:  Implementation
    14  * Description:  Implementation
    15  *
    15  *
    16 */
    16  */
    17 
       
    18 
    17 
    19 #include <usbotgdefs.h>
    18 #include <usbotgdefs.h>
    20 
    19 
    21 #include "cusbidpinobserver.h"
    20 #include "cusbidpinobserver.h"
    22 
    21 
    38 // 
    37 // 
    39 // ---------------------------------------------------------------------------
    38 // ---------------------------------------------------------------------------
    40 //
    39 //
    41 void CUsbIdPinObserver::ConstructL()
    40 void CUsbIdPinObserver::ConstructL()
    42     {
    41     {
    43 
    42     LOG_FUNC
    44         FLOG( _L( "[USBOTGWATCHER]\tCUsbIdPinObserver::ConstructL" ) );
       
    45 
    43 
    46     User::LeaveIfError(iIdPin.Attach(KUidUsbManCategory,
    44     User::LeaveIfError(iIdPin.Attach(KUidUsbManCategory,
    47             KUsbOtgIdPinPresentProperty));
    45             KUsbOtgIdPinPresentProperty));
    48 
    46 
    49     }
    47     }
    52 // 
    50 // 
    53 // ---------------------------------------------------------------------------
    51 // ---------------------------------------------------------------------------
    54 //
    52 //
    55 CUsbIdPinObserver* CUsbIdPinObserver::NewL()
    53 CUsbIdPinObserver* CUsbIdPinObserver::NewL()
    56     {
    54     {
    57 
    55     LOG_FUNC
    58         FLOG( _L( "[USBOTGWATCHER]\tCUsbIdPinObserver::NewL" ) );
       
    59 
    56 
    60     CUsbIdPinObserver* self = new (ELeave) CUsbIdPinObserver();
    57     CUsbIdPinObserver* self = new (ELeave) CUsbIdPinObserver();
    61     CleanupStack::PushL(self);
    58     CleanupStack::PushL(self);
    62     self->ConstructL();
    59     self->ConstructL();
    63     CleanupStack::Pop(self);
    60     CleanupStack::Pop(self);
    68 // 
    65 // 
    69 // ---------------------------------------------------------------------------
    66 // ---------------------------------------------------------------------------
    70 //
    67 //
    71 CUsbIdPinObserver::~CUsbIdPinObserver()
    68 CUsbIdPinObserver::~CUsbIdPinObserver()
    72     {
    69     {
    73 
    70     LOG_FUNC
    74         FLOG( _L( "[USBOTGWATCHER]\tCUsbIdPinObserver::~CUsbIdPinObserver" ) );
       
    75 
    71 
    76     Cancel();
    72     Cancel();
    77 
    73 
    78     iIdPin.Close();
    74     iIdPin.Close();
    79 
    75 
    87 //
    83 //
    88 CUsbIdPinObserver::TState CUsbIdPinObserver::IdPin()
    84 CUsbIdPinObserver::TState CUsbIdPinObserver::IdPin()
    89 /* this getter is not const, because for some reason RProperty::Get is not const */
    85 /* this getter is not const, because for some reason RProperty::Get is not const */
    90     {
    86     {
    91 
    87 
    92         FLOG( _L( "[USBOTGWATCHER]\tCUsbIdPinObserver::IdPin" ) );
       
    93 
       
    94     TInt val(0);
    88     TInt val(0);
    95 
    89 
    96     TInt err = iIdPin.Get(val);
    90     TInt err = iIdPin.Get(val);
    97 
    91 
    98     if (KErrNone != err)
    92     if (KErrNone != err)
    99         {
    93         {
   100             FLOG( _L( "[USBOTGWATCHER]\tCUsbIdPinObserver::IdPin CanNotGetIdPinProperty" ) );
    94         LOG("CanNotGetIdPinProperty" );
   101         Panic(ECanNotGetIdPinProperty);
    95         Panic( ECanNotGetIdPinProperty);
   102         }
    96         }
   103 
       
   104         FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbIdPinObserver::IdPin = %d" ), val ));
       
   105 
    97 
   106     return (EFalse == val ? EIdPinOff : EIdPinOn);
    98     return (EFalse == val ? EIdPinOff : EIdPinOn);
   107     }
    99     }
   108 
   100 
   109 // ---------------------------------------------------------------------------
   101 // ---------------------------------------------------------------------------
   110 // 
   102 // 
   111 // ---------------------------------------------------------------------------
   103 // ---------------------------------------------------------------------------
   112 //   
   104 //   
   113 void CUsbIdPinObserver::SubscribeL(MUsbIdPinObserver& aObserver)
   105 void CUsbIdPinObserver::SubscribeL(MUsbIdPinObserver& aObserver)
   114     {
   106     {
   115         FLOG( _L( "[USBOTGWATCHER]\tCUsbIdPinObserver::SubscribeL" ) );
   107     LOG_FUNC
       
   108 
   116     // check if the same observer already exist in a list
   109     // check if the same observer already exist in a list
   117     if(KErrNotFound != iObservers.Find(&aObserver))
   110     if (KErrNotFound != iObservers.Find(&aObserver))
   118         {
   111         {
   119         FLOG( _L( "[USBOTGWATCHER]\tCUsbIdPinObserver::SubscribeL Observer already exists." ) );
   112         LOG("Observer already exists" );
   120         Panic(EObserverAlreadyExists);
   113         Panic( EObserverAlreadyExists);
   121         return;
   114         return;
   122         }
   115         }
   123     iObservers.AppendL(&aObserver);
   116     iObservers.AppendL(&aObserver);
   124 
   117 
   125     if (KFirst == iObservers.Count()) // first item
   118     if (KFirst == iObservers.Count()) // first item
   134 // 
   127 // 
   135 // ---------------------------------------------------------------------------
   128 // ---------------------------------------------------------------------------
   136 //
   129 //
   137 void CUsbIdPinObserver::UnsubscribeL(MUsbIdPinObserver& aObserver)
   130 void CUsbIdPinObserver::UnsubscribeL(MUsbIdPinObserver& aObserver)
   138     {
   131     {
   139     FLOG( _L( "[USBOTGWATCHER]\tCUsbIdPinObserver::UnsubscribeL" ) );
   132     LOG_FUNC
   140     
   133 
   141     TInt i(iObservers.Find(&aObserver));
   134     TInt i(iObservers.Find(&aObserver));
   142     if(KErrNotFound == i)
   135     if (KErrNotFound == i)
   143         {
   136         {
   144         FLOG( _L( "[USBOTGWATCHER]\tCUsbIdPinObserver::UnsubscribeL Observer not found." ) );
   137         LOG("Observer not found");
   145         Panic(ECanNotFindIdPinObserver);
   138         Panic( ECanNotFindIdPinObserver);
   146         return;
   139         return;
   147         }
   140         }
   148     
   141 
   149     iObservers.Remove(i);
   142     iObservers.Remove(i);
   150     
   143 
   151     if (0 == iObservers.Count()) // no observers anymore
   144     if (0 == iObservers.Count()) // no observers anymore
   152         {
   145         {
   153         // cancel pending request
   146         // cancel pending request
   154         Cancel();
   147         Cancel();
   155         }
   148         }
   159 //
   152 //
   160 // ---------------------------------------------------------------------------
   153 // ---------------------------------------------------------------------------
   161 //
   154 //
   162 void CUsbIdPinObserver::RunL()
   155 void CUsbIdPinObserver::RunL()
   163     {
   156     {
   164         FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbIdPinObserver::RunL iStatus = %d" ), iStatus.Int()));
   157     LOG_FUNC
   165 
   158 
   166         // if error occured, tell to Observers
   159     LOG1( "iStatus = %d" , iStatus.Int());
   167         if(KErrNone != iStatus.Int()) 
   160 
   168             {
   161     // if error occured, tell to Observers
   169             for (TInt i(0); i < iObservers.Count(); ++i)
   162     if (KErrNone != iStatus.Int())
   170                  {
   163         {
   171                  iObservers[i]->IdPinErrorL(iStatus.Int());
   164         for (TInt i(0); i < iObservers.Count(); ++i)
   172                  }
   165             {
   173             return;
   166             iObservers[i]->IdPinErrorL(iStatus.Int());
   174             }
   167             }
       
   168         return;
       
   169         }
   175 
   170 
   176     // re-issue request first
   171     // re-issue request first
   177     iIdPin.Subscribe(iStatus);
   172     iIdPin.Subscribe(iStatus);
   178     SetActive();
   173     SetActive();
   179 
   174 
   183     // report change   
   178     // report change   
   184     switch (state)
   179     switch (state)
   185         {
   180         {
   186         case EIdPinOn:
   181         case EIdPinOn:
   187             {
   182             {
   188                 FLOG(_L( "[USBOTGWATCHER]\tCUsbIdPinObserver::RunL IdPin ON"));
   183             LOG("IdPin ON");
   189 
   184 
   190             for (TInt i(0); i < iObservers.Count(); ++i)
   185             for (TInt i(0); i < iObservers.Count(); ++i)
   191                 {
   186                 {
   192                 iObservers[i]->IdPinOnL();
   187                 iObservers[i]->IdPinOnL();
   193                 }
   188                 }
   195             }
   190             }
   196             ;
   191             ;
   197 
   192 
   198         case EIdPinOff:
   193         case EIdPinOff:
   199             {
   194             {
   200                 FLOG(_L( "[USBOTGWATCHER]\tCUsbIdPinObserver::RunL IdPin OFF"));
   195             LOG("IdPin OFF");
   201 
   196 
   202             for (TInt i(0); i < iObservers.Count(); ++i)
   197             for (TInt i(0); i < iObservers.Count(); ++i)
   203                 {
   198                 {
   204                 iObservers[i]->IdPinOffL();
   199                 iObservers[i]->IdPinOffL();
   205                 }
   200                 }
   207             }
   202             }
   208             ;
   203             ;
   209 
   204 
   210         default:
   205         default:
   211             {
   206             {
   212                 FLOG(_L( "[USBOTGWATCHER]\tCUsbIdPinObserver::RunL WrongIdPinState"));
   207             LOG("WrongIdPinState");
   213             Panic(EWrongIdPinState);
   208             Panic( EWrongIdPinState);
   214             }
   209             }
   215         }
   210         }
   216 
   211 
   217     }
   212     }
   218 
   213 
   229 // 
   224 // 
   230 // ---------------------------------------------------------------------------
   225 // ---------------------------------------------------------------------------
   231 //
   226 //
   232 TInt CUsbIdPinObserver::RunError(TInt aError)
   227 TInt CUsbIdPinObserver::RunError(TInt aError)
   233     {
   228     {
   234 
   229     LOG_FUNC
   235         FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbIdPinObserver::RunError aError = %d" ), aError));
   230 
       
   231     LOG1( "aError = %d", aError);
   236 
   232 
   237     // try to continue	
   233     // try to continue	
   238     return KErrNone;
   234     return KErrNone;
   239 
   235 
   240     }
   236     }