usbengines/usbotgwatcher/src/cusbbusactivityobserver.cpp
branchRCL_3
changeset 64 8ecef05bbada
parent 0 1e05558e2206
child 20 a15c582fbf97
equal deleted inserted replaced
8:7e15987c4500 64:8ecef05bbada
    87 // ---------------------------------------------------------------------------
    87 // ---------------------------------------------------------------------------
    88 //
    88 //
    89 CUsbBusActivityObserver::TBusActivity CUsbBusActivityObserver::BusActivity()
    89 CUsbBusActivityObserver::TBusActivity CUsbBusActivityObserver::BusActivity()
    90     {
    90     {
    91 
    91 
    92         FLOG( _L( "[USBOTGWATCHER]\tCUsbBusActivityObserver::BusActivity" ) );
       
    93 
       
    94     TInt val(0);
    92     TInt val(0);
    95 
    93 
    96     TInt err = iBusActivity.Get(val);
    94     TInt err = iBusActivity.Get(val);
    97 
    95 
    98     if (KErrNone != err)
    96     if (KErrNone != err)
   109 
   107 
   110 // ---------------------------------------------------------------------------
   108 // ---------------------------------------------------------------------------
   111 // 
   109 // 
   112 // ---------------------------------------------------------------------------
   110 // ---------------------------------------------------------------------------
   113 //
   111 //
   114 void CUsbBusActivityObserver::SubscribeL(MUsbBusActivityObserver* aObserver)
   112 void CUsbBusActivityObserver::SubscribeL(MUsbBusActivityObserver& aObserver)
   115     {
   113     {
   116         FLOG( _L( "[USBOTGWATCHER]\tCUsbBusActivityObserver::SubscribeL" ) );
   114         FLOG( _L( "[USBOTGWATCHER]\tCUsbBusActivityObserver::SubscribeL" ) );
   117 
   115     // check if the same observer already exist in a list
   118     User::LeaveIfError(iObservers.Append(aObserver));
   116     if(KErrNotFound != iObservers.Find(&aObserver))
       
   117         {
       
   118         FLOG( _L( "[USBOTGWATCHER]\tCUsbIdPinObserver::SubscribeL Observer already exists." ) );
       
   119         Panic(EObserverAlreadyExists);
       
   120         return;
       
   121         }
       
   122     iObservers.AppendL(&aObserver);
   119 
   123 
   120     if (KFirst == iObservers.Count()) // first item
   124     if (KFirst == iObservers.Count()) // first item
   121         {
   125         {
   122         iBusActivity.Subscribe(iStatus);
   126         iBusActivity.Subscribe(iStatus);
   123         SetActive();
   127         SetActive();
   127 
   131 
   128 // ---------------------------------------------------------------------------
   132 // ---------------------------------------------------------------------------
   129 // 
   133 // 
   130 // ---------------------------------------------------------------------------
   134 // ---------------------------------------------------------------------------
   131 //
   135 //
   132 void CUsbBusActivityObserver::UnsubscribeL(MUsbBusActivityObserver* aObserver)
   136 void CUsbBusActivityObserver::UnsubscribeL(MUsbBusActivityObserver& aObserver)
   133     {
   137     {
   134         FLOG( _L( "[USBOTGWATCHER]\tCUsbBusActivityObserver::UnsubscribeL" ) );
   138         FLOG( _L( "[USBOTGWATCHER]\tCUsbBusActivityObserver::UnsubscribeL" ) );
   135 
   139 
   136     if (0 == iObservers.Count()) // no items
   140     TInt i(iObservers.Find(&aObserver));
   137         {
   141     if(KErrNotFound == i)
   138         FLOG( _L( "[USBOTGWATCHER]\tCUsbBusActivityObserver::UnsubscribeL No observers" ) );
   142         {
       
   143         FLOG( _L( "[USBOTGWATCHER]\tCUsbBusActivityObserver::UnsubscribeL Observer not found." ) );
       
   144         Panic(ECanNotFindIdPinObserver);
   139         return;
   145         return;
   140         }
   146         }
   141         
   147     
   142     TInt i(0);
   148     iObservers.Remove(i);
   143     while (i < iObservers.Count() && aObserver != iObservers[i])
   149     
   144         ++i;
   150     if (0 == iObservers.Count()) // no observers anymore
   145 
       
   146     if (aObserver == iObservers[i]) // found
       
   147         {
       
   148         iObservers.Remove(i);
       
   149         }
       
   150     else
       
   151         {
       
   152             FLOG( _L( "[USBOTGWATCHER]\tCUsbBusActivityObserver::UnsubscribeL CanNotFindBusActivityObserver " ) );
       
   153         Panic(ECanNotFindBusActivityObserver);
       
   154         }
       
   155 
       
   156     if (0 == iObservers.Count()) // no items
       
   157         {
   151         {
   158         // cancel pending request
   152         // cancel pending request
   159         Cancel();
   153         Cancel();
   160         }
   154         }
   161     }
   155     }