sl@0: // Copyright (c) 1999-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 "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: // Redirection server for STDLIB test programs sl@0: // Implement a redirection server which uses ... a console. sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include "CTEST.H" sl@0: #include "testconsole.h" sl@0: sl@0: _LIT(KReDirServerName,"RedirServer"); sl@0: sl@0: struct rendezvous sl@0: { sl@0: RThread iCaller; sl@0: TRequestStatus* iStatus; sl@0: }; sl@0: sl@0: sl@0: TInt threadFunction(TAny* aPtr) sl@0: // sl@0: // Create and run an active scheduler containing a RedirectionServer sl@0: // sl@0: { sl@0: CTrapCleanup* TheTrapCleanup=CTrapCleanup::New(); sl@0: sl@0: struct rendezvous* rvp = (struct rendezvous *)aPtr; sl@0: TInt ret=KErrNone; sl@0: // start scheduler and server sl@0: CActiveScheduler *pA=new CActiveScheduler; sl@0: if (pA!=NULL) sl@0: { sl@0: CActiveScheduler::Install(pA); sl@0: // ***** TRAP(ret, CRedirServer::NewL(CTestConsoleFactory::NewL()); sl@0: TRAP(ret, CRedirServer2::NewL(CTestConsoleFactory::NewL())); sl@0: // ret=KErrNotSupported; sl@0: } sl@0: // signal to the caller that we've started (or failed!) sl@0: rvp->iCaller.RequestComplete(rvp->iStatus,ret); sl@0: if (ret==KErrNone) sl@0: { sl@0: // start fielding requests from clients sl@0: CActiveScheduler::Start(); sl@0: } sl@0: // finished sl@0: delete TheTrapCleanup; sl@0: return(KErrNone); sl@0: } sl@0: sl@0: sl@0: EXPORT_C int start_redirection_server() sl@0: // sl@0: // Try to start a redirection server thread, assuming there isn't one already sl@0: // sl@0: { sl@0: RRedirSession2 probe; sl@0: TInt err=probe.Connect(); sl@0: probe.Close(); sl@0: if (err==KErrNone) sl@0: return KErrNone; // server already exists sl@0: TRequestStatus status(KRequestPending); sl@0: struct rendezvous rv; sl@0: rv.iCaller.Duplicate(RThread(),EOwnerProcess); sl@0: rv.iStatus=&status; sl@0: RThread server; sl@0: err=server.Create(KReDirServerName,threadFunction,0x2000,NULL,&rv); sl@0: if (err==KErrNone) sl@0: { sl@0: server.Resume(); sl@0: User::WaitForRequest(status); sl@0: err=status.Int(); sl@0: server.Close(); sl@0: } sl@0: rv.iCaller.Close(); sl@0: return err; sl@0: } sl@0: sl@0: sl@0: