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