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