blob: 1786148ffed8d2eb34658eda894aded8e37da1ba [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
Nanang Izzuddincb2789a2008-07-24 15:30:44 +000030// Needed by APS
31TPtrC APP_UID = _L("A000000E");
32
Benny Prijonoba5926a2007-05-02 11:29:37 +000033
Benny Prijonoc71ad432007-05-04 07:25:19 +000034////////////////////////////////////////////////////////////////////////////
Benny Prijonoba5926a2007-05-02 11:29:37 +000035class MyTask : public CActive
36{
37public:
Benny Prijono897f9f82007-05-03 19:56:21 +000038 static MyTask *NewL(CActiveSchedulerWait *asw);
39 ~MyTask();
Benny Prijonoba5926a2007-05-02 11:29:37 +000040 void Start();
41
42protected:
Benny Prijono897f9f82007-05-03 19:56:21 +000043 MyTask(CActiveSchedulerWait *asw);
Benny Prijonoba5926a2007-05-02 11:29:37 +000044 void ConstructL();
45 virtual void RunL();
46 virtual void DoCancel();
Benny Prijonoba5926a2007-05-02 11:29:37 +000047
48private:
49 RTimer timer_;
Benny Prijono897f9f82007-05-03 19:56:21 +000050 CActiveSchedulerWait *asw_;
Benny Prijonoba5926a2007-05-02 11:29:37 +000051};
52
Benny Prijono897f9f82007-05-03 19:56:21 +000053MyTask::MyTask(CActiveSchedulerWait *asw)
54: CActive(EPriorityNormal), asw_(asw)
Benny Prijonoba5926a2007-05-02 11:29:37 +000055{
56}
57
Benny Prijono897f9f82007-05-03 19:56:21 +000058MyTask::~MyTask()
59{
60 timer_.Close();
61}
62
Benny Prijonoba5926a2007-05-02 11:29:37 +000063void MyTask::ConstructL()
64{
65 timer_.CreateLocal();
66 CActiveScheduler::Add(this);
67}
68
Benny Prijono897f9f82007-05-03 19:56:21 +000069MyTask *MyTask::NewL(CActiveSchedulerWait *asw)
Benny Prijonoba5926a2007-05-02 11:29:37 +000070{
Benny Prijono897f9f82007-05-03 19:56:21 +000071 MyTask *self = new (ELeave) MyTask(asw);
Benny Prijonoba5926a2007-05-02 11:29:37 +000072 CleanupStack::PushL(self);
73
74 self->ConstructL();
75
76 CleanupStack::Pop(self);
77 return self;
78}
79
80void MyTask::Start()
81{
82 timer_.After(iStatus, 0);
83 SetActive();
84}
85
86void MyTask::RunL()
87{
Benny Prijono19a35172007-10-17 06:21:44 +000088 ua_main();
Benny Prijono897f9f82007-05-03 19:56:21 +000089 asw_->AsyncStop();
Benny Prijonoba5926a2007-05-02 11:29:37 +000090}
91
92void MyTask::DoCancel()
93{
Benny Prijonoc71ad432007-05-04 07:25:19 +000094
Benny Prijonoba5926a2007-05-02 11:29:37 +000095}
96
Benny Prijonoc71ad432007-05-04 07:25:19 +000097////////////////////////////////////////////////////////////////////////////
98
Benny Prijonoba5926a2007-05-02 11:29:37 +000099LOCAL_C void DoStartL()
100{
Benny Prijono897f9f82007-05-03 19:56:21 +0000101 CActiveScheduler *scheduler = new (ELeave) CActiveScheduler;
Benny Prijonoba5926a2007-05-02 11:29:37 +0000102 CleanupStack::PushL(scheduler);
103 CActiveScheduler::Install(scheduler);
104
Benny Prijono897f9f82007-05-03 19:56:21 +0000105 CActiveSchedulerWait *asw = new CActiveSchedulerWait;
106 CleanupStack::PushL(asw);
107
108 MyTask *task = MyTask::NewL(asw);
Benny Prijonoba5926a2007-05-02 11:29:37 +0000109 task->Start();
110
Benny Prijonoba5926a2007-05-02 11:29:37 +0000111 asw->Start();
112
Benny Prijono897f9f82007-05-03 19:56:21 +0000113 delete task;
114
115 CleanupStack::Pop(asw);
Benny Prijonoba5926a2007-05-02 11:29:37 +0000116 delete asw;
Benny Prijono897f9f82007-05-03 19:56:21 +0000117
118 CActiveScheduler::Install(NULL);
Benny Prijonoba5926a2007-05-02 11:29:37 +0000119 CleanupStack::Pop(scheduler);
Benny Prijono897f9f82007-05-03 19:56:21 +0000120 delete scheduler;
Benny Prijono5d542642007-05-02 18:54:19 +0000121}
122
123
124////////////////////////////////////////////////////////////////////////////
125
Benny Prijonoc71ad432007-05-04 07:25:19 +0000126// E32Main()
Benny Prijonoba5926a2007-05-02 11:29:37 +0000127GLDEF_C TInt E32Main()
128{
Benny Prijonoc71ad432007-05-04 07:25:19 +0000129 // Mark heap usage
Benny Prijono897f9f82007-05-03 19:56:21 +0000130 __UHEAP_MARK;
Benny Prijonoc71ad432007-05-04 07:25:19 +0000131
132 // Create cleanup stack
Benny Prijonoba5926a2007-05-02 11:29:37 +0000133 CTrapCleanup* cleanup = CTrapCleanup::New();
134
135 // Create output console
136 TRAPD(createError, console = Console::NewL(_L("Console"), TSize(KConsFullScreen,KConsFullScreen)));
137 if (createError)
138 return createError;
139
140 TRAPD(startError, DoStartL());
141
142 console->Printf(_L("[press any key to close]\n"));
Benny Prijonoc71ad432007-05-04 07:25:19 +0000143 console->Getch();
Benny Prijonoba5926a2007-05-02 11:29:37 +0000144
145 delete console;
146 delete cleanup;
Benny Prijono897f9f82007-05-03 19:56:21 +0000147
Benny Prijonoc71ad432007-05-04 07:25:19 +0000148 CloseSTDLIB();
149
150 // Mark end of heap usage, detect memory leaks
Benny Prijono897f9f82007-05-03 19:56:21 +0000151 __UHEAP_MARKEND;
Benny Prijonoba5926a2007-05-02 11:29:37 +0000152 return KErrNone;
153}
154