author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 24 Nov 2009 08:56:33 +0200 | |
changeset 33 | 50974a8b132e |
parent 19 | 989d2f495d90 |
permissions | -rw-r--r-- |
19 | 1 |
/* |
2 |
* Copyright (c) 2002 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 the License "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: ?Description |
|
15 |
* |
|
16 |
*/ |
|
17 |
||
18 |
||
19 |
#include <e32std.h> |
|
33
50974a8b132e
Revision: 200945
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
20 |
#include <liwservicehandler.h> |
19 | 21 |
|
22 |
#include "tsysinfoprovidergeneraltests.h" |
|
33
50974a8b132e
Revision: 200945
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
23 |
#include "tcriticalmemnoti.h" |
19 | 24 |
#include "watchtimer.h" |
25 |
||
26 |
#include "entitykeys.h" |
|
27 |
#include "sysinfoaiwparams.hrh" |
|
28 |
||
29 |
using namespace LIW ; |
|
30 |
using namespace SysInfo; |
|
31 |
using namespace sysinfoaiwparams; |
|
32 |
||
33 |
_LIT(KDriveSeperator,":\\"); |
|
34 |
const TInt KMaxDriveLength = 5; |
|
35 |
||
36 |
CTCriticalMemNotification* CTCriticalMemNotification::NewL(CStifLogger* aLog,TInt aDrvNo) |
|
37 |
{ |
|
38 |
CTCriticalMemNotification* self = new(ELeave) CTCriticalMemNotification(aLog,aDrvNo); |
|
39 |
self->ConstructL(); |
|
40 |
return self; |
|
41 |
} |
|
42 |
||
43 |
CTCriticalMemNotification::~CTCriticalMemNotification() |
|
44 |
{ |
|
45 |
Cancel(); |
|
46 |
if(iWaitSchedular->IsStarted()) |
|
47 |
iWaitSchedular->AsyncStop(); |
|
48 |
||
49 |
delete iTimer; |
|
50 |
iInParamList->Reset(); |
|
51 |
iOutParamList->Reset(); |
|
52 |
iInterface->Close(); |
|
53 |
delete iServiceHandler; |
|
54 |
delete iWaitSchedular; |
|
55 |
} |
|
56 |
||
57 |
void CTCriticalMemNotification::ConstructL() |
|
58 |
{ |
|
59 |
iWaitSchedular = new(ELeave) CActiveSchedulerWait(); |
|
60 |
iTimer = CWatchTimer::NewL(EPriorityNormal,this); |
|
61 |
CreateInterfaceL(); |
|
62 |
CActiveScheduler::Add(this); |
|
63 |
} |
|
64 |
||
65 |
CTCriticalMemNotification::CTCriticalMemNotification(CStifLogger* aLog,TInt aDrvNo) : |
|
66 |
CActive(EPriorityStandard),iLog(aLog),iDrvNo(aDrvNo) |
|
67 |
{ |
|
68 |
} |
|
69 |
||
70 |
void CTCriticalMemNotification::DoCancel() |
|
71 |
{ |
|
72 |
//TRAPD(err1,iSysInfoService->GetInfoL(req1)); |
|
73 |
} |
|
74 |
||
75 |
void CTCriticalMemNotification::RunL() |
|
76 |
{ |
|
77 |
TestFuncL(); |
|
78 |
} |
|
79 |
||
80 |
void CTCriticalMemNotification::Start() |
|
81 |
{ |
|
82 |
SetActive(); |
|
83 |
TRequestStatus* temp = &iStatus; |
|
84 |
User::RequestComplete(temp, KErrNone); |
|
85 |
iWaitSchedular->Start(); |
|
86 |
} |
|
87 |
||
88 |
TInt CTCriticalMemNotification::Result() |
|
89 |
{ |
|
90 |
return iResult; |
|
91 |
} |
|
92 |
||
93 |
void CTCriticalMemNotification::TestFuncL() |
|
94 |
{ |
|
95 |
TInt criticalspace(0); |
|
96 |
TInt32 Err(PASS); |
|
97 |
TInt RetVal(PASS); |
|
98 |
||
99 |
//--------------------------------------------------------------------------- |
|
100 |
{ |
|
101 |
CLiwMap* inputmap = CLiwDefaultMap::NewL(); |
|
102 |
||
103 |
TBuf<KMaxDriveLength> drive; |
|
104 |
drive.FillZ(); |
|
105 |
drive.Append('A'+iDrvNo); |
|
106 |
drive.Append(KDriveSeperator); |
|
107 |
||
108 |
inputmap->InsertL(KDriveNo,TLiwVariant(drive)); |
|
109 |
||
110 |
iInParamList->AppendL(TLiwGenericParam(KEntity,TLiwVariant(KMemory))); |
|
111 |
iInParamList->AppendL(TLiwGenericParam(KKey,TLiwVariant(KDriveInfo))); |
|
112 |
iInParamList->AppendL(TLiwGenericParam(KSysData,TLiwVariant(inputmap))); |
|
113 |
||
114 |
iInterface->ExecuteCmdL(KGetInfo,*iInParamList,*iOutParamList); |
|
115 |
||
116 |
RetVal |= CheckErrorCode(*iOutParamList,Err); |
|
117 |
if ( Err ) |
|
118 |
{ |
|
119 |
iLog->Log( _L("GetInfo retured error : %d"),Err ); |
|
120 |
User::Leave(Err); |
|
121 |
} |
|
122 |
||
123 |
TInt index=0; |
|
124 |
const TLiwGenericParam* ret_val = iOutParamList->FindFirst(index,KReturnValue); |
|
125 |
if(!ret_val) |
|
126 |
{ |
|
127 |
iLog->Log( _L("Return value parameter not found")); |
|
128 |
User::Leave(FAIL); |
|
129 |
} |
|
130 |
else |
|
131 |
{ |
|
132 |
const CLiwMap* outmap = ret_val->Value().AsMap(); |
|
133 |
TLiwVariant info; |
|
134 |
if (outmap->FindL(KFreeSpace,info)) |
|
135 |
{ |
|
136 |
TLex freespace(info.AsDes()); |
|
137 |
TInt64 freespaceval; |
|
138 |
if ( KErrNone != freespace.Val(freespaceval) ) |
|
139 |
{ |
|
140 |
iLog->Log( _L("Invalid free space string") ); |
|
141 |
User::Leave(FAIL); |
|
142 |
} |
|
143 |
iLog->Log( _L("Free Space: %s"),info.AsDes().Ptr() ); |
|
144 |
criticalspace = freespaceval/2; |
|
145 |
} |
|
146 |
info.Reset(); |
|
147 |
((CLiwMap*)outmap)->DecRef(); |
|
148 |
} |
|
149 |
inputmap->DecRef(); |
|
150 |
} |
|
151 |
iInParamList->Reset(); |
|
152 |
iOutParamList->Reset(); |
|
153 |
||
154 |
//--------------------------------------------------------------------------- |
|
155 |
{ |
|
156 |
CLiwMap* inputmap = CLiwDefaultMap::NewL(); |
|
157 |
inputmap->InsertL(KCriticalSpace,TLiwVariant((TInt32)criticalspace)); |
|
158 |
||
159 |
TBuf<KMaxDriveLength> drive; |
|
160 |
drive.FillZ(); |
|
161 |
drive.Append('A'+iDrvNo); |
|
162 |
drive.Append(KDriveSeperator); |
|
163 |
||
164 |
inputmap->InsertL(KDriveNo,TLiwVariant(drive)); |
|
165 |
||
166 |
iInParamList->AppendL(TLiwGenericParam(KEntity,TLiwVariant(KMemory))); |
|
167 |
iInParamList->AppendL(TLiwGenericParam(KKey,TLiwVariant(KCriticalMemory))); |
|
168 |
iInParamList->AppendL(TLiwGenericParam(KSysData,TLiwVariant(inputmap))); |
|
169 |
iLog->Log( _L("Critical Free Space Set to: %d"),criticalspace ); |
|
170 |
||
171 |
iInterface->ExecuteCmdL(KGetNotification,*iInParamList,*iOutParamList,KLiwOptASyncronous,this); |
|
172 |
RetVal |= CheckErrorCode(*iOutParamList,Err); |
|
173 |
if ( Err ) |
|
174 |
{ |
|
175 |
iLog->Log( _L("GetNotification retured error : %d"),Err ); |
|
176 |
User::Leave(Err); |
|
177 |
} |
|
178 |
||
179 |
TInt index=0; |
|
180 |
const TLiwGenericParam* ret_val = iOutParamList->FindFirst(index,KTransactionId); |
|
181 |
if(!ret_val) |
|
182 |
{ |
|
183 |
iLog->Log( _L("Transaction ID not found")); |
|
184 |
User::Leave(FAIL); |
|
185 |
} |
|
186 |
else |
|
187 |
{ |
|
188 |
iTransID = ret_val->Value().AsTInt32(); |
|
189 |
iLog->Log( _L("Transaction ID: %d"),iTransID); |
|
190 |
} |
|
191 |
inputmap->DecRef(); |
|
192 |
} |
|
193 |
iInParamList->Reset(); |
|
194 |
iOutParamList->Reset(); |
|
195 |
||
196 |
const TTimeIntervalMicroSeconds32 OneMinute(120000000); |
|
197 |
iTimer->After(OneMinute); |
|
198 |
||
199 |
return ; |
|
200 |
} |
|
201 |
||
202 |
TInt CTCriticalMemNotification::HandleNotifyL( TInt aTransID, TInt aEventId, |
|
203 |
CLiwGenericParamList& aEventParamList, |
|
204 |
const CLiwGenericParamList& /*aInParamList*/) |
|
205 |
{ |
|
206 |
aEventId=aEventId; |
|
207 |
delete iTimer; |
|
208 |
iTimer = NULL; |
|
209 |
{ |
|
210 |
TInt index=0; |
|
211 |
TPtrC entity,key; |
|
212 |
TPtrC drive; |
|
213 |
const TLiwGenericParam* ret_val = aEventParamList.FindFirst(index,KReturnValue); |
|
214 |
if(!ret_val) |
|
215 |
{ |
|
216 |
iLog->Log( _L("Return value parameter not found")); |
|
217 |
User::Leave(FAIL); |
|
218 |
} |
|
219 |
else |
|
220 |
{ |
|
221 |
const CLiwMap* outmap = ret_val->Value().AsMap(); |
|
222 |
TLiwVariant ventity,vkey,vstatus; |
|
223 |
if( !outmap->FindL(KEntity,ventity) ) |
|
224 |
{ |
|
225 |
iLog->Log( _L("Entity parameter not found")); |
|
226 |
User::Leave(FAIL); |
|
227 |
} |
|
228 |
if( !outmap->FindL(KKey,vkey) ) |
|
229 |
{ |
|
230 |
iLog->Log( _L("Key parameter not found")); |
|
231 |
User::Leave(FAIL); |
|
232 |
} |
|
233 |
||
234 |
if( !outmap->FindL(KStringData,vstatus) ) |
|
235 |
{ |
|
236 |
iLog->Log( _L("Drive not found")); |
|
237 |
User::Leave(FAIL); |
|
238 |
} |
|
239 |
ventity.Get(entity); |
|
240 |
vkey.Get(key); |
|
241 |
||
242 |
if ( !vstatus.Get(drive) ) |
|
243 |
{ |
|
244 |
iLog->Log( _L("Drive not found")); |
|
245 |
User::Leave(FAIL); |
|
246 |
} |
|
247 |
||
248 |
if( !(entity.Compare(KMemory) || key.Compare(KCriticalMemory)) ) |
|
249 |
{ |
|
250 |
if(!(aTransID == iTransID)) |
|
251 |
{ |
|
252 |
iLog->Log(_L("Incorrect TransactionID: %d"),aTransID); |
|
253 |
iResult |= FAIL; |
|
254 |
} |
|
255 |
||
256 |
iLog->Log(_L("CRITICAL MEMORY Notification..")); |
|
257 |
iLog->Log(_L("LOW MEMORY DETECTED ON DRIVE %s"),drive.Ptr()); |
|
258 |
iResult |= PASS; |
|
259 |
} |
|
260 |
||
261 |
ventity.Reset(); |
|
262 |
vkey.Reset(); |
|
263 |
} |
|
264 |
} |
|
265 |
||
266 |
iResult |= PASS; |
|
267 |
iWaitSchedular->AsyncStop(); |
|
268 |
return KErrNone; |
|
269 |
} |
|
270 |
||
271 |
void CTCriticalMemNotification::HandleTimeOut() |
|
272 |
{ |
|
273 |
iLog->Log(_L("TimeOut reached. LOW MEMORY Notification not detected..")); |
|
274 |
// iSysInfoService->Cancel(1); |
|
275 |
iResult = FAIL; |
|
276 |
iWaitSchedular->AsyncStop(); |
|
277 |
} |
|
278 |
||
279 |
void CTCriticalMemNotification::CreateInterfaceL() |
|
280 |
{ |
|
281 |
iServiceHandler = CLiwServiceHandler::NewL(); |
|
282 |
CleanupStack::PushL(iServiceHandler); |
|
283 |
||
284 |
iInParamList = &(iServiceHandler->InParamListL()); |
|
285 |
iOutParamList = &(iServiceHandler->OutParamListL()); |
|
286 |
||
287 |
CLiwCriteriaItem* crit = CLiwCriteriaItem::NewL(1,KIDataSource,KService); |
|
288 |
CleanupStack::PushL(crit); |
|
289 |
crit->SetServiceClass(TUid::Uid(KLiwClassBase)); |
|
290 |
RCriteriaArray a; |
|
291 |
CleanupClosePushL(a); |
|
292 |
a.AppendL(crit); |
|
293 |
iServiceHandler->AttachL(a); |
|
294 |
iServiceHandler->ExecuteServiceCmdL(*crit,*iInParamList,*iOutParamList); |
|
295 |
||
296 |
TInt Index = 0; |
|
297 |
const TLiwGenericParam* param = iOutParamList->FindFirst(Index,KIDataSource); |
|
298 |
if(!param) |
|
299 |
{ |
|
300 |
iLog->Log( _L("Interface Not found ")); |
|
301 |
User::Leave(KErrGeneral); |
|
302 |
} |
|
303 |
||
304 |
iInterface = param->Value().AsInterface(); |
|
305 |
CleanupStack::PopAndDestroy(&a); |
|
306 |
CleanupStack::PopAndDestroy (crit); |
|
307 |
||
308 |
CleanupStack::Pop (iServiceHandler); |
|
309 |
} |
|
310 |
||
311 |
TInt CTCriticalMemNotification::CheckErrorCode( const CLiwGenericParamList& aOutList, TInt32 &aError ) |
|
312 |
{ |
|
313 |
TInt Index = 0; |
|
314 |
const TLiwGenericParam* errcode = aOutList.FindFirst(Index,KErrorCode); |
|
315 |
if ( KErrNotFound == Index ) |
|
316 |
{ |
|
317 |
iLog->Log( _L("ErrorCode not found in output ArgList") ); |
|
318 |
return FAIL; |
|
319 |
} |
|
320 |
else |
|
321 |
errcode->Value().Get(aError); |
|
322 |
return PASS; |
|
323 |
} |
|
324 |
//End of file. |
|
325 |