usbengines/usbotgwatcher/src/cusbidpinobserver.cpp
branchRCL_3
changeset 64 8ecef05bbada
parent 0 1e05558e2206
child 20 a15c582fbf97
equal deleted inserted replaced
8:7e15987c4500 64:8ecef05bbada
   101         Panic(ECanNotGetIdPinProperty);
   101         Panic(ECanNotGetIdPinProperty);
   102         }
   102         }
   103 
   103 
   104         FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbIdPinObserver::IdPin = %d" ), val ));
   104         FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbIdPinObserver::IdPin = %d" ), val ));
   105 
   105 
   106     // not found in docs clear definition of this property. Verification is needed   
   106     return (EFalse == val ? EIdPinOff : EIdPinOn);
   107     return (0 == val ? EIdPinOff : EIdPinOn);
       
   108     }
   107     }
   109 
   108 
   110 // ---------------------------------------------------------------------------
   109 // ---------------------------------------------------------------------------
   111 // 
   110 // 
   112 // ---------------------------------------------------------------------------
   111 // ---------------------------------------------------------------------------
   113 //   
   112 //   
   114 void CUsbIdPinObserver::SubscribeL(MUsbIdPinObserver* aObserver)
   113 void CUsbIdPinObserver::SubscribeL(MUsbIdPinObserver& aObserver)
   115     {
   114     {
   116         FLOG( _L( "[USBOTGWATCHER]\tCUsbIdPinObserver::SubscribeL" ) );
   115         FLOG( _L( "[USBOTGWATCHER]\tCUsbIdPinObserver::SubscribeL" ) );
   117 
   116     // check if the same observer already exist in a list
   118     User::LeaveIfError(iObservers.Append(aObserver));
   117     if(KErrNotFound != iObservers.Find(&aObserver))
       
   118         {
       
   119         FLOG( _L( "[USBOTGWATCHER]\tCUsbIdPinObserver::SubscribeL Observer already exists." ) );
       
   120         Panic(EObserverAlreadyExists);
       
   121         return;
       
   122         }
       
   123     iObservers.AppendL(&aObserver);
   119 
   124 
   120     if (KFirst == iObservers.Count()) // first item
   125     if (KFirst == iObservers.Count()) // first item
   121         {
   126         {
   122         iIdPin.Subscribe(iStatus);
   127         iIdPin.Subscribe(iStatus);
   123         SetActive();
   128         SetActive();
   127 
   132 
   128 // ---------------------------------------------------------------------------
   133 // ---------------------------------------------------------------------------
   129 // 
   134 // 
   130 // ---------------------------------------------------------------------------
   135 // ---------------------------------------------------------------------------
   131 //
   136 //
   132 void CUsbIdPinObserver::UnsubscribeL(MUsbIdPinObserver* aObserver)
   137 void CUsbIdPinObserver::UnsubscribeL(MUsbIdPinObserver& aObserver)
   133     {
   138     {
   134         FLOG( _L( "[USBOTGWATCHER]\tCUsbIdPinObserver::UnsubscribeL" ) );
   139     FLOG( _L( "[USBOTGWATCHER]\tCUsbIdPinObserver::UnsubscribeL" ) );
   135     if (0 == iObservers.Count()) // no items
   140     
   136         {
   141     TInt i(iObservers.Find(&aObserver));
   137         FLOG( _L( "[USBOTGWATCHER]\tCUsbIdPinObserver::UnsubscribeL No observers" ) );
   142     if(KErrNotFound == i)
       
   143         {
       
   144         FLOG( _L( "[USBOTGWATCHER]\tCUsbIdPinObserver::UnsubscribeL Observer not found." ) );
       
   145         Panic(ECanNotFindIdPinObserver);
   138         return;
   146         return;
   139         }
   147         }
   140     
   148     
   141     TInt i(0);
   149     iObservers.Remove(i);
   142     while (i < iObservers.Count() && aObserver != iObservers[i])
   150     
   143         ++i;
   151     if (0 == iObservers.Count()) // no observers anymore
   144 
       
   145     if (aObserver == iObservers[i]) // found
       
   146         {
       
   147         iObservers.Remove(i);
       
   148         }
       
   149     else
       
   150         {
       
   151             FLOG( _L( "[USBOTGWATCHER]\tCUsbIdPinObserver::UnsubscribeL CanNotGetIdPinObserver" ) );
       
   152         Panic(ECanNotFindIdPinObserver);
       
   153         }
       
   154 
       
   155     if (0 == iObservers.Count()) // no items
       
   156         {
   152         {
   157         // cancel pending request
   153         // cancel pending request
   158         Cancel();
   154         Cancel();
   159         }
   155         }
   160     }
   156     }