os/kernelhwsrv/kerneltest/e32test/misc/t_alive.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) 1996-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 the License "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
// e32test\misc\t_alive.cpp
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#include <e32test.h>
sl@0
    19
#include <e32base.h>
sl@0
    20
#include <e32base_private.h>
sl@0
    21
#include <e32svr.h>
sl@0
    22
sl@0
    23
RTest test(_L("T_ALIVE"));
sl@0
    24
sl@0
    25
class CTim : public CActive
sl@0
    26
	{
sl@0
    27
public:
sl@0
    28
	static CTim* New();
sl@0
    29
	CTim() : CActive(EPriorityStandard) {}
sl@0
    30
	void RunL();
sl@0
    31
	void DoCancel() {}
sl@0
    32
public:
sl@0
    33
	RTimer iTimer;
sl@0
    34
	};
sl@0
    35
sl@0
    36
class CTest : public CActive
sl@0
    37
	{
sl@0
    38
public:
sl@0
    39
	CTest() : CActive(EPriorityUserInput) {}
sl@0
    40
	static CTest* New();
sl@0
    41
	void RunL();
sl@0
    42
	void DoCancel() {}
sl@0
    43
	void Start();
sl@0
    44
	};
sl@0
    45
sl@0
    46
LOCAL_C void DisplayProcesses()
sl@0
    47
	{
sl@0
    48
	TFindProcess fp(_L("*"));
sl@0
    49
	TFullName fn;
sl@0
    50
	while(fp.Next(fn)==KErrNone)
sl@0
    51
		{
sl@0
    52
		RDebug::Print(_L("%S"),&fn);
sl@0
    53
		}
sl@0
    54
	}
sl@0
    55
sl@0
    56
sl@0
    57
CTim* CTim::New()
sl@0
    58
	{
sl@0
    59
	CTim* pC=new CTim;
sl@0
    60
	if (pC)
sl@0
    61
		{
sl@0
    62
		TInt r=pC->iTimer.CreateLocal();
sl@0
    63
		if (r!=KErrNone)
sl@0
    64
			{
sl@0
    65
			delete pC;
sl@0
    66
			pC=NULL;
sl@0
    67
			}
sl@0
    68
		}
sl@0
    69
	return pC;
sl@0
    70
	}
sl@0
    71
sl@0
    72
void CTim::RunL()
sl@0
    73
	{
sl@0
    74
	DisplayProcesses();
sl@0
    75
	iTimer.HighRes(iStatus,2100000);
sl@0
    76
	SetActive();
sl@0
    77
	}
sl@0
    78
sl@0
    79
CTest* CTest::New()
sl@0
    80
	{
sl@0
    81
	return new CTest;
sl@0
    82
	}
sl@0
    83
sl@0
    84
void CTest::Start()
sl@0
    85
	{
sl@0
    86
	test.Console()->Read(iStatus);
sl@0
    87
	SetActive();
sl@0
    88
	}
sl@0
    89
sl@0
    90
void CTest::RunL()
sl@0
    91
	{
sl@0
    92
	TKeyCode k=test.Console()->KeyCode();
sl@0
    93
	TChar c=(TUint)k;
sl@0
    94
	TBuf<1> b;
sl@0
    95
	b.SetLength(1);
sl@0
    96
	b[0]=(TText)c;
sl@0
    97
	RDebug::Print(_L("%S"),&b);
sl@0
    98
	if (c!='0')
sl@0
    99
		Start();
sl@0
   100
	else
sl@0
   101
		CActiveScheduler::Stop();
sl@0
   102
	}
sl@0
   103
sl@0
   104
GLDEF_C TInt E32Main()
sl@0
   105
	{
sl@0
   106
	test.Title();
sl@0
   107
	CActiveScheduler* pS=new CActiveScheduler;
sl@0
   108
	if (!pS)
sl@0
   109
		User::Panic(_L("SCHED"),0);
sl@0
   110
	CActiveScheduler::Install(pS);
sl@0
   111
	CTim* pT2=CTim::New();
sl@0
   112
	if (!pT2)
sl@0
   113
		User::Panic(_L("TIM2"),0);
sl@0
   114
	CActiveScheduler::Add(pT2);
sl@0
   115
	CTest* pTest=CTest::New();
sl@0
   116
	if (!pTest)
sl@0
   117
		User::Panic(_L("TEST"),0);
sl@0
   118
	CActiveScheduler::Add(pTest);
sl@0
   119
	pT2->RunL();
sl@0
   120
	pTest->Start();
sl@0
   121
	CActiveScheduler::Start();
sl@0
   122
	return 0;
sl@0
   123
	}