os/mm/mmplugins/cameraplugins/source/mmcameraclientplugin/mmcameraclientsession/src/mmcameraclientinterface.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/mm/mmplugins/cameraplugins/source/mmcameraclientplugin/mmcameraclientsession/src/mmcameraclientinterface.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,178 @@
     1.4 +// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +/**
    1.20 + @file
    1.21 + @internalComponent
    1.22 +*/
    1.23 +
    1.24 +#include "mmcameraclientinterface.h"
    1.25 +#include <e32uid.h>
    1.26 +
    1.27 +
    1.28 +/**
    1.29 + * Starts the server process. 
    1.30 + * 
    1.31 + * Simultaneous launching of two such processes should be detected when the second
    1.32 + * one attempts to create the server object, failing with KErrAlreadyExists.
    1.33 + */
    1.34 +static TInt StartServer()
    1.35 +    {
    1.36 +    const TUidType serverUid(KNullUid, KExecutableImageUid, KECamServerUid3);
    1.37 +    RProcess server;
    1.38 +    TInt err = server.Create(KMMCameraServerExe, KNullDesC, serverUid);
    1.39 +    if (err != KErrNone)
    1.40 +		{
    1.41 +        return err;
    1.42 +		}
    1.43 +    TRequestStatus stat;
    1.44 +    server.Rendezvous(stat);
    1.45 +    if (stat != KRequestPending)
    1.46 +		{
    1.47 +        server.Kill(0);     // abort startup
    1.48 +		}
    1.49 +    else
    1.50 +		{
    1.51 +        server.Resume();    // logon OK - start the server
    1.52 +		}
    1.53 +
    1.54 +    User::WaitForRequest(stat);     // wait for start or death
    1.55 +    // we can't use the 'exit reason' if the server panicked as this
    1.56 +    // is the panic 'reason' and may be '0' which cannot be distinguished
    1.57 +    // from KErrNone
    1.58 +    err = (server.ExitType() == EExitPanic) ? KErrGeneral : stat.Int();
    1.59 +    server.Close();
    1.60 +
    1.61 +    return err;
    1.62 +    }
    1.63 +
    1.64 +
    1.65 +/**
    1.66 + * Connect to the server.
    1.67 + * 
    1.68 + * Will attempt to start the server if it has not yet been started or has been shut down.
    1.69 + */
    1.70 +TInt RMMCameraSession::Connect()
    1.71 +    {
    1.72 +    TInt serverStartRetries = 2;
    1.73 +    for (;;)
    1.74 +        {
    1.75 +        // Attempt to create a session to the server
    1.76 +        TInt err = CreateSession(KMMCameraServerName, TVersion(0, 0, 0), KECamNumAsynchMsg);
    1.77 +        if (err != KErrNotFound && err != KErrServerTerminated)
    1.78 +			{
    1.79 +            return err;
    1.80 +			}
    1.81 +
    1.82 +		if (--serverStartRetries == 0)
    1.83 +			{
    1.84 +            return err;
    1.85 +			}
    1.86 +
    1.87 +		// Server not found or shut down so (re)start the server
    1.88 +        err = StartServer();
    1.89 +        if (err != KErrNone && err != KErrAlreadyExists)
    1.90 +            {
    1.91 +			return err;
    1.92 +			}
    1.93 +        }
    1.94 +    }
    1.95 +
    1.96 +
    1.97 +//
    1.98 +// Synchronous interface APIs
    1.99 +//
   1.100 +
   1.101 +TInt RMMCameraSession::SendMessage(TECamMsgId aMsgId, TCameraParameterId aParameterId, TDes8& aMessage)
   1.102 +	{
   1.103 +	if (aMessage.Length() > KECamMaxMessage)
   1.104 +    	{
   1.105 +    	return KErrArgument;
   1.106 +    	}
   1.107 +
   1.108 +	return SendReceive(aMsgId, TIpcArgs(aParameterId, &aMessage));
   1.109 +	}
   1.110 +
   1.111 +TInt RMMCameraSession::SendMessage(TECamMsgId aMsgId, TCameraParameterId aParameterId, TInt aMessage)
   1.112 +	{
   1.113 +	return SendReceive(aMsgId, TIpcArgs(aParameterId, aMessage));
   1.114 +	}
   1.115 +
   1.116 +TInt RMMCameraSession::SendMessage(TECamMsgId aMsgId, TDes8& aMessage)
   1.117 +    {
   1.118 +    if (aMessage.Length() > KECamMaxMessage)
   1.119 +    	{
   1.120 +    	return KErrArgument;
   1.121 +    	}
   1.122 +
   1.123 +    return SendReceive(aMsgId, TIpcArgs(&aMessage));
   1.124 +    }
   1.125 +
   1.126 +TInt RMMCameraSession::SendMessage(TECamMsgId aMsgId, TInt aMessage)
   1.127 +	{
   1.128 +	return SendReceive(aMsgId, TIpcArgs(aMessage));
   1.129 +	}
   1.130 +
   1.131 +TInt RMMCameraSession::SendMessage(TECamMsgId aMsgId)
   1.132 +	{
   1.133 +	return SendReceive(aMsgId);
   1.134 +	}
   1.135 +
   1.136 +TInt RMMCameraSession::SendRxMessage(TECamMsgId aMsgId, TCameraParameterId aParameterId, TDes8& aMessage) const
   1.137 +	{
   1.138 +	if (aMessage.Length() > KECamMaxMessage)
   1.139 +    	{
   1.140 +    	return KErrArgument;
   1.141 +    	}
   1.142 +
   1.143 +	return SendReceive(aMsgId, TIpcArgs(aParameterId, &aMessage));
   1.144 +	}
   1.145 +
   1.146 +TInt RMMCameraSession::SendRxMessage(TECamMsgId aMsgId, TCameraParameterId aParameterId, TInt aMessage) const
   1.147 +	{
   1.148 +	return SendReceive(aMsgId, TIpcArgs(aParameterId, aMessage));
   1.149 +	}
   1.150 +
   1.151 +TInt RMMCameraSession::SendRxMessage(TECamMsgId aMsgId, TDes8& aMessage) const
   1.152 +	{
   1.153 +	if (aMessage.Length() > KECamMaxMessage)
   1.154 +    	{
   1.155 +    	return KErrArgument;
   1.156 +    	}
   1.157 +
   1.158 +    return SendReceive(aMsgId, TIpcArgs(&aMessage));
   1.159 +	}
   1.160 +
   1.161 +
   1.162 +//
   1.163 +// Asynchronous interface APIs
   1.164 +//
   1.165 +
   1.166 +TInt RMMCameraSession::ReceiveMessage(TECamMsgId aMsgId, TDes8& aMessage, TRequestStatus& aStatus)
   1.167 +    {
   1.168 +    if (aMessage.Length() > KECamMaxMessage)
   1.169 +    	{
   1.170 +    	return KErrArgument;
   1.171 +    	}
   1.172 +
   1.173 +    SendReceive(aMsgId, TIpcArgs(&aMessage), aStatus);
   1.174 +
   1.175 +	return KErrNone;
   1.176 +    }
   1.177 +
   1.178 +void RMMCameraSession::ReceiveMessage(TECamMsgId aMsgId, TInt aMessage, TRequestStatus& aStatus)
   1.179 +    {
   1.180 +    SendReceive(aMsgId, TIpcArgs(aMessage), aStatus);
   1.181 +    }