cryptoservices/certificateandkeymgmt/tpkcs12intgrtn/src/tpkcs12libtestserver.cpp
changeset 0 2c201484c85f
child 8 35751d3474b7
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cryptoservices/certificateandkeymgmt/tpkcs12intgrtn/src/tpkcs12libtestserver.cpp	Wed Jul 08 11:25:26 2009 +0100
@@ -0,0 +1,153 @@
+/*
+* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of the License "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description: 
+*
+*/
+
+
+
+#include "tpkcs12libtestserver.h"
+#include "tpkcs12libteststep.h"
+
+
+_LIT(KServerName, "tpkcs12libtest");
+CPKCS12LibTestServer* CPKCS12LibTestServer::NewL()
+/**
+ * @return - Instance of the test server
+ * Called inside the Mail() function to create and start the 
+ * CTestServer derived server
+ *
+ */
+	{	
+	CPKCS12LibTestServer* server = new (ELeave) CPKCS12LibTestServer();
+	CleanupStack::PushL(server);
+	server->ConstructL(KServerName);
+	CleanupStack::Pop(server);
+	return server;
+	}
+
+
+CTestStep* CPKCS12LibTestServer::CreateTestStep(const TDesC& aStepName)
+/**
+ * @return - A CTestStep derived instance
+ * Implementation of CTestServer pure virtual
+ */
+	{
+	CTestStep* testStep = NULL;
+
+	if(aStepName == KStep)
+		{
+		testStep = new CPKCS12LibTestStep();	
+		}	  
+	if(aStepName == KTPKCS12OOMStep)
+		{
+		testStep = new CTPKCS12OOMStep();	
+		}
+
+	return testStep;
+	}
+
+// Just an E32Main and a MainL()
+LOCAL_C void MainL()
+/**
+ * Much simpler, uses the new Rendezvous() call to sync with the client
+ */
+	{
+	// Leave the hooks in for platform security
+#if (defined __DATA_CAGING__)
+	RProcess().DataCaging(RProcess::EDataCagingOn);
+	RProcess().SecureApi(RProcess::ESecureApiOn);
+#endif
+	CActiveScheduler* sched=NULL;
+	sched=new(ELeave) CActiveScheduler;
+	CActiveScheduler::Install(sched);
+	// __EDIT_ME__ Your server name
+	CPKCS12LibTestServer* server = NULL;
+	// Create the CTestServer derived server
+	// __EDIT_ME__ Your server name
+	TRAPD(err,server = CPKCS12LibTestServer::NewL());
+	if(!err)
+		{
+		// Sync with the client and enter the active scheduler
+		RProcess::Rendezvous(KErrNone);
+		sched->Start();
+		}
+	delete server;
+	delete sched;
+	}
+
+
+GLDEF_C TInt E32Main()
+/**
+ * @return - Standard Epoc error code on exit
+ */
+	{
+	CTrapCleanup* cleanup = CTrapCleanup::New();
+	if(cleanup == NULL)
+		{
+		return KErrNoMemory;
+		}
+	TRAPD(err,MainL());
+	// This if statement is here just to shut up RVCT, which would otherwise warn
+	// that err was set but never used
+	if(err)
+		{
+		err = KErrNone;
+		}
+	delete cleanup;
+	return KErrNone;
+    }
+
+// Create a thread in the calling process
+// Emulator typhoon and earlier
+#if (defined __WINS__ && !defined EKA2)
+TInt ThreadFunc (TAny* /*aParam*/)
+/**
+ * @return - Server exit code
+ * @param - unused
+ * Server Thread function. Guts of the code in the MainL() function
+ */
+	{
+	return E32Main();
+	}
+
+EXPORT_C TInt WinsMain() 
+/**
+ * @return - Standard Epoc error codes
+ * 1st and only ordinal, called by the client API to initialise the server
+ */
+	{
+	_LIT(KThread,"Thread");
+	RThread thread;
+	// __EDIT_ME__ - Make sure the TBuf is large enough
+	TBuf<KMaxTestExecuteNameLength> threadName(KServerName);
+	// Create a hopefully unique thread name and use the ThreadFunc
+	threadName.Append(KThread);
+	const TInt KMaxHeapSize = 0x1000000;			///< Allow a 1Mb max heap
+	TInt err = thread.Create(threadName, ThreadFunc, KDefaultStackSize,
+													KMinHeapSize, KMaxHeapSize,
+													NULL, EOwnerProcess);
+	if(err)
+		return err;
+	thread.Resume();
+	thread.Close();
+	return KErrNone;
+	}
+
+GLDEF_C TInt E32Dll(enum TDllReason)
+	{
+	return 0;
+	}
+
+#endif