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