|
1 /* |
|
2 * Copyright (c) 2006-2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 #include <avkon.hrh> |
|
23 #include <aknquerydialog.h> |
|
24 #include <commondialogs.hrh> |
|
25 #include <akncommondialogsdynmem.h> |
|
26 #include <f32file.h> |
|
27 #include <t_oomtestapp.rsg> |
|
28 #include "t_oomtestappcmd.hrh" |
|
29 #include "t_oomtestappApplication.h" |
|
30 #include "t_oomtestappAppUi.h" |
|
31 #include "t_oomtestappAppView.h" |
|
32 |
|
33 _LIT( KOomConfigTargetFile, "c:\\private\\10207218\\oomconfig.xml" ); |
|
34 _LIT( KOomPriorityNormal, "normal" ); |
|
35 _LIT( KOomPriorityHigh, "high" ); |
|
36 _LIT( KOomPriorityBusy, "busy" ); |
|
37 const TInt KInitialAllocSize = 2048; |
|
38 |
|
39 // --------------------------------------------------------------------------- |
|
40 // AskPathL |
|
41 // --------------------------------------------------------------------------- |
|
42 // |
|
43 static TBool AskPathL( TDes& aPath ) |
|
44 { |
|
45 TParsePtr parse( aPath ); |
|
46 TPtrC rootFolder = parse.DriveAndPath(); |
|
47 TBool ret = AknCommonDialogsDynMem::RunSelectDlgLD( |
|
48 AknCommonDialogsDynMem::EMemoryTypePhone | |
|
49 AknCommonDialogsDynMem::EMemoryTypeMMC, |
|
50 aPath, |
|
51 rootFolder, |
|
52 R_MEMORY_SELECTION, |
|
53 R_FILE_SELECTION ); |
|
54 return ret; |
|
55 } |
|
56 |
|
57 |
|
58 // ============================ MEMBER FUNCTIONS =============================== |
|
59 |
|
60 |
|
61 // ----------------------------------------------------------------------------- |
|
62 // Ct_oomtestappAppUi::ConstructL() |
|
63 // Symbian 2nd phase constructor can leave. |
|
64 // ----------------------------------------------------------------------------- |
|
65 // |
|
66 void Ct_oomtestappAppUi::ConstructL() |
|
67 { |
|
68 // Initialise app UI with standard value. |
|
69 BaseConstructL(CAknAppUi::EAknEnableSkin); |
|
70 |
|
71 User::LeaveIfError( iOomSession.Connect() ); |
|
72 |
|
73 // Create view object |
|
74 iAppView = Ct_oomtestappAppView::NewL(ClientRect(), *this); |
|
75 |
|
76 } |
|
77 |
|
78 // ----------------------------------------------------------------------------- |
|
79 // Ct_oomtestappAppUi::Ct_oomtestappAppUi() |
|
80 // C++ default constructor can NOT contain any code, that might leave. |
|
81 // ----------------------------------------------------------------------------- |
|
82 // |
|
83 Ct_oomtestappAppUi::Ct_oomtestappAppUi() |
|
84 { |
|
85 } |
|
86 |
|
87 // ----------------------------------------------------------------------------- |
|
88 // Ct_oomtestappAppUi::~Ct_oomtestappAppUi() |
|
89 // Destructor. |
|
90 // ----------------------------------------------------------------------------- |
|
91 // |
|
92 Ct_oomtestappAppUi::~Ct_oomtestappAppUi() |
|
93 { |
|
94 delete iAppView; |
|
95 iOomSession.Close(); |
|
96 User::Free(iMem); |
|
97 } |
|
98 |
|
99 // ----------------------------------------------------------------------------- |
|
100 // Ct_oomtestappAppUi::HandleCommandL() |
|
101 // Takes care of command handling. |
|
102 // ----------------------------------------------------------------------------- |
|
103 // |
|
104 void Ct_oomtestappAppUi::HandleCommandL(TInt aCommand) |
|
105 { |
|
106 switch (aCommand) |
|
107 { |
|
108 case EOomTestAppSelectConfig: |
|
109 { |
|
110 TFileName fileName; |
|
111 if ( AskPathL( fileName ) ) |
|
112 { |
|
113 RFs& fs( iEikonEnv->FsSession() ); |
|
114 fs.MkDirAll( KOomConfigTargetFile ); // Ignore error |
|
115 CFileMan* fileMan = CFileMan::NewL( fs ); |
|
116 CleanupStack::PushL( fileMan ); |
|
117 User::LeaveIfError( fileMan->Copy( fileName, KOomConfigTargetFile ) ); |
|
118 CleanupStack::PopAndDestroy( fileMan ); |
|
119 } |
|
120 break; |
|
121 } |
|
122 case EOomTestAppToggleSystem: |
|
123 { |
|
124 iEikonEnv->SetSystem( !(iEikonEnv->IsSystem()) ); |
|
125 iAppView->DrawDeferred(); |
|
126 break; |
|
127 } |
|
128 case EOomTestAppAllocMemory: |
|
129 { |
|
130 TInt size(KInitialAllocSize); |
|
131 CAknNumberQueryDialog* query = CAknNumberQueryDialog::NewL(size); |
|
132 if ( query->ExecuteLD( R_ALLOC_QUERY ) ) |
|
133 { |
|
134 User::Free(iMem); |
|
135 iMem = NULL; |
|
136 size *= KKiloByte; |
|
137 iMem = User::AllocL(size); |
|
138 iAppView->DrawDeferred(); |
|
139 } |
|
140 break; |
|
141 } |
|
142 case EOomTestAppFreeMemory: |
|
143 { |
|
144 User::Free(iMem); |
|
145 iMem = NULL; |
|
146 iAppView->DrawDeferred(); |
|
147 break; |
|
148 } |
|
149 case EOomTestAppAllocMemWithPermission: |
|
150 { |
|
151 TInt size(KInitialAllocSize); |
|
152 CAknNumberQueryDialog* query = CAknNumberQueryDialog::NewL(size); |
|
153 if ( query->ExecuteLD( R_ALLOC_QUERY ) ) |
|
154 { |
|
155 User::Free(iMem); |
|
156 iMem = NULL; |
|
157 size *= KKiloByte; |
|
158 if ( iPriority != ROomMonitorSession::EOomPriorityBusy ) |
|
159 { |
|
160 // Prevent OOM to close this app while it is freeing memory |
|
161 iOomSession.SetOomPriority(ROomMonitorSession::EOomPriorityBusy); |
|
162 } |
|
163 iOomSession.RequestFreeMemory( size ); |
|
164 if ( iPriority != ROomMonitorSession::EOomPriorityBusy ) |
|
165 { |
|
166 // Allow OOM to close this app again |
|
167 iOomSession.SetOomPriority(iPriority); |
|
168 } |
|
169 iMem = User::AllocL(size); |
|
170 iAppView->DrawDeferred(); |
|
171 } |
|
172 break; |
|
173 } |
|
174 case EOomTestAppSetPriorityNormal: |
|
175 { |
|
176 iPriority = ROomMonitorSession::EOomPriorityNormal; |
|
177 iOomSession.SetOomPriority(iPriority); |
|
178 iAppView->DrawDeferred(); |
|
179 break; |
|
180 } |
|
181 case EOomTestAppSetPriorityHigh: |
|
182 { |
|
183 iPriority = ROomMonitorSession::EOomPriorityHigh; |
|
184 iOomSession.SetOomPriority(iPriority); |
|
185 iAppView->DrawDeferred(); |
|
186 break; |
|
187 } |
|
188 case EOomTestAppSetPriorityBusy: |
|
189 { |
|
190 iPriority = ROomMonitorSession::EOomPriorityBusy; |
|
191 iOomSession.SetOomPriority(iPriority); |
|
192 iAppView->DrawDeferred(); |
|
193 break; |
|
194 } |
|
195 case EEikCmdExit: |
|
196 case EAknSoftkeyExit: // Fall through |
|
197 { |
|
198 Exit(); |
|
199 break; |
|
200 } |
|
201 default: |
|
202 { |
|
203 break; |
|
204 } |
|
205 } |
|
206 } |
|
207 |
|
208 // ----------------------------------------------------------------------------- |
|
209 // Called by the framework when the application status pane |
|
210 // size is changed. Passes the new client rectangle to the |
|
211 // AppView |
|
212 // ----------------------------------------------------------------------------- |
|
213 // |
|
214 void Ct_oomtestappAppUi::HandleStatusPaneSizeChange() |
|
215 { |
|
216 iAppView->SetRect(ClientRect()); |
|
217 } |
|
218 |
|
219 // ----------------------------------------------------------------------------- |
|
220 // Ct_oomtestappAppUi::AllocatedHeap |
|
221 // ----------------------------------------------------------------------------- |
|
222 // |
|
223 TInt Ct_oomtestappAppUi::AllocatedHeap() const |
|
224 { |
|
225 TInt ret( 0 ); |
|
226 RHeap& heap( User::Heap() ); |
|
227 heap.AllocSize( ret ); |
|
228 return ret; |
|
229 } |
|
230 |
|
231 // ----------------------------------------------------------------------------- |
|
232 // Ct_oomtestappAppUi::Priority |
|
233 // ----------------------------------------------------------------------------- |
|
234 // |
|
235 TPtrC Ct_oomtestappAppUi::Priority() const |
|
236 { |
|
237 switch ( iPriority ) |
|
238 { |
|
239 case ROomMonitorSession::EOomPriorityNormal: |
|
240 { |
|
241 return KOomPriorityNormal(); |
|
242 } |
|
243 case ROomMonitorSession::EOomPriorityHigh: |
|
244 { |
|
245 return KOomPriorityHigh(); |
|
246 } |
|
247 case ROomMonitorSession::EOomPriorityBusy: |
|
248 { |
|
249 return KOomPriorityBusy(); |
|
250 } |
|
251 default: |
|
252 { |
|
253 break; |
|
254 } |
|
255 } |
|
256 return KNullDesC(); |
|
257 } |
|
258 |
|
259 |
|
260 // End of File |