camerauis/cameraapp/generic/src/cameracontroller/camflashsimulator.cpp
changeset 0 1ddebce53859
equal deleted inserted replaced
-1:000000000000 0:1ddebce53859
       
     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:  Simulator for flash recharging
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // ===========================================================================
       
    21 // Includes
       
    22 #include <ECam.h>            // TECAMEvent
       
    23 #include <ecamadvsettings.h> // ECam event ids
       
    24 
       
    25 #include "camlogging.h"
       
    26 #include "camcameracontroller.h"
       
    27 #include "camflashsimulator.h"
       
    28 
       
    29 
       
    30 // ===========================================================================
       
    31 // Local constants
       
    32 static const TUint KEventInterest = ECamCameraEventClassNone
       
    33                                   | ECamCameraEventClassImage;
       
    34 
       
    35 
       
    36 // ===========================================================================
       
    37 // Methods
       
    38 
       
    39 // ---------------------------------------------------------------------------
       
    40 // CCamFlashSimulator::CCamFlashSimulator
       
    41 // ---------------------------------------------------------------------------
       
    42 //
       
    43 CCamFlashSimulator::CCamFlashSimulator( CCamCameraController& aController )
       
    44   : iController   ( aController ),
       
    45     iError        ( KErrNone    ),
       
    46     iFlashRequired( EFalse      ),
       
    47     iFlashReady   ( ETrue       )
       
    48   {
       
    49   }
       
    50 
       
    51 // ---------------------------------------------------------------------------
       
    52 // CCamFlashSimulator::~CCamFlashSimulator
       
    53 // ---------------------------------------------------------------------------
       
    54 //    
       
    55 CCamFlashSimulator::~CCamFlashSimulator()
       
    56   {
       
    57   iController.DetachObserver( this );
       
    58 
       
    59   if( iRechargeTimer )
       
    60     {
       
    61     iRechargeTimer->Cancel();
       
    62     delete iRechargeTimer;
       
    63     }
       
    64   // DeleteProperty();
       
    65   }
       
    66     
       
    67 
       
    68 // ---------------------------------------------------------------------------
       
    69 // CCamFlashSimulator::NewL
       
    70 // ---------------------------------------------------------------------------
       
    71 // 
       
    72 CCamFlashSimulator*
       
    73 CCamFlashSimulator::NewL( CCamCameraController& aController )
       
    74   {
       
    75   CCamFlashSimulator* self = 
       
    76       new (ELeave) CCamFlashSimulator( aController );
       
    77   CleanupStack::PushL( self );
       
    78   self->ConstructL();
       
    79   CleanupStack::Pop(); // self
       
    80   return self;
       
    81   }
       
    82 
       
    83 // ---------------------------------------------------------------------------
       
    84 // CCamFlashSimulator::ConstructL
       
    85 // ---------------------------------------------------------------------------
       
    86 //
       
    87 void
       
    88 CCamFlashSimulator::ConstructL()
       
    89   {
       
    90   iRechargeTimer = CPeriodic::NewL( EPriorityNormal );
       
    91 
       
    92   iController.AttachObserverL( this, KEventInterest );
       
    93   }
       
    94     
       
    95 
       
    96 // ---------------------------------------------------------------------------
       
    97 // HandleCameraEventL <<virtual>>
       
    98 // ---------------------------------------------------------------------------
       
    99 //
       
   100 void 
       
   101 CCamFlashSimulator::HandleCameraEventL( TInt              aStatus, 
       
   102                                         TCamCameraEventId aEventId, 
       
   103                                         TAny*             aEventData /*=NULL*/ )
       
   104   {
       
   105   switch( aEventId )
       
   106     {
       
   107     case ECamCameraEventImageInit :
       
   108       {
       
   109       StartRecharging();
       
   110       break;
       
   111       }
       
   112     
       
   113     default :
       
   114       {
       
   115       break;
       
   116       }
       
   117     }
       
   118   }
       
   119 
       
   120 
       
   121 // ---------------------------------------------------------------------------
       
   122 // CCamFlashSimulator::SetFlashRequired
       
   123 // ---------------------------------------------------------------------------
       
   124 //
       
   125 void
       
   126 CCamFlashSimulator::SetFlashRequired( TBool aFlashRequired )
       
   127   {
       
   128   iFlashRequired = aFlashRequired;
       
   129   }
       
   130 
       
   131 // ---------------------------------------------------------------------------
       
   132 // CCamFlashSimulator::SetFlashError
       
   133 // ---------------------------------------------------------------------------
       
   134 //    
       
   135 void
       
   136 CCamFlashSimulator::SetFlashError( TBool aFlashError )
       
   137   {
       
   138   iError = aFlashError;
       
   139   }
       
   140     
       
   141 
       
   142 // ---------------------------------------------------------------------------
       
   143 // CCamFlashSimulator::StartRecharging
       
   144 // ---------------------------------------------------------------------------
       
   145 //    
       
   146 void
       
   147 CCamFlashSimulator::StartRecharging( TBool aError )
       
   148   {
       
   149   if( iRechargeTimer )
       
   150     {
       
   151     // Empty the flash, and publish the property value
       
   152     iFlashReady = EFalse;  
       
   153     
       
   154     // The possible error shall be published when the recharging is done
       
   155     iError = aError;
       
   156     
       
   157     // Start recharging timer
       
   158     iRechargeTimer->Cancel();
       
   159     iRechargeTimer->Start( KSimulatedChargingTime,
       
   160                            KMaxTInt32,
       
   161                            TCallBack( RechargeTimerCallback, this ) );    
       
   162 
       
   163     // Send "flash not ready" event to Camera Controller
       
   164     NotifyController();
       
   165     }
       
   166   }
       
   167 
       
   168 
       
   169 // ---------------------------------------------------------------------------
       
   170 // NotifyController
       
   171 // ---------------------------------------------------------------------------
       
   172 //
       
   173 void 
       
   174 CCamFlashSimulator::NotifyController()
       
   175   {
       
   176   PRINT2( _L("Camera => CCamFlashSimulator::NotifyController, flash ready:%d, status:%d"), iFlashReady, iError )
       
   177 
       
   178   const TUid eventId( iFlashReady 
       
   179                     ? KUidECamEventFlashReady 
       
   180                     : KUidECamEventFlashNotReady );   
       
   181   const TECAMEvent event( eventId, iError );
       
   182 
       
   183   iController.HandleEvent( event );
       
   184 
       
   185   PRINT ( _L("Camera <= CCamFlashSimulator::NotifyController") );
       
   186   }
       
   187 
       
   188 // ---------------------------------------------------------------------------
       
   189 // CCamFlashSimulator::RechargeTimerCallback
       
   190 // ---------------------------------------------------------------------------
       
   191 //
       
   192 TInt
       
   193 CCamFlashSimulator::RechargeTimerCallback( TAny* aSelf )
       
   194   {
       
   195   CCamFlashSimulator* self = static_cast<CCamFlashSimulator*>( aSelf );
       
   196   if( self )
       
   197     {
       
   198     self->iRechargeTimer->Cancel();
       
   199     // Set the flash to ready state and publish value
       
   200     self->iFlashReady = ETrue;
       
   201 
       
   202     // Send "flash ready" event to Camera Controller
       
   203     self->NotifyController();
       
   204     }
       
   205   return KErrNone;    
       
   206   }