os/mm/mmplugins/cameraplugins/source/mmcameraclientplugin/mmcameraserver/src/mmcameraserver.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/mm/mmplugins/cameraplugins/source/mmcameraclientplugin/mmcameraserver/src/mmcameraserver.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,151 @@
     1.4 +// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +/**
    1.20 + @file
    1.21 + @internalComponent
    1.22 +*/
    1.23 +
    1.24 +#include "mmcameraserver.h"
    1.25 +#include "mmcameraserversession.h"
    1.26 +#include "mmcameraservercontroller.h"
    1.27 +#include "mmcameraservershutdown.h"
    1.28 +
    1.29 +
    1.30 +CMMCameraServer* CMMCameraServer::NewLC()
    1.31 +	{
    1.32 +	CMMCameraServer* self = new(ELeave) CMMCameraServer();
    1.33 +	CleanupStack::PushL(self);
    1.34 +	self->ConstructL();
    1.35 +	return self;
    1.36 +	}
    1.37 +
    1.38 +CMMCameraServer::CMMCameraServer() 
    1.39 +	: CServer2 (CActive::EPriorityStandard),
    1.40 +    iCamSessionCount(0),
    1.41 +    iCamControllerQ(_FOFF(CMMCameraServerController,iCamCntrlLink))
    1.42 +	{
    1.43 +	}
    1.44 +
    1.45 +CMMCameraServer::~CMMCameraServer()
    1.46 +	{
    1.47 +	if (iShutdown)
    1.48 +		{
    1.49 +		iShutdown->Cancel();
    1.50 +		}
    1.51 +
    1.52 +	while (!iCamControllerQ.IsEmpty())   // free the memory on the heap used for controller queues 
    1.53 +		{
    1.54 +		CMMCameraServerController *pCntrl = iCamControllerQ.First();
    1.55 +		delete pCntrl;
    1.56 +		}
    1.57 +
    1.58 +	delete iPolicyManager;
    1.59 +	delete iShutdown;
    1.60 +	}
    1.61 +
    1.62 +void CMMCameraServer::ConstructL()
    1.63 +	{
    1.64 +	iPolicyManager = CMMCameraServerPolicyManager::NewL();
    1.65 +	StartL(KMMCameraServerName);
    1.66 +
    1.67 +	iShutdown = CMMCameraServerShutdown::NewL();
    1.68 +	iShutdown->Start();
    1.69 +	}
    1.70 +
    1.71 +void CMMCameraServer::AddSession()
    1.72 +	{
    1.73 +    ++iCamSessionCount;
    1.74 +    if(iCamSessionCount == 1)
    1.75 +        {
    1.76 +    	iShutdown->Cancel();
    1.77 +        }
    1.78 +	}
    1.79 +
    1.80 +void CMMCameraServer::DropSession()
    1.81 +	{
    1.82 +	--iCamSessionCount; 
    1.83 +	if(iCamSessionCount == 0)
    1.84 +	    {
    1.85 +	    if (!iShutdown->IsActive())
    1.86 +			{
    1.87 +	    	iShutdown->Start();
    1.88 +			}
    1.89 +	    }
    1.90 +	}
    1.91 +
    1.92 +/**
    1.93 + * Provides a Camera controller object for the specified camera index.
    1.94 + */
    1.95 +void CMMCameraServer::GetCameraControllerL(TInt aCameraIndex, CMMCameraServerController*& aCameraController)
    1.96 +	{
    1.97 +	TDblQueIter<CMMCameraServerController> controllerIterator(iCamControllerQ);
    1.98 +	controllerIterator.SetToFirst();
    1.99 +	CMMCameraServerController* pCntrl = controllerIterator;
   1.100 +
   1.101 +	// loop through iterator to find desired camera controller
   1.102 +	while(pCntrl)
   1.103 +		{
   1.104 +		if(aCameraIndex == pCntrl->CameraIndex())
   1.105 +			{
   1.106 +			// found required controller
   1.107 +			aCameraController = controllerIterator;
   1.108 +			break;
   1.109 +			}
   1.110 +		controllerIterator++;
   1.111 +		pCntrl = controllerIterator;
   1.112 +		}
   1.113 +
   1.114 +	// No controllers exist for specified camera index so create new one and append to queue
   1.115 +	if(!pCntrl)
   1.116 +		{
   1.117 +		aCameraController = CMMCameraServerController::NewL(aCameraIndex);
   1.118 +		iCamControllerQ.AddLast(*aCameraController);
   1.119 +		}
   1.120 +	}
   1.121 +
   1.122 +void CMMCameraServer::GetCameraControllerQueryL(CMMCameraServerControllerQuery*& aCameraControllerQuery)
   1.123 +	{
   1.124 +	aCameraControllerQuery = CMMCameraServerControllerQuery::NewL();
   1.125 +	}
   1.126 +
   1.127 +CSession2* CMMCameraServer::NewSessionL(const TVersion& aVersion, const RMessage2& aMessage) const
   1.128 +	{
   1.129 +	// Check that the version is OK
   1.130 +    TVersion version(KECamServMajorVerNumber, KECamServMinorVerNumber, KECamServBuildVerNumber);
   1.131 +    if (!User::QueryVersionSupported(version, aVersion))
   1.132 +    	{
   1.133 +    	User::Leave(KErrNotSupported);
   1.134 +    	}
   1.135 +
   1.136 +	iPolicyManager->OnConnectL(aMessage);
   1.137 +	
   1.138 +	return new(ELeave) CMMCameraServerSession();
   1.139 +	}
   1.140 +
   1.141 +TInt CMMCameraServer::RunError(TInt aError)
   1.142 +	{
   1.143 +	Message().Complete(aError); //send error back to client
   1.144 +	// should have :- if(!IsActive())
   1.145 +	ReStart();
   1.146 +
   1.147 +	return (KErrNone);
   1.148 +	}
   1.149 +
   1.150 +void CMMCameraServer::PanicClient(const RMessage2& aMessage, TServerPanic aPanic)
   1.151 +	{
   1.152 +	_LIT(KPanic, "MMCameraServer");
   1.153 +	aMessage.Panic(KPanic, aPanic);
   1.154 +	}