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