camerauis/cameraapp/generic/dummyengine/CameraappDummyCallbackActive.cpp
branchRCL_3
changeset 24 bac7acad7cb3
parent 0 1ddebce53859
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:  Dummy callback active object class for Cameraapp Unit Tests*
       
    15 */
       
    16 
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "CameraappDummyCallbackActive.h"
       
    21 #include "CameraappTestBitmapManager.h"
       
    22 #include <CaeEngine.h>
       
    23 
       
    24 // EXTERNAL DATA STRUCTURES
       
    25 //extern  ?external_data;
       
    26 
       
    27 // EXTERNAL FUNCTION PROTOTYPES  
       
    28 //extern ?external_function( ?arg_type,?arg_type );
       
    29 
       
    30 // CONSTANTS
       
    31 
       
    32 // MACROS
       
    33 //#define ?macro ?macro_def
       
    34 
       
    35 // LOCAL CONSTANTS AND MACROS
       
    36 //const ?type ?constant_var = ?constant;
       
    37 //#define ?macro_name ?macro_def
       
    38 
       
    39 // MODULE DATA STRUCTURES
       
    40 //enum ?declaration
       
    41 //typedef ?declaration
       
    42 
       
    43 // LOCAL FUNCTION PROTOTYPES
       
    44 //?type ?function_name( ?arg_type, ?arg_type );
       
    45 
       
    46 // FORWARD DECLARATIONS
       
    47 //class ?FORWARD_CLASSNAME;
       
    48 
       
    49 // ============================ MEMBER FUNCTIONS ===============================
       
    50 
       
    51 // -----------------------------------------------------------------------------
       
    52 // CCameraappDummyCallbackActive::NewL
       
    53 // Two-phased constructor.
       
    54 // -----------------------------------------------------------------------------
       
    55 //
       
    56 CCameraappDummyCallbackActive* CCameraappDummyCallbackActive::NewL( 
       
    57                             MCamAppEngineObserver& aController )
       
    58     {
       
    59     CCameraappDummyCallbackActive* self = new( ELeave ) CCameraappDummyCallbackActive( aController );
       
    60     CleanupStack::PushL( self );
       
    61     self->ConstructL();
       
    62     CleanupStack::Pop( self );
       
    63 
       
    64     return self;
       
    65     }
       
    66 
       
    67     
       
    68 // Destructor
       
    69 CCameraappDummyCallbackActive::~CCameraappDummyCallbackActive()
       
    70     {  
       
    71     delete iBitmapManager;
       
    72     }
       
    73 
       
    74 void CCameraappDummyCallbackActive::Cancel()
       
    75     {
       
    76     CActive::Cancel();
       
    77     DoCancel();
       
    78     }
       
    79 
       
    80 void CCameraappDummyCallbackActive::SetBurstObserver( MCaeStillBurstObserver* aBurstObserver )
       
    81     {
       
    82     iBurstObserver = aBurstObserver;
       
    83     }
       
    84 
       
    85 CCameraappDummyCallbackActive::CCameraappDummyCallbackActive( 
       
    86                             MCamAppEngineObserver& aController )
       
    87     : CActive( EPriorityLow ),
       
    88       iController( aController )
       
    89     {
       
    90     }
       
    91 
       
    92 void CCameraappDummyCallbackActive::InitComplete( )
       
    93     {
       
    94     iInitComplete = ETrue;
       
    95     if ( !IsActive() )
       
    96         {
       
    97         SetActiveAndCompleteRequest();    
       
    98         }    
       
    99     }
       
   100 
       
   101 void CCameraappDummyCallbackActive::StillPrepareComplete( )
       
   102     {
       
   103     iStillPrepareComplete = ETrue;
       
   104     if ( !IsActive() )
       
   105         {
       
   106         SetActiveAndCompleteRequest();
       
   107         }
       
   108     }
       
   109 
       
   110 void CCameraappDummyCallbackActive::VideoPrepareComplete( )
       
   111     {
       
   112     iVideoPrepareComplete = ETrue;
       
   113     if ( !IsActive() )
       
   114         {
       
   115         SetActiveAndCompleteRequest();
       
   116         }
       
   117     }
       
   118 
       
   119 void CCameraappDummyCallbackActive::SendViewFinderFrames( )
       
   120     {
       
   121     iViewFinderFrame = ETrue;
       
   122     if ( !IsActive() )
       
   123         {
       
   124         SetActiveAndCompleteRequest();
       
   125         }
       
   126     }
       
   127     
       
   128 void CCameraappDummyCallbackActive::StopViewFinderFrames()
       
   129 	{
       
   130 	iViewFinderFrame = EFalse;
       
   131 	}
       
   132 
       
   133 void CCameraappDummyCallbackActive::CaptureStill()
       
   134     {
       
   135     iCaptureStill = ETrue;
       
   136     if ( !IsActive() )
       
   137         {
       
   138         SetActiveAndCompleteRequest();
       
   139         }
       
   140     }
       
   141 
       
   142 void CCameraappDummyCallbackActive::CaptureBurst( TInt aImageCount )
       
   143     {
       
   144     iStopBurst = EFalse;
       
   145     iCaptureBurst = ETrue;
       
   146     iBurstCount = aImageCount;
       
   147     iBurstCaptureImage = 0;
       
   148     iBurstSnapImage = 0;
       
   149     iCompletedBurst = 0;
       
   150     if ( !IsActive() )
       
   151         {
       
   152         SetActiveAndCompleteRequest();
       
   153         }
       
   154     }
       
   155 
       
   156 void CCameraappDummyCallbackActive::StopBurst()
       
   157     {
       
   158     iStopBurst = ETrue;
       
   159     }
       
   160 
       
   161 void CCameraappDummyCallbackActive::VideoRecordingStopped()
       
   162     {
       
   163     iVideoStopped = ETrue;
       
   164     if ( !IsActive() )
       
   165         {
       
   166         SetActiveAndCompleteRequest();
       
   167         }
       
   168     }
       
   169 
       
   170 void CCameraappDummyCallbackActive::VideoRecordingPaused()
       
   171     {
       
   172     iVideoPaused = ETrue;
       
   173     if ( !IsActive() )
       
   174         {
       
   175         SetActiveAndCompleteRequest();
       
   176         }
       
   177     }
       
   178 
       
   179 void CCameraappDummyCallbackActive::VideoRecordingResumed()
       
   180     {
       
   181     iVideoResumed = ETrue;
       
   182     if ( !IsActive() )
       
   183         {
       
   184         SetActiveAndCompleteRequest();
       
   185         }
       
   186     }
       
   187 
       
   188 void CCameraappDummyCallbackActive::SetActiveAndCompleteRequest()
       
   189     {
       
   190     SetActive();
       
   191     TRequestStatus* statusPtr = &iStatus;
       
   192     User::RequestComplete( statusPtr, KErrNone );
       
   193     }
       
   194 
       
   195 void CCameraappDummyCallbackActive::DoInitComplete( )
       
   196     {
       
   197     iController.McaeoInitComplete( KErrNone );
       
   198     iInitComplete = EFalse;
       
   199     }
       
   200 
       
   201 // -----------------------------------------------------------------------------
       
   202 // CCameraappDummyCallbackActive::StillPrepareComplete
       
   203 // Prepare CCamAppControllerBase and CamAppEngine for current mode
       
   204 // -----------------------------------------------------------------------------
       
   205 //
       
   206 void CCameraappDummyCallbackActive::DoStillPrepareComplete()
       
   207     {
       
   208     iController.McaeoStillPrepareComplete( KErrNone );
       
   209     iStillPrepareComplete = EFalse;
       
   210     }
       
   211 
       
   212 // -----------------------------------------------------------------------------
       
   213 // CCameraappDummyCallbackActive::VideoPrepareComplete
       
   214 // Prepare CCamAppControllerBase and CamAppEngine for current mode
       
   215 // -----------------------------------------------------------------------------
       
   216 //
       
   217 void CCameraappDummyCallbackActive::DoVideoPrepareComplete()
       
   218     {
       
   219     iController.McaeoVideoPrepareComplete( KErrNone );
       
   220 
       
   221     TTimeIntervalMicroSeconds timeElapsed( 1 );
       
   222     TTimeIntervalMicroSeconds timeRem( 100000000 );
       
   223     iController.McaeoVideoRecordingTimes( timeElapsed, timeRem, KErrNone );
       
   224     iVideoPrepareComplete = EFalse;
       
   225     }
       
   226 
       
   227 // -----------------------------------------------------------------------------
       
   228 // CCameraappDummyCallbackActive::ViewFinderFrame
       
   229 // Start the viewfinder
       
   230 // -----------------------------------------------------------------------------
       
   231 //
       
   232 void CCameraappDummyCallbackActive::DoViewFinderFrame()
       
   233     {
       
   234     iController.McaeoViewFinderFrameReady( iBitmapManager->NextBitmap(), KErrNone ); 
       
   235     if ( iViewFinderFrame )
       
   236         {
       
   237         if ( !IsActive() )
       
   238             {
       
   239             SetActiveAndCompleteRequest();
       
   240             }
       
   241         }
       
   242     }
       
   243 
       
   244 void CCameraappDummyCallbackActive::DoCaptureStillL()
       
   245     {
       
   246     iCaptureStill = EFalse;
       
   247     iController.McaeoSnapImageReady( iBitmapManager->Bitmap( 2 ), KErrNone );
       
   248     HBufC8* testData = HBufC8::NewL( KTestData( ).Length() );
       
   249     testData->Des().Copy( KTestData );
       
   250     // ownership of testData transferred to iController
       
   251     iController.McaeoStillImageReady( NULL, testData, KErrNone );
       
   252     }
       
   253 
       
   254 void CCameraappDummyCallbackActive::DoCaptureBurstL()
       
   255     {
       
   256     if ( !iBurstObserver )
       
   257         {
       
   258         return;
       
   259         }   
       
   260     // if we are still taking burst images
       
   261     if ( iBurstCaptureImage < iBurstCount )
       
   262         {   
       
   263         if ( iStopBurst )
       
   264             {
       
   265             iBurstCount = iBurstCaptureImage;
       
   266             }
       
   267         else
       
   268             {
       
   269             iBurstObserver->McaesboStillBurstCaptureMoment( KErrNone );
       
   270             if (!iStopBurst )
       
   271                 {
       
   272                 iBurstCaptureImage++;
       
   273                 }
       
   274             }
       
   275         if ( !IsActive() )
       
   276             {
       
   277             SetActiveAndCompleteRequest();
       
   278             }
       
   279         }
       
   280     // if we are sending back snap images
       
   281     else if ( iBurstSnapImage < iBurstCount )
       
   282         {
       
   283         iBurstSnapImage++;
       
   284         iController.McaeoSnapImageReady( iBitmapManager->Bitmap( 2 ), KErrNone );
       
   285         if ( !IsActive() )
       
   286             {
       
   287             SetActiveAndCompleteRequest();
       
   288             }
       
   289         }
       
   290     // if we are sending back still images
       
   291     else if ( iCompletedBurst < iBurstCount )
       
   292         {
       
   293         iCompletedBurst++;
       
   294         // ownership of testData transferred to iController
       
   295         HBufC8* testData = HBufC8::NewL( KTestData( ).Length() );
       
   296         testData->Des().Copy( KTestData );
       
   297         iController.McaeoStillImageReady( NULL, testData, KErrNone );
       
   298         if ( !IsActive() )
       
   299             {
       
   300             SetActiveAndCompleteRequest();
       
   301             }
       
   302         }
       
   303     else // all finished
       
   304         {
       
   305         iCaptureBurst = EFalse;
       
   306         iBurstObserver->McaesboStillBurstComplete( iBurstCount, KErrNone );
       
   307         iBurstCount = 0;
       
   308         iCompletedBurst = 0;
       
   309         iBurstSnapImage = 0;
       
   310         iBurstCaptureImage = 0;
       
   311         }    
       
   312     }
       
   313 
       
   314 void CCameraappDummyCallbackActive::DoVideoPaused()
       
   315     {
       
   316     iVideoPaused = EFalse;
       
   317     iController.McaeoVideoRecordingPaused( KErrNone );
       
   318     }
       
   319 
       
   320 void CCameraappDummyCallbackActive::DoVideoResumed()
       
   321     {
       
   322     iVideoResumed = EFalse;
       
   323     iController.McaeoVideoRecordingOn( KErrNone );
       
   324     }
       
   325 
       
   326 void CCameraappDummyCallbackActive::DoVideoStopped()
       
   327     {
       
   328     iVideoStopped = EFalse;
       
   329     iController.McaeoVideoRecordingComplete( KErrNone );
       
   330     }
       
   331 
       
   332 void CCameraappDummyCallbackActive::ConstructL()
       
   333     {
       
   334     CActiveScheduler::Add( this );
       
   335     iBitmapManager = CCameraappTestBitmapManager::NewL();
       
   336     }
       
   337 
       
   338 // -----------------------------------------------------------------------------
       
   339 // CCameraappDummyCallbackActive::DoCancel
       
   340 // Cancels the active object
       
   341 // -----------------------------------------------------------------------------
       
   342 //
       
   343 void CCameraappDummyCallbackActive::DoCancel()
       
   344     {
       
   345     iInitComplete = EFalse;
       
   346     iStillPrepareComplete = EFalse;
       
   347     iVideoPrepareComplete = EFalse;
       
   348     iViewFinderFrame = EFalse;
       
   349     iVideoPaused = EFalse;
       
   350     iVideoResumed = EFalse;
       
   351     }
       
   352 
       
   353 void CCameraappDummyCallbackActive::RunL()
       
   354     {
       
   355     if ( iInitComplete )
       
   356         {
       
   357         DoInitComplete();
       
   358         }
       
   359     else if ( iStillPrepareComplete )
       
   360         {
       
   361         DoStillPrepareComplete();
       
   362         }
       
   363     else if ( iVideoPrepareComplete )
       
   364         {
       
   365         DoVideoPrepareComplete();
       
   366         }
       
   367     else if ( iCaptureStill )
       
   368         {
       
   369         DoCaptureStillL();
       
   370         }
       
   371     else if ( iCaptureBurst )
       
   372         {
       
   373         DoCaptureBurstL();
       
   374         }
       
   375     else if ( iVideoPaused )
       
   376         {
       
   377         DoVideoPaused();
       
   378         }
       
   379     else if ( iVideoResumed )
       
   380         {
       
   381         DoVideoResumed();
       
   382         }
       
   383     else if ( iVideoStopped )
       
   384         {
       
   385         DoVideoStopped();
       
   386         }
       
   387     else
       
   388         {
       
   389         }
       
   390         
       
   391    	if ( iViewFinderFrame )
       
   392         {
       
   393         DoViewFinderFrame();
       
   394         }
       
   395     }
       
   396 //  End of File