usbengines/usbotgwatcher/src/cusbmessagenotificationobserver.cpp
branchRCL_3
changeset 65 a44cdf4b4bf0
parent 64 8ecef05bbada
child 21 ff9df6630274
equal deleted inserted replaced
64:8ecef05bbada 65:a44cdf4b4bf0
     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 <usbman.h>
    18 #include <usbman.h>
    20 #include <d32usbdi_errors.h>
    19 #include <d32usbdi_errors.h>
    21 #include <d32otgdi_errors.h>
    20 #include <d32otgdi_errors.h>
    22 
    21 
    40 // 
    39 // 
    41 // ---------------------------------------------------------------------------
    40 // ---------------------------------------------------------------------------
    42 //
    41 //
    43 void CUsbMessageNotificationObserver::ConstructL()
    42 void CUsbMessageNotificationObserver::ConstructL()
    44     {
    43     {
    45 
    44     LOG_FUNC
    46         FLOG( _L( "[USBOTGWATCHER]\tCUsbMessageNotificationObserver::ConstructL" ) );
       
    47 
    45 
    48     }
    46     }
    49 
    47 
    50 // ---------------------------------------------------------------------------
    48 // ---------------------------------------------------------------------------
    51 // 
    49 // 
    52 // ---------------------------------------------------------------------------
    50 // ---------------------------------------------------------------------------
    53 //
    51 //
    54 CUsbMessageNotificationObserver* CUsbMessageNotificationObserver::NewL(
    52 CUsbMessageNotificationObserver* CUsbMessageNotificationObserver::NewL(
    55         RUsb* aUsb)
    53         RUsb* aUsb)
    56     {
    54     {
    57 
    55     LOG_FUNC
    58         FLOG( _L( "[USBOTGWATCHER]\tCUsbMessageNotificationObserver::NewL" ) );
       
    59 
    56 
    60     CUsbMessageNotificationObserver* self =
    57     CUsbMessageNotificationObserver* self =
    61             new (ELeave) CUsbMessageNotificationObserver(aUsb);
    58             new (ELeave) CUsbMessageNotificationObserver(aUsb);
    62     CleanupStack::PushL(self);
    59     CleanupStack::PushL(self);
    63     self->ConstructL();
    60     self->ConstructL();
    69 // 
    66 // 
    70 // ---------------------------------------------------------------------------
    67 // ---------------------------------------------------------------------------
    71 //
    68 //
    72 CUsbMessageNotificationObserver::~CUsbMessageNotificationObserver()
    69 CUsbMessageNotificationObserver::~CUsbMessageNotificationObserver()
    73     {
    70     {
    74 
    71     LOG_FUNC
    75         FLOG( _L( "[USBOTGWATCHER]\tCUsbMessageNotificationObserver::~CUsbMessageNotificationObserver" ) );
       
    76 
    72 
    77     Cancel();
    73     Cancel();
    78 
    74 
    79     iObservers.Close();
    75     iObservers.Close();
    80 
    76 
    85 // ---------------------------------------------------------------------------
    81 // ---------------------------------------------------------------------------
    86 //
    82 //
    87 void CUsbMessageNotificationObserver::SubscribeL(
    83 void CUsbMessageNotificationObserver::SubscribeL(
    88         MUsbMessageNotificationObserver& aObserver)
    84         MUsbMessageNotificationObserver& aObserver)
    89     {
    85     {
    90         FLOG( _L( "[USBOTGWATCHER]\tCUsbMessageNotificationObserver::SubscribeL" ) );
    86     LOG_FUNC
    91 
    87 
    92         // check if the same observer already exist in a list
    88     // check if the same observer already exist in a list
    93         if(KErrNotFound != iObservers.Find(&aObserver))
    89     if (KErrNotFound != iObservers.Find(&aObserver))
    94             {
    90         {
    95             FLOG( _L( "[USBOTGWATCHER]\tCUsbMessageNotificationObserver::SubscribeL Observer already exists." ) );
    91         LOG("Observer already exists");
    96             Panic(EObserverAlreadyExists);
    92         Panic( EObserverAlreadyExists);
    97             return;
    93         return;
    98             }
    94         }
    99         iObservers.AppendL(&aObserver);
    95     iObservers.AppendL(&aObserver);
   100 
    96 
   101     if (KFirst == iObservers.Count()) // first item
    97     if (KFirst == iObservers.Count()) // first item
   102         {
    98         {
   103         iUsb->MessageNotification(iStatus, iMessage);
    99         iUsb->MessageNotification(iStatus, iMessage);
   104         SetActive();
   100         SetActive();
   110 // ---------------------------------------------------------------------------
   106 // ---------------------------------------------------------------------------
   111 //
   107 //
   112 void CUsbMessageNotificationObserver::UnsubscribeL(
   108 void CUsbMessageNotificationObserver::UnsubscribeL(
   113         MUsbMessageNotificationObserver& aObserver)
   109         MUsbMessageNotificationObserver& aObserver)
   114     {
   110     {
   115         FLOG( _L( "[USBOTGWATCHER]\tCUsbMessageNotificationObserver::UnsubscribeL" ) );
   111     LOG_FUNC
   116 
   112 
   117         TInt i(iObservers.Find(&aObserver));
   113     TInt i(iObservers.Find(&aObserver));
   118         if(KErrNotFound == i)
   114     if (KErrNotFound == i)
   119             {
   115         {
   120             FLOG( _L( "[USBOTGWATCHER]\tCUsbIdPinObserver::UnsubscribeL Observer not found." ) );
   116         LOG("Observer not found" )
   121             Panic(ECanNotFindMessageNotificationObserver);
   117         Panic( ECanNotFindMessageNotificationObserver);
   122             return;
   118         return;
   123             }
   119         }
   124         
   120 
   125         iObservers.Remove(i);
   121     iObservers.Remove(i);
   126 
   122 
   127     if (0 == iObservers.Count()) // no items
   123     if (0 == iObservers.Count()) // no items
   128         {
   124         {
   129         // cancel pending request
   125         // cancel pending request
   130         Cancel();
   126         Cancel();
   135 //
   131 //
   136 // ---------------------------------------------------------------------------
   132 // ---------------------------------------------------------------------------
   137 //
   133 //
   138 void CUsbMessageNotificationObserver::RunL()
   134 void CUsbMessageNotificationObserver::RunL()
   139     {
   135     {
       
   136     // Log the event
       
   137     LOG1( "Message notification observer iMessage = %d" , iMessage);
       
   138 
   140     // if error occured, tell to Observers
   139     // if error occured, tell to Observers
   141     if(KErrNone != iStatus.Int()) 
   140     if (KErrNone != iStatus.Int())
   142         {
   141         {
   143         for (TInt i(0); i < iObservers.Count(); ++i)
   142         for (TInt i(0); i < iObservers.Count(); ++i)
   144              {
   143             {
   145              iObservers[i]->MessageNotificationErrorL(iStatus.Int());
   144             iObservers[i]->MessageNotificationErrorL(iStatus.Int());
   146              }
   145             }
   147         return;
   146         return;
   148         }
   147         }
   149 
   148 
   150     TInt message(iMessage);
   149     TInt message(iMessage);
   151 
   150 
   152     // re-issue request first
   151     // re-issue request first
   153     iUsb->MessageNotification(iStatus, iMessage);
   152     iUsb->MessageNotification(iStatus, iMessage);
   154     SetActive();
   153     SetActive();
   155 
   154 
   156         // Log the event
       
   157         FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbMessageNotificationObserver::RunL iMessage = %d" ), message));
       
   158 
       
   159     // then process property change
   155     // then process property change
   160     switch (message)
   156     switch (message)
   161         {
   157         {
   162         case KErrUsbBadHubPosition:
   158         case KErrUsbBadHubPosition:
   163             {
   159             {
   164                 FLOG( _L( "[USBOTGWATCHER]\tCUsbMessageNotificationObserver::RunL HubBadPosition" ) );
   160             LOG("HubBadPosition" );
   165 
   161 
   166             for (TInt i(0); i < iObservers.Count(); ++i)
   162             for (TInt i(0); i < iObservers.Count(); ++i)
   167                 {
   163                 {
   168                 iObservers[i]->BadHubPositionL();
   164                 iObservers[i]->BadHubPositionL();
   169                 }
   165                 }
   170             break;
   166             break;
   171             }
   167             }
   172         case KErrUsbOtgVbusError:
   168         case KErrUsbOtgVbusError:
   173             {
   169             {
   174                 FLOG( _L( "[USBOTGWATCHER]\tCUsbMessageNotificationObserver::RunL VBusError" ) );
   170             LOG( "VBusError");
   175 
   171 
   176             for (TInt i(0); i < iObservers.Count(); ++i)
   172             for (TInt i(0); i < iObservers.Count(); ++i)
   177                 {
   173                 {
   178                 iObservers[i]->VBusErrorL();
   174                 iObservers[i]->VBusErrorL();
   179                 }
   175                 }
   180             break;
   176             break;
   181             }
   177             }
   182         case KUsbMessageSrpReceived:
   178         case KUsbMessageSrpReceived:
   183             {
   179             {
   184                 FLOG( _L( "[USBOTGWATCHER]\tCUsbMessageNotificationObserver::RunL SRP received" ) );
   180             LOG("SRP received" );
   185 
   181 
   186             for (TInt i(0); i < iObservers.Count(); ++i)
   182             for (TInt i(0); i < iObservers.Count(); ++i)
   187                 {
   183                 {
   188                 iObservers[i]->SrpReceivedL();
   184                 iObservers[i]->SrpReceivedL();
   189                 }
   185                 }
   190             break;
   186             break;
   191             }
   187             }
   192         case KUsbMessageRequestSession:
   188         case KUsbMessageRequestSession:
   193             {
   189             {
   194                 FLOG( _L( "[USBOTGWATCHER]\tCUsbMessageNotificationObserver::RunL Session Requested" ) );
   190             LOG("Session requested" );
   195 
   191 
   196             for (TInt i(0); i < iObservers.Count(); ++i)
   192             for (TInt i(0); i < iObservers.Count(); ++i)
   197                 {
   193                 {
   198                 iObservers[i]->SessionRequestedL();
   194                 iObservers[i]->SessionRequestedL();
   199                 }
   195                 }
   200             break;
   196             break;
   201             }
   197             }
   202             // notify states with other messages  
   198             // notify states with other messages  
   203         default:
   199         default:
   204             {
   200             {
       
   201 
   205             for (TInt i(0); i < iObservers.Count(); ++i)
   202             for (TInt i(0); i < iObservers.Count(); ++i)
   206                 {
   203                 {
   207                 iObservers[i]->MessageNotificationReceivedL(message);
   204                 iObservers[i]->MessageNotificationReceivedL(message);
   208                 }
   205                 }
   209             break;
   206             break;
   226 // 
   223 // 
   227 // ---------------------------------------------------------------------------
   224 // ---------------------------------------------------------------------------
   228 //
   225 //
   229 TInt CUsbMessageNotificationObserver::RunError(TInt aError)
   226 TInt CUsbMessageNotificationObserver::RunError(TInt aError)
   230     {
   227     {
   231 
   228     LOG_FUNC
   232         FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbMessageNotificationObserver::RunError aError = %d" ), aError));
   229 
       
   230     LOG1( "aError = %d" , aError);
   233 
   231 
   234     // try to recover and continue	
   232     // try to recover and continue	
   235     return KErrNone;
   233     return KErrNone;
   236 
   234 
   237     }
   235     }