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" |
|
23 |
#include "tmemnotifier.h" |
|
24 |
#include "entitykeys.h" |
|
25 |
#include "watchtimer.h" |
|
26 |
||
27 |
#include "entitykeys.h" |
|
28 |
#include "sysinfoaiwparams.hrh" |
|
29 |
||
30 |
using namespace LIW ; |
|
31 |
using namespace SysInfo; |
|
32 |
using namespace sysinfoaiwparams; |
|
33 |
||
34 |
||
35 |
CTestMemNotification* CTestMemNotification::NewL(CStifLogger* aLog) |
|
36 |
{ |
|
37 |
CTestMemNotification* self = new(ELeave) CTestMemNotification(aLog); |
|
38 |
self->ConstructL(); |
|
39 |
return self; |
|
40 |
} |
|
41 |
||
42 |
CTestMemNotification::~CTestMemNotification() |
|
43 |
{ |
|
44 |
Cancel(); |
|
45 |
if(iWaitSchedular->IsStarted()) |
|
46 |
iWaitSchedular->AsyncStop(); |
|
47 |
||
48 |
delete iTimer; |
|
49 |
iInParamList->Reset(); |
|
50 |
iOutParamList->Reset(); |
|
51 |
iInterface->Close(); |
|
52 |
delete iServiceHandler; |
|
53 |
delete iWaitSchedular; |
|
54 |
} |
|
55 |
||
56 |
void CTestMemNotification::ConstructL() |
|
57 |
{ |
|
58 |
iWaitSchedular = new(ELeave) CActiveSchedulerWait(); |
|
59 |
iTimer = CWatchTimer::NewL(EPriorityNormal,this); |
|
60 |
CreateInterfaceL(); |
|
61 |
CActiveScheduler::Add(this); |
|
62 |
} |
|
63 |
||
64 |
CTestMemNotification::CTestMemNotification(CStifLogger* aLog) : |
|
65 |
CActive(EPriorityStandard),iLog(aLog) |
|
66 |
{ |
|
67 |
} |
|
68 |
||
69 |
void CTestMemNotification::DoCancel() |
|
70 |
{ |
|
71 |
//TRAPD(err1,iSysInfoService->GetInfoL(req1)); |
|
72 |
} |
|
73 |
||
74 |
void CTestMemNotification::RunL() |
|
75 |
{ |
|
76 |
TestFuncL(); |
|
77 |
} |
|
78 |
||
79 |
void CTestMemNotification::Start() |
|
80 |
{ |
|
81 |
SetActive(); |
|
82 |
TRequestStatus* temp = &iStatus; |
|
83 |
User::RequestComplete(temp, KErrNone); |
|
84 |
iWaitSchedular->Start(); |
|
85 |
} |
|
86 |
||
87 |
TInt CTestMemNotification::Result() |
|
88 |
{ |
|
89 |
return iResult; |
|
90 |
} |
|
91 |
||
92 |
void CTestMemNotification::TestFuncL() |
|
93 |
{ |
|
94 |
TInt RetVal(PASS); |
|
95 |
TInt32 Err; |
|
96 |
||
97 |
iInParamList->AppendL(TLiwGenericParam(KEntity,TLiwVariant(KMemory))); |
|
98 |
iInParamList->AppendL(TLiwGenericParam(KKey,TLiwVariant(KMemoryCard))); |
|
99 |
||
100 |
iInterface->ExecuteCmdL(KGetNotification,*iInParamList,*iOutParamList,KLiwOptASyncronous,this); |
|
101 |
RetVal |= CheckErrorCode(*iOutParamList,Err); |
|
102 |
if ( Err ) |
|
103 |
{ |
|
104 |
iLog->Log( _L("GetNotification retured error : %d"),Err ); |
|
105 |
User::Leave(Err); |
|
106 |
} |
|
107 |
||
108 |
TInt index=0; |
|
109 |
const TLiwGenericParam* ret_val = iOutParamList->FindFirst(index,KTransactionId); |
|
110 |
if(!ret_val) |
|
111 |
{ |
|
112 |
iLog->Log( _L("Transaction ID not found")); |
|
113 |
User::Leave(FAIL); |
|
114 |
} |
|
115 |
else |
|
116 |
{ |
|
117 |
iTransID = ret_val->Value().AsTInt32(); |
|
118 |
iLog->Log( _L("Transaction ID: %d"),iTransID); |
|
119 |
} |
|
120 |
||
121 |
const TTimeIntervalMicroSeconds32 OneMinute(120000000); |
|
122 |
iTimer->After(OneMinute); |
|
123 |
||
124 |
return; |
|
125 |
} |
|
126 |
||
127 |
||
128 |
TInt CTestMemNotification::HandleNotifyL( TInt aTransID, TInt aEventId, |
|
129 |
CLiwGenericParamList& aEventParamList, |
|
130 |
const CLiwGenericParamList& /*aInParamList*/) |
|
131 |
{ |
|
132 |
aEventId=aEventId; |
|
133 |
delete iTimer; |
|
134 |
iTimer = NULL; |
|
135 |
{ |
|
136 |
TInt index=0; |
|
137 |
TPtrC entity,key; |
|
138 |
TInt32 status; |
|
139 |
const TLiwGenericParam* ret_val = aEventParamList.FindFirst(index,KReturnValue); |
|
140 |
if(!ret_val) |
|
141 |
{ |
|
142 |
iLog->Log( _L("Return value parameter not found")); |
|
143 |
User::Leave(FAIL); |
|
144 |
} |
|
145 |
else |
|
146 |
{ |
|
147 |
const CLiwMap* outmap = ret_val->Value().AsMap(); |
|
148 |
TLiwVariant ventity,vkey,vstatus; |
|
149 |
if( !outmap->FindL(KEntity,ventity) ) |
|
150 |
{ |
|
151 |
iLog->Log( _L("Entity parameter not found")); |
|
152 |
User::Leave(FAIL); |
|
153 |
} |
|
154 |
if( !outmap->FindL(KKey,vkey) ) |
|
155 |
{ |
|
156 |
iLog->Log( _L("Key parameter not found")); |
|
157 |
User::Leave(FAIL); |
|
158 |
} |
|
159 |
||
160 |
if( !outmap->FindL(KStatus,vstatus) ) |
|
161 |
{ |
|
162 |
iLog->Log( _L("Key parameter not found")); |
|
163 |
User::Leave(FAIL); |
|
164 |
} |
|
165 |
ventity.Get(entity); |
|
166 |
vkey.Get(key); |
|
167 |
status = vstatus.AsTInt32(); |
|
168 |
||
169 |
// ((CLiwMap)outmap)->DecRef(); |
|
170 |
||
171 |
if( !(entity.Compare(KMemory) || key.Compare(KMemoryCard)) ) |
|
172 |
{ |
|
173 |
if(!(aTransID == iTransID)) |
|
174 |
{ |
|
175 |
iLog->Log(_L("Incorrect TransactionID: %d"),aTransID); |
|
176 |
iResult |= FAIL; |
|
177 |
} |
|
178 |
||
179 |
iLog->Log(_L("Memoty Card Notification Notification..")); |
|
180 |
if(status) |
|
181 |
iLog->Log(_L("Memory Card Inserted..")); |
|
182 |
else |
|
183 |
iLog->Log(_L("Memory Card Removed..")); |
|
184 |
||
185 |
iResult |= PASS; |
|
186 |
} |
|
187 |
||
188 |
ventity.Reset(); |
|
189 |
vkey.Reset(); |
|
190 |
} |
|
191 |
} |
|
192 |
||
193 |
iResult |= PASS; |
|
194 |
iWaitSchedular->AsyncStop(); |
|
195 |
return KErrNone; |
|
196 |
} |
|
197 |
||
198 |
void CTestMemNotification::HandleTimeOut() |
|
199 |
{ |
|
200 |
iLog->Log(_L("TimeOut reached. Memorycard not inserted..")); |
|
201 |
// iSysInfoService->Cancel(1); |
|
202 |
iResult = FAIL; |
|
203 |
iWaitSchedular->AsyncStop(); |
|
204 |
} |
|
205 |
||
206 |
void CTestMemNotification::CreateInterfaceL() |
|
207 |
{ |
|
208 |
iServiceHandler = CLiwServiceHandler::NewL(); |
|
209 |
CleanupStack::PushL(iServiceHandler); |
|
210 |
||
211 |
iInParamList = &(iServiceHandler->InParamListL()); |
|
212 |
iOutParamList = &(iServiceHandler->OutParamListL()); |
|
213 |
||
214 |
CLiwCriteriaItem* crit = CLiwCriteriaItem::NewL(1,KIDataSource,KService); |
|
215 |
CleanupStack::PushL(crit); |
|
216 |
crit->SetServiceClass(TUid::Uid(KLiwClassBase)); |
|
217 |
RCriteriaArray a; |
|
218 |
CleanupClosePushL(a); |
|
219 |
a.AppendL(crit); |
|
220 |
iServiceHandler->AttachL(a); |
|
221 |
iServiceHandler->ExecuteServiceCmdL(*crit,*iInParamList,*iOutParamList); |
|
222 |
||
223 |
TInt Index = 0; |
|
224 |
const TLiwGenericParam* param = iOutParamList->FindFirst(Index,KIDataSource); |
|
225 |
if(!param) |
|
226 |
{ |
|
227 |
iLog->Log( _L("Interface Not found ")); |
|
228 |
User::Leave(KErrGeneral); |
|
229 |
} |
|
230 |
||
231 |
iInterface = param->Value().AsInterface(); |
|
232 |
CleanupStack::PopAndDestroy(&a); |
|
233 |
CleanupStack::PopAndDestroy (crit); |
|
234 |
||
235 |
CleanupStack::Pop (iServiceHandler); |
|
236 |
} |
|
237 |
||
238 |
TInt CTestMemNotification::CheckErrorCode( const CLiwGenericParamList& aOutList, TInt32 &aError ) |
|
239 |
{ |
|
240 |
TInt Index = 0; |
|
241 |
const TLiwGenericParam* errcode = aOutList.FindFirst(Index,KErrorCode); |
|
242 |
if ( KErrNotFound == Index ) |
|
243 |
{ |
|
244 |
iLog->Log( _L("ErrorCode not found in output ArgList") ); |
|
245 |
return FAIL; |
|
246 |
} |
|
247 |
else |
|
248 |
errcode->Value().Get(aError); |
|
249 |
return PASS; |
|
250 |
} |
|
251 |
//End of file. |
|
252 |
||
253 |