usbengines/usbotgwatcher/src/cusbhosteventnotificationobserver.cpp
branchRCL_3
changeset 64 8ecef05bbada
parent 0 1e05558e2206
child 20 a15c582fbf97
equal deleted inserted replaced
8:7e15987c4500 64:8ecef05bbada
    82 // ---------------------------------------------------------------------------
    82 // ---------------------------------------------------------------------------
    83 // 
    83 // 
    84 // ---------------------------------------------------------------------------
    84 // ---------------------------------------------------------------------------
    85 //
    85 //
    86 void CUsbHostEventNotificationObserver::SubscribeL(
    86 void CUsbHostEventNotificationObserver::SubscribeL(
    87         MUsbHostEventNotificationObserver* aObserver)
    87         MUsbHostEventNotificationObserver& aObserver)
    88     {
    88     {
    89         FLOG( _L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::SubscribeL" ) );
    89         FLOG( _L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::SubscribeL" ) );
    90 
    90 
    91     User::LeaveIfError(iObservers.Append(aObserver));
    91         // check if the same observer already exist in a list
       
    92         if(KErrNotFound != iObservers.Find(&aObserver))
       
    93             {
       
    94             FLOG( _L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::SubscribeL Observer already exists." ) );
       
    95             Panic(EObserverAlreadyExists);
       
    96             return;
       
    97             }
       
    98         
       
    99     iObservers.AppendL(&aObserver);
    92 
   100 
    93     if (KFirst == iObservers.Count()) // first item
   101     if (KFirst == iObservers.Count()) // first item
    94         {
   102         {
    95         iUsb->HostEventNotification(iStatus, iEventInfo);
   103         iUsb->HostEventNotification(iStatus, iEventInfo);
    96         SetActive();
   104         SetActive();
   101 // ---------------------------------------------------------------------------
   109 // ---------------------------------------------------------------------------
   102 // 
   110 // 
   103 // ---------------------------------------------------------------------------
   111 // ---------------------------------------------------------------------------
   104 //
   112 //
   105 void CUsbHostEventNotificationObserver::UnsubscribeL(
   113 void CUsbHostEventNotificationObserver::UnsubscribeL(
   106         MUsbHostEventNotificationObserver* aObserver)
   114         MUsbHostEventNotificationObserver& aObserver)
   107     {
   115     {
   108         FLOG( _L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::UnsubscribeL" ) );
   116         FLOG( _L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::UnsubscribeL" ) );
   109     if (0 == iObservers.Count()) // no items
   117         TInt i(iObservers.Find(&aObserver));
   110         {
   118         if(KErrNotFound == i)
   111         FLOG( _L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::UnsubscribeL No observers" ) );
   119                 {
   112         return;
   120                 FLOG( _L( "[USBOTGWATCHER]\tCUsbHostEventNotificationObserver::UnsubscribeL Observer not found." ) );
   113         }
   121                 Panic(ECanNotFindHostEventNotificationObserver);
   114         
   122                 return;
   115     TInt i(0);
   123                 }
   116     while (i < iObservers.Count() && aObserver != iObservers[i])
   124             
   117         ++i;
   125             iObservers.Remove(i);
   118 
   126             
   119     if (aObserver == iObservers[i]) // found
   127             if (0 == iObservers.Count()) // no observers anymore
   120         {
   128                 {
   121         iObservers.Remove(i);
   129                 // cancel pending request
   122         }
   130                 Cancel();
   123     else
   131                 }
   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     }
   132     }
   135 
   133 
   136 // ---------------------------------------------------------------------------
   134 // ---------------------------------------------------------------------------
   137 //
   135 //
   138 // ---------------------------------------------------------------------------
   136 // ---------------------------------------------------------------------------