usbengines/usbotgwatcher/src/cusbindicatornotifier.cpp
changeset 1 705ec7b86991
parent 0 1e05558e2206
child 3 47c263f7e521
equal deleted inserted replaced
0:1e05558e2206 1:705ec7b86991
    19 #include <AknSmallIndicator.h>
    19 #include <AknSmallIndicator.h>
    20 #include <avkon.hrh>
    20 #include <avkon.hrh>
    21 #include <usbuinotif.h>
    21 #include <usbuinotif.h>
    22 
    22 
    23 #include "cusbindicatornotifier.h"
    23 #include "cusbindicatornotifier.h"
    24 #include "cusbnotifier.h"
    24 #include "cusbstate.h"
    25 #include "definitions.h"
    25 #include "definitions.h"
    26 
    26 
    27 #include "debug.h"
    27 #include "debug.h"
    28 #include "panic.h"
    28 #include "panic.h"
    29 
    29 
    31 
    31 
    32 // -----------------------------------------------------------------------------
    32 // -----------------------------------------------------------------------------
    33 // Two-phased constructor.
    33 // Two-phased constructor.
    34 // -----------------------------------------------------------------------------
    34 // -----------------------------------------------------------------------------
    35 //
    35 //
    36 CUsbIndicatorNotifier* CUsbIndicatorNotifier::NewL(CUsbNotifManager* aNotifManager)
    36 CUsbIndicatorNotifier* CUsbIndicatorNotifier::NewL(CUsbNotifManager* aNotifManager, CUsbOtgWatcher* aOtgWatcher)
    37     {
    37     {
    38     FLOG( _L( "[USBOTGWATCHER]\tCUsbIndicatorNotifier::NewL" ));
    38     FLOG( _L( "[USBOTGWATCHER]\tCUsbIndicatorNotifier::NewL" ));
    39 
    39 
    40     CUsbIndicatorNotifier* self = new (ELeave) CUsbIndicatorNotifier(aNotifManager);
    40     CUsbIndicatorNotifier* self = new (ELeave) CUsbIndicatorNotifier(aNotifManager, aOtgWatcher);
    41     CleanupStack::PushL(self);
    41     CleanupStack::PushL(self);
    42     self->ConstructL();
    42     self->ConstructL();
    43     CleanupStack::Pop(self);
    43     CleanupStack::Pop(self);
    44     return self;
    44     return self;
    45     }
    45     }
    52     {
    52     {
    53     FLOG( _L( "[USBOTGWATCHER]\tCUsbIndicatorNotifier::~CUsbIndicatorNotifier" ) );
    53     FLOG( _L( "[USBOTGWATCHER]\tCUsbIndicatorNotifier::~CUsbIndicatorNotifier" ) );
    54         
    54         
    55     Close();
    55     Close();
    56     delete iIconBlinkingTimer;
    56     delete iIconBlinkingTimer;
       
    57     
       
    58     // Unsubscribe from VBus change notifications
       
    59     iOtgWatcher->VBusObserver()->UnsubscribeL(this);
       
    60     
       
    61     // Unsubscribe from otg watcher states change notifications
       
    62     iOtgWatcher->UnsubscribeL(this);
       
    63     }
       
    64 
       
    65 // ---------------------------------------------------------------------------
       
    66 // C++ constructor
       
    67 // ---------------------------------------------------------------------------
       
    68 //
       
    69 CUsbIndicatorNotifier::CUsbIndicatorNotifier(CUsbNotifManager* aNotifManager, CUsbOtgWatcher* aOtgWatcher) :
       
    70     CUsbNotifier(aNotifManager, KUsbUiNotifOtgIndicator, NULL), iOtgWatcher(aOtgWatcher)
       
    71     {
       
    72     FLOG( _L( "[USBOTGWATCHER]\tCUsbIndicatorNotifier::CUsbIndicatorNotifier" ) );
       
    73 
       
    74     //To be changed to EAknIndicatorStateAnimate and remove iIconBlinkingTimer
       
    75     //when AVKON implements animation form of usb indicator.
       
    76     iIndicatorState = EAknIndicatorStateOn;
       
    77     }
       
    78 
       
    79 // ---------------------------------------------------------------------------
       
    80 // Second-phase constructor
       
    81 // ---------------------------------------------------------------------------
       
    82 //
       
    83 void CUsbIndicatorNotifier::ConstructL()
       
    84     {
       
    85     FLOG( _L( "[USBOTGWATCHER]\tCUsbIndicatorNotifier::ConstructL" ) );
       
    86     
       
    87     // Subscribe for VBus change notifications
       
    88     iOtgWatcher->VBusObserver()->SubscribeL(this);
       
    89     
       
    90     // Subscribe for otg watcher states change notifications
       
    91     iOtgWatcher->SubscribeL(this);
       
    92 
       
    93     iIconBlinkingTimer = CUsbTimer::NewL(this, EIconBlinkingTimer);
       
    94     
       
    95     // check here for condition to set usb indicator
       
    96     SetIndicatorL();
       
    97 
    57     }
    98     }
    58 
    99 
    59 // ---------------------------------------------------------------------------
   100 // ---------------------------------------------------------------------------
    60 // Show/hide static icon of the indicator. 
   101 // Show/hide static icon of the indicator. 
    61 // If the indicator is blinking, stop blinking it and show/hide the static 
   102 // If the indicator is blinking, stop blinking it and show/hide the static 
    62 // form of the indicator.
   103 // form of the indicator.
    63 // ---------------------------------------------------------------------------
   104 // ---------------------------------------------------------------------------
    64 //
   105 //
    65 void CUsbIndicatorNotifier::ShowIndicatorL(TBool aVisible)
   106 void CUsbIndicatorNotifier::ShowStaticL(TBool aVisible)
    66     {
   107     {
    67     FTRACE( FPrint (_L( "[USBOTGWATCHER]\tCUsbIndicatorNotifier::ShowIndicator, aVisible=%d" ), aVisible));
   108     FTRACE( FPrint (_L( "[USBOTGWATCHER]\tCUsbIndicatorNotifier::ShowStaticL, aVisible=%d" ), aVisible));
    68 
   109 
    69     iIconBlinkingTimer->Cancel();
   110     iIconBlinkingTimer->Cancel();
    70 
   111 
    71     SetIndicatorStateL(aVisible ? EAknIndicatorStateOn : EAknIndicatorStateOff);    
   112     SetIndicatorStateL(aVisible ? EAknIndicatorStateOn : EAknIndicatorStateOff);    
    72     }
   113     }
    73 
   114 
    74 // ---------------------------------------------------------------------------
   115 // ---------------------------------------------------------------------------
    75 // From CUsbNotifier
   116 // 
    76 // ---------------------------------------------------------------------------
   117 // ---------------------------------------------------------------------------
    77 //
   118 //
    78 void CUsbIndicatorNotifier::ShowL()
   119 void CUsbIndicatorNotifier::BlinkL()
    79     {
   120     {
    80     FLOG( _L( "[USBOTGWATCHER]\tCUsbIndicatorNotifier::ShowL" ));
   121     FLOG( _L( "[USBOTGWATCHER]\tCUsbIndicatorNotifier::BlinkL" ));
    81 
   122 
    82     // Will be canceled if active in After()
   123     // Will be canceled if active in After()
    83     iIconBlinkingTimer->After(0);
   124     iIconBlinkingTimer->After(0);
    84     }
   125     }
    85 
   126 
    86 // ---------------------------------------------------------------------------
   127 // ---------------------------------------------------------------------------
       
   128 // From base class CUsbNotifier
       
   129 // ---------------------------------------------------------------------------
       
   130 //
       
   131 void CUsbIndicatorNotifier::ShowL()
       
   132     {
       
   133     FLOG( _L( "[USBOTGWATCHER]\tCUsbIndicatorNotifier::ShowL" ) );
       
   134     
       
   135     ShowStaticL(ETrue);
       
   136     }
       
   137 
       
   138 // ---------------------------------------------------------------------------
    87 // From CUsbNotifier
   139 // From CUsbNotifier
    88 // ---------------------------------------------------------------------------
   140 // ---------------------------------------------------------------------------
    89 //
   141 //
    90 void CUsbIndicatorNotifier::Close()
   142 void CUsbIndicatorNotifier::Close()
    91     {
   143     {
    92     FLOG( _L( "[USBOTGWATCHER]\tCUsbIndicatorNotifier::Close" ) );
   144     FLOG( _L( "[USBOTGWATCHER]\tCUsbIndicatorNotifier::Close" ) );
    93     
   145     
    94     iIconBlinkingTimer->Cancel();
   146     iIconBlinkingTimer->Cancel();
    95     TRAP_IGNORE( ShowIndicatorL(EFalse) );
   147     TRAP_IGNORE( ShowStaticL(EFalse) );
    96     }
   148     }
    97 
   149 
    98 // ---------------------------------------------------------------------------
   150 // ---------------------------------------------------------------------------
    99 // From MUsbTimerObserver
   151 // From MUsbTimerObserver
   100 // ---------------------------------------------------------------------------
   152 // ---------------------------------------------------------------------------
   122             }
   174             }
   123         }
   175         }
   124     }
   176     }
   125 
   177 
   126 // ---------------------------------------------------------------------------
   178 // ---------------------------------------------------------------------------
   127 // C++ constructor
       
   128 // ---------------------------------------------------------------------------
       
   129 //
       
   130 CUsbIndicatorNotifier::CUsbIndicatorNotifier(CUsbNotifManager* aNotifManager) :
       
   131     CUsbNotifier(aNotifManager, KUsbUiNotifOtgIndicator, NULL)
       
   132     {
       
   133     FLOG( _L( "[USBOTGWATCHER]\tCUsbIndicatorNotifier::CUsbIndicatorNotifier" ) );
       
   134 
       
   135     //To be changed to EAknIndicatorStateAnimate and remove iIconBlinkingTimer
       
   136     //when AVKON implements animation form of usb indicator.
       
   137     iIndicatorState = EAknIndicatorStateOn;
       
   138     }
       
   139 
       
   140 // ---------------------------------------------------------------------------
       
   141 // Second-phase constructor
       
   142 // ---------------------------------------------------------------------------
       
   143 //
       
   144 void CUsbIndicatorNotifier::ConstructL()
       
   145     {
       
   146     FLOG( _L( "[USBOTGWATCHER]\tCUsbIndicatorNotifier::ConstructL" ) );
       
   147 
       
   148     iIconBlinkingTimer = CUsbTimer::NewL(this, EIconBlinkingTimer);
       
   149     }
       
   150 
       
   151 // ---------------------------------------------------------------------------
       
   152 // Set USB indicator On or Off
   179 // Set USB indicator On or Off
   153 // ---------------------------------------------------------------------------
   180 // ---------------------------------------------------------------------------
   154 //
   181 //
   155 void CUsbIndicatorNotifier::SetIndicatorStateL(const TInt aState)
   182 void CUsbIndicatorNotifier::SetIndicatorStateL(const TInt aState)
   156     {
   183     {
   159     CAknSmallIndicator* indicator = CAknSmallIndicator::NewLC(TUid::Uid(EAknIndicatorUSBConnection));
   186     CAknSmallIndicator* indicator = CAknSmallIndicator::NewLC(TUid::Uid(EAknIndicatorUSBConnection));
   160     indicator->SetIndicatorStateL( aState );
   187     indicator->SetIndicatorStateL( aState );
   161     CleanupStack::PopAndDestroy( indicator ); //indicator    
   188     CleanupStack::PopAndDestroy( indicator ); //indicator    
   162     }
   189     }
   163 
   190 
       
   191 // ---------------------------------------------------------------------------
       
   192 // 
       
   193 // ---------------------------------------------------------------------------
       
   194 //
       
   195 void CUsbIndicatorNotifier::OtgWatcherStateChangedL(TUsbStateIds aState)
       
   196     {
       
   197     FTRACE( FPrint (_L( "[USBOTGWATCHER]\tCUsbIndicatorNotifier::OtgWatcherStateChangedL - aState=%d" ), aState));
       
   198     SetIndicatorL();
       
   199     }
       
   200 
       
   201 // ---------------------------------------------------------------------------
       
   202 // 
       
   203 // ---------------------------------------------------------------------------
       
   204 //
       
   205 void CUsbIndicatorNotifier::VBusDownL()
       
   206     {
       
   207     FLOG( _L( "[USBOTGWATCHER]\tCUsbIndicatorNotifier::VBusDownL" ) );
       
   208     SetIndicatorL();
       
   209     }
       
   210 
       
   211 // ---------------------------------------------------------------------------
       
   212 // 
       
   213 // ---------------------------------------------------------------------------
       
   214 //
       
   215 void CUsbIndicatorNotifier::VBusUpL()
       
   216     {
       
   217     FLOG( _L( "[USBOTGWATCHER]\tCUsbIndicatorNotifier::VBusUpL" ) );
       
   218     SetIndicatorL();
       
   219     }
       
   220 
       
   221 // ---------------------------------------------------------------------------
       
   222 // 
       
   223 // ---------------------------------------------------------------------------
       
   224 //  
       
   225 void CUsbIndicatorNotifier::VBusObserverErrorL(TInt aError)
       
   226     {
       
   227     FLOG( _L( "[USBOTGWATCHER]\tCUsbIndicatorNotifier::VBusObserverErrorL" ) );
       
   228     // do not care
       
   229     }
       
   230 
       
   231 // ---------------------------------------------------------------------------
       
   232 // 
       
   233 // ---------------------------------------------------------------------------
       
   234 //  
       
   235 void CUsbIndicatorNotifier::SetIndicatorL()
       
   236     {
       
   237     FLOG( _L( "[USBOTGWATCHER]\tCUsbIndicatorNotifier::SetIndicatorL" ) );
       
   238     // if VBus Up and we are host -> show indicator
       
   239     if ((iOtgWatcher->VBusObserver()->VBus() == CUsbVBusObserver::EVBusUp) &&
       
   240             (iOtgWatcher->CurrentHostState()->Id() == EUsbStateHostAHost))
       
   241         {
       
   242         ShowStaticL(ETrue);
       
   243         }
       
   244     // if VBus up and we are not host -> Blink indicator
       
   245     else if((iOtgWatcher->VBusObserver()->VBus() == CUsbVBusObserver::EVBusUp) &&
       
   246             (iOtgWatcher->CurrentHostState()->Id() != EUsbStateHostAHost))
       
   247         {
       
   248         BlinkL();
       
   249         }
       
   250     else
       
   251     // Otherwise do not show indicator
       
   252         {
       
   253         ShowStaticL(EFalse);
       
   254         }
       
   255     }
       
   256 
   164 // End of file
   257 // End of file