os/mm/mmplugins/cameraplugins/source/mmcameraclientplugin/mmcameraclientsession/src/mmcameraclientinterface.cpp
First public contribution.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
21 #include "mmcameraclientinterface.h"
26 * Starts the server process.
28 * Simultaneous launching of two such processes should be detected when the second
29 * one attempts to create the server object, failing with KErrAlreadyExists.
31 static TInt StartServer()
33 const TUidType serverUid(KNullUid, KExecutableImageUid, KECamServerUid3);
35 TInt err = server.Create(KMMCameraServerExe, KNullDesC, serverUid);
41 server.Rendezvous(stat);
42 if (stat != KRequestPending)
44 server.Kill(0); // abort startup
48 server.Resume(); // logon OK - start the server
51 User::WaitForRequest(stat); // wait for start or death
52 // we can't use the 'exit reason' if the server panicked as this
53 // is the panic 'reason' and may be '0' which cannot be distinguished
55 err = (server.ExitType() == EExitPanic) ? KErrGeneral : stat.Int();
63 * Connect to the server.
65 * Will attempt to start the server if it has not yet been started or has been shut down.
67 TInt RMMCameraSession::Connect()
69 TInt serverStartRetries = 2;
72 // Attempt to create a session to the server
73 TInt err = CreateSession(KMMCameraServerName, TVersion(0, 0, 0), KECamNumAsynchMsg);
74 if (err != KErrNotFound && err != KErrServerTerminated)
79 if (--serverStartRetries == 0)
84 // Server not found or shut down so (re)start the server
86 if (err != KErrNone && err != KErrAlreadyExists)
95 // Synchronous interface APIs
98 TInt RMMCameraSession::SendMessage(TECamMsgId aMsgId, TCameraParameterId aParameterId, TDes8& aMessage)
100 if (aMessage.Length() > KECamMaxMessage)
105 return SendReceive(aMsgId, TIpcArgs(aParameterId, &aMessage));
108 TInt RMMCameraSession::SendMessage(TECamMsgId aMsgId, TCameraParameterId aParameterId, TInt aMessage)
110 return SendReceive(aMsgId, TIpcArgs(aParameterId, aMessage));
113 TInt RMMCameraSession::SendMessage(TECamMsgId aMsgId, TDes8& aMessage)
115 if (aMessage.Length() > KECamMaxMessage)
120 return SendReceive(aMsgId, TIpcArgs(&aMessage));
123 TInt RMMCameraSession::SendMessage(TECamMsgId aMsgId, TInt aMessage)
125 return SendReceive(aMsgId, TIpcArgs(aMessage));
128 TInt RMMCameraSession::SendMessage(TECamMsgId aMsgId)
130 return SendReceive(aMsgId);
133 TInt RMMCameraSession::SendRxMessage(TECamMsgId aMsgId, TCameraParameterId aParameterId, TDes8& aMessage) const
135 if (aMessage.Length() > KECamMaxMessage)
140 return SendReceive(aMsgId, TIpcArgs(aParameterId, &aMessage));
143 TInt RMMCameraSession::SendRxMessage(TECamMsgId aMsgId, TCameraParameterId aParameterId, TInt aMessage) const
145 return SendReceive(aMsgId, TIpcArgs(aParameterId, aMessage));
148 TInt RMMCameraSession::SendRxMessage(TECamMsgId aMsgId, TDes8& aMessage) const
150 if (aMessage.Length() > KECamMaxMessage)
155 return SendReceive(aMsgId, TIpcArgs(&aMessage));
160 // Asynchronous interface APIs
163 TInt RMMCameraSession::ReceiveMessage(TECamMsgId aMsgId, TDes8& aMessage, TRequestStatus& aStatus)
165 if (aMessage.Length() > KECamMaxMessage)
170 SendReceive(aMsgId, TIpcArgs(&aMessage), aStatus);
175 void RMMCameraSession::ReceiveMessage(TECamMsgId aMsgId, TInt aMessage, TRequestStatus& aStatus)
177 SendReceive(aMsgId, TIpcArgs(aMessage), aStatus);