genericopenlibs/cstdlib/TSTLIB/testcons.cpp
changeset 0 e4d67989cc36
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     1 // Copyright (c) 1999-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Redirection server for STDLIB test programs
       
    15 // Implement a redirection server which uses ... a console.
       
    16 // 
       
    17 //
       
    18 
       
    19 #include <e32std.h>
       
    20 #include <e32cons.h>
       
    21 #include <redircli.h>
       
    22 #include <redircliinternal.h>
       
    23 #include "CTEST.H"
       
    24 #include "testconsole.h"
       
    25 
       
    26 _LIT(KReDirServerName,"RedirServer");
       
    27 
       
    28 struct rendezvous 
       
    29 	{
       
    30 	RThread iCaller;
       
    31 	TRequestStatus* iStatus;
       
    32 	};
       
    33 
       
    34 
       
    35 TInt threadFunction(TAny* aPtr)
       
    36 //
       
    37 // Create and run an active scheduler containing a RedirectionServer
       
    38 //
       
    39 	{
       
    40 	CTrapCleanup* TheTrapCleanup=CTrapCleanup::New();
       
    41 
       
    42 	struct rendezvous* rvp = (struct rendezvous *)aPtr;
       
    43 	TInt ret=KErrNone;
       
    44 	// start scheduler and server
       
    45 	CActiveScheduler *pA=new CActiveScheduler;
       
    46 	if (pA!=NULL) 
       
    47 		{
       
    48 		CActiveScheduler::Install(pA);
       
    49 		// ***** TRAP(ret, CRedirServer::NewL(CTestConsoleFactory::NewL());
       
    50 		TRAP(ret, CRedirServer2::NewL(CTestConsoleFactory::NewL()));
       
    51 //		ret=KErrNotSupported;
       
    52 		}
       
    53 	// signal to the caller that we've started (or failed!)
       
    54 	rvp->iCaller.RequestComplete(rvp->iStatus,ret);
       
    55 	if (ret==KErrNone)
       
    56 		{
       
    57 		// start fielding requests from clients
       
    58 		CActiveScheduler::Start();
       
    59 		}
       
    60 	// finished
       
    61 	delete TheTrapCleanup;
       
    62 	return(KErrNone);
       
    63 	}
       
    64 
       
    65 
       
    66 EXPORT_C int start_redirection_server()
       
    67 //
       
    68 // Try to start a redirection server thread, assuming there isn't one already
       
    69 //
       
    70 	{
       
    71 	RRedirSession2 probe;
       
    72 	TInt err=probe.Connect();
       
    73 	probe.Close();
       
    74 	if (err==KErrNone)
       
    75 		return KErrNone;	// server already exists
       
    76 	TRequestStatus status(KRequestPending);
       
    77 	struct rendezvous rv;
       
    78 	rv.iCaller.Duplicate(RThread(),EOwnerProcess);
       
    79 	rv.iStatus=&status;
       
    80 	RThread server;
       
    81 	err=server.Create(KReDirServerName,threadFunction,0x2000,NULL,&rv);
       
    82 	if (err==KErrNone) 
       
    83 		{
       
    84 		server.Resume();
       
    85 		User::WaitForRequest(status);
       
    86 		err=status.Int();
       
    87 		server.Close();
       
    88 		}
       
    89 	rv.iCaller.Close();
       
    90 	return err;
       
    91 	}
       
    92 
       
    93 
       
    94