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 "mmcameraclientinterface.h" sl@0: #include sl@0: sl@0: sl@0: /** sl@0: * Starts the server process. sl@0: * sl@0: * Simultaneous launching of two such processes should be detected when the second sl@0: * one attempts to create the server object, failing with KErrAlreadyExists. sl@0: */ sl@0: static TInt StartServer() sl@0: { sl@0: const TUidType serverUid(KNullUid, KExecutableImageUid, KECamServerUid3); sl@0: RProcess server; sl@0: TInt err = server.Create(KMMCameraServerExe, KNullDesC, serverUid); sl@0: if (err != KErrNone) sl@0: { sl@0: return err; sl@0: } sl@0: TRequestStatus stat; sl@0: server.Rendezvous(stat); sl@0: if (stat != KRequestPending) sl@0: { sl@0: server.Kill(0); // abort startup sl@0: } sl@0: else sl@0: { sl@0: server.Resume(); // logon OK - start the server sl@0: } sl@0: sl@0: User::WaitForRequest(stat); // wait for start or death sl@0: // we can't use the 'exit reason' if the server panicked as this sl@0: // is the panic 'reason' and may be '0' which cannot be distinguished sl@0: // from KErrNone sl@0: err = (server.ExitType() == EExitPanic) ? KErrGeneral : stat.Int(); sl@0: server.Close(); sl@0: sl@0: return err; sl@0: } sl@0: sl@0: sl@0: /** sl@0: * Connect to the server. sl@0: * sl@0: * Will attempt to start the server if it has not yet been started or has been shut down. sl@0: */ sl@0: TInt RMMCameraSession::Connect() sl@0: { sl@0: TInt serverStartRetries = 2; sl@0: for (;;) sl@0: { sl@0: // Attempt to create a session to the server sl@0: TInt err = CreateSession(KMMCameraServerName, TVersion(0, 0, 0), KECamNumAsynchMsg); sl@0: if (err != KErrNotFound && err != KErrServerTerminated) sl@0: { sl@0: return err; sl@0: } sl@0: sl@0: if (--serverStartRetries == 0) sl@0: { sl@0: return err; sl@0: } sl@0: sl@0: // Server not found or shut down so (re)start the server sl@0: err = StartServer(); sl@0: if (err != KErrNone && err != KErrAlreadyExists) sl@0: { sl@0: return err; sl@0: } sl@0: } sl@0: } sl@0: sl@0: sl@0: // sl@0: // Synchronous interface APIs sl@0: // sl@0: sl@0: TInt RMMCameraSession::SendMessage(TECamMsgId aMsgId, TCameraParameterId aParameterId, TDes8& aMessage) sl@0: { sl@0: if (aMessage.Length() > KECamMaxMessage) sl@0: { sl@0: return KErrArgument; sl@0: } sl@0: sl@0: return SendReceive(aMsgId, TIpcArgs(aParameterId, &aMessage)); sl@0: } sl@0: sl@0: TInt RMMCameraSession::SendMessage(TECamMsgId aMsgId, TCameraParameterId aParameterId, TInt aMessage) sl@0: { sl@0: return SendReceive(aMsgId, TIpcArgs(aParameterId, aMessage)); sl@0: } sl@0: sl@0: TInt RMMCameraSession::SendMessage(TECamMsgId aMsgId, TDes8& aMessage) sl@0: { sl@0: if (aMessage.Length() > KECamMaxMessage) sl@0: { sl@0: return KErrArgument; sl@0: } sl@0: sl@0: return SendReceive(aMsgId, TIpcArgs(&aMessage)); sl@0: } sl@0: sl@0: TInt RMMCameraSession::SendMessage(TECamMsgId aMsgId, TInt aMessage) sl@0: { sl@0: return SendReceive(aMsgId, TIpcArgs(aMessage)); sl@0: } sl@0: sl@0: TInt RMMCameraSession::SendMessage(TECamMsgId aMsgId) sl@0: { sl@0: return SendReceive(aMsgId); sl@0: } sl@0: sl@0: TInt RMMCameraSession::SendRxMessage(TECamMsgId aMsgId, TCameraParameterId aParameterId, TDes8& aMessage) const sl@0: { sl@0: if (aMessage.Length() > KECamMaxMessage) sl@0: { sl@0: return KErrArgument; sl@0: } sl@0: sl@0: return SendReceive(aMsgId, TIpcArgs(aParameterId, &aMessage)); sl@0: } sl@0: sl@0: TInt RMMCameraSession::SendRxMessage(TECamMsgId aMsgId, TCameraParameterId aParameterId, TInt aMessage) const sl@0: { sl@0: return SendReceive(aMsgId, TIpcArgs(aParameterId, aMessage)); sl@0: } sl@0: sl@0: TInt RMMCameraSession::SendRxMessage(TECamMsgId aMsgId, TDes8& aMessage) const sl@0: { sl@0: if (aMessage.Length() > KECamMaxMessage) sl@0: { sl@0: return KErrArgument; sl@0: } sl@0: sl@0: return SendReceive(aMsgId, TIpcArgs(&aMessage)); sl@0: } sl@0: sl@0: sl@0: // sl@0: // Asynchronous interface APIs sl@0: // sl@0: sl@0: TInt RMMCameraSession::ReceiveMessage(TECamMsgId aMsgId, TDes8& aMessage, TRequestStatus& aStatus) sl@0: { sl@0: if (aMessage.Length() > KECamMaxMessage) sl@0: { sl@0: return KErrArgument; sl@0: } sl@0: sl@0: SendReceive(aMsgId, TIpcArgs(&aMessage), aStatus); sl@0: sl@0: return KErrNone; sl@0: } sl@0: sl@0: void RMMCameraSession::ReceiveMessage(TECamMsgId aMsgId, TInt aMessage, TRequestStatus& aStatus) sl@0: { sl@0: SendReceive(aMsgId, TIpcArgs(aMessage), aStatus); sl@0: }