📄 cameramanager.cpp
字号:
/**
*
* @brief Definition of CCameraManager
*
* Copyright (c) EMCC Software Ltd 2003
* @version 1.0
*/
// INCLUDE FILES
// Class include
#include "CameraManager.h"
// System includes
// User includes
#include "CameraObserver.h"
// Constants
const TInt KCameraManagerNotReady = 1;
_LIT(KCameraPanic, "CCameraManager");
// ================= MEMBER FUNCTIONS =======================
/**
* Symbian OS 2 phase constructor.
* Constructs the CCameraManger using the NewLC method, popping
* the constructed object from the CleanupStack before returning it.
*
* @param aObserver the observer of the cameramanager
* @return The newly constructed CCameraManager
*/
CCameraManager* CCameraManager::NewL(MCameraObserver& aObserver)
{
CCameraManager* self = CCameraManager::NewLC(aObserver);
CleanupStack::Pop(self);
return self;
}
/**
* Symbian OS 2 phase constructor.
* Constructs the CCameraManager using the constructor and ConstructL
* method, leaving the constructed object on the CleanupStack before returning it.
*
* @param aObserver the observer of the cameramanager
* @return The newly constructed CCameraManager
*/
CCameraManager* CCameraManager::NewLC(MCameraObserver& aObserver)
{
CCameraManager* self = new (ELeave) CCameraManager(aObserver);
CleanupStack::PushL(self);
self->ConstructL();
return self;
}
/**
* Constructs the document for aApp
*
* @param aObserver the observer of the cameramanager
*/
CCameraManager::CCameraManager(MCameraObserver& aObserver)
: CActive(CActive::EPriorityStandard),
iObserver(aObserver),
iCameraState(EUninitalised)
{
}
/**
* Destructor. Frees up memory, and turns the camera off.
*/
CCameraManager::~CCameraManager()
{
Cancel();
if (iCameraState != EUninitalised)
{
// Connected to the server so shut the camera down
iCameraServer.TurnCameraOff();
iCameraServer.Close();
}
}
/**
* Symbian OS 2nd phase constructor. Connects to the camera server,
*
*/
void CCameraManager::ConstructL()
{
// This function will leave if there camera server
// is not available on the hardware or if the
// camera server is already in use by another application.
User::LeaveIfError(iCameraServer.Connect());
CActiveScheduler::Add(this);
StartCamera();
}
/**
* Symbian OS 2nd phase constructor.
* Issues an asyncronous request to the
* camera serve to turn on the camera.
*
*/
void CCameraManager::StartCamera()
{
iCameraState = EStartingCamera;
iCameraServer.TurnCameraOn(iStatus);
SetActive();
}
/**
* Returns whether the camera is ready to take a picture
*
* @return Is the camera ready
*/
TBool CCameraManager::IsReady() const
{
return (iCameraState == EReady);
}
/**
* Issues an asyncronous request to take a picture
*
* @param handle to bitmap, which if the request completes
* successfully will contain the created image.
*/
void CCameraManager::TakePicture(CFbsBitmap& aBitmap)
{
__ASSERT_DEBUG(IsReady(), User::Panic(KCameraPanic, KCameraManagerNotReady));
iCameraState = ETakingPicture;
iCameraServer.GetImage(iStatus, aBitmap);
SetActive();
}
/**
* Called from CActive::Cancel() is called, allowing this object
* to provide specific cleanup activity.
*
*/
void CCameraManager::DoCancel()
{
// Do nothing
}
/**
* Called when the an asyncronous request completes. If there has been an
* error, the observer's CameraErrorL is called. If the request completes
* successfully a state pattern is used to determine which oberver
* function is called.
*
*/
void CCameraManager::RunL()
{
if (iStatus != KErrNone)
{
if (iStatus == KErrBadPower)
{
// The camera has powered down
iCameraState = EError;
}
// report the error to the observer
iObserver.CameraErrorL(iStatus.Int());
return;
}
switch (iCameraState)
{
case EStartingCamera:
// The camera has been turned on, successfully so
// set the image quality to low and the lighting conditions to normal.
iCameraServer.SetLightingConditions(RCameraServ::ELightingNormal);
iCameraServer.SetImageQuality(RCameraServ::EQualityLow);
iCameraState = EReady;
iObserver.CameraReadyL();
break;
case ETakingPicture:
iCameraState = EReady;
iObserver.PictureTakenL();
break;
case EReady:
case EError:
default:
iCameraState = EError; // For the invalid cases
iObserver.CameraErrorL(KErrGeneral);
}
}
/**
* Called if RunL leaves
*/
TInt CCameraManager::RunError(TInt aError)
{
return aError;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -