Benny Prijono | c71ad43 | 2007-05-04 07:25:19 +0000 | [diff] [blame] | 1 | /* $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 Prijono | ba5926a | 2007-05-02 11:29:37 +0000 | [diff] [blame] | 19 | #include "ua.h" |
Benny Prijono | ba5926a | 2007-05-02 11:29:37 +0000 | [diff] [blame] | 20 | |
| 21 | #include <e32std.h> |
Benny Prijono | ba5926a | 2007-05-02 11:29:37 +0000 | [diff] [blame] | 22 | #include <e32base.h> |
| 23 | #include <e32std.h> |
Benny Prijono | c71ad43 | 2007-05-04 07:25:19 +0000 | [diff] [blame] | 24 | #include <stdlib.h> |
Benny Prijono | ba5926a | 2007-05-02 11:29:37 +0000 | [diff] [blame] | 25 | |
| 26 | |
| 27 | // Global Variables |
| 28 | CConsoleBase* console; |
Benny Prijono | ba5926a | 2007-05-02 11:29:37 +0000 | [diff] [blame] | 29 | |
| 30 | |
Benny Prijono | c71ad43 | 2007-05-04 07:25:19 +0000 | [diff] [blame] | 31 | //////////////////////////////////////////////////////////////////////////// |
Benny Prijono | ba5926a | 2007-05-02 11:29:37 +0000 | [diff] [blame] | 32 | class MyTask : public CActive |
| 33 | { |
| 34 | public: |
Benny Prijono | 897f9f8 | 2007-05-03 19:56:21 +0000 | [diff] [blame] | 35 | static MyTask *NewL(CActiveSchedulerWait *asw); |
| 36 | ~MyTask(); |
Benny Prijono | ba5926a | 2007-05-02 11:29:37 +0000 | [diff] [blame] | 37 | void Start(); |
| 38 | |
| 39 | protected: |
Benny Prijono | 897f9f8 | 2007-05-03 19:56:21 +0000 | [diff] [blame] | 40 | MyTask(CActiveSchedulerWait *asw); |
Benny Prijono | ba5926a | 2007-05-02 11:29:37 +0000 | [diff] [blame] | 41 | void ConstructL(); |
| 42 | virtual void RunL(); |
| 43 | virtual void DoCancel(); |
Benny Prijono | ba5926a | 2007-05-02 11:29:37 +0000 | [diff] [blame] | 44 | |
| 45 | private: |
| 46 | RTimer timer_; |
Benny Prijono | 897f9f8 | 2007-05-03 19:56:21 +0000 | [diff] [blame] | 47 | CActiveSchedulerWait *asw_; |
Benny Prijono | ba5926a | 2007-05-02 11:29:37 +0000 | [diff] [blame] | 48 | }; |
| 49 | |
Benny Prijono | 897f9f8 | 2007-05-03 19:56:21 +0000 | [diff] [blame] | 50 | MyTask::MyTask(CActiveSchedulerWait *asw) |
| 51 | : CActive(EPriorityNormal), asw_(asw) |
Benny Prijono | ba5926a | 2007-05-02 11:29:37 +0000 | [diff] [blame] | 52 | { |
| 53 | } |
| 54 | |
Benny Prijono | 897f9f8 | 2007-05-03 19:56:21 +0000 | [diff] [blame] | 55 | MyTask::~MyTask() |
| 56 | { |
| 57 | timer_.Close(); |
| 58 | } |
| 59 | |
Benny Prijono | ba5926a | 2007-05-02 11:29:37 +0000 | [diff] [blame] | 60 | void MyTask::ConstructL() |
| 61 | { |
| 62 | timer_.CreateLocal(); |
| 63 | CActiveScheduler::Add(this); |
| 64 | } |
| 65 | |
Benny Prijono | 897f9f8 | 2007-05-03 19:56:21 +0000 | [diff] [blame] | 66 | MyTask *MyTask::NewL(CActiveSchedulerWait *asw) |
Benny Prijono | ba5926a | 2007-05-02 11:29:37 +0000 | [diff] [blame] | 67 | { |
Benny Prijono | 897f9f8 | 2007-05-03 19:56:21 +0000 | [diff] [blame] | 68 | MyTask *self = new (ELeave) MyTask(asw); |
Benny Prijono | ba5926a | 2007-05-02 11:29:37 +0000 | [diff] [blame] | 69 | CleanupStack::PushL(self); |
| 70 | |
| 71 | self->ConstructL(); |
| 72 | |
| 73 | CleanupStack::Pop(self); |
| 74 | return self; |
| 75 | } |
| 76 | |
| 77 | void MyTask::Start() |
| 78 | { |
| 79 | timer_.After(iStatus, 0); |
| 80 | SetActive(); |
| 81 | } |
| 82 | |
| 83 | void MyTask::RunL() |
| 84 | { |
Benny Prijono | 19a3517 | 2007-10-17 06:21:44 +0000 | [diff] [blame] | 85 | ua_main(); |
Benny Prijono | 897f9f8 | 2007-05-03 19:56:21 +0000 | [diff] [blame] | 86 | asw_->AsyncStop(); |
Benny Prijono | ba5926a | 2007-05-02 11:29:37 +0000 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | void MyTask::DoCancel() |
| 90 | { |
Benny Prijono | c71ad43 | 2007-05-04 07:25:19 +0000 | [diff] [blame] | 91 | |
Benny Prijono | ba5926a | 2007-05-02 11:29:37 +0000 | [diff] [blame] | 92 | } |
| 93 | |
Benny Prijono | c71ad43 | 2007-05-04 07:25:19 +0000 | [diff] [blame] | 94 | //////////////////////////////////////////////////////////////////////////// |
| 95 | |
Benny Prijono | ba5926a | 2007-05-02 11:29:37 +0000 | [diff] [blame] | 96 | LOCAL_C void DoStartL() |
| 97 | { |
Benny Prijono | 897f9f8 | 2007-05-03 19:56:21 +0000 | [diff] [blame] | 98 | CActiveScheduler *scheduler = new (ELeave) CActiveScheduler; |
Benny Prijono | ba5926a | 2007-05-02 11:29:37 +0000 | [diff] [blame] | 99 | CleanupStack::PushL(scheduler); |
| 100 | CActiveScheduler::Install(scheduler); |
| 101 | |
Benny Prijono | 897f9f8 | 2007-05-03 19:56:21 +0000 | [diff] [blame] | 102 | CActiveSchedulerWait *asw = new CActiveSchedulerWait; |
| 103 | CleanupStack::PushL(asw); |
| 104 | |
| 105 | MyTask *task = MyTask::NewL(asw); |
Benny Prijono | ba5926a | 2007-05-02 11:29:37 +0000 | [diff] [blame] | 106 | task->Start(); |
| 107 | |
Benny Prijono | ba5926a | 2007-05-02 11:29:37 +0000 | [diff] [blame] | 108 | asw->Start(); |
| 109 | |
Benny Prijono | 897f9f8 | 2007-05-03 19:56:21 +0000 | [diff] [blame] | 110 | delete task; |
| 111 | |
| 112 | CleanupStack::Pop(asw); |
Benny Prijono | ba5926a | 2007-05-02 11:29:37 +0000 | [diff] [blame] | 113 | delete asw; |
Benny Prijono | 897f9f8 | 2007-05-03 19:56:21 +0000 | [diff] [blame] | 114 | |
| 115 | CActiveScheduler::Install(NULL); |
Benny Prijono | ba5926a | 2007-05-02 11:29:37 +0000 | [diff] [blame] | 116 | CleanupStack::Pop(scheduler); |
Benny Prijono | 897f9f8 | 2007-05-03 19:56:21 +0000 | [diff] [blame] | 117 | delete scheduler; |
Benny Prijono | 5d54264 | 2007-05-02 18:54:19 +0000 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | |
| 121 | //////////////////////////////////////////////////////////////////////////// |
| 122 | |
Benny Prijono | c71ad43 | 2007-05-04 07:25:19 +0000 | [diff] [blame] | 123 | // E32Main() |
Benny Prijono | ba5926a | 2007-05-02 11:29:37 +0000 | [diff] [blame] | 124 | GLDEF_C TInt E32Main() |
| 125 | { |
Benny Prijono | c71ad43 | 2007-05-04 07:25:19 +0000 | [diff] [blame] | 126 | // Mark heap usage |
Benny Prijono | 897f9f8 | 2007-05-03 19:56:21 +0000 | [diff] [blame] | 127 | __UHEAP_MARK; |
Benny Prijono | c71ad43 | 2007-05-04 07:25:19 +0000 | [diff] [blame] | 128 | |
| 129 | // Create cleanup stack |
Benny Prijono | ba5926a | 2007-05-02 11:29:37 +0000 | [diff] [blame] | 130 | 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 Prijono | c71ad43 | 2007-05-04 07:25:19 +0000 | [diff] [blame] | 140 | console->Getch(); |
Benny Prijono | ba5926a | 2007-05-02 11:29:37 +0000 | [diff] [blame] | 141 | |
| 142 | delete console; |
| 143 | delete cleanup; |
Benny Prijono | 897f9f8 | 2007-05-03 19:56:21 +0000 | [diff] [blame] | 144 | |
Benny Prijono | c71ad43 | 2007-05-04 07:25:19 +0000 | [diff] [blame] | 145 | CloseSTDLIB(); |
| 146 | |
| 147 | // Mark end of heap usage, detect memory leaks |
Benny Prijono | 897f9f8 | 2007-05-03 19:56:21 +0000 | [diff] [blame] | 148 | __UHEAP_MARKEND; |
Benny Prijono | ba5926a | 2007-05-02 11:29:37 +0000 | [diff] [blame] | 149 | return KErrNone; |
| 150 | } |
| 151 | |