cryptoservices/certificateandkeymgmt/tpkcs12intgrtn/src/tpkcs12libtestserver.cpp
changeset 0 2c201484c85f
child 8 35751d3474b7
equal deleted inserted replaced
-1:000000000000 0:2c201484c85f
       
     1 /*
       
     2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include "tpkcs12libtestserver.h"
       
    21 #include "tpkcs12libteststep.h"
       
    22 
       
    23 
       
    24 _LIT(KServerName, "tpkcs12libtest");
       
    25 CPKCS12LibTestServer* CPKCS12LibTestServer::NewL()
       
    26 /**
       
    27  * @return - Instance of the test server
       
    28  * Called inside the Mail() function to create and start the 
       
    29  * CTestServer derived server
       
    30  *
       
    31  */
       
    32 	{	
       
    33 	CPKCS12LibTestServer* server = new (ELeave) CPKCS12LibTestServer();
       
    34 	CleanupStack::PushL(server);
       
    35 	server->ConstructL(KServerName);
       
    36 	CleanupStack::Pop(server);
       
    37 	return server;
       
    38 	}
       
    39 
       
    40 
       
    41 CTestStep* CPKCS12LibTestServer::CreateTestStep(const TDesC& aStepName)
       
    42 /**
       
    43  * @return - A CTestStep derived instance
       
    44  * Implementation of CTestServer pure virtual
       
    45  */
       
    46 	{
       
    47 	CTestStep* testStep = NULL;
       
    48 
       
    49 	if(aStepName == KStep)
       
    50 		{
       
    51 		testStep = new CPKCS12LibTestStep();	
       
    52 		}	  
       
    53 	if(aStepName == KTPKCS12OOMStep)
       
    54 		{
       
    55 		testStep = new CTPKCS12OOMStep();	
       
    56 		}
       
    57 
       
    58 	return testStep;
       
    59 	}
       
    60 
       
    61 // Just an E32Main and a MainL()
       
    62 LOCAL_C void MainL()
       
    63 /**
       
    64  * Much simpler, uses the new Rendezvous() call to sync with the client
       
    65  */
       
    66 	{
       
    67 	// Leave the hooks in for platform security
       
    68 #if (defined __DATA_CAGING__)
       
    69 	RProcess().DataCaging(RProcess::EDataCagingOn);
       
    70 	RProcess().SecureApi(RProcess::ESecureApiOn);
       
    71 #endif
       
    72 	CActiveScheduler* sched=NULL;
       
    73 	sched=new(ELeave) CActiveScheduler;
       
    74 	CActiveScheduler::Install(sched);
       
    75 	// __EDIT_ME__ Your server name
       
    76 	CPKCS12LibTestServer* server = NULL;
       
    77 	// Create the CTestServer derived server
       
    78 	// __EDIT_ME__ Your server name
       
    79 	TRAPD(err,server = CPKCS12LibTestServer::NewL());
       
    80 	if(!err)
       
    81 		{
       
    82 		// Sync with the client and enter the active scheduler
       
    83 		RProcess::Rendezvous(KErrNone);
       
    84 		sched->Start();
       
    85 		}
       
    86 	delete server;
       
    87 	delete sched;
       
    88 	}
       
    89 
       
    90 
       
    91 GLDEF_C TInt E32Main()
       
    92 /**
       
    93  * @return - Standard Epoc error code on exit
       
    94  */
       
    95 	{
       
    96 	CTrapCleanup* cleanup = CTrapCleanup::New();
       
    97 	if(cleanup == NULL)
       
    98 		{
       
    99 		return KErrNoMemory;
       
   100 		}
       
   101 	TRAPD(err,MainL());
       
   102 	// This if statement is here just to shut up RVCT, which would otherwise warn
       
   103 	// that err was set but never used
       
   104 	if(err)
       
   105 		{
       
   106 		err = KErrNone;
       
   107 		}
       
   108 	delete cleanup;
       
   109 	return KErrNone;
       
   110     }
       
   111 
       
   112 // Create a thread in the calling process
       
   113 // Emulator typhoon and earlier
       
   114 #if (defined __WINS__ && !defined EKA2)
       
   115 TInt ThreadFunc (TAny* /*aParam*/)
       
   116 /**
       
   117  * @return - Server exit code
       
   118  * @param - unused
       
   119  * Server Thread function. Guts of the code in the MainL() function
       
   120  */
       
   121 	{
       
   122 	return E32Main();
       
   123 	}
       
   124 
       
   125 EXPORT_C TInt WinsMain() 
       
   126 /**
       
   127  * @return - Standard Epoc error codes
       
   128  * 1st and only ordinal, called by the client API to initialise the server
       
   129  */
       
   130 	{
       
   131 	_LIT(KThread,"Thread");
       
   132 	RThread thread;
       
   133 	// __EDIT_ME__ - Make sure the TBuf is large enough
       
   134 	TBuf<KMaxTestExecuteNameLength> threadName(KServerName);
       
   135 	// Create a hopefully unique thread name and use the ThreadFunc
       
   136 	threadName.Append(KThread);
       
   137 	const TInt KMaxHeapSize = 0x1000000;			///< Allow a 1Mb max heap
       
   138 	TInt err = thread.Create(threadName, ThreadFunc, KDefaultStackSize,
       
   139 													KMinHeapSize, KMaxHeapSize,
       
   140 													NULL, EOwnerProcess);
       
   141 	if(err)
       
   142 		return err;
       
   143 	thread.Resume();
       
   144 	thread.Close();
       
   145 	return KErrNone;
       
   146 	}
       
   147 
       
   148 GLDEF_C TInt E32Dll(enum TDllReason)
       
   149 	{
       
   150 	return 0;
       
   151 	}
       
   152 
       
   153 #endif