usbengines/usbotgwatcher/src/cusbindicatornotifier.cpp
branchRCL_3
changeset 20 a15c582fbf97
parent 13 7068aba64af5
child 21 ff9df6630274
equal deleted inserted replaced
13:7068aba64af5 20:a15c582fbf97
     1 /*
     1 /*
     2 * Copyright (c) 2009 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".
     8 *
     8  *
     9 * Initial Contributors:
     9  * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    10  * Nokia Corporation - initial contribution.
    11 *
    11  *
    12 * Contributors:
    12  * Contributors:
    13 *
    13  *
    14 * Description:  Blink/show Usb indicator notifier implementation
    14  * Description:  Blink/show Usb indicator notifier implementation
    15  *
    15  *
    16 */
    16  */
    17 
       
    18 
    17 
    19 #include <AknSmallIndicator.h>
    18 #include <AknSmallIndicator.h>
    20 #include <avkon.hrh>
    19 #include <avkon.hrh>
    21 #include <usbuinotif.h>
    20 #include <usbuinotif.h>
    22 
    21 
    31 
    30 
    32 // -----------------------------------------------------------------------------
    31 // -----------------------------------------------------------------------------
    33 // Two-phased constructor.
    32 // Two-phased constructor.
    34 // -----------------------------------------------------------------------------
    33 // -----------------------------------------------------------------------------
    35 //
    34 //
    36 CUsbIndicatorNotifier* CUsbIndicatorNotifier::NewL(CUsbNotifManager* aNotifManager, CUsbOtgWatcher* aOtgWatcher)
    35 CUsbIndicatorNotifier* CUsbIndicatorNotifier::NewL(
    37     {
    36         CUsbNotifManager& aNotifManager, CUsbOtgWatcher& aOtgWatcher)
    38     FLOG( _L( "[USBOTGWATCHER]\tCUsbIndicatorNotifier::NewL" ));
    37     {
    39 
    38     LOG_FUNC
    40     CUsbIndicatorNotifier* self = new (ELeave) CUsbIndicatorNotifier(aNotifManager, aOtgWatcher);
    39 
       
    40     CUsbIndicatorNotifier* self = new (ELeave) CUsbIndicatorNotifier(
       
    41             aNotifManager, aOtgWatcher);
    41     CleanupStack::PushL(self);
    42     CleanupStack::PushL(self);
    42     self->ConstructL();
    43     self->ConstructL();
    43     CleanupStack::Pop(self);
    44     CleanupStack::Pop(self);
    44     return self;
    45     return self;
    45     }
    46     }
    48 // Destructor
    49 // Destructor
    49 // ---------------------------------------------------------------------------
    50 // ---------------------------------------------------------------------------
    50 //
    51 //
    51 CUsbIndicatorNotifier::~CUsbIndicatorNotifier()
    52 CUsbIndicatorNotifier::~CUsbIndicatorNotifier()
    52     {
    53     {
    53     FLOG( _L( "[USBOTGWATCHER]\tCUsbIndicatorNotifier::~CUsbIndicatorNotifier" ) );
    54     LOG_FUNC
    54         
    55 
    55     Close();
    56     Close();
    56     delete iIconBlinkingTimer;
    57     delete iIconBlinkingTimer;
    57     
    58 
    58     // Unsubscribe from VBus change notifications
    59     if (iOtgWatcher.VBusObserver())
    59     if(iOtgWatcher)
    60         {
    60         {
    61         TRAP_IGNORE(iOtgWatcher.VBusObserver()->UnsubscribeL(*this));
    61         if(iOtgWatcher->VBusObserver())
    62         }
    62             {
    63 
    63             TRAP_IGNORE(iOtgWatcher->VBusObserver()->UnsubscribeL(*this));
    64     // Unsubscribe from otg watcher states change notifications
    64             }
    65     TRAP_IGNORE(iOtgWatcher.UnsubscribeL(*this));
    65         
       
    66         // Unsubscribe from otg watcher states change notifications
       
    67         TRAP_IGNORE(iOtgWatcher->UnsubscribeL(*this));
       
    68         }
       
    69     }
    66     }
    70 
    67 
    71 // ---------------------------------------------------------------------------
    68 // ---------------------------------------------------------------------------
    72 // C++ constructor
    69 // C++ constructor
    73 // ---------------------------------------------------------------------------
    70 // ---------------------------------------------------------------------------
    74 //
    71 //
    75 CUsbIndicatorNotifier::CUsbIndicatorNotifier(CUsbNotifManager* aNotifManager, CUsbOtgWatcher* aOtgWatcher) :
    72 CUsbIndicatorNotifier::CUsbIndicatorNotifier(CUsbNotifManager& aNotifManager,
    76     CUsbNotifier(aNotifManager, KUsbUiNotifOtgIndicator, NULL), iOtgWatcher(aOtgWatcher)
    73         CUsbOtgWatcher& aOtgWatcher) :
    77     {
    74     CUsbNotifier(aNotifManager, KUsbUiNotifOtgIndicator, NULL), iOtgWatcher(
    78     FLOG( _L( "[USBOTGWATCHER]\tCUsbIndicatorNotifier::CUsbIndicatorNotifier" ) );
    75             aOtgWatcher)
       
    76     {
       
    77     LOG_FUNC
    79 
    78 
    80     //To be changed to EAknIndicatorStateAnimate and remove iIconBlinkingTimer
    79     //To be changed to EAknIndicatorStateAnimate and remove iIconBlinkingTimer
    81     //when AVKON implements animation form of usb indicator.
    80     //when AVKON implements animation form of usb indicator.
    82     iIndicatorState = EAknIndicatorStateOn;
    81     iIndicatorState = EAknIndicatorStateOn;
    83     }
    82     }
    86 // Second-phase constructor
    85 // Second-phase constructor
    87 // ---------------------------------------------------------------------------
    86 // ---------------------------------------------------------------------------
    88 //
    87 //
    89 void CUsbIndicatorNotifier::ConstructL()
    88 void CUsbIndicatorNotifier::ConstructL()
    90     {
    89     {
    91     FLOG( _L( "[USBOTGWATCHER]\tCUsbIndicatorNotifier::ConstructL" ) );
    90     LOG_FUNC
    92     
    91 
    93     // Subscribe for VBus change notifications
    92     // Subscribe for VBus change notifications
    94     iOtgWatcher->VBusObserver()->SubscribeL(*this);
    93     iOtgWatcher.VBusObserver()->SubscribeL(*this);
    95     
    94 
    96     // Subscribe for otg watcher states change notifications
    95     // Subscribe for otg watcher states change notifications
    97     iOtgWatcher->SubscribeL(*this);
    96     iOtgWatcher.SubscribeL(*this);
    98 
    97 
    99     iIconBlinkingTimer = CUsbTimer::NewL(this, EIconBlinkingTimer);
    98     iIconBlinkingTimer = CUsbTimer::NewL(*this, EIconBlinkingTimer);
   100     
    99 
   101     // check here for condition to set usb indicator
   100     // check here for condition to set usb indicator
   102     SetIndicatorL();
   101     SetIndicatorL();
   103 
   102 
   104     }
   103     }
   105 
   104 
   109 // form of the indicator.
   108 // form of the indicator.
   110 // ---------------------------------------------------------------------------
   109 // ---------------------------------------------------------------------------
   111 //
   110 //
   112 void CUsbIndicatorNotifier::ShowStaticL(TBool aVisible)
   111 void CUsbIndicatorNotifier::ShowStaticL(TBool aVisible)
   113     {
   112     {
   114     FTRACE( FPrint (_L( "[USBOTGWATCHER]\tCUsbIndicatorNotifier::ShowStaticL, aVisible=%d" ), aVisible));
   113     LOG_FUNC
       
   114 
       
   115     LOG1("aVisible = %d" , aVisible);
   115 
   116 
   116     iIconBlinkingTimer->Cancel();
   117     iIconBlinkingTimer->Cancel();
   117 
   118 
   118     SetIndicatorStateL(aVisible ? EAknIndicatorStateOn : EAknIndicatorStateOff);    
   119     SetIndicatorStateL(aVisible
       
   120                                 ? EAknIndicatorStateOn
       
   121                                    : EAknIndicatorStateOff);
   119     }
   122     }
   120 
   123 
   121 // ---------------------------------------------------------------------------
   124 // ---------------------------------------------------------------------------
   122 // 
   125 // 
   123 // ---------------------------------------------------------------------------
   126 // ---------------------------------------------------------------------------
   124 //
   127 //
   125 void CUsbIndicatorNotifier::BlinkL()
   128 void CUsbIndicatorNotifier::BlinkL()
   126     {
   129     {
   127     FLOG( _L( "[USBOTGWATCHER]\tCUsbIndicatorNotifier::BlinkL" ));
   130     LOG_FUNC
   128 
   131 
   129     // Will be canceled if active in After()
   132     // Will be canceled if active in After()
   130     iIconBlinkingTimer->After(0);
   133     iIconBlinkingTimer->After(0);
   131     }
   134     }
   132 
   135 
   134 // From base class CUsbNotifier
   137 // From base class CUsbNotifier
   135 // ---------------------------------------------------------------------------
   138 // ---------------------------------------------------------------------------
   136 //
   139 //
   137 void CUsbIndicatorNotifier::ShowL()
   140 void CUsbIndicatorNotifier::ShowL()
   138     {
   141     {
   139     FLOG( _L( "[USBOTGWATCHER]\tCUsbIndicatorNotifier::ShowL" ) );
   142     LOG_FUNC
   140     
   143 
   141     ShowStaticL(ETrue);
   144     ShowStaticL(ETrue);
   142     }
   145     }
   143 
   146 
   144 // ---------------------------------------------------------------------------
   147 // ---------------------------------------------------------------------------
   145 // From CUsbNotifier
   148 // From CUsbNotifier
   146 // ---------------------------------------------------------------------------
   149 // ---------------------------------------------------------------------------
   147 //
   150 //
   148 void CUsbIndicatorNotifier::Close()
   151 void CUsbIndicatorNotifier::Close()
   149     {
   152     {
   150     FLOG( _L( "[USBOTGWATCHER]\tCUsbIndicatorNotifier::Close" ) );
   153     LOG_FUNC
   151     
   154 
   152     iIconBlinkingTimer->Cancel();
   155     iIconBlinkingTimer->Cancel();
   153     TRAP_IGNORE( ShowStaticL(EFalse) );
   156     TRAP_IGNORE( ShowStaticL(EFalse) );
   154     }
   157     }
   155 
   158 
   156 // ---------------------------------------------------------------------------
   159 // ---------------------------------------------------------------------------
   161     {
   164     {
   162     switch (aTimerId)
   165     switch (aTimerId)
   163         {
   166         {
   164         case EIconBlinkingTimer:
   167         case EIconBlinkingTimer:
   165             {
   168             {
   166             SetIndicatorStateL(iIndicatorState ? EAknIndicatorStateOn : EAknIndicatorStateOff);    
   169             SetIndicatorStateL(iIndicatorState
   167 
   170                                                ? EAknIndicatorStateOn
   168             iIndicatorState = (iIndicatorState == EAknIndicatorStateOn
   171                                                   : EAknIndicatorStateOff);
   169                                     ? EAknIndicatorStateOff : EAknIndicatorStateOn);
   172 
       
   173             iIndicatorState
       
   174                     = (iIndicatorState == EAknIndicatorStateOn
       
   175                                                                ? EAknIndicatorStateOff
       
   176                                                                   : EAknIndicatorStateOn);
   170 
   177 
   171             // Will be canceled if active in After()
   178             // Will be canceled if active in After()
   172             iIconBlinkingTimer->After(KUsbIndicatorBlinkingInterval);
   179             iIconBlinkingTimer->After(KUsbIndicatorBlinkingInterval);
   173             break;
   180             break;
   174             }
   181             }
   175         default:
   182         default:
   176             {
   183             {
   177             FLOG( _L( "[USBOTGWATCHER]\tCUsbIndicatorNotifier::TimerElapsedL - Unknown timer" ) );
   184             LOG1("Unknown timer id = %d", aTimerId)
   178             
       
   179             Panic(EWrongTimerId);
   185             Panic(EWrongTimerId);
   180             }
   186             }
   181         }
   187         }
   182     }
   188     }
   183 
   189 
   185 // Set USB indicator On or Off
   191 // Set USB indicator On or Off
   186 // ---------------------------------------------------------------------------
   192 // ---------------------------------------------------------------------------
   187 //
   193 //
   188 void CUsbIndicatorNotifier::SetIndicatorStateL(const TInt aState)
   194 void CUsbIndicatorNotifier::SetIndicatorStateL(const TInt aState)
   189     {
   195     {
   190     FTRACE( FPrint (_L( "[USBOTGWATCHER]\tCUsbIndicatorNotifier::SetIndicatorStateL - aState=%d" ), aState));
   196 
   191 
   197     LOG1( "USB indicator State = %d" , aState);
   192     CAknSmallIndicator* indicator = CAknSmallIndicator::NewLC(TUid::Uid(EAknIndicatorUSBConnection));
   198 
   193     indicator->SetIndicatorStateL( aState );
   199     CAknSmallIndicator* indicator = CAknSmallIndicator::NewLC(TUid::Uid(
   194     CleanupStack::PopAndDestroy( indicator ); //indicator    
   200             EAknIndicatorUSBConnection));
       
   201     indicator->SetIndicatorStateL(aState);
       
   202     CleanupStack::PopAndDestroy(indicator); //indicator    
   195     }
   203     }
   196 
   204 
   197 // ---------------------------------------------------------------------------
   205 // ---------------------------------------------------------------------------
   198 // 
   206 // 
   199 // ---------------------------------------------------------------------------
   207 // ---------------------------------------------------------------------------
   200 //
   208 //
   201 void CUsbIndicatorNotifier::OtgWatcherStateChangedL(TUsbStateIds aState)
   209 void CUsbIndicatorNotifier::OtgWatcherStateChangedL(TUsbStateIds aState)
   202     {
   210     {
   203     FTRACE( FPrint (_L( "[USBOTGWATCHER]\tCUsbIndicatorNotifier::OtgWatcherStateChangedL - aState=%d" ), aState));
       
   204     SetIndicatorL();
   211     SetIndicatorL();
   205     }
   212     }
   206 
   213 
   207 // ---------------------------------------------------------------------------
   214 // ---------------------------------------------------------------------------
   208 // 
   215 // 
   209 // ---------------------------------------------------------------------------
   216 // ---------------------------------------------------------------------------
   210 //
   217 //
   211 void CUsbIndicatorNotifier::VBusDownL()
   218 void CUsbIndicatorNotifier::VBusDownL()
   212     {
   219     {
   213     FLOG( _L( "[USBOTGWATCHER]\tCUsbIndicatorNotifier::VBusDownL" ) );
       
   214     SetIndicatorL();
   220     SetIndicatorL();
   215     }
   221     }
   216 
   222 
   217 // ---------------------------------------------------------------------------
   223 // ---------------------------------------------------------------------------
   218 // 
   224 // 
   219 // ---------------------------------------------------------------------------
   225 // ---------------------------------------------------------------------------
   220 //
   226 //
   221 void CUsbIndicatorNotifier::VBusUpL()
   227 void CUsbIndicatorNotifier::VBusUpL()
   222     {
   228     {
   223     FLOG( _L( "[USBOTGWATCHER]\tCUsbIndicatorNotifier::VBusUpL" ) );
       
   224     SetIndicatorL();
   229     SetIndicatorL();
   225     }
   230     }
   226 
   231 
   227 // ---------------------------------------------------------------------------
   232 // ---------------------------------------------------------------------------
   228 // 
   233 // 
   229 // ---------------------------------------------------------------------------
   234 // ---------------------------------------------------------------------------
   230 //  
   235 //  
   231 void CUsbIndicatorNotifier::VBusObserverErrorL(TInt aError)
   236 void CUsbIndicatorNotifier::VBusObserverErrorL(TInt aError)
   232     {
   237     {
   233     FLOG( _L( "[USBOTGWATCHER]\tCUsbIndicatorNotifier::VBusObserverErrorL" ) );
   238     // do nothing
   234     // do not care
       
   235     }
   239     }
   236 
   240 
   237 // ---------------------------------------------------------------------------
   241 // ---------------------------------------------------------------------------
   238 // 
   242 // 
   239 // ---------------------------------------------------------------------------
   243 // ---------------------------------------------------------------------------
   240 //  
   244 //  
   241 void CUsbIndicatorNotifier::SetIndicatorL()
   245 void CUsbIndicatorNotifier::SetIndicatorL()
   242     {
   246     {
   243     FLOG( _L( "[USBOTGWATCHER]\tCUsbIndicatorNotifier::SetIndicatorL" ) );
   247     if (!(iOtgWatcher.IsDeviceA()))
   244     
       
   245     if (!(iOtgWatcher->IsDeviceA()))
       
   246         {
   248         {
   247         // if B, than other party (usbwatcher) takes care of usb indicator
   249         // if B, than other party (usbwatcher) takes care of usb indicator
   248         // in combined usbwatcher (if role swap allowed) one class has to manage usb indicator 
   250         // in combined usbwatcher (if role swap allowed) one class has to manage usb indicator 
   249         return;
   251         return;
   250         }
   252         }
   251     
   253 
   252     // if VBus Up and we are host -> show indicator
   254     // if VBus Up and we are host -> show indicator
   253     if ((iOtgWatcher->VBusObserver()->VBus() == CUsbVBusObserver::EVBusUp) &&
   255     if ((iOtgWatcher.VBusObserver()->VBus() == CUsbVBusObserver::EVBusUp)
   254             (iOtgWatcher->CurrentHostState()->Id() == EUsbStateHostAHost))
   256             && (iOtgWatcher.CurrentHostState()->Id() == EUsbStateHostAHost))
   255         {
   257         {
   256         ShowStaticL(ETrue);
   258         ShowStaticL(ETrue);
   257         }
   259         }
   258     // if VBus up and we are not host -> Blink indicator
   260     // if VBus up and we are not host -> Blink indicator
   259     else if((iOtgWatcher->VBusObserver()->VBus() == CUsbVBusObserver::EVBusUp) &&
   261     else if ((iOtgWatcher.VBusObserver()->VBus() == CUsbVBusObserver::EVBusUp)
   260             (iOtgWatcher->CurrentHostState()->Id() != EUsbStateHostAHost))
   262             && (iOtgWatcher.CurrentHostState()->Id() != EUsbStateHostAHost))
   261         {
   263         {
   262         BlinkL();
   264         BlinkL();
   263         }
   265         }
   264     else
   266     else
   265     // Otherwise do not show indicator
   267     // Otherwise do not show indicator