os/security/cryptomgmtlibs/securitycommonutils/source/scsserver/startup.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/security/cryptomgmtlibs/securitycommonutils/source/scsserver/startup.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,95 @@
     1.4 +/*
     1.5 +* Copyright (c) 2007-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 +* Boilerplate code starts up server and exits the process when
    1.19 +* the server has stopped.
    1.20 +*
    1.21 +*/
    1.22 +
    1.23 +
    1.24 +/**
    1.25 + @file
    1.26 +*/
    1.27 +
    1.28 +#include <scs/scsserver.h>
    1.29 +#include <e32debug.h>
    1.30 +
    1.31 +NONSHARABLE_CLASS(CSystemActiveScheduler) : public CActiveScheduler
    1.32 +	{
    1.33 +	virtual void Error(TInt aError) const;
    1.34 +	};
    1.35 +
    1.36 +void CSystemActiveScheduler::Error(TInt aError) const
    1.37 +	{
    1.38 +	// Ignore the error and continue...
    1.39 +	RDebug::Printf("SCS- Active object failed with code %d - IGNORED\n", aError);
    1.40 +	}
    1.41 +
    1.42 +static void RunServerL(TScsServerFactory aServerFactoryLC)
    1.43 +/**
    1.44 +	Allocate and start the session counting server.
    1.45 +
    1.46 +	@param	aServerFactoryLC Factory function defined in the implementation
    1.47 +							EXE, which allocates an instance of the server object
    1.48 +							and puts it on the cleanup stack.
    1.49 + */
    1.50 +	{
    1.51 +	CActiveScheduler* as = new(ELeave) CSystemActiveScheduler;
    1.52 +	CleanupStack::PushL(as);
    1.53 +	CActiveScheduler::Install(as);
    1.54 +
    1.55 +	// the server is started when it is allocated
    1.56 +	(void) aServerFactoryLC();
    1.57 +
    1.58 +	// tell launching process the server has started successfully
    1.59 +	RProcess::Rendezvous(KErrNone);
    1.60 +
    1.61 +	CActiveScheduler::Start();
    1.62 +
    1.63 +	// the active scheduler has been stopped here because there have
    1.64 +	// been no current sessions for the shutdown period.
    1.65 +	CleanupStack::PopAndDestroy(2, as);
    1.66 +	}
    1.67 +
    1.68 +EXPORT_C TInt StartScsServer(TScsServerFactory aServerFactoryLC)
    1.69 +/**
    1.70 +	This function must be called from the server executable's E32Main function.
    1.71 +	It sets up a cleanup stack and active scheduler before starting the server.
    1.72 +	
    1.73 +	If the server is started successfully then this function does not return
    1.74 +	until the server shuts down.
    1.75 +
    1.76 +	@param	aServerFactoryLC Factory function defined in the implementation
    1.77 +							EXE, which allocates an instance of the server object
    1.78 +							and puts it on the cleanup stack.
    1.79 +	@return					Symbian OS error code.	KErrNone indicates success,
    1.80 +							and any other value indicates failure.
    1.81 + */
    1.82 +	{
    1.83 +	__UHEAP_MARK;
    1.84 +
    1.85 +	// allocating a cleanup stack also installs it
    1.86 +	CTrapCleanup* tc = CTrapCleanup::New();
    1.87 +	if (tc == 0)
    1.88 +		return KErrNoMemory;
    1.89 +
    1.90 +	TRAPD(r, RunServerL(aServerFactoryLC));
    1.91 +
    1.92 +	delete tc;
    1.93 +
    1.94 +	__UHEAP_MARKEND;
    1.95 +
    1.96 +	return r;
    1.97 +	}
    1.98 +