os/mm/mmplugins/cameraplugins/source/mmcameraclientplugin/mmcameraclientsession/src/mmcameraclientinterface.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
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".
     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 "mmcameraclientinterface.h"
    22 #include <e32uid.h>
    23 
    24 
    25 /**
    26  * Starts the server process. 
    27  * 
    28  * Simultaneous launching of two such processes should be detected when the second
    29  * one attempts to create the server object, failing with KErrAlreadyExists.
    30  */
    31 static TInt StartServer()
    32     {
    33     const TUidType serverUid(KNullUid, KExecutableImageUid, KECamServerUid3);
    34     RProcess server;
    35     TInt err = server.Create(KMMCameraServerExe, KNullDesC, serverUid);
    36     if (err != KErrNone)
    37 		{
    38         return err;
    39 		}
    40     TRequestStatus stat;
    41     server.Rendezvous(stat);
    42     if (stat != KRequestPending)
    43 		{
    44         server.Kill(0);     // abort startup
    45 		}
    46     else
    47 		{
    48         server.Resume();    // logon OK - start the server
    49 		}
    50 
    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
    54     // from KErrNone
    55     err = (server.ExitType() == EExitPanic) ? KErrGeneral : stat.Int();
    56     server.Close();
    57 
    58     return err;
    59     }
    60 
    61 
    62 /**
    63  * Connect to the server.
    64  * 
    65  * Will attempt to start the server if it has not yet been started or has been shut down.
    66  */
    67 TInt RMMCameraSession::Connect()
    68     {
    69     TInt serverStartRetries = 2;
    70     for (;;)
    71         {
    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)
    75 			{
    76             return err;
    77 			}
    78 
    79 		if (--serverStartRetries == 0)
    80 			{
    81             return err;
    82 			}
    83 
    84 		// Server not found or shut down so (re)start the server
    85         err = StartServer();
    86         if (err != KErrNone && err != KErrAlreadyExists)
    87             {
    88 			return err;
    89 			}
    90         }
    91     }
    92 
    93 
    94 //
    95 // Synchronous interface APIs
    96 //
    97 
    98 TInt RMMCameraSession::SendMessage(TECamMsgId aMsgId, TCameraParameterId aParameterId, TDes8& aMessage)
    99 	{
   100 	if (aMessage.Length() > KECamMaxMessage)
   101     	{
   102     	return KErrArgument;
   103     	}
   104 
   105 	return SendReceive(aMsgId, TIpcArgs(aParameterId, &aMessage));
   106 	}
   107 
   108 TInt RMMCameraSession::SendMessage(TECamMsgId aMsgId, TCameraParameterId aParameterId, TInt aMessage)
   109 	{
   110 	return SendReceive(aMsgId, TIpcArgs(aParameterId, aMessage));
   111 	}
   112 
   113 TInt RMMCameraSession::SendMessage(TECamMsgId aMsgId, TDes8& aMessage)
   114     {
   115     if (aMessage.Length() > KECamMaxMessage)
   116     	{
   117     	return KErrArgument;
   118     	}
   119 
   120     return SendReceive(aMsgId, TIpcArgs(&aMessage));
   121     }
   122 
   123 TInt RMMCameraSession::SendMessage(TECamMsgId aMsgId, TInt aMessage)
   124 	{
   125 	return SendReceive(aMsgId, TIpcArgs(aMessage));
   126 	}
   127 
   128 TInt RMMCameraSession::SendMessage(TECamMsgId aMsgId)
   129 	{
   130 	return SendReceive(aMsgId);
   131 	}
   132 
   133 TInt RMMCameraSession::SendRxMessage(TECamMsgId aMsgId, TCameraParameterId aParameterId, TDes8& aMessage) const
   134 	{
   135 	if (aMessage.Length() > KECamMaxMessage)
   136     	{
   137     	return KErrArgument;
   138     	}
   139 
   140 	return SendReceive(aMsgId, TIpcArgs(aParameterId, &aMessage));
   141 	}
   142 
   143 TInt RMMCameraSession::SendRxMessage(TECamMsgId aMsgId, TCameraParameterId aParameterId, TInt aMessage) const
   144 	{
   145 	return SendReceive(aMsgId, TIpcArgs(aParameterId, aMessage));
   146 	}
   147 
   148 TInt RMMCameraSession::SendRxMessage(TECamMsgId aMsgId, TDes8& aMessage) const
   149 	{
   150 	if (aMessage.Length() > KECamMaxMessage)
   151     	{
   152     	return KErrArgument;
   153     	}
   154 
   155     return SendReceive(aMsgId, TIpcArgs(&aMessage));
   156 	}
   157 
   158 
   159 //
   160 // Asynchronous interface APIs
   161 //
   162 
   163 TInt RMMCameraSession::ReceiveMessage(TECamMsgId aMsgId, TDes8& aMessage, TRequestStatus& aStatus)
   164     {
   165     if (aMessage.Length() > KECamMaxMessage)
   166     	{
   167     	return KErrArgument;
   168     	}
   169 
   170     SendReceive(aMsgId, TIpcArgs(&aMessage), aStatus);
   171 
   172 	return KErrNone;
   173     }
   174 
   175 void RMMCameraSession::ReceiveMessage(TECamMsgId aMsgId, TInt aMessage, TRequestStatus& aStatus)
   176     {
   177     SendReceive(aMsgId, TIpcArgs(aMessage), aStatus);
   178     }