sl@0: /* sl@0: * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of the License "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * Boilerplate code starts up server and exits the process when sl@0: * the server has stopped. sl@0: * sl@0: */ sl@0: sl@0: sl@0: /** sl@0: @file sl@0: */ sl@0: sl@0: #include sl@0: #include sl@0: sl@0: NONSHARABLE_CLASS(CSystemActiveScheduler) : public CActiveScheduler sl@0: { sl@0: virtual void Error(TInt aError) const; sl@0: }; sl@0: sl@0: void CSystemActiveScheduler::Error(TInt aError) const sl@0: { sl@0: // Ignore the error and continue... sl@0: RDebug::Printf("SCS- Active object failed with code %d - IGNORED\n", aError); sl@0: } sl@0: sl@0: static void RunServerL(TScsServerFactory aServerFactoryLC) sl@0: /** sl@0: Allocate and start the session counting server. sl@0: sl@0: @param aServerFactoryLC Factory function defined in the implementation sl@0: EXE, which allocates an instance of the server object sl@0: and puts it on the cleanup stack. sl@0: */ sl@0: { sl@0: CActiveScheduler* as = new(ELeave) CSystemActiveScheduler; sl@0: CleanupStack::PushL(as); sl@0: CActiveScheduler::Install(as); sl@0: sl@0: // the server is started when it is allocated sl@0: (void) aServerFactoryLC(); sl@0: sl@0: // tell launching process the server has started successfully sl@0: RProcess::Rendezvous(KErrNone); sl@0: sl@0: CActiveScheduler::Start(); sl@0: sl@0: // the active scheduler has been stopped here because there have sl@0: // been no current sessions for the shutdown period. sl@0: CleanupStack::PopAndDestroy(2, as); sl@0: } sl@0: sl@0: EXPORT_C TInt StartScsServer(TScsServerFactory aServerFactoryLC) sl@0: /** sl@0: This function must be called from the server executable's E32Main function. sl@0: It sets up a cleanup stack and active scheduler before starting the server. sl@0: sl@0: If the server is started successfully then this function does not return sl@0: until the server shuts down. sl@0: sl@0: @param aServerFactoryLC Factory function defined in the implementation sl@0: EXE, which allocates an instance of the server object sl@0: and puts it on the cleanup stack. sl@0: @return Symbian OS error code. KErrNone indicates success, sl@0: and any other value indicates failure. sl@0: */ sl@0: { sl@0: __UHEAP_MARK; sl@0: sl@0: // allocating a cleanup stack also installs it sl@0: CTrapCleanup* tc = CTrapCleanup::New(); sl@0: if (tc == 0) sl@0: return KErrNoMemory; sl@0: sl@0: TRAPD(r, RunServerL(aServerFactoryLC)); sl@0: sl@0: delete tc; sl@0: sl@0: __UHEAP_MARKEND; sl@0: sl@0: return r; sl@0: } sl@0: