camerauis/cameraapp/generic/src/camflashstatus.cpp
branchRCL_3
changeset 24 bac7acad7cb3
parent 0 1ddebce53859
child 25 2c87b2808fd7
equal deleted inserted replaced
23:61bc0f252b2b 24:bac7acad7cb3
       
     1 /*
       
     2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Implemantation for CCamFlashStatus class.
       
    15 *
       
    16 *  Copyright © 2007 Nokia.  All rights reserved.
       
    17 *  This material, including documentation and any related computer
       
    18 *  programs, is protected by copyright controlled by Nokia.  All
       
    19 *  rights are reserved.  Copying, including reproducing, storing,
       
    20 *  adapting or translating, any or all of this material requires the
       
    21 *  prior written consent of Nokia.  This material also contains
       
    22 *  confidential information which may not be disclosed to others
       
    23 *  without the prior written consent of Nokia.
       
    24 
       
    25 *
       
    26 *
       
    27 */
       
    28 
       
    29 
       
    30 // #include "CamPropertyWatcher.h"
       
    31 // #include "CamUtility.h"
       
    32 #include "camlogging.h"
       
    33 #include "CamSettings.hrh"
       
    34 #include "CamSettingsInternal.hrh"
       
    35 #include "camcameraevents.h"
       
    36 #include "CamAppController.h"
       
    37 #include "camflashstatus.h"
       
    38 
       
    39 static const TUint KCameraEventInterest = ECamCameraEventClassFlashStatus;
       
    40 
       
    41 // ---------------------------------------------------------------------------
       
    42 // CCamFlashStatus::CCamFlashStatus
       
    43 // ---------------------------------------------------------------------------
       
    44 //
       
    45 CCamFlashStatus::CCamFlashStatus( CCamAppController& aController ):
       
    46     iErrorCallbacksEnabled( ETrue ),
       
    47     iController( aController )
       
    48     {    
       
    49     }
       
    50 
       
    51 // ---------------------------------------------------------------------------
       
    52 // CCamFlashStatus::~CCamFlashStatus
       
    53 // ---------------------------------------------------------------------------
       
    54 //    
       
    55 CCamFlashStatus::~CCamFlashStatus()
       
    56     {  
       
    57     iController.RemoveCameraObserver( this );
       
    58 
       
    59     if( iBlinkTimer )
       
    60         {
       
    61         iBlinkTimer->Cancel();
       
    62         delete iBlinkTimer;
       
    63         }
       
    64     }
       
    65 
       
    66 // ---------------------------------------------------------------------------
       
    67 // CCamFlashStatus::NewL
       
    68 // ---------------------------------------------------------------------------
       
    69 //
       
    70 CCamFlashStatus*
       
    71 CCamFlashStatus::NewL( CCamAppController& aController )
       
    72     {
       
    73     CCamFlashStatus* self = 
       
    74         new (ELeave) CCamFlashStatus( aController );
       
    75     CleanupStack::PushL( self );
       
    76     self->ConstructL();
       
    77     CleanupStack::Pop(); // self
       
    78     return self;        
       
    79     }
       
    80 
       
    81 
       
    82 // ---------------------------------------------------------------------------
       
    83 // CCamFlashStatus::ConstructL
       
    84 // ---------------------------------------------------------------------------
       
    85 //
       
    86 void    
       
    87 CCamFlashStatus::ConstructL()
       
    88     {
       
    89     iBlinkTimer = CPeriodic::NewL( EPriorityLow );
       
    90 
       
    91     iController.AddCameraObserverL( this, KCameraEventInterest );
       
    92     iFlashError    = EFalse;
       
    93     iFlashRequired = EFalse;
       
    94     iFlashReady    = EFalse;
       
    95     }
       
    96        
       
    97 // ---------------------------------------------------------------------------
       
    98 // CCamFlashStatus::Subscribe
       
    99 // ---------------------------------------------------------------------------
       
   100 //    
       
   101 void
       
   102 CCamFlashStatus::Subscribe( MFlashStatusObserver* aObserver )
       
   103     {
       
   104     PRINT1( _L("Camera => CCamFlashStatus::Subscribe, observer ptr:%d"), aObserver );
       
   105     iObserver = aObserver;
       
   106     
       
   107     // If there is need to blink, but no observer before,
       
   108     // we need to recheck the blinking status when observer subscribes.
       
   109     CheckBlinkingStatus();
       
   110 
       
   111     PRINT ( _L("Camera <= CCamFlashStatus::Subscribe") );
       
   112     }
       
   113     
       
   114     
       
   115 // ---------------------------------------------------------------------------
       
   116 // CCamFlashStatus::FlashReady
       
   117 // ---------------------------------------------------------------------------
       
   118 //    
       
   119 TBool
       
   120 CCamFlashStatus::FlashReady() const
       
   121     {
       
   122     return iFlashReady;
       
   123     }
       
   124     
       
   125 // ---------------------------------------------------------------------------
       
   126 // CCamFlashStatus::FlashError
       
   127 // ---------------------------------------------------------------------------
       
   128 //    
       
   129 TBool
       
   130 CCamFlashStatus::FlashError() const
       
   131     {
       
   132     return iFlashError;
       
   133     }
       
   134     
       
   135 // ---------------------------------------------------------------------------
       
   136 // CCamFlashStatus::SetFlashError
       
   137 // ---------------------------------------------------------------------------
       
   138 //     
       
   139 void
       
   140 CCamFlashStatus::SetFlashError( TBool aFlashError )
       
   141     {
       
   142     iFlashError = aFlashError;
       
   143     }    
       
   144     
       
   145 // ---------------------------------------------------------------------------
       
   146 // CCamFlashStatus::ErrorCallbacksEnabled
       
   147 // ---------------------------------------------------------------------------
       
   148 //    
       
   149 TBool
       
   150 CCamFlashStatus::ErrorCallbacksEnabled() const
       
   151     {
       
   152     return iErrorCallbacksEnabled;
       
   153     }
       
   154     
       
   155 // ---------------------------------------------------------------------------
       
   156 // CCamFlashStatus::EnableErrorCallback
       
   157 // ---------------------------------------------------------------------------
       
   158 //    
       
   159 void
       
   160 CCamFlashStatus::EnableErrorCallbacks( TBool aCallbacksEnabled )
       
   161     {
       
   162     iErrorCallbacksEnabled = aCallbacksEnabled;
       
   163     }
       
   164 
       
   165 // ---------------------------------------------------------------------------
       
   166 // CCamFlashStatus::FlashIconVisible
       
   167 // ---------------------------------------------------------------------------
       
   168 //    
       
   169 TBool
       
   170 CCamFlashStatus::FlashIconVisible() const
       
   171     {
       
   172     return iBlinkStatus;
       
   173     }
       
   174 
       
   175 
       
   176 // ---------------------------------------------------------------------------
       
   177 // HandleCameraEventL <<virtual>>
       
   178 //
       
   179 // ---------------------------------------------------------------------------
       
   180 //
       
   181 void 
       
   182 CCamFlashStatus::HandleCameraEventL( TInt              aStatus, 
       
   183                                      TCamCameraEventId aEventId, 
       
   184                                      TAny*             aEventData /*= NULL*/ )
       
   185   {
       
   186   PRINT( _L("Camera => CCamFlashStatus::HandleCameraEventL") );
       
   187 
       
   188   switch( aEventId )
       
   189     {
       
   190     // ---------------------------------------------------
       
   191     // Flash ready.
       
   192     case ECamCameraEventFlashReady:
       
   193       {
       
   194       PRINT ( _L("Camera <> CCamFlashStatus: Flash ready") );
       
   195       iFlashError = aStatus;
       
   196       iFlashReady = (KErrNone == aStatus);
       
   197       break;
       
   198       }
       
   199     // ---------------------------------------------------
       
   200     // Flash not ready, e.g. recharging.
       
   201     case ECamCameraEventFlashNotReady:
       
   202       {
       
   203       PRINT ( _L("Camera <> CCamFlashStatus: Flash NOT ready") );
       
   204       iFlashError = aStatus;
       
   205       iFlashReady = EFalse;
       
   206       break;
       
   207       }
       
   208     // ---------------------------------------------------
       
   209     default:
       
   210       {
       
   211       PRINT ( _L("Camera <> CCamFlashStatus: unhandled event!") );
       
   212       break;
       
   213       }
       
   214     // ---------------------------------------------------
       
   215     }
       
   216 
       
   217   // Check if need to start/stop blinking      
       
   218   CheckBlinkingStatus();
       
   219   
       
   220   // Notify error
       
   221   if( iFlashError )
       
   222     {
       
   223     NotifyObserverAboutFlashError();
       
   224     }
       
   225 
       
   226   PRINT( _L("Camera <= CCamFlashStatus::HandleCameraEventL") );
       
   227   }
       
   228   
       
   229 
       
   230 // ---------------------------------------------------------------------------
       
   231 // CheckBlinkingStatus
       
   232 //
       
   233 // ---------------------------------------------------------------------------
       
   234 //
       
   235 void
       
   236 CCamFlashStatus::CheckBlinkingStatus()
       
   237   {
       
   238   // If blinking is on, check if it needs to be stopped
       
   239   if( iBlinking )
       
   240     {
       
   241     // No observer OR flash ready OR flash error OR flash off 
       
   242     // => stop blinking
       
   243     if( !iObserver 
       
   244      ||  iFlashReady
       
   245      ||  iFlashError
       
   246      ||  IsFlashOff() )
       
   247       {
       
   248       StopBlinking();
       
   249       }
       
   250     }
       
   251   // If blinking is off, check if it needs to be started.
       
   252   else
       
   253     {
       
   254     // Observer joined AND flash not ready AND no error AND flash used 
       
   255     // => start blinking
       
   256     if( iObserver && !iFlashReady && !iFlashError && !IsFlashOff() )
       
   257       {
       
   258       StartBlinking();
       
   259       }
       
   260     }
       
   261   }
       
   262 
       
   263 
       
   264 
       
   265 // ---------------------------------------------------------------------------
       
   266 // CCamFlashStatus::StartBlinking
       
   267 // ---------------------------------------------------------------------------
       
   268 //   
       
   269 void
       
   270 CCamFlashStatus::StartBlinking()
       
   271   {
       
   272   // Start blinking only if some observer is displaying the status
       
   273   if( iObserver )
       
   274     {
       
   275     PRINT( _L("Camera =><= CamFlashStatus::StartBlinking - starting blinking") )
       
   276     iBlinking    = ETrue;
       
   277     iBlinkStatus = EFalse;
       
   278     // Make first callback to make the flash icon visible
       
   279     BlinkTimerCallback( this );     
       
   280 
       
   281     // Start the blinking timer    
       
   282     iBlinkTimer->Cancel();
       
   283     iBlinkTimer->Start( KFlashIconBlinkDelay,
       
   284                         KFlashIconBlinkDelay,
       
   285                         TCallBack( BlinkTimerCallback, this) );                                                            
       
   286       
       
   287     }
       
   288   }
       
   289 
       
   290 // ---------------------------------------------------------------------------
       
   291 // CCamFlashStatus::StopBlinking
       
   292 // ---------------------------------------------------------------------------
       
   293 //
       
   294 void 
       
   295 CCamFlashStatus::StopBlinking()
       
   296   {
       
   297   PRINT( _L("Camera =><= CamFlashStatus::StopBlinking - stopping blinking") )
       
   298   
       
   299   // Stop blinking
       
   300   iBlinking = EFalse;
       
   301   iBlinkTimer->Cancel();
       
   302                                                                           
       
   303   if( iBlinkStatus )
       
   304     {
       
   305     // The flash icon is visible. Make one more callback to
       
   306     // hide it.
       
   307     BlinkTimerCallback( this );    
       
   308     }
       
   309   }
       
   310    
       
   311 
       
   312 // ---------------------------------------------------------------------------
       
   313 // CCamFlashStatus::BlinkTimerCallback
       
   314 // ---------------------------------------------------------------------------
       
   315 //   
       
   316 TInt
       
   317 CCamFlashStatus::BlinkTimerCallback( TAny* aSelf )
       
   318   {
       
   319   PRINT( _L("Camera => CamFlashStatus::BlinkTimerCallback") )
       
   320   
       
   321   CCamFlashStatus* self = static_cast<CCamFlashStatus*>( aSelf );
       
   322   if( self )
       
   323     {
       
   324     // Invert icon visibility
       
   325     TBool newBlinkStatus = self->iBlinkStatus ? EFalse : ETrue;
       
   326     self->iBlinkStatus = newBlinkStatus;
       
   327     
       
   328     // Inform observer of change
       
   329     if( self->iObserver )
       
   330       {
       
   331       self->iObserver->FlashIconVisible( newBlinkStatus );
       
   332       }
       
   333     }    
       
   334    
       
   335   PRINT( _L("Camera <= CamFlashStatus::BlinkTimerCallback") )
       
   336   return KErrNone;     
       
   337   }
       
   338 
       
   339 
       
   340 // ---------------------------------------------------------------------------
       
   341 // FlashOff
       
   342 // ---------------------------------------------------------------------------
       
   343 //
       
   344 TBool 
       
   345 CCamFlashStatus::IsFlashOff() const
       
   346   {
       
   347   TInt           key  = KErrNotFound;
       
   348   TCamCameraMode mode = iController.CurrentMode();
       
   349 
       
   350   switch( mode )
       
   351     {
       
   352     case ECamControllerImage: key = ECamSettingItemDynamicPhotoFlash; break;
       
   353     case ECamControllerVideo: key = ECamSettingItemDynamicVideoFlash; break;
       
   354     default:
       
   355       break;
       
   356     }
       
   357 
       
   358   TBool off = ( KErrNotFound == key // Not prepared or standby mode.
       
   359              || ECamFlashOff == iController.IntegerSettingValue( key )
       
   360               );
       
   361 
       
   362   return off;
       
   363   }
       
   364 
       
   365 // ---------------------------------------------------------------------------
       
   366 // CCamFlashStatus::NotifyObserverAboutFlashError
       
   367 // ---------------------------------------------------------------------------
       
   368 //    
       
   369 void
       
   370 CCamFlashStatus::NotifyObserverAboutFlashError()
       
   371   {
       
   372   if( iErrorCallbacksEnabled && iObserver )
       
   373     {
       
   374     // Give error callback to the observer. 
       
   375     iObserver->FlashError();
       
   376     }    
       
   377   }
       
   378     
       
   379 
       
   380 // End of file
       
   381