os/mm/mmplugins/cameraplugins/source/mmcameraclientplugin/mmcameraclientsession/src/mmcameraclientsession.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 <ecom/ecom.h>
    22 #include <ecom/implementationproxy.h>
    23 #include <f32file.h>
    24 
    25 #include "mmcameraclientsession.h"
    26 #include "mmdirectviewfinder.h"
    27 
    28 #include <graphics/surfaceconfiguration.h>
    29 #include "w32std.h"
    30 
    31 /**
    32  * First-phase constructor
    33  */
    34 CMMCameraClientSession::CMMCameraClientSession():iCameraObserver2(NULL),
    35 									 iReserved(EFalse),
    36 									 iPoweredUp(EFalse),
    37 									 iPrepareCompleted(EFalse),
    38 									 iCollaborativeClient(EFalse)
    39 	{
    40 	}
    41 
    42 /**
    43  * NewL() factory function
    44  */
    45 CMMCameraClientSession* CMMCameraClientSession::NewL()
    46 	{
    47 	FileDependencyUtil::CheckFileDependencyL();
    48 	return new (ELeave) CMMCameraClientSession;
    49 	}
    50 
    51 /**
    52  * Destructor
    53  */
    54 CMMCameraClientSession::~CMMCameraClientSession()
    55 	{
    56 	delete iCameraPowerHandler;
    57 	delete iCameraAccessHandler;
    58 
    59 	iHashMap.Close();
    60 	iCameraSession.Close();
    61 	}
    62 
    63 
    64 //
    65 // from CCameraPlugin
    66 //
    67 
    68 /**
    69  * Derived from CCameraPlugin. Second Phase contruction
    70  *
    71  * @see CCameraPlugin
    72  */
    73 void CMMCameraClientSession::Construct2L(MCameraObserver& /*aObserver*/, TInt /*aCameraIndex*/)
    74 	{
    75 	User::Leave(KErrNotSupported);
    76 	}
    77 
    78 /**
    79  * Derived from CCameraPlugin. Second Phase contruction for collaborative clients
    80  *
    81  * @see CCameraPlugin
    82  */
    83 void CMMCameraClientSession::Construct2DupL(MCameraObserver& /*aObserver*/, TInt /*aCameraHandle*/)
    84 	{
    85 	User::Leave(KErrNotSupported);
    86 	}
    87 
    88 /**
    89  * Derived from CCameraPlugin. Second Phase contruction
    90  *
    91  * @see CCameraPlugin
    92  */
    93 void CMMCameraClientSession::Construct2L(MCameraObserver2& aObserver, TInt aCameraIndex, TInt aPriority)
    94 	{
    95 	if (aCameraIndex > CamerasAvailable())
    96 		{
    97 		User::Leave(KErrNotSupported);
    98 		}
    99 
   100 	iCameraIndex = aCameraIndex;
   101 	iPriority = aPriority;
   102 	iCameraObserver2 = &aObserver;
   103 
   104 	//initialize server
   105 	//create session
   106 	User::LeaveIfError(iCameraSession.Connect());
   107 
   108 	//open camera
   109 	TOpenCamera openCam;
   110 
   111 	openCam.iCameraIndex = iCameraIndex;
   112 	openCam.iPriority = iPriority;
   113 	openCam.iHandle = KECamHandleNotKnown;
   114 	openCam.iMMCapability = ETrue;  //could be changed.
   115 	openCam.iCollaborativeClient = EFalse;
   116 
   117 	TOpenCameraPckg openCamBuf(openCam);
   118 
   119 	User::LeaveIfError(iCameraSession.SendMessage(ECamOpenCamera, openCamBuf));
   120 					// since this call is synchronous, providing reference to local
   121 					//  varialbe is not a problem.
   122 												   
   123 	iCameraAccessHandler = CMMCameraAccessHandler::NewL(this, CActive::EPriorityStandard);
   124 	iCameraPowerHandler = CMMCameraPowerHandler::NewL(this, CActive::EPriorityStandard);
   125 	}
   126 
   127 /**
   128  * Derived from CCameraPlugin. Second Phase contruction for collaborative clients
   129  *
   130  * @see CCameraPlugin
   131  */
   132 void CMMCameraClientSession::Construct2DupL(MCameraObserver2& /*aObserver*/, TInt /*aCameraHandle*/)
   133 	{
   134 	User::Leave(KErrNotSupported);	
   135 	}
   136 
   137 
   138 //
   139 // from CCamera itself
   140 //
   141 
   142 /**
   143  * Retrieves information about the currectly reserved camera device
   144  *
   145  * @see CCamera::CameraInfo()
   146  */
   147 void CMMCameraClientSession::CameraInfo(TCameraInfo& /*aInfo*/) const
   148 	{ 
   149 	return;
   150 	}
   151 
   152 /**
   153  * Reserves the camera
   154  *
   155  * @see CCamera::Reserve()
   156  */
   157 void CMMCameraClientSession::Reserve()
   158 	{
   159 	iCameraAccessHandler->Reserve();
   160 	}
   161 
   162 /**
   163  * Relinquishes control of the camera device
   164  *
   165  * @see CCamera::Release()
   166  */
   167 void CMMCameraClientSession::Release()
   168 	{
   169 	iCameraSession.SendMessage(ECamCameraAccessControl, ECameraRelease);
   170 	iPoweredUp = EFalse;
   171 	}
   172 
   173 /**
   174  * Powers on the camera device
   175  *
   176  * @see CCamera::PowerOn()
   177  */
   178 void CMMCameraClientSession::PowerOn()
   179 	{
   180 	iCameraPowerHandler->PowerOn();
   181 	}
   182 
   183 /**
   184  * Powers down the camera device
   185  *
   186  * @see CCamera::PowerOff()
   187  */
   188 void CMMCameraClientSession::PowerOff()
   189 	{	
   190 	iCameraSession.SendMessage(ECamPowerCamera, ECameraPowerOff);
   191 	iPoweredUp = EFalse;
   192 	}
   193 
   194 /**
   195  * Retrieves the handle of the currently reserved camera
   196  *
   197  * @see CCamera::Handle()
   198  */
   199 TInt CMMCameraClientSession::Handle()
   200 	{
   201 	TCameraHandle handle;
   202 	TCameraHandlePckg pckg(handle);
   203 
   204 	iCameraSession.SendRxMessage(ECamCameraHandle, pckg);
   205 
   206 	handle = pckg();
   207 	return handle.iHandle;
   208 	}
   209 
   210 /**
   211  * Sets the optical zoom level
   212  *
   213  * @see CCamera::SetZoomFactorL()
   214  */
   215 void CMMCameraClientSession::SetZoomFactorL(TInt aZoomFactor)
   216 	{
   217 	User::LeaveIfError(iCameraSession.SendMessage(ECamSetParameter, EZoomFactor, aZoomFactor));
   218 	}
   219 
   220 /**
   221  *  Retrieves current optical zoom level
   222  *
   223  * @see CCamera::ZoomFactor()
   224  */
   225 TInt CMMCameraClientSession::ZoomFactor() const
   226 	{
   227 	TCameraZoom zoomFactor;
   228 	TCameraZoomPckg pckg(zoomFactor);
   229 	iCameraSession.SendRxMessage(ECamGetParameter, EZoomFactor, pckg);
   230 	zoomFactor = pckg();
   231 	return zoomFactor.iZoom;
   232 	}
   233 
   234 /**
   235  * Sets the digital zoom level
   236  *
   237  * @see CCamera::SetDigitalZoomFactorL()
   238  */
   239 void CMMCameraClientSession::SetDigitalZoomFactorL(TInt aDigitalZoomFactor)
   240 	{
   241 	User::LeaveIfError(iCameraSession.SendMessage(ECamSetParameter, EDigitalZoomFactor, aDigitalZoomFactor));
   242 	}
   243 
   244 /**
   245  * Retrieves the current digital zoom level
   246  *
   247  * @see CCamera::DigitalZoomFactor()
   248  */
   249 TInt CMMCameraClientSession::DigitalZoomFactor() const
   250 	{
   251 	TCameraDigitalZoom digitalZoomFactor;
   252 	TCameraDigitalZoomPckg pckg(digitalZoomFactor);
   253 	iCameraSession.SendRxMessage(ECamGetParameter, EDigitalZoomFactor, pckg);
   254 	digitalZoomFactor = pckg();
   255 	return digitalZoomFactor.iDigitalZoom;
   256 	}
   257 
   258 /**
   259  * Sets the contrast level
   260  *
   261  * @see CCamera::SetContrastL()
   262  */
   263 void CMMCameraClientSession::SetContrastL(TInt aContrast)
   264 	{
   265 	User::LeaveIfError(iCameraSession.SendMessage(ECamSetParameter, EContrast, aContrast));
   266 	}
   267 
   268 /**
   269  * Retrieves the current contrast level
   270  *
   271  * @see CCamera::Contrast()
   272  */
   273 TInt CMMCameraClientSession::Contrast() const
   274 	{
   275 	TCameraContrast contrast;
   276 	TCameraContrastPckg pckg(contrast);
   277 	iCameraSession.SendRxMessage(ECamGetParameter, EContrast, pckg);
   278 	contrast = pckg();
   279 	return contrast.iContrast;
   280 	}
   281 
   282 /**
   283  * Sets the brightness level
   284  *
   285  * @see CCamera::SetBrightnessL()
   286  */
   287 void CMMCameraClientSession::SetBrightnessL(TInt aBrightness)
   288 	{
   289 	User::LeaveIfError(iCameraSession.SendMessage(ECamSetParameter, EBrightness, aBrightness));
   290 	}
   291 
   292 /**
   293  * Retrieves the current brightness level
   294  *
   295  * @see CCamera::Brigthness()
   296  */
   297 TInt CMMCameraClientSession::Brightness() const
   298 	{
   299 	TCameraBrightness brightness;
   300 	TCameraBrightnessPckg pckg(brightness);
   301 	iCameraSession.SendRxMessage(ECamGetParameter, EBrightness, pckg);
   302 	brightness = pckg();
   303 	return brightness.iBrightness;
   304 	}
   305 
   306 /**
   307  * Sets the flash level
   308  *
   309  * @see CCamera::SetFlashL()
   310  */
   311 void CMMCameraClientSession::SetFlashL(TFlash aFlash)
   312 	{
   313 	TCameraFlash flash;
   314 	flash.iFlash = aFlash;
   315 	TCameraFlashPckg pckg(flash);
   316 
   317 	User::LeaveIfError(iCameraSession.SendMessage(ECamSetParameter, EFlash, pckg));
   318 	}
   319 
   320 /**
   321  * Retrieves the current flash level
   322  *
   323  * @see CCamera::Flash()
   324  */
   325 CCamera::TFlash CMMCameraClientSession::Flash() const
   326 	{
   327 	TCameraFlash flash;
   328 	TCameraFlashPckg pckg(flash);
   329 	
   330 	iCameraSession.SendRxMessage(ECamGetParameter, EFlash, pckg);
   331 	flash = pckg();
   332 	return flash.iFlash;
   333 	}
   334 
   335 /**
   336  * Sets the exposure level
   337  *
   338  * @see CCamera::SetExposureL()
   339  */
   340 void CMMCameraClientSession::SetExposureL(TExposure aExposure)
   341 	{
   342 	TCameraExposure exposure;
   343 	exposure.iExposure = aExposure;
   344 	TCameraExposurePckg pckg(exposure);
   345 
   346 	User::LeaveIfError(iCameraSession.SendMessage(ECamSetParameter, EExposure, pckg));
   347 	}
   348 
   349 /**
   350  * Retrieves the current exposure level
   351  *
   352  * @see CCamera::Exposure()
   353  */
   354 CCamera::TExposure CMMCameraClientSession::Exposure() const
   355 	{
   356 	TCameraExposure exposure;
   357 	TCameraExposurePckg pckg(exposure);
   358 	
   359 	iCameraSession.SendRxMessage(ECamGetParameter, EExposure, pckg);
   360 	exposure = pckg();
   361 	return exposure.iExposure;
   362 	}
   363 
   364 /**
   365  * Sets the white balance level
   366  *
   367  * @see CCamera::SetWhiteBalance()
   368  */
   369 void CMMCameraClientSession::SetWhiteBalanceL(TWhiteBalance aWhiteBalance)
   370 	{
   371 	TCameraWhiteBalance whiteBalance;
   372 	whiteBalance.iWhiteBalance = aWhiteBalance;
   373 	TCameraWhiteBalancePckg pckg(whiteBalance);
   374 
   375 	User::LeaveIfError(iCameraSession.SendMessage(ECamSetParameter, EWhiteBalance, pckg));
   376 	}
   377 
   378 /**
   379  * Retrieves the current white balance level
   380  *
   381  * @see CCamera::WhiteBalance()
   382  */
   383 CCamera::TWhiteBalance CMMCameraClientSession::WhiteBalance() const
   384 	{
   385 	TCameraWhiteBalance whiteBalance;
   386 	TCameraWhiteBalancePckg pckg(whiteBalance);
   387 	
   388 	iCameraSession.SendRxMessage(ECamGetParameter, EWhiteBalance, pckg);
   389 	whiteBalance = pckg();
   390 	return whiteBalance.iWhiteBalance;	
   391 	}
   392 
   393 /**
   394  * Starts client direct viewfinder.
   395  * Not supported in this implementation.
   396  * 
   397  * @see CCamera::StartViewFinderDirectL()
   398  */
   399 void CMMCameraClientSession::StartViewFinderDirectL(RWsSession& /*aWs*/, CWsScreenDevice& /*aScreenDevice*/, RWindowBase& /*aWindow*/, TRect& /*aScreenRect*/)
   400 	{
   401 	User::Leave(KErrNotSupported);	
   402 	}
   403 
   404 /**
   405  * Starts client direct viewfinder.
   406  * Not supported in this implementation.
   407  * 
   408  * @see CCamera::StartViewFinderDirectL()
   409  */
   410 void CMMCameraClientSession::StartViewFinderDirectL(RWsSession& /*aWs*/, CWsScreenDevice& /*aScreenDevice*/, RWindowBase& /*aWindow*/, TRect& /*aScreenRect*/, TRect& /*aClipRect*/)
   411 	{
   412 	User::Leave(KErrNotSupported);
   413 	}
   414 
   415 /**
   416  * Starts client viewfinder.
   417  * Not supported in this implementation.
   418  * 
   419  * @see CCamera::StartViewFinderBitmapsL()
   420  */
   421 void CMMCameraClientSession::StartViewFinderBitmapsL(TSize& /*aSize*/)
   422 	{
   423 	User::Leave(KErrNotSupported);
   424 	}
   425 
   426 /**
   427  * Starts client viewfinder.
   428  * Not supported in this implementation.
   429  * 
   430  * @see CCamera::StartViewFinderBitmapsL()
   431  */
   432 void CMMCameraClientSession::StartViewFinderBitmapsL(TSize& /*aSize*/, TRect& /*aClipRect*/)
   433 	{
   434 	User::Leave(KErrNotSupported);	
   435 	}
   436 
   437 /**
   438  * Starts client viewfinder.
   439  * Not supported in this implementation.
   440  * 
   441  * @see CCamera::StartViewFinderL()
   442  */
   443 void CMMCameraClientSession::StartViewFinderL(CCamera::TFormat /*aImageFormat*/, TSize& /*aSize*/)
   444 	{
   445 	User::Leave(KErrNotSupported);
   446 	}
   447 
   448 /**
   449  * Starts client viewfinder.
   450  * Not supported in this implementation.
   451  * 
   452  * @see CCamera::StartViewFinderL()
   453  */
   454 void CMMCameraClientSession::StartViewFinderL(CCamera::TFormat /*aImageFormat*/, TSize& /*aSize*/, TRect& /*aClipRect*/)
   455 	{
   456 	User::Leave(KErrNotSupported);	
   457 	}
   458 
   459 /**
   460  * Stops client viewfinder.
   461  * Not supported in this implementation.
   462  * 
   463  * @see CCamera::StopViewFinder()
   464  */
   465 void CMMCameraClientSession::StopViewFinder()
   466 	{
   467 	return;
   468 	}
   469 
   470 /**
   471  * Queries if viewfinder is active.
   472  * Not supported in this implementation.
   473  * 
   474  * @see CCamera::ViewFinderActive()
   475  */
   476 TBool CMMCameraClientSession::ViewFinderActive() const
   477 	{
   478 	return EFalse;
   479 	}
   480 
   481 /**
   482  * Turns on/off viewfinder mirrorring.
   483  * Not supported in this implementation.
   484  * 
   485  * @see CCamera::SetViewFinderMirrorL()
   486  */
   487 void CMMCameraClientSession::SetViewFinderMirrorL(TBool /*aMirror*/)
   488 	{
   489 	User::Leave(KErrNotSupported);
   490 	}
   491 
   492 /**
   493  * Queries whether viewfinder mirrorring is on or off.
   494  * Not supported in this implementation.
   495  * 
   496  * @see CCamera::ViewFinderMirrorL()
   497  */
   498 TBool CMMCameraClientSession::ViewFinderMirror() const
   499 	{
   500 	return EFalse;
   501 	}
   502 
   503 /**
   504  * Prepares image capture.
   505  * 
   506  * @see CCamera::PrepareImageCapture()
   507  */
   508 void CMMCameraClientSession::PrepareImageCaptureL(CCamera::TFormat /*aImageFormat*/, TInt /*aSizeIndex*/)
   509 	{
   510 	User::Leave(KErrNotSupported);
   511 	}
   512 
   513 /**
   514  * Prepares image capture.
   515  * 
   516  * @see CCamera::PrepareImageCapture()
   517  */
   518 void CMMCameraClientSession::PrepareImageCaptureL(CCamera::TFormat /*aImageFormat*/, TInt /*aSizeIndex*/, const TRect& /*aClipRect*/)
   519 	{
   520 	User::Leave(KErrNotSupported);
   521 	}
   522 
   523 /**
   524  * Captures image.
   525  * 
   526  * @see CCamera::CaptureImage()
   527  */
   528 void CMMCameraClientSession::CaptureImage()
   529 	{
   530 	return;
   531 	}
   532 
   533 /**
   534  * Cancels any ongoing image capture.
   535  * 
   536  * @see CCamera::CaptureImage()
   537  */
   538 void CMMCameraClientSession::CancelCaptureImage()
   539 	{
   540 	return;
   541 	}
   542 
   543 /**
   544  * Enumerates image capture sizes.
   545  * 
   546  * @see CCamera::EnumerateCaptureSizes()
   547  */
   548 void CMMCameraClientSession::EnumerateCaptureSizes(TSize& /*aSize*/, TInt /*aSizeIndex*/, CCamera::TFormat /*aFormat*/) const
   549 	{
   550 	return;
   551 	}
   552 
   553 /**
   554  * Prepares video capture.
   555  * 
   556  * @see CCamera::PrepareVideoCaptureL()
   557  */
   558 void CMMCameraClientSession::PrepareVideoCaptureL(CCamera::TFormat /*aFormat*/, TInt /*aSizeIndex*/, TInt /*aRateIndex*/, TInt /*aBuffersToUse*/, TInt /*aFramesPerBuffer*/)
   559 	{
   560 	User::Leave(KErrNotSupported);
   561 	}
   562 
   563 /**
   564  * Prepares video capture.
   565  * 
   566  * @see CCamera::PrepareVideoCaptureL()
   567  */
   568 void CMMCameraClientSession::PrepareVideoCaptureL(CCamera::TFormat /*aFormat*/, TInt /*aSizeIndex*/, TInt /*aRateIndex*/, TInt /*aBuffersToUse*/, TInt /*aFramesPerBuffer*/, const TRect& /*aClipRect*/)
   569 	{
   570 	User::Leave(KErrNotSupported);
   571 	}
   572 
   573 /**
   574  * Starts video capture.
   575  * 
   576  * @see CCamera::StartVideoCapture()
   577  */
   578 void CMMCameraClientSession::StartVideoCapture()
   579 	{
   580 	return;
   581 	}
   582 
   583 /**
   584  * Stops video capture.
   585  * 
   586  * @see CCamera::StopVideoCapture()
   587  */
   588 void CMMCameraClientSession::StopVideoCapture()
   589 	{
   590 	return;
   591 	}
   592 
   593 /**
   594  * Queries whether video capture is active.
   595  * 
   596  * @see CCamera::VideoCaptureActive()
   597  */
   598 TBool CMMCameraClientSession::VideoCaptureActive() const
   599 	{
   600 	return EFalse;	
   601 	}
   602 
   603 /**
   604  * Enumerates video frame sizes.
   605  * 
   606  * @see CCamera::EnumerateVideoFrameSizes()
   607  */
   608 void CMMCameraClientSession::EnumerateVideoFrameSizes(TSize& /*aSize*/, TInt /*aSizeIndex*/, CCamera::TFormat /*aFormat*/) const
   609 	{
   610 	return;
   611 	}
   612 
   613 /**
   614  * Enumerates video frame rates.
   615  * 
   616  * @see CCamera::EnumerateVideoFrameRates()
   617  */
   618 void CMMCameraClientSession::EnumerateVideoFrameRates(TReal32& /*aRate*/, TInt /*aRateIndex*/, CCamera::TFormat /*aFormat*/, TInt /*aSizeIndex*/, TExposure /*aExposure*/) const
   619 	{
   620 	return;
   621 	}
   622 
   623 /**
   624  * Retrieve the frame size.
   625  * 
   626  * @see CCamera::GetFrameSize()
   627  */
   628 void CMMCameraClientSession::GetFrameSize(TSize& /*aSize*/) const
   629 	{
   630 	return;	
   631 	}
   632 
   633 /**
   634  * Retrieve the frame rate.
   635  * 
   636  * @see CCamera::FrameRate()
   637  */
   638 TReal32 CMMCameraClientSession::FrameRate() const
   639 	{
   640 	return static_cast<TReal32>(0);
   641 	}
   642 
   643 /**
   644  * Retrieve the number of buffers currently in use.
   645  * 
   646  * @see CCamera::BuffersInUse()
   647  */
   648 TInt CMMCameraClientSession::BuffersInUse() const
   649 	{
   650 	return 0;
   651 	}
   652 
   653 /**
   654  * Retrieve the number of frames per buffer.
   655  * 
   656  * @see CCamera::FramesPerBuffer()
   657  */
   658 TInt CMMCameraClientSession::FramesPerBuffer() const
   659 	{
   660 	return 0;	
   661 	}
   662 
   663 /**
   664  * Set the Jpeg quality.
   665  * 
   666  * @see CCamera::SetJpegQuality()
   667  */
   668 void CMMCameraClientSession::SetJpegQuality(TInt /*aQuality*/)
   669 	{
   670 	return;
   671 	}
   672 
   673 /**
   674  * Retrieve the Jpeg quality.
   675  * 
   676  * @see CCamera::JpegQuality()
   677  */
   678 TInt CMMCameraClientSession::JpegQuality() const
   679 	{
   680 	return 0;	
   681 	}
   682 
   683 /**
   684  * Retrieves a custom interface based on the id passed in by the client.
   685  * 
   686  * @see CCamera::CustomInterface()
   687  */
   688 TAny* CMMCameraClientSession::CustomInterface(TUid aInterface)
   689 	{
   690 	switch (aInterface.iUid)
   691 		{
   692 		// The framework retrieves KECamMCameraV2DirectViewFinderUidValue followed by KECamMCameraBaseV2DirectViewFinderUidValue
   693 		// We take care to initialise iDirectViewFinder in the first case and use it in the subsequent call
   694 		case KECamMCameraV2DirectViewFinderUidValue:
   695 			{
   696 			ASSERT(!iDirectViewFinder);
   697 			TRAPD(err, iDirectViewFinder = CMMDirectViewFinder::NewL(*this));
   698 			if (err != KErrNone)
   699 				{
   700 				return NULL;
   701 				}
   702 
   703 			return static_cast<MCameraV2DirectViewFinder*>(iDirectViewFinder);
   704 	        }
   705 
   706 		case KECamMCameraBaseV2DirectViewFinderUidValue:
   707 			{
   708 			ASSERT(iDirectViewFinder);
   709 			iVF = static_cast<MCameraViewFinder*>(iDirectViewFinder);
   710 			//delete iDirectViewFinder;
   711 			iDirectViewFinder = NULL;
   712 			return iVF;
   713 	        }
   714 
   715 		default:
   716 			{
   717 			return NULL;
   718 			}
   719 		}
   720 	}
   721 
   722 //
   723 // From CCameraInfoPlugin
   724 //
   725 CMMCameraClientSessionInfo* CMMCameraClientSessionInfo::NewL()
   726 	{
   727 	FileDependencyUtil::CheckFileDependencyL();
   728 	return new (ELeave) CMMCameraClientSessionInfo;
   729 	}
   730 
   731 CMMCameraClientSessionInfo::~CMMCameraClientSessionInfo()
   732 	{
   733 	}
   734 
   735 /**
   736  * Retrieves the number of cameras available.
   737  * 
   738  * @see CCameraInfoPlugin::CamerasAvailable()
   739  */
   740 TInt CMMCameraClientSessionInfo::CamerasAvailable()
   741 	{
   742 	// One-off connection to the server
   743 	RMMCameraSession cameraSession;
   744 	TInt error = cameraSession.Connect();
   745 	if (error != KErrNone)
   746 		{
   747 		return 0;
   748 		}
   749 
   750 	TCamerasAvailable info;
   751 	TCamerasAvailablePckg pckg(info);
   752 
   753 	error = cameraSession.SendMessage(ECamQueryCamerasAvailable, pckg);
   754 	cameraSession.Close();
   755 	if (error != KErrNone)
   756 		{
   757 		return 0;
   758 		}
   759 
   760 	info = pckg();
   761 	return info.iCameraCount;
   762 	}
   763 
   764 CMMCameraClientSessionInfo::CMMCameraClientSessionInfo()
   765 	{
   766 	}
   767 
   768 
   769 
   770 void FileDependencyUtil::CheckFileDependencyL()
   771 	{	
   772 	RFs fsSession;
   773   	RFile file;
   774     CleanupClosePushL(fsSession);
   775   	User::LeaveIfError(fsSession.Connect());
   776     TInt err = file.Open(fsSession, KMMCameraPluginName, EFileRead);
   777   	file.Close();
   778   	if(err != KErrNone)
   779   		{
   780 	    User::LeaveIfError(KErrNotSupported);
   781   		}
   782   	CleanupStack::PopAndDestroy(&fsSession);
   783 	}
   784 
   785 
   786 //
   787 // CLASS CMMCameraAccessHandler
   788 //
   789 
   790 CMMCameraAccessHandler::CMMCameraAccessHandler(CMMCameraClientSession* aPlugin, TInt aPriority): CActive(aPriority), 
   791 																					   iPlugin(aPlugin)
   792 	{
   793 	}
   794 
   795 CMMCameraAccessHandler* CMMCameraAccessHandler::NewL(CMMCameraClientSession* aPlugin, TInt aPriority)
   796 	{
   797 	CMMCameraAccessHandler* self = new (ELeave) CMMCameraAccessHandler(aPlugin, aPriority);
   798 	CActiveScheduler::Add(self);
   799 	return self;
   800 	}
   801 
   802 CMMCameraAccessHandler::~CMMCameraAccessHandler()
   803 	{
   804 	Cancel();
   805 	}
   806 
   807 void CMMCameraAccessHandler::Reserve()
   808 	{
   809 	if(!IsActive())
   810 		{
   811 		// Reserve the camera
   812 		iPlugin->iCameraSession.ReceiveMessage(ECamCameraAccessControl, ECameraReservedNotification, iStatus);
   813 		SetActive();
   814 		}
   815 	else
   816 		{
   817 		// Reserve has been called again before first call has completed so notify the client
   818 		TECAMEvent ecamEvent(KUidECamEventReserveComplete, KErrInUse);
   819 		iPlugin->iCameraObserver2->HandleEvent(ecamEvent);
   820 		}
   821 	}
   822 
   823 void CMMCameraAccessHandler::RunL()
   824 	{ 
   825 	TInt ret = iStatus.Int();
   826 
   827 	if(!iPlugin->iReserved)
   828 		{
   829 		if(KErrNone == ret)
   830 			{
   831 			iPlugin->iReserved = ETrue;
   832 			if(!IsActive())
   833 				{
   834 				// Continue monitoring for overthrow messages should a higher priority client reserve the same camera index
   835 				iPlugin->iCameraSession.ReceiveMessage(ECamCameraAccessControl, ECameraOverthrowNotification, iStatus);
   836 				SetActive();
   837 				}
   838 			}
   839 
   840 		// notify the client that reserve has completed, successfully or otherwise
   841 		TECAMEvent ecamEvent(KUidECamEventReserveComplete, ret);	
   842 		iPlugin->iCameraObserver2->HandleEvent(ecamEvent);
   843 		}
   844 	else
   845 		{
   846 		iPlugin->iReserved = EFalse;
   847 
   848 		if (ret == KErrNone)
   849 			{
   850 			// Client has been overthrown by a second client with higher priority
   851 			TECAMEvent ecamEvent(KUidECamEventCameraNoLongerReserved, ret);
   852 			iPlugin->iCameraObserver2->HandleEvent(ecamEvent);		
   853 			}
   854 		}
   855 	}
   856 
   857 void CMMCameraAccessHandler::DoCancel()
   858 	{
   859 	if(!iPlugin->iReserved)
   860 		{
   861 		iPlugin->iCameraSession.SendMessage(ECamCameraAccessControl, ECameraCancelReservedNotification);
   862 
   863 		// Notify client that ongoing reserve request was cancelled
   864 		TECAMEvent ecamEvent(KUidECamEventReserveComplete, KErrCancel);
   865 		iPlugin->iCameraObserver2->HandleEvent(ecamEvent);
   866 		}
   867 	else
   868 		{
   869 		iPlugin->iCameraSession.SendMessage(ECamCameraAccessControl, ECameraCancelOverthrowNotification);
   870 		iPlugin->iReserved = EFalse;
   871 		}
   872 	}
   873 
   874 
   875 //
   876 //
   877 // CLASS CMMCameraPowerHandler
   878 //
   879 
   880 CMMCameraPowerHandler::CMMCameraPowerHandler(CMMCameraClientSession* aPlugin, TInt aPriority): CActive(aPriority), 
   881 																					 iPlugin(aPlugin)
   882 	{
   883 	}
   884 
   885 CMMCameraPowerHandler* CMMCameraPowerHandler::NewL(CMMCameraClientSession* aPlugin, TInt aPriority)
   886 	{
   887 	CMMCameraPowerHandler* self = new (ELeave) CMMCameraPowerHandler(aPlugin, aPriority);
   888 	CActiveScheduler::Add(self);
   889 	return self;
   890 	}
   891 
   892 CMMCameraPowerHandler::~CMMCameraPowerHandler()
   893 	{
   894 	Cancel();
   895 	}
   896 
   897 void CMMCameraPowerHandler::PowerOn()
   898 	{ 
   899 	if(!IsActive())
   900 		{
   901 		iPlugin->iCameraSession.ReceiveMessage(ECamPowerCamera, ECameraPowerOnNotification, iStatus);
   902 		SetActive();
   903 		}
   904 	else
   905 		{
   906 		// PowerOn has been called again before first call has completed so notify the client
   907 		TECAMEvent ecamEvent(KUidECamEventPowerOnComplete, KErrAlreadyExists);	
   908 		iPlugin->iCameraObserver2->HandleEvent(ecamEvent);	
   909 		}
   910 	}
   911 
   912 void CMMCameraPowerHandler::RunL()
   913 	{ 
   914 	TInt ret = iStatus.Int();
   915 
   916 	if(!iPlugin->iPoweredUp)
   917 		{
   918 		if (ret == KErrNone)
   919 			{
   920 			iPlugin->iPoweredUp = ETrue;
   921 			}
   922 		}
   923 
   924 	TECAMEvent ecamEvent(KUidECamEventPowerOnComplete, ret);	
   925 	iPlugin->iCameraObserver2->HandleEvent(ecamEvent);
   926 	}
   927 
   928 void CMMCameraPowerHandler::DoCancel()
   929 	{
   930 	if(!iPlugin->iPoweredUp)
   931 		{
   932 		iPlugin->iCameraSession.SendMessage(ECamPowerCamera, ECameraCancelPowerOnNotification);
   933 		} 
   934 	}
   935 
   936 
   937 // __________________________________________________________________________
   938 // Exported proxy for instantiation method resolution
   939 // Define the interface UIDs
   940 const TImplementationProxy ImplementationTable[] = 
   941 	{
   942 	IMPLEMENTATION_PROXY_ENTRY(KUidMMCameraClientSession, CMMCameraClientSession::NewL),
   943 	IMPLEMENTATION_PROXY_ENTRY(KUidMMCameraClientSessionInfo, CMMCameraClientSessionInfo::NewL)
   944 	};
   945 
   946 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)
   947 	{
   948 	aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy);
   949 
   950 	return ImplementationTable;
   951 	}