I Don't understand how this simple timer implementation works. All I want is to call the function DoSnapL(); in S60CameraExample after 5 secs, because if I call the function immediately, it crash. I've this functions in CameraExappui.cpp
Code:
//Timer
CExampleTimer::CExampleTimer(MExampleTimerNotify& aNotify)
:CActive(EPriorityStandard),iNotify(aNotify)
{
}
CExampleTimer::~CExampleTimer()
{
Cancel();
iTimer.Close();
}
CExampleTimer* CExampleTimer::NewL(MExampleTimerNotify& aNotify)
{ CExampleTimer* me = new (ELeave) CExampleTimer(aNotify);
CleanupStack::PushL(me);
me->ConstructL();
CleanupStack::Pop();
return me;
}
void CExampleTimer::ConstructL(void)
{
CActiveScheduler::Add(this);
iTimer.CreateLocal();
}
void CExampleTimer::After(TTimeIntervalMicroSeconds32 aInterval)
{
Cancel();
iTimer.After(iStatus,aInterval);
SetActive();
}
void CExampleTimer::At(const TTime& aTime)
{
Cancel();
iTimer.At(iStatus,aTime);
SetActive();
}
void CExampleTimer::Inactivity(TTimeIntervalSeconds aSeconds)
{
Cancel();
iTimer.Inactivity(iStatus,aSeconds);
SetActive();
}
void CExampleTimer::DoCancel()
{
iTimer.Cancel();
}
void CExampleTimer::RunL()
{
iNotify.TimerExpired(this,iStatus.Int());
}
//TimerController
void CTimerController::ConstructL()
{
iYourTimer = CExampleTimer::NewL(*this);
TTimeIntervalMicroSeconds32 someInterVal(5000000);
//you can call After/At/Inactivity depending on what you want to do
iYourTimer->After(someInterVal);
}
/** * Callback implementation when the timer activity happens in the CExampleTimer class **/
void CTimerController::TimerExpired(TAny* aTimer,TInt aError)
{ if(aError == KErrNone)
{ // Timer successfully completed, handle it
CExampleTimer* timer = (CExampleTimer*)aTimer;
TTimeIntervalSeconds seconds(10);
timer->Inactivity(seconds); //Notify inactivity after 10 seconds
}
}
I Declared in CameraExAppUi class CTimerController* iTimercon;
This is CameraExappui.h
Code:
/*
* Copyright © 2008 Nokia Corporation.
*/
#ifndef __CAMERAEX_APPUI_H__
#define __CAMERAEX_APPUI_H__
#include <eikapp.h>
#include <eikdoc.h>
#include <e32std.h>
#include <coeccntx.h>
#include <aknviewappui.h>
#include "CameraEx.hrh"
class CCameraExContainer;
class CCameraExController;
class CCameraExView;
class CExampleTimer;
class MExampleTimerNotify;
// The native Media Gallery application's UID in S60 platform 2nd Edition FP1
// (Symbian OS v7.0s) and older
const TInt KMediaGalleryUID3PreFP1 = 0x101f4d8f;
// The native Media Gallery application's UID in S60 platform 2nd Edition FP2
// (Symbian OS v8.0a) and newer, including 3rd Edition
const TInt KMediaGalleryUID3PostFP1 = 0x101f8599;
const TInt KMediaGalleryListViewUID = 0x00000001;
const TInt KMediaGalleryCmdMoveFocusTo = 0x00000001;
const TInt KStdKeyCameraFocus = 0xe2;
const TInt KStdKeyCameraFocus2 = 0xeb; // S60 3.2 and onwards
const TInt KKeyCameraShutter = 0xf883;
const TInt KKeyCameraShutter2 = 0xf849; // S60 3.2
const TInt EKeyCameraNseries2 = 0xf88c; // S60 3.2 Nseries
const TInt KNumOfFrames = 5;
//const TInt KAppOrientationLandscape = 0x00030000;
/**
* Application UI class.
* Provides support for the following features:
* - EIKON control architecture
* - view architecture
* - status pane
*/
class CCameraExAppUi : public CAknViewAppUi,
public MCoeForegroundObserver
{
public: // Constructors and destructor
/**
* Constructor.
*/
CCameraExAppUi();
/**
* Symbian OS 2nd phase constructor.
*/
void ConstructL();
/**
* Destructor.
*/
~CCameraExAppUi();
public: // Public methods
void ResetEngine();
/**
* Returns the camera mode.
*/
TCameraMode CameraMode();
/**
* Prepares to snap the next image.
*/
void DoNewImageL();
/**
* Snaps an image.
*/
void ReserveCamera();
void WriteToFile(const TDesC8& aContent8);
void DoSnapL();
private:
/**
* From CEikAppUi.
* Takes care of command handling.
*
* @param aCommand command to be handled
*/
void HandleCommandL(TInt aCommand);
void HandleResourceChangeL( TInt aType );
/**
* From CEikAppUi.
* Handles key events.
*
* @param aKeyEvent Event to be handled.
* @param aType Type of the key event.
* @return Response code (EKeyWasConsumed, EKeyWasNotConsumed).
*/
virtual TKeyResponse HandleKeyEventL(
const TKeyEvent& aKeyEvent,TEventCode aType);
/**
* From CEikAppUi.
* Returns the help context for this application.
*
* @return A pointer to the help context.
*/
CArrayFix<TCoeHelpContext>* HelpContextL() const;
private:
/**
* Launches Media Gallery application for viewing the images.
*/
void GoToMediaGalleryL();
TUint32 ResolveCameraOrientation();
private: // From MCoeForegroundObserver
void HandleGainingForeground();
void HandleLosingForeground();
public: // Data
CCameraExController* iController;
CTimerController* iTimercon;
private: // Data
CCameraExView* iView;
// Whether the camera is in viewfinding mode or in the
// image snapped mode
TCameraMode iCameraMode;
TInt iMediaGalleryUid3;
};
class MExampleTimerNotify
{
public:
~MExampleTimerNotify();
// Two-phased constructor.
static MExampleTimerNotify* NewL();
// Two-phased constructor.
static MExampleTimerNotify* NewLC();
virtual void TimerExpired(TAny* aTimer,TInt aError) = 0;
};
class CExampleTimer: public CActive
{
public:
static CExampleTimer* NewL(MExampleTimerNotify& aNotify);
~CExampleTimer();
public:
void At(const TTime& aTime);
void After(TTimeIntervalMicroSeconds32 aInterval);
void Inactivity(TTimeIntervalSeconds aSeconds);
protected:
void RunL();
void DoCancel();
private:
CExampleTimer(MExampleTimerNotify& aNotify);
void ConstructL();
private:
RTimer iTimer;
MExampleTimerNotify& iNotify;
};
//End of Timer Class
//Controller Class
class CTimerController : public CBase, public MExampleTimerNotify
{
public:
void ConstructL();
void TimerExpired(TAny* aTimer,TInt aError);
private :
CExampleTimer* iYourTimer;
};