os/security/cryptoservices/certificateandkeymgmt/tpkcs12intgrtn/src/tpkcs12libtestserver.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/security/cryptoservices/certificateandkeymgmt/tpkcs12intgrtn/src/tpkcs12libtestserver.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,153 @@
1.4 +/*
1.5 +* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of the License "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +*
1.19 +*/
1.20 +
1.21 +
1.22 +
1.23 +#include "tpkcs12libtestserver.h"
1.24 +#include "tpkcs12libteststep.h"
1.25 +
1.26 +
1.27 +_LIT(KServerName, "tpkcs12libtest");
1.28 +CPKCS12LibTestServer* CPKCS12LibTestServer::NewL()
1.29 +/**
1.30 + * @return - Instance of the test server
1.31 + * Called inside the Mail() function to create and start the
1.32 + * CTestServer derived server
1.33 + *
1.34 + */
1.35 + {
1.36 + CPKCS12LibTestServer* server = new (ELeave) CPKCS12LibTestServer();
1.37 + CleanupStack::PushL(server);
1.38 + server->ConstructL(KServerName);
1.39 + CleanupStack::Pop(server);
1.40 + return server;
1.41 + }
1.42 +
1.43 +
1.44 +CTestStep* CPKCS12LibTestServer::CreateTestStep(const TDesC& aStepName)
1.45 +/**
1.46 + * @return - A CTestStep derived instance
1.47 + * Implementation of CTestServer pure virtual
1.48 + */
1.49 + {
1.50 + CTestStep* testStep = NULL;
1.51 +
1.52 + if(aStepName == KStep)
1.53 + {
1.54 + testStep = new CPKCS12LibTestStep();
1.55 + }
1.56 + if(aStepName == KTPKCS12OOMStep)
1.57 + {
1.58 + testStep = new CTPKCS12OOMStep();
1.59 + }
1.60 +
1.61 + return testStep;
1.62 + }
1.63 +
1.64 +// Just an E32Main and a MainL()
1.65 +LOCAL_C void MainL()
1.66 +/**
1.67 + * Much simpler, uses the new Rendezvous() call to sync with the client
1.68 + */
1.69 + {
1.70 + // Leave the hooks in for platform security
1.71 +#if (defined __DATA_CAGING__)
1.72 + RProcess().DataCaging(RProcess::EDataCagingOn);
1.73 + RProcess().SecureApi(RProcess::ESecureApiOn);
1.74 +#endif
1.75 + CActiveScheduler* sched=NULL;
1.76 + sched=new(ELeave) CActiveScheduler;
1.77 + CActiveScheduler::Install(sched);
1.78 + // __EDIT_ME__ Your server name
1.79 + CPKCS12LibTestServer* server = NULL;
1.80 + // Create the CTestServer derived server
1.81 + // __EDIT_ME__ Your server name
1.82 + TRAPD(err,server = CPKCS12LibTestServer::NewL());
1.83 + if(!err)
1.84 + {
1.85 + // Sync with the client and enter the active scheduler
1.86 + RProcess::Rendezvous(KErrNone);
1.87 + sched->Start();
1.88 + }
1.89 + delete server;
1.90 + delete sched;
1.91 + }
1.92 +
1.93 +
1.94 +GLDEF_C TInt E32Main()
1.95 +/**
1.96 + * @return - Standard Epoc error code on exit
1.97 + */
1.98 + {
1.99 + CTrapCleanup* cleanup = CTrapCleanup::New();
1.100 + if(cleanup == NULL)
1.101 + {
1.102 + return KErrNoMemory;
1.103 + }
1.104 + TRAPD(err,MainL());
1.105 + // This if statement is here just to shut up RVCT, which would otherwise warn
1.106 + // that err was set but never used
1.107 + if(err)
1.108 + {
1.109 + err = KErrNone;
1.110 + }
1.111 + delete cleanup;
1.112 + return KErrNone;
1.113 + }
1.114 +
1.115 +// Create a thread in the calling process
1.116 +// Emulator typhoon and earlier
1.117 +#if (defined __WINS__ && !defined EKA2)
1.118 +TInt ThreadFunc (TAny* /*aParam*/)
1.119 +/**
1.120 + * @return - Server exit code
1.121 + * @param - unused
1.122 + * Server Thread function. Guts of the code in the MainL() function
1.123 + */
1.124 + {
1.125 + return E32Main();
1.126 + }
1.127 +
1.128 +EXPORT_C TInt WinsMain()
1.129 +/**
1.130 + * @return - Standard Epoc error codes
1.131 + * 1st and only ordinal, called by the client API to initialise the server
1.132 + */
1.133 + {
1.134 + _LIT(KThread,"Thread");
1.135 + RThread thread;
1.136 + // __EDIT_ME__ - Make sure the TBuf is large enough
1.137 + TBuf<KMaxTestExecuteNameLength> threadName(KServerName);
1.138 + // Create a hopefully unique thread name and use the ThreadFunc
1.139 + threadName.Append(KThread);
1.140 + const TInt KMaxHeapSize = 0x1000000; ///< Allow a 1Mb max heap
1.141 + TInt err = thread.Create(threadName, ThreadFunc, KDefaultStackSize,
1.142 + KMinHeapSize, KMaxHeapSize,
1.143 + NULL, EOwnerProcess);
1.144 + if(err)
1.145 + return err;
1.146 + thread.Resume();
1.147 + thread.Close();
1.148 + return KErrNone;
1.149 + }
1.150 +
1.151 +GLDEF_C TInt E32Dll(enum TDllReason)
1.152 + {
1.153 + return 0;
1.154 + }
1.155 +
1.156 +#endif