blob: 62de1581680576807ac040a4499395d1de191def [file] [log] [blame]
Benny Prijonoc71ad432007-05-04 07:25:19 +00001/* $Id$ */
2/*
3 * Copyright (C) 2003-2007 Benny Prijono <benny@prijono.org>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
Benny Prijonoba5926a2007-05-02 11:29:37 +000019#include "ua.h"
Benny Prijonoba5926a2007-05-02 11:29:37 +000020
21#include <e32std.h>
Benny Prijonoba5926a2007-05-02 11:29:37 +000022#include <e32base.h>
23#include <e32std.h>
Benny Prijonoc71ad432007-05-04 07:25:19 +000024#include <stdlib.h>
Benny Prijonoba5926a2007-05-02 11:29:37 +000025
26
27// Global Variables
28CConsoleBase* console;
Benny Prijonoba5926a2007-05-02 11:29:37 +000029
30
Benny Prijonoc71ad432007-05-04 07:25:19 +000031////////////////////////////////////////////////////////////////////////////
Benny Prijonoba5926a2007-05-02 11:29:37 +000032class MyTask : public CActive
33{
34public:
Benny Prijono897f9f82007-05-03 19:56:21 +000035 static MyTask *NewL(CActiveSchedulerWait *asw);
36 ~MyTask();
Benny Prijonoba5926a2007-05-02 11:29:37 +000037 void Start();
38
39protected:
Benny Prijono897f9f82007-05-03 19:56:21 +000040 MyTask(CActiveSchedulerWait *asw);
Benny Prijonoba5926a2007-05-02 11:29:37 +000041 void ConstructL();
42 virtual void RunL();
43 virtual void DoCancel();
Benny Prijonoba5926a2007-05-02 11:29:37 +000044
45private:
46 RTimer timer_;
Benny Prijono897f9f82007-05-03 19:56:21 +000047 CActiveSchedulerWait *asw_;
Benny Prijonoba5926a2007-05-02 11:29:37 +000048};
49
Benny Prijono897f9f82007-05-03 19:56:21 +000050MyTask::MyTask(CActiveSchedulerWait *asw)
51: CActive(EPriorityNormal), asw_(asw)
Benny Prijonoba5926a2007-05-02 11:29:37 +000052{
53}
54
Benny Prijono897f9f82007-05-03 19:56:21 +000055MyTask::~MyTask()
56{
57 timer_.Close();
58}
59
Benny Prijonoba5926a2007-05-02 11:29:37 +000060void MyTask::ConstructL()
61{
62 timer_.CreateLocal();
63 CActiveScheduler::Add(this);
64}
65
Benny Prijono897f9f82007-05-03 19:56:21 +000066MyTask *MyTask::NewL(CActiveSchedulerWait *asw)
Benny Prijonoba5926a2007-05-02 11:29:37 +000067{
Benny Prijono897f9f82007-05-03 19:56:21 +000068 MyTask *self = new (ELeave) MyTask(asw);
Benny Prijonoba5926a2007-05-02 11:29:37 +000069 CleanupStack::PushL(self);
70
71 self->ConstructL();
72
73 CleanupStack::Pop(self);
74 return self;
75}
76
77void MyTask::Start()
78{
79 timer_.After(iStatus, 0);
80 SetActive();
81}
82
83void MyTask::RunL()
84{
Benny Prijono19a35172007-10-17 06:21:44 +000085 ua_main();
Benny Prijono897f9f82007-05-03 19:56:21 +000086 asw_->AsyncStop();
Benny Prijonoba5926a2007-05-02 11:29:37 +000087}
88
89void MyTask::DoCancel()
90{
Benny Prijonoc71ad432007-05-04 07:25:19 +000091
Benny Prijonoba5926a2007-05-02 11:29:37 +000092}
93
Benny Prijonoc71ad432007-05-04 07:25:19 +000094////////////////////////////////////////////////////////////////////////////
95
Benny Prijonoba5926a2007-05-02 11:29:37 +000096LOCAL_C void DoStartL()
97{
Benny Prijono897f9f82007-05-03 19:56:21 +000098 CActiveScheduler *scheduler = new (ELeave) CActiveScheduler;
Benny Prijonoba5926a2007-05-02 11:29:37 +000099 CleanupStack::PushL(scheduler);
100 CActiveScheduler::Install(scheduler);
101
Benny Prijono897f9f82007-05-03 19:56:21 +0000102 CActiveSchedulerWait *asw = new CActiveSchedulerWait;
103 CleanupStack::PushL(asw);
104
105 MyTask *task = MyTask::NewL(asw);
Benny Prijonoba5926a2007-05-02 11:29:37 +0000106 task->Start();
107
Benny Prijonoba5926a2007-05-02 11:29:37 +0000108 asw->Start();
109
Benny Prijono897f9f82007-05-03 19:56:21 +0000110 delete task;
111
112 CleanupStack::Pop(asw);
Benny Prijonoba5926a2007-05-02 11:29:37 +0000113 delete asw;
Benny Prijono897f9f82007-05-03 19:56:21 +0000114
115 CActiveScheduler::Install(NULL);
Benny Prijonoba5926a2007-05-02 11:29:37 +0000116 CleanupStack::Pop(scheduler);
Benny Prijono897f9f82007-05-03 19:56:21 +0000117 delete scheduler;
Benny Prijono5d542642007-05-02 18:54:19 +0000118}
119
120
121////////////////////////////////////////////////////////////////////////////
122
Benny Prijonoc71ad432007-05-04 07:25:19 +0000123// E32Main()
Benny Prijonoba5926a2007-05-02 11:29:37 +0000124GLDEF_C TInt E32Main()
125{
Benny Prijonoc71ad432007-05-04 07:25:19 +0000126 // Mark heap usage
Benny Prijono897f9f82007-05-03 19:56:21 +0000127 __UHEAP_MARK;
Benny Prijonoc71ad432007-05-04 07:25:19 +0000128
129 // Create cleanup stack
Benny Prijonoba5926a2007-05-02 11:29:37 +0000130 CTrapCleanup* cleanup = CTrapCleanup::New();
131
132 // Create output console
133 TRAPD(createError, console = Console::NewL(_L("Console"), TSize(KConsFullScreen,KConsFullScreen)));
134 if (createError)
135 return createError;
136
137 TRAPD(startError, DoStartL());
138
139 console->Printf(_L("[press any key to close]\n"));
Benny Prijonoc71ad432007-05-04 07:25:19 +0000140 console->Getch();
Benny Prijonoba5926a2007-05-02 11:29:37 +0000141
142 delete console;
143 delete cleanup;
Benny Prijono897f9f82007-05-03 19:56:21 +0000144
Benny Prijonoc71ad432007-05-04 07:25:19 +0000145 CloseSTDLIB();
146
147 // Mark end of heap usage, detect memory leaks
Benny Prijono897f9f82007-05-03 19:56:21 +0000148 __UHEAP_MARKEND;
Benny Prijonoba5926a2007-05-02 11:29:37 +0000149 return KErrNone;
150}
151