blob: bc160bd63c65e921fb3d798afd74a83157a9668a [file] [log] [blame]
Benny Prijono96811bf2007-08-31 15:04:52 +00001/* $Id$ */
2/*
Benny Prijono844653c2008-12-23 17:27:53 +00003 * Copyright (C) 2008-2009 Teluu Inc. (http://www.teluu.com)
4 * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
Benny Prijono96811bf2007-08-31 15:04:52 +00005 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21#include <e32std.h>
22#include <e32base.h>
23#include <e32std.h>
24#include <e32cons.h>
25#include <stdlib.h>
26
27
28// Global Variables
29CConsoleBase* console;
30
Nanang Izzuddincb2789a2008-07-24 15:30:44 +000031// Needed by APS
32TPtrC APP_UID = _L("A000000D");
33
Benny Prijono96811bf2007-08-31 15:04:52 +000034int app_main();
35
36
37////////////////////////////////////////////////////////////////////////////
38class MyTask : public CActive
39{
40public:
41 static MyTask *NewL(CActiveSchedulerWait *asw);
42 ~MyTask();
43 void Start();
44
45protected:
46 MyTask(CActiveSchedulerWait *asw);
47 void ConstructL();
48 virtual void RunL();
49 virtual void DoCancel();
50
51private:
52 RTimer timer_;
53 CActiveSchedulerWait *asw_;
54};
55
56MyTask::MyTask(CActiveSchedulerWait *asw)
57: CActive(EPriorityNormal), asw_(asw)
58{
59}
60
61MyTask::~MyTask()
62{
63 timer_.Close();
64}
65
66void MyTask::ConstructL()
67{
68 timer_.CreateLocal();
69 CActiveScheduler::Add(this);
70}
71
72MyTask *MyTask::NewL(CActiveSchedulerWait *asw)
73{
74 MyTask *self = new (ELeave) MyTask(asw);
75 CleanupStack::PushL(self);
76
77 self->ConstructL();
78
79 CleanupStack::Pop(self);
80 return self;
81}
82
83void MyTask::Start()
84{
85 timer_.After(iStatus, 0);
86 SetActive();
87}
88
89void MyTask::RunL()
90{
91 int rc = app_main();
92 asw_->AsyncStop();
93}
94
95void MyTask::DoCancel()
96{
97
98}
99
100////////////////////////////////////////////////////////////////////////////
101
102LOCAL_C void DoStartL()
103{
104 CActiveScheduler *scheduler = new (ELeave) CActiveScheduler;
105 CleanupStack::PushL(scheduler);
106 CActiveScheduler::Install(scheduler);
107
108 CActiveSchedulerWait *asw = new CActiveSchedulerWait;
109 CleanupStack::PushL(asw);
110
111 MyTask *task = MyTask::NewL(asw);
112 task->Start();
113
114 asw->Start();
115
116 delete task;
117
118 CleanupStack::Pop(asw);
119 delete asw;
120
121 CActiveScheduler::Install(NULL);
122 CleanupStack::Pop(scheduler);
123 delete scheduler;
124}
125
126
127////////////////////////////////////////////////////////////////////////////
128
129// E32Main()
130GLDEF_C TInt E32Main()
131{
132 // Mark heap usage
133 __UHEAP_MARK;
134
135 // Create cleanup stack
136 CTrapCleanup* cleanup = CTrapCleanup::New();
137
138 // Create output console
139 TRAPD(createError, console = Console::NewL(_L("Console"), TSize(KConsFullScreen,KConsFullScreen)));
140 if (createError)
141 return createError;
142
143 TRAPD(startError, DoStartL());
144
145 console->Printf(_L("[press any key to close]\n"));
146 console->Getch();
147
148 delete console;
149 delete cleanup;
150
151 CloseSTDLIB();
152
153 // Mark end of heap usage, detect memory leaks
154 __UHEAP_MARKEND;
155 return KErrNone;
156}
157