usbengines/usbotgwatcher/src/cusbhosteventnotificationobserver.cpp
changeset 0 1e05558e2206
child 5 7068aba64af5
equal deleted inserted replaced
-1:000000000000 0:1e05558e2206
       
     1 /*
       
     2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Implementation
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 #include <usbman.h>
       
    20 
       
    21 #include "cusbhosteventnotificationobserver.h"
       
    22 
       
    23 #include "definitions.h"
       
    24 #include "debug.h"
       
    25 #include "panic.h"
       
    26 
       
    27 // ---------------------------------------------------------------------------
       
    28 // 
       
    29 // ---------------------------------------------------------------------------
       
    30 //
       
    31 CUsbHostEventNotificationObserver::CUsbHostEventNotificationObserver(
       
    32         RUsb* aUsb) :
       
    33     CActive(EPriorityStandard), iUsb(aUsb)
       
    34     {
       
    35     CActiveScheduler::Add(this);
       
    36     }
       
    37 
       
    38 // ---------------------------------------------------------------------------
       
    39 // 
       
    40 // ---------------------------------------------------------------------------
       
    41 //
       
    42 void CUsbHostEventNotificationObserver::ConstructL()
       
    43     {
       
    44 
       
    45         FLOG( _L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::ConstructL" ) );
       
    46 
       
    47     }
       
    48 
       
    49 // ---------------------------------------------------------------------------
       
    50 // 
       
    51 // ---------------------------------------------------------------------------
       
    52 //
       
    53 CUsbHostEventNotificationObserver* CUsbHostEventNotificationObserver::NewL(
       
    54         RUsb* aUsb)
       
    55     {
       
    56 
       
    57         FLOG( _L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::NewL" ) );
       
    58 
       
    59     CUsbHostEventNotificationObserver* self =
       
    60             new (ELeave) CUsbHostEventNotificationObserver(aUsb);
       
    61     CleanupStack::PushL(self);
       
    62     self->ConstructL();
       
    63     CleanupStack::Pop(self);
       
    64     return self;
       
    65     }
       
    66 
       
    67 // ---------------------------------------------------------------------------
       
    68 // 
       
    69 // ---------------------------------------------------------------------------
       
    70 //
       
    71 CUsbHostEventNotificationObserver::~CUsbHostEventNotificationObserver()
       
    72     {
       
    73 
       
    74         FLOG( _L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::~CUsbHostEventNotificationObserver" ) );
       
    75 
       
    76     Cancel();
       
    77 
       
    78     iObservers.Close();
       
    79 
       
    80     }
       
    81 
       
    82 // ---------------------------------------------------------------------------
       
    83 // 
       
    84 // ---------------------------------------------------------------------------
       
    85 //
       
    86 void CUsbHostEventNotificationObserver::SubscribeL(
       
    87         MUsbHostEventNotificationObserver* aObserver)
       
    88     {
       
    89         FLOG( _L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::SubscribeL" ) );
       
    90 
       
    91     User::LeaveIfError(iObservers.Append(aObserver));
       
    92 
       
    93     if (KFirst == iObservers.Count()) // first item
       
    94         {
       
    95         iUsb->HostEventNotification(iStatus, iEventInfo);
       
    96         SetActive();
       
    97 
       
    98         }
       
    99     }
       
   100 
       
   101 // ---------------------------------------------------------------------------
       
   102 // 
       
   103 // ---------------------------------------------------------------------------
       
   104 //
       
   105 void CUsbHostEventNotificationObserver::UnsubscribeL(
       
   106         MUsbHostEventNotificationObserver* aObserver)
       
   107     {
       
   108         FLOG( _L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::UnsubscribeL" ) );
       
   109     if (0 == iObservers.Count()) // no items
       
   110         {
       
   111         FLOG( _L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::UnsubscribeL No observers" ) );
       
   112         return;
       
   113         }
       
   114         
       
   115     TInt i(0);
       
   116     while (i < iObservers.Count() && aObserver != iObservers[i])
       
   117         ++i;
       
   118 
       
   119     if (aObserver == iObservers[i]) // found
       
   120         {
       
   121         iObservers.Remove(i);
       
   122         }
       
   123     else
       
   124         {
       
   125             FLOG( _L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::UnsubscribeL CanNotFindIdPinObserver" ) );
       
   126         Panic(ECanNotFindIdPinObserver);
       
   127         }
       
   128 
       
   129     if (0 == iObservers.Count()) // no items
       
   130         {
       
   131         // cancel pending request
       
   132         Cancel();
       
   133         }
       
   134     }
       
   135 
       
   136 // ---------------------------------------------------------------------------
       
   137 //
       
   138 // ---------------------------------------------------------------------------
       
   139 //
       
   140 void CUsbHostEventNotificationObserver::RunL()
       
   141     {
       
   142         FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::RunL iStatus = %d" ), iStatus.Int()));
       
   143 
       
   144         // if error occured, tell to Observers
       
   145         if(KErrNone != iStatus.Int()) 
       
   146             {
       
   147             for (TInt i(0); i < iObservers.Count(); ++i)
       
   148                  {
       
   149                  iObservers[i]->HostEventNotificationErrorL(iStatus.Int());
       
   150                  }
       
   151             return;
       
   152             }
       
   153 
       
   154     TDeviceEventInformation dei(iEventInfo);
       
   155 
       
   156     // re-issue request first
       
   157     iUsb->HostEventNotification(iStatus, iEventInfo);
       
   158     SetActive();
       
   159 
       
   160         // Log the event
       
   161         FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::RunL iEventInfo.iDeviceId         = %d" ), dei.iDeviceId));
       
   162         FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::RunL iEventInfo.iEventType        = %d" ), dei.iEventType));
       
   163         FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::RunL iEventInfo.iError            = %d" ), dei.iError));
       
   164         FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::RunL iEventInfo.iDriverLoadStatus = %d" ), dei.iDriverLoadStatus));
       
   165         FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::RunL iEventInfo.iVid              = %d" ), dei.iVid));
       
   166         FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::RunL iEventInfo.iPid              = %d" ), dei.iPid));
       
   167 
       
   168     // then process property change
       
   169     switch (dei.iEventType)
       
   170         {
       
   171         case EDeviceAttachment:
       
   172             {
       
   173                 FLOG( _L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::RunL DeviceAttachment" ) );
       
   174 
       
   175             for (TInt i(0); i < iObservers.Count(); ++i)
       
   176                 {
       
   177                 iObservers[i]->DeviceAttachedL(dei);
       
   178                 }
       
   179             break;
       
   180             }
       
   181 
       
   182         case EDeviceDetachment:
       
   183             {
       
   184                 FLOG( _L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::RunL DeviceDetachment" ) );
       
   185 
       
   186             for (TInt i(0); i < iObservers.Count(); ++i)
       
   187                 {
       
   188                 iObservers[i]->DeviceDetachedL(dei);
       
   189                 }
       
   190             break;
       
   191             }
       
   192 
       
   193         case EDriverLoad:
       
   194             {
       
   195             switch (dei.iDriverLoadStatus)
       
   196                 {
       
   197                 case EDriverLoadSuccess:
       
   198                     {
       
   199                         FLOG( _L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::RunL DriverLoadSuccess" ) );
       
   200 
       
   201                     for (TInt i(0); i < iObservers.Count(); ++i)
       
   202                         {
       
   203                         iObservers[i]->DriverLoadSuccessL(dei);
       
   204                         }
       
   205 
       
   206                     break;
       
   207                     }
       
   208                 case EDriverLoadPartialSuccess:
       
   209                     {
       
   210                         FLOG( _L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::RunL DriverLoadPartialSuccess" ) );
       
   211 
       
   212                     for (TInt i(0); i < iObservers.Count(); ++i)
       
   213                         {
       
   214                         iObservers[i]->DriverLoadPartialSuccessL(dei);
       
   215                         }
       
   216                     break;
       
   217 
       
   218                     }
       
   219                 case EDriverLoadFailure:
       
   220                     {
       
   221                         FLOG( _L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::RunL DriverLoadFailure" ) );
       
   222 
       
   223                     for (TInt i(0); i < iObservers.Count(); ++i)
       
   224                         {
       
   225                         iObservers[i]->DriverLoadFailureL(dei);
       
   226                         }
       
   227                     break;
       
   228                     }
       
   229                 default:
       
   230                     {
       
   231                         FLOG( _L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::RunL DriverLoadFailure WrongDriverLoadStatus" ) );
       
   232                     Panic(EWrongDriverLoadStatus);
       
   233                     }
       
   234                 }
       
   235             break;
       
   236 
       
   237             }
       
   238         default:
       
   239             {
       
   240                 FLOG( _L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::RunL WrongHostEventNotification" ) );
       
   241             Panic(EWrongHostEventNotification);
       
   242             }
       
   243 
       
   244         }
       
   245 
       
   246     }
       
   247 
       
   248 // ---------------------------------------------------------------------------
       
   249 // 
       
   250 // ---------------------------------------------------------------------------
       
   251 //
       
   252 void CUsbHostEventNotificationObserver::DoCancel()
       
   253     {
       
   254     iUsb->HostEventNotificationCancel();
       
   255     }
       
   256 
       
   257 // ---------------------------------------------------------------------------
       
   258 // 
       
   259 // ---------------------------------------------------------------------------
       
   260 //
       
   261 TInt CUsbHostEventNotificationObserver::RunError(TInt aError)
       
   262     {
       
   263 
       
   264         FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::RunError aError = %d" ), aError));
       
   265 
       
   266     // try to recover and continue	
       
   267     return KErrNone;
       
   268 
       
   269     }
       
   270