usbengines/usbotgwatcher/src/cusbindicatornotifier.cpp
branchRCL_3
changeset 80 e02eb84a14d2
parent 79 25fce757be94
equal deleted inserted replaced
79:25fce757be94 80:e02eb84a14d2
     1 /*
     1 /*
     2  * Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
     2  * Copyright (c) 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".
    13  *
    13  *
    14  * Description:  Blink/show Usb indicator notifier implementation
    14  * Description:  Blink/show Usb indicator notifier implementation
    15  *
    15  *
    16  */
    16  */
    17 
    17 
       
    18 #include <AknSmallIndicator.h>
       
    19 #include <avkon.hrh>
    18 #include <usbuinotif.h>
    20 #include <usbuinotif.h>
    19 #include <hb/hbcore/hbindicatorsymbian.h>
       
    20 
    21 
    21 #include "cusbindicatornotifier.h"
    22 #include "cusbindicatornotifier.h"
    22 #include "cusbstate.h"
    23 #include "cusbstate.h"
    23 #include "definitions.h"
    24 #include "definitions.h"
    24 
    25 
    59         TRAP_IGNORE(iOtgWatcher.VBusObserver()->UnsubscribeL(*this));
    60         TRAP_IGNORE(iOtgWatcher.VBusObserver()->UnsubscribeL(*this));
    60         }
    61         }
    61 
    62 
    62     // Unsubscribe from otg watcher states change notifications
    63     // Unsubscribe from otg watcher states change notifications
    63     TRAP_IGNORE(iOtgWatcher.UnsubscribeL(*this));
    64     TRAP_IGNORE(iOtgWatcher.UnsubscribeL(*this));
    64 
       
    65     delete iUsbConnectingIndicator; 
       
    66     }
    65     }
    67 
    66 
    68 // ---------------------------------------------------------------------------
    67 // ---------------------------------------------------------------------------
    69 // C++ constructor
    68 // C++ constructor
    70 // ---------------------------------------------------------------------------
    69 // ---------------------------------------------------------------------------
    71 //
    70 //
    72 CUsbIndicatorNotifier::CUsbIndicatorNotifier(CUsbNotifManager& aNotifManager,
    71 CUsbIndicatorNotifier::CUsbIndicatorNotifier(CUsbNotifManager& aNotifManager,
    73         CUsbOtgWatcher& aOtgWatcher) :
    72         CUsbOtgWatcher& aOtgWatcher) :
    74         iOtgWatcher(aOtgWatcher)
    73     CUsbNotifier(aNotifManager, KUsbUiNotifOtgIndicator, NULL), iOtgWatcher(
    75     {
    74             aOtgWatcher)
    76     LOG_FUNC
    75     {
    77     
    76     LOG_FUNC
       
    77 
       
    78     //To be changed to EAknIndicatorStateAnimate and remove iIconBlinkingTimer
       
    79     //when AVKON implements animation form of usb indicator.
       
    80     iIndicatorState = EAknIndicatorStateOn;
    78     }
    81     }
    79 
    82 
    80 // ---------------------------------------------------------------------------
    83 // ---------------------------------------------------------------------------
    81 // Second-phase constructor
    84 // Second-phase constructor
    82 // ---------------------------------------------------------------------------
    85 // ---------------------------------------------------------------------------
    83 //
    86 //
    84 void CUsbIndicatorNotifier::ConstructL()
    87 void CUsbIndicatorNotifier::ConstructL()
    85     {
    88     {
    86     LOG_FUNC
    89     LOG_FUNC
    87 
    90 
    88     iUsbConnectingIndicator = CHbIndicatorSymbian::NewL();
       
    89     
       
    90     // Subscribe for VBus change notifications
    91     // Subscribe for VBus change notifications
    91     iOtgWatcher.VBusObserver()->SubscribeL(*this);
    92     iOtgWatcher.VBusObserver()->SubscribeL(*this);
    92 
    93 
    93     // Subscribe for otg watcher states change notifications
    94     // Subscribe for otg watcher states change notifications
    94     iOtgWatcher.SubscribeL(*this);
    95     iOtgWatcher.SubscribeL(*this);
    95 
    96 
    96     iConnectingIndicatorOn = EFalse;
       
    97 
       
    98     // check here for condition to set usb indicator
    97     // check here for condition to set usb indicator
    99     SetIndicator();
    98     SetIndicatorL();
   100    
    99     }
   101     }
   100 
   102 
   101 // ---------------------------------------------------------------------------
       
   102 // Show/hide static icon of the indicator. 
       
   103 // If the indicator is blinking, stop blinking it and show/hide the static 
       
   104 // form of the indicator.
       
   105 // ---------------------------------------------------------------------------
       
   106 //
       
   107 void CUsbIndicatorNotifier::ShowStaticL(TBool aVisible)
       
   108     {
       
   109     LOG_FUNC
       
   110 
       
   111     LOG1("aVisible = %d" , aVisible);
       
   112 
       
   113     SetIndicatorStateL(aVisible
       
   114                                 ? EAknIndicatorStateOn
       
   115                                    : EAknIndicatorStateOff);
       
   116     }
       
   117 
       
   118 // ---------------------------------------------------------------------------
       
   119 // 
       
   120 // ---------------------------------------------------------------------------
       
   121 //
       
   122 void CUsbIndicatorNotifier::BlinkL()
       
   123     {
       
   124     LOG_FUNC
       
   125 
       
   126     SetIndicatorStateL( EAknIndicatorStateAnimate );
       
   127     }
       
   128 
       
   129 // ---------------------------------------------------------------------------
       
   130 // From base class CUsbNotifier
       
   131 // ---------------------------------------------------------------------------
       
   132 //
       
   133 void CUsbIndicatorNotifier::ShowL()
       
   134     {
       
   135     LOG_FUNC
       
   136 
       
   137     ShowStaticL(ETrue);
       
   138     }
   103 
   139 
   104 // ---------------------------------------------------------------------------
   140 // ---------------------------------------------------------------------------
   105 // From CUsbNotifier
   141 // From CUsbNotifier
   106 // ---------------------------------------------------------------------------
   142 // ---------------------------------------------------------------------------
   107 //
   143 //
   108 void CUsbIndicatorNotifier::Close()
   144 void CUsbIndicatorNotifier::Close()
   109     {
   145     {
   110     LOG_FUNC
   146     LOG_FUNC
   111 
   147 
   112     ToggleConnectingIndicator( EFalse );
   148     TRAP_IGNORE( ShowStaticL(EFalse) );
   113     }
   149     }
   114 
   150 
   115 // ---------------------------------------------------------------------------
   151 // ---------------------------------------------------------------------------
   116 // Set USB indicator On or Off
   152 // Set USB indicator On or Off
   117 // ---------------------------------------------------------------------------
   153 // ---------------------------------------------------------------------------
   118 //
   154 //
   119 void CUsbIndicatorNotifier::ToggleConnectingIndicator(TBool aEnable)
   155 void CUsbIndicatorNotifier::SetIndicatorStateL(const TInt aState)
   120     {
   156     {
   121     LOG1( "toggle connecting indicator = %d" , aEnable);
   157 
   122     
   158     LOG1( "USB indicator State = %d" , aState);
   123     TBool success = ETrue;
   159 
   124     
   160     CAknSmallIndicator* indicator = CAknSmallIndicator::NewLC(TUid::Uid(
   125     if (aEnable && !iConnectingIndicatorOn)
   161             EAknIndicatorUSBConnection));
   126         {
   162     indicator->SetIndicatorStateL(aState);
   127         success = iUsbConnectingIndicator->Activate(KUsbConnectingIndicator);   
   163     CleanupStack::PopAndDestroy(indicator); //indicator    
   128         LOG1( "calling CHbIndicatorSymbian::Activate(), returned %d", success);   
   164     }
   129         if (success)
   165 
   130             {
       
   131             iConnectingIndicatorOn = ETrue;
       
   132             }  
       
   133                    
       
   134         }
       
   135    
       
   136     if (!aEnable && iConnectingIndicatorOn)
       
   137         {
       
   138         success = iUsbConnectingIndicator->Deactivate(KUsbConnectingIndicator); 
       
   139         if (success)
       
   140             {
       
   141             iConnectingIndicatorOn = EFalse;
       
   142             }  
       
   143         LOG1( "calling CHbIndicatorSymbian::Deactivate(), returned %d", success);                  
       
   144         }   
       
   145         
       
   146     // if success became false loading the indicator failed, log the error    
       
   147     if (!success)
       
   148         {
       
   149         TInt error = iUsbConnectingIndicator->Error();
       
   150         LOG1( "indicator error is %d", error);       
       
   151         }         
       
   152     }
       
   153        
       
   154 // ---------------------------------------------------------------------------
   166 // ---------------------------------------------------------------------------
   155 // 
   167 // 
   156 // ---------------------------------------------------------------------------
   168 // ---------------------------------------------------------------------------
   157 //
   169 //
   158 void CUsbIndicatorNotifier::OtgWatcherStateChangedL(TUsbStateIds aState)
   170 void CUsbIndicatorNotifier::OtgWatcherStateChangedL(TUsbStateIds aState)
   159     {
   171     {
   160      LOG_FUNC
   172     SetIndicatorL();
   161     SetIndicator();
       
   162     }
   173     }
   163 
   174 
   164 // ---------------------------------------------------------------------------
   175 // ---------------------------------------------------------------------------
   165 // 
   176 // 
   166 // ---------------------------------------------------------------------------
   177 // ---------------------------------------------------------------------------
   167 //
   178 //
   168 void CUsbIndicatorNotifier::VBusDownL()
   179 void CUsbIndicatorNotifier::VBusDownL()
   169     {
   180     {
   170      LOG_FUNC
   181     SetIndicatorL();
   171     SetIndicator();
       
   172     }
   182     }
   173 
   183 
   174 // ---------------------------------------------------------------------------
   184 // ---------------------------------------------------------------------------
   175 // 
   185 // 
   176 // ---------------------------------------------------------------------------
   186 // ---------------------------------------------------------------------------
   177 //
   187 //
   178 void CUsbIndicatorNotifier::VBusUpL()
   188 void CUsbIndicatorNotifier::VBusUpL()
   179     {
   189     {
   180      LOG_FUNC
   190     SetIndicatorL();
   181     SetIndicator();
       
   182     }
   191     }
   183 
   192 
   184 // ---------------------------------------------------------------------------
   193 // ---------------------------------------------------------------------------
   185 // 
   194 // 
   186 // ---------------------------------------------------------------------------
   195 // ---------------------------------------------------------------------------
   187 //  
   196 //  
   188 void CUsbIndicatorNotifier::VBusObserverErrorL(TInt aError)
   197 void CUsbIndicatorNotifier::VBusObserverErrorL(TInt aError)
   189     {
   198     {
   190     LOG_FUNC
       
   191     // do nothing
   199     // do nothing
   192     }
   200     }
   193 
   201 
   194 // ---------------------------------------------------------------------------
   202 // ---------------------------------------------------------------------------
   195 // 
   203 // 
   196 // ---------------------------------------------------------------------------
   204 // ---------------------------------------------------------------------------
   197 //  
   205 //  
   198 void CUsbIndicatorNotifier::SetIndicator()
   206 void CUsbIndicatorNotifier::SetIndicatorL()
   199     {
   207     {
   200     LOG_FUNC
       
   201     if (!(iOtgWatcher.IsDeviceA()) || iOtgWatcher.CurrentHostState()->Id() == EUsbStateHostAPeripheral)
   208     if (!(iOtgWatcher.IsDeviceA()) || iOtgWatcher.CurrentHostState()->Id() == EUsbStateHostAPeripheral)
   202         {
   209         {
   203         // if B or peripheral, than other party (usbwatcher) takes care of usb indicator
   210         // if B or peripheral, than other party (usbwatcher) takes care of usb indicator
   204         // in combined usbwatcher (if role swap allowed) one class has to manage usb indicator 
   211         // in combined usbwatcher (if role swap allowed) one class has to manage usb indicator 
   205         return;
   212         return;
   206         }
   213         }
   207 
   214 
   208     // if VBus up and we are not host -> show connecting indicator
   215     // if VBus Up and we are host -> show indicator
   209     if ((iOtgWatcher.VBusObserver()->VBus() == CUsbVBusObserver::EVBusUp)
   216     if ((iOtgWatcher.VBusObserver()->VBus() == CUsbVBusObserver::EVBusUp)
       
   217             && (iOtgWatcher.CurrentHostState()->Id() == EUsbStateHostAHost))
       
   218         {
       
   219         ShowStaticL(ETrue);
       
   220         }
       
   221     // if VBus up and we are not host -> Blink indicator
       
   222     else if ((iOtgWatcher.VBusObserver()->VBus() == CUsbVBusObserver::EVBusUp)
   210             && (iOtgWatcher.CurrentHostState()->Id() != EUsbStateHostAHost))
   223             && (iOtgWatcher.CurrentHostState()->Id() != EUsbStateHostAHost))
   211         {
   224         {
   212         ToggleConnectingIndicator( ETrue );
   225         BlinkL();
   213         }
   226         }
   214     else
   227     else
   215     // Otherwise do not show indicator
   228     // Otherwise do not show indicator
   216         {
   229         {
   217         ToggleConnectingIndicator( EFalse );
   230         ShowStaticL(EFalse);
   218         }
   231         }
   219     }
   232     }
   220 
   233 
   221 // End of file
   234 // End of file