os/mm/mmplugins/cameraplugins/source/mmcameraclientplugin/mmcameraserver/src/mmcameraserver.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
/**
sl@0
    17
 @file
sl@0
    18
 @internalComponent
sl@0
    19
*/
sl@0
    20
sl@0
    21
#include "mmcameraserver.h"
sl@0
    22
#include "mmcameraserversession.h"
sl@0
    23
#include "mmcameraservercontroller.h"
sl@0
    24
#include "mmcameraservershutdown.h"
sl@0
    25
sl@0
    26
sl@0
    27
CMMCameraServer* CMMCameraServer::NewLC()
sl@0
    28
	{
sl@0
    29
	CMMCameraServer* self = new(ELeave) CMMCameraServer();
sl@0
    30
	CleanupStack::PushL(self);
sl@0
    31
	self->ConstructL();
sl@0
    32
	return self;
sl@0
    33
	}
sl@0
    34
sl@0
    35
CMMCameraServer::CMMCameraServer() 
sl@0
    36
	: CServer2 (CActive::EPriorityStandard),
sl@0
    37
    iCamSessionCount(0),
sl@0
    38
    iCamControllerQ(_FOFF(CMMCameraServerController,iCamCntrlLink))
sl@0
    39
	{
sl@0
    40
	}
sl@0
    41
sl@0
    42
CMMCameraServer::~CMMCameraServer()
sl@0
    43
	{
sl@0
    44
	if (iShutdown)
sl@0
    45
		{
sl@0
    46
		iShutdown->Cancel();
sl@0
    47
		}
sl@0
    48
sl@0
    49
	while (!iCamControllerQ.IsEmpty())   // free the memory on the heap used for controller queues 
sl@0
    50
		{
sl@0
    51
		CMMCameraServerController *pCntrl = iCamControllerQ.First();
sl@0
    52
		delete pCntrl;
sl@0
    53
		}
sl@0
    54
sl@0
    55
	delete iPolicyManager;
sl@0
    56
	delete iShutdown;
sl@0
    57
	}
sl@0
    58
sl@0
    59
void CMMCameraServer::ConstructL()
sl@0
    60
	{
sl@0
    61
	iPolicyManager = CMMCameraServerPolicyManager::NewL();
sl@0
    62
	StartL(KMMCameraServerName);
sl@0
    63
sl@0
    64
	iShutdown = CMMCameraServerShutdown::NewL();
sl@0
    65
	iShutdown->Start();
sl@0
    66
	}
sl@0
    67
sl@0
    68
void CMMCameraServer::AddSession()
sl@0
    69
	{
sl@0
    70
    ++iCamSessionCount;
sl@0
    71
    if(iCamSessionCount == 1)
sl@0
    72
        {
sl@0
    73
    	iShutdown->Cancel();
sl@0
    74
        }
sl@0
    75
	}
sl@0
    76
sl@0
    77
void CMMCameraServer::DropSession()
sl@0
    78
	{
sl@0
    79
	--iCamSessionCount; 
sl@0
    80
	if(iCamSessionCount == 0)
sl@0
    81
	    {
sl@0
    82
	    if (!iShutdown->IsActive())
sl@0
    83
			{
sl@0
    84
	    	iShutdown->Start();
sl@0
    85
			}
sl@0
    86
	    }
sl@0
    87
	}
sl@0
    88
sl@0
    89
/**
sl@0
    90
 * Provides a Camera controller object for the specified camera index.
sl@0
    91
 */
sl@0
    92
void CMMCameraServer::GetCameraControllerL(TInt aCameraIndex, CMMCameraServerController*& aCameraController)
sl@0
    93
	{
sl@0
    94
	TDblQueIter<CMMCameraServerController> controllerIterator(iCamControllerQ);
sl@0
    95
	controllerIterator.SetToFirst();
sl@0
    96
	CMMCameraServerController* pCntrl = controllerIterator;
sl@0
    97
sl@0
    98
	// loop through iterator to find desired camera controller
sl@0
    99
	while(pCntrl)
sl@0
   100
		{
sl@0
   101
		if(aCameraIndex == pCntrl->CameraIndex())
sl@0
   102
			{
sl@0
   103
			// found required controller
sl@0
   104
			aCameraController = controllerIterator;
sl@0
   105
			break;
sl@0
   106
			}
sl@0
   107
		controllerIterator++;
sl@0
   108
		pCntrl = controllerIterator;
sl@0
   109
		}
sl@0
   110
sl@0
   111
	// No controllers exist for specified camera index so create new one and append to queue
sl@0
   112
	if(!pCntrl)
sl@0
   113
		{
sl@0
   114
		aCameraController = CMMCameraServerController::NewL(aCameraIndex);
sl@0
   115
		iCamControllerQ.AddLast(*aCameraController);
sl@0
   116
		}
sl@0
   117
	}
sl@0
   118
sl@0
   119
void CMMCameraServer::GetCameraControllerQueryL(CMMCameraServerControllerQuery*& aCameraControllerQuery)
sl@0
   120
	{
sl@0
   121
	aCameraControllerQuery = CMMCameraServerControllerQuery::NewL();
sl@0
   122
	}
sl@0
   123
sl@0
   124
CSession2* CMMCameraServer::NewSessionL(const TVersion& aVersion, const RMessage2& aMessage) const
sl@0
   125
	{
sl@0
   126
	// Check that the version is OK
sl@0
   127
    TVersion version(KECamServMajorVerNumber, KECamServMinorVerNumber, KECamServBuildVerNumber);
sl@0
   128
    if (!User::QueryVersionSupported(version, aVersion))
sl@0
   129
    	{
sl@0
   130
    	User::Leave(KErrNotSupported);
sl@0
   131
    	}
sl@0
   132
sl@0
   133
	iPolicyManager->OnConnectL(aMessage);
sl@0
   134
	
sl@0
   135
	return new(ELeave) CMMCameraServerSession();
sl@0
   136
	}
sl@0
   137
sl@0
   138
TInt CMMCameraServer::RunError(TInt aError)
sl@0
   139
	{
sl@0
   140
	Message().Complete(aError); //send error back to client
sl@0
   141
	// should have :- if(!IsActive())
sl@0
   142
	ReStart();
sl@0
   143
sl@0
   144
	return (KErrNone);
sl@0
   145
	}
sl@0
   146
sl@0
   147
void CMMCameraServer::PanicClient(const RMessage2& aMessage, TServerPanic aPanic)
sl@0
   148
	{
sl@0
   149
	_LIT(KPanic, "MMCameraServer");
sl@0
   150
	aMessage.Panic(KPanic, aPanic);
sl@0
   151
	}