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