|
1 // SkeletonTemplate.cpp |
|
2 // |
|
3 // [[COPYRIGHT]] |
|
4 // |
|
5 |
|
6 #include <e32base.h> |
|
7 #include <e32cons.h> |
|
8 #include "SkeletonTemplate.h" |
|
9 |
|
10 void MainL() |
|
11 { |
|
12 CConsoleBase* cons = Console::NewL(_L(" SkeletonTemplate "), TSize(KConsFullScreen, KConsFullScreen)); |
|
13 CleanupStack::PushL(cons); |
|
14 |
|
15 CActiveScheduler* as = new(ELeave)CActiveScheduler(); |
|
16 CleanupStack::PushL(as); |
|
17 CActiveScheduler::Install(as); |
|
18 |
|
19 CSkeletonTemplate* echo = CSkeletonTemplate::NewLC(*cons); |
|
20 |
|
21 cons->Printf(_L("Hello World!\n")); |
|
22 cons->Printf(_L("Press escape to exit\n")); |
|
23 |
|
24 echo->Start(); |
|
25 |
|
26 CActiveScheduler::Start(); |
|
27 |
|
28 |
|
29 CleanupStack::PopAndDestroy(3); // cons, as, echo |
|
30 } |
|
31 |
|
32 TInt E32Main() |
|
33 { |
|
34 __UHEAP_MARK; |
|
35 CTrapCleanup* cleanup = CTrapCleanup::New(); // get clean-up stack |
|
36 TInt err = KErrNone; |
|
37 |
|
38 if (cleanup) |
|
39 { |
|
40 TRAP(err, MainL() ); |
|
41 delete cleanup; // destroy clean-up stack |
|
42 } |
|
43 else |
|
44 { |
|
45 err = KErrNoMemory; |
|
46 } |
|
47 |
|
48 __UHEAP_MARKEND; |
|
49 return err; |
|
50 } |
|
51 |
|
52 //______________________________________________________________________________ |
|
53 // CSkeletonTemplate |
|
54 CSkeletonTemplate* CSkeletonTemplate::NewLC(CConsoleBase& aConsole) |
|
55 { |
|
56 CSkeletonTemplate* self = new(ELeave)CSkeletonTemplate(aConsole); |
|
57 CleanupStack::PushL(self); |
|
58 self->ConstructL(); |
|
59 return self; |
|
60 } |
|
61 |
|
62 CSkeletonTemplate* CSkeletonTemplate::NewL(CConsoleBase& aConsole) |
|
63 { |
|
64 CSkeletonTemplate* self = NewLC(aConsole); |
|
65 CleanupStack::Pop(self); |
|
66 return self; |
|
67 } |
|
68 |
|
69 CSkeletonTemplate::~CSkeletonTemplate() |
|
70 { |
|
71 Cancel(); |
|
72 } |
|
73 |
|
74 void CSkeletonTemplate::Start() |
|
75 { |
|
76 if (!IsActive()) |
|
77 { |
|
78 iConsole.Read(iStatus); |
|
79 SetActive(); |
|
80 } |
|
81 } |
|
82 |
|
83 void CSkeletonTemplate::RunL() |
|
84 { |
|
85 TKeyCode key = iConsole.KeyCode(); |
|
86 if (key == EKeyEscape) |
|
87 { |
|
88 CActiveScheduler::Stop(); |
|
89 return; |
|
90 } |
|
91 else if (key == EKeyEnter) |
|
92 { |
|
93 iConsole.Printf(_L("\n")); |
|
94 } |
|
95 else |
|
96 { |
|
97 TBuf<1> buf; |
|
98 buf.Append(key); |
|
99 iConsole.Write(buf); |
|
100 } |
|
101 // reissue read request |
|
102 Start(); |
|
103 } |
|
104 |
|
105 void CSkeletonTemplate::DoCancel() |
|
106 { |
|
107 iConsole.ReadCancel(); |
|
108 } |
|
109 |
|
110 CSkeletonTemplate::CSkeletonTemplate(CConsoleBase& aConsole) |
|
111 : CActive(CActive::EPriorityStandard), iConsole(aConsole) |
|
112 { |
|
113 } |
|
114 |
|
115 void CSkeletonTemplate::ConstructL() |
|
116 { |
|
117 CActiveScheduler::Add(this); |
|
118 } |