os/mm/mmtestenv/mmtestfw/Source/SimulProc/SimulProcClient.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2002-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 // Implementation of the RTestServ and RTestSession API's
    15 // 
    16 //
    17 
    18 /**
    19  @file TestClient.cpp
    20 */
    21 //#include "..\..\SampleServer\src\SampleServer.h"
    22 #include <simulprocserver.h>
    23 #include <simulprocclient.h>
    24 
    25 
    26 TVersion RTestServ::Version() const
    27 	{
    28 	return(TVersion(1,0,1));
    29 	}
    30 
    31 EXPORT_C TInt RTestServ::Connect(const TDesC& aServerName)
    32 /**
    33  * @param aServerName - Human readable name of the test server
    34  * @param aDebugMode - Set to true for just in time debugging
    35  * @return int - Standard error codes
    36  * Secure version of the API call. Expects the server binary to be
    37  * ServerXXX.exe
    38  */
    39 	{
    40 	if(aServerName.Length() > iServerName.MaxLength())
    41 		return KErrTooBig;
    42 	iServerName = aServerName;
    43 	// Assume the server is already running and attempt to create a session
    44 	// 4 message slots
    45 	TInt err = CreateSession(aServerName,Version(),4);
    46 	if(err == KErrNotFound)
    47 		{
    48 		// Server not running
    49 		// Construct the server binary name
    50 		TBuf<KMaxServerNameLength> serverFile;
    51 		RProcess server;
    52 		_LIT(KEmpty,"");
    53 		_LIT(KExe,".exe");
    54 
    55 		serverFile.Copy(aServerName);
    56 		serverFile.Append(KExe);
    57 		err = server.Create(serverFile,KEmpty);
    58 		if(err != KErrNone)
    59 			return err;
    60 		// Synchronise with the server
    61 		TRequestStatus reqStatus;
    62 		server.Rendezvous(reqStatus);
    63 
    64 		if (reqStatus!=KRequestPending)
    65 			{
    66 			server.Kill(0);
    67 			}
    68 		else
    69 			{
    70 			// Start the test harness
    71 			server.Resume();
    72 			// Server will call the reciprocal static synchronise call		
    73 			}
    74 		User::WaitForRequest(reqStatus); // wait for start or death
    75 		server.Close();
    76 		if(reqStatus.Int() != KErrNone)
    77 			return reqStatus.Int();
    78 		
    79 		// Create the root server session
    80 		err = CreateSession(aServerName,Version(),4);
    81 		}
    82 	return err;
    83 	}
    84 
    85 EXPORT_C const TDesC& RTestServ::ServerName() const
    86 /**
    87  * @return - The human readable server name
    88  */
    89 	{
    90 	return iServerName;
    91 	}
    92 
    93 //
    94 EXPORT_C TInt RTestSession::Open(RTestServ& aServ, const TDesC& aStepName, TBool aSharedData)
    95 /**
    96  * @param aServ - Reference to the root server session
    97  * @param aStepName - Reference to the name of the test step owned by the server
    98  * @return Standard error codes
    99  * Secure and Non-secure variants
   100  * Synchronously open a server test step session
   101  */
   102 	{
   103 	if(aStepName.Length() > KMaxServerNameLength)
   104 		return KErrTooBig;
   105 	TIpcArgs args;
   106 	args.Set(0,&aStepName);
   107 	args.Set(1,aSharedData);
   108 	return CreateSubSession(aServ,EMMTSOpenTestStep,args);
   109 	}
   110 
   111 EXPORT_C void RTestSession::StartProcessing(TRequestStatus& aStatus)
   112 /**
   113  *
   114  * @param aCommandString - The arguments to the RUN_TEST_STEP command
   115  * @return aPanicString  - If the test step panics, this member is set up with the panic string
   116  * @param aStatus - For completion to the caller
   117  * Secure and Non-secure variants
   118  * Send the RUN_TEST_STEP arguments to the test server
   119  */
   120 	{
   121 	SendReceive(EMMTSStartProcessing,aStatus);
   122 	}
   123 
   124 EXPORT_C TVerdict RTestSession::EndProcessingAndReturnResult(TDes8& aMessage)
   125 /**
   126  *
   127  * @return - Standard Epoc error codes 
   128  * Secure and Non-secure variants
   129  * Synchronous abort of the the test step
   130  */
   131 	{
   132 
   133 	TPckgBuf<TVerdict> v;
   134 	TIpcArgs args;
   135 	args.Set(0,&v);
   136 	args.Set(1,&aMessage);
   137 	SendReceive(EMMTSStopProcessing, args);
   138 	return v();
   139 	}
   140 
   141 EXPORT_C void RTestSession::Close()
   142 	{
   143 	CloseSubSession(EMMTSClose);
   144 	}