sl@0: // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: /** sl@0: @file sl@0: @internalComponent sl@0: */ sl@0: sl@0: #include "mmcameraserver.h" sl@0: #include "mmcameraserversession.h" sl@0: #include "mmcameraservercontroller.h" sl@0: #include "mmcameraservershutdown.h" sl@0: sl@0: sl@0: CMMCameraServer* CMMCameraServer::NewLC() sl@0: { sl@0: CMMCameraServer* self = new(ELeave) CMMCameraServer(); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(); sl@0: return self; sl@0: } sl@0: sl@0: CMMCameraServer::CMMCameraServer() sl@0: : CServer2 (CActive::EPriorityStandard), sl@0: iCamSessionCount(0), sl@0: iCamControllerQ(_FOFF(CMMCameraServerController,iCamCntrlLink)) sl@0: { sl@0: } sl@0: sl@0: CMMCameraServer::~CMMCameraServer() sl@0: { sl@0: if (iShutdown) sl@0: { sl@0: iShutdown->Cancel(); sl@0: } sl@0: sl@0: while (!iCamControllerQ.IsEmpty()) // free the memory on the heap used for controller queues sl@0: { sl@0: CMMCameraServerController *pCntrl = iCamControllerQ.First(); sl@0: delete pCntrl; sl@0: } sl@0: sl@0: delete iPolicyManager; sl@0: delete iShutdown; sl@0: } sl@0: sl@0: void CMMCameraServer::ConstructL() sl@0: { sl@0: iPolicyManager = CMMCameraServerPolicyManager::NewL(); sl@0: StartL(KMMCameraServerName); sl@0: sl@0: iShutdown = CMMCameraServerShutdown::NewL(); sl@0: iShutdown->Start(); sl@0: } sl@0: sl@0: void CMMCameraServer::AddSession() sl@0: { sl@0: ++iCamSessionCount; sl@0: if(iCamSessionCount == 1) sl@0: { sl@0: iShutdown->Cancel(); sl@0: } sl@0: } sl@0: sl@0: void CMMCameraServer::DropSession() sl@0: { sl@0: --iCamSessionCount; sl@0: if(iCamSessionCount == 0) sl@0: { sl@0: if (!iShutdown->IsActive()) sl@0: { sl@0: iShutdown->Start(); sl@0: } sl@0: } sl@0: } sl@0: sl@0: /** sl@0: * Provides a Camera controller object for the specified camera index. sl@0: */ sl@0: void CMMCameraServer::GetCameraControllerL(TInt aCameraIndex, CMMCameraServerController*& aCameraController) sl@0: { sl@0: TDblQueIter controllerIterator(iCamControllerQ); sl@0: controllerIterator.SetToFirst(); sl@0: CMMCameraServerController* pCntrl = controllerIterator; sl@0: sl@0: // loop through iterator to find desired camera controller sl@0: while(pCntrl) sl@0: { sl@0: if(aCameraIndex == pCntrl->CameraIndex()) sl@0: { sl@0: // found required controller sl@0: aCameraController = controllerIterator; sl@0: break; sl@0: } sl@0: controllerIterator++; sl@0: pCntrl = controllerIterator; sl@0: } sl@0: sl@0: // No controllers exist for specified camera index so create new one and append to queue sl@0: if(!pCntrl) sl@0: { sl@0: aCameraController = CMMCameraServerController::NewL(aCameraIndex); sl@0: iCamControllerQ.AddLast(*aCameraController); sl@0: } sl@0: } sl@0: sl@0: void CMMCameraServer::GetCameraControllerQueryL(CMMCameraServerControllerQuery*& aCameraControllerQuery) sl@0: { sl@0: aCameraControllerQuery = CMMCameraServerControllerQuery::NewL(); sl@0: } sl@0: sl@0: CSession2* CMMCameraServer::NewSessionL(const TVersion& aVersion, const RMessage2& aMessage) const sl@0: { sl@0: // Check that the version is OK sl@0: TVersion version(KECamServMajorVerNumber, KECamServMinorVerNumber, KECamServBuildVerNumber); sl@0: if (!User::QueryVersionSupported(version, aVersion)) sl@0: { sl@0: User::Leave(KErrNotSupported); sl@0: } sl@0: sl@0: iPolicyManager->OnConnectL(aMessage); sl@0: sl@0: return new(ELeave) CMMCameraServerSession(); sl@0: } sl@0: sl@0: TInt CMMCameraServer::RunError(TInt aError) sl@0: { sl@0: Message().Complete(aError); //send error back to client sl@0: // should have :- if(!IsActive()) sl@0: ReStart(); sl@0: sl@0: return (KErrNone); sl@0: } sl@0: sl@0: void CMMCameraServer::PanicClient(const RMessage2& aMessage, TServerPanic aPanic) sl@0: { sl@0: _LIT(KPanic, "MMCameraServer"); sl@0: aMessage.Panic(KPanic, aPanic); sl@0: }