author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 11 May 2010 17:01:36 +0300 | |
branch | RCL_3 |
changeset 58 | ea43c23d28d2 |
parent 19 | 989d2f495d90 |
child 65 | 0b68a1b0c15e |
permissions | -rw-r--r-- |
19 | 1 |
/* |
2 |
* Copyright (c) 2002 - 2007 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: tsysinfogripstatus |
|
15 |
* |
|
16 |
*/ |
|
17 |
||
18 |
||
19 |
||
20 |
#include "sysinfoservice.h" |
|
21 |
#include"entitykeys.h" |
|
22 |
#include<e32err.h> |
|
23 |
||
24 |
using namespace SysInfo; |
|
25 |
class CTestAsync6 : public CActive ,public ISystemObserver |
|
26 |
{ |
|
27 |
public: |
|
28 |
static CTestAsync6* NewL(); |
|
29 |
~CTestAsync6(); |
|
30 |
void Start(); |
|
31 |
TInt Result(); |
|
32 |
||
33 |
void HandleResponseL(const TDesC& aEntity,const TDesC& aKey, |
|
34 |
CSysData* aResponse, TInt32 aTransID, |
|
35 |
TSysRequest::TRequestType aType,TInt aError=KErrNone); |
|
36 |
||
37 |
private: |
|
38 |
void ConstructL(); |
|
39 |
CTestAsync6(); |
|
40 |
||
41 |
virtual void DoCancel(); |
|
42 |
virtual void RunL(); |
|
43 |
||
44 |
||
45 |
void TestFunc(); |
|
46 |
||
47 |
||
48 |
||
49 |
private: |
|
50 |
CActiveSchedulerWait* iWaitSchedular; |
|
51 |
CSysInfoService* iSysInfoService; |
|
52 |
TInt gripstatus ; |
|
53 |
TInt iResult; |
|
54 |
}; |
|
55 |
||
56 |
CTestAsync6* CTestAsync6::NewL() |
|
57 |
{ |
|
58 |
CTestAsync6* self = new(ELeave) CTestAsync6(); |
|
59 |
self->ConstructL(); |
|
60 |
return self; |
|
61 |
} |
|
62 |
||
63 |
CTestAsync6::~CTestAsync6() |
|
64 |
{ |
|
65 |
Cancel(); |
|
66 |
||
67 |
if(iWaitSchedular->IsStarted()) |
|
68 |
iWaitSchedular->AsyncStop(); |
|
69 |
||
70 |
if(iSysInfoService) |
|
71 |
delete iSysInfoService; |
|
72 |
||
73 |
if(iWaitSchedular) |
|
74 |
delete iWaitSchedular; |
|
75 |
} |
|
76 |
||
77 |
void CTestAsync6::ConstructL() |
|
78 |
{ |
|
79 |
CActiveScheduler::Add(this); |
|
80 |
iSysInfoService = CSysInfoService::NewL(); |
|
81 |
iWaitSchedular = new(ELeave) CActiveSchedulerWait(); |
|
82 |
} |
|
83 |
||
84 |
CTestAsync6::CTestAsync6() : |
|
85 |
CActive(EPriorityStandard),iResult(-1) |
|
86 |
{ |
|
87 |
} |
|
88 |
||
89 |
void CTestAsync6::DoCancel() |
|
90 |
{ |
|
91 |
||
92 |
||
93 |
} |
|
94 |
||
95 |
void CTestAsync6::RunL() |
|
96 |
{ |
|
97 |
TestFunc(); |
|
98 |
} |
|
99 |
||
100 |
void CTestAsync6::Start() |
|
101 |
{ |
|
102 |
||
103 |
SetActive(); |
|
104 |
TRequestStatus* temp = &iStatus; |
|
105 |
User::RequestComplete(temp, KErrNone); |
|
106 |
iWaitSchedular->Start(); |
|
107 |
} |
|
108 |
||
109 |
TInt CTestAsync6::Result() |
|
110 |
{ |
|
111 |
return iResult; |
|
112 |
} |
|
113 |
||
114 |
void CTestAsync6::TestFunc() |
|
115 |
{ |
|
116 |
||
117 |
CStatus* data = CStatus::NewL(gripstatus); |
|
118 |
||
119 |
TRAPD(err1,iSysInfoService->GetNotificationL(KGeneral,KGripStatus,444,this)); |
|
120 |
iResult = err1; |
|
121 |
||
122 |
if(err1 == KErrNone) |
|
123 |
{ |
|
124 |
||
125 |
CSysData* data1 = NULL; |
|
126 |
||
127 |
TRAPD(err2,iSysInfoService->GetInfoL(KGeneral,KGripStatus,data1)); |
|
58
ea43c23d28d2
Revision: 201016
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
128 |
iResult = err2; |
ea43c23d28d2
Revision: 201016
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
129 |
if( err2 != KErrNone ) |
ea43c23d28d2
Revision: 201016
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
130 |
return; |
19 | 131 |
gripstatus = ((CStatus*)data1)->Status(); |
132 |
||
133 |
CStatus* data2 = CStatus::NewL(!gripstatus); |
|
134 |
||
135 |
TRAPD(err3,iSysInfoService->SetInfoL(KGeneral,KGripStatus,data2)); |
|
58
ea43c23d28d2
Revision: 201016
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
136 |
iResult = err3; |
ea43c23d28d2
Revision: 201016
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
137 |
if( err3 != KErrNone ) |
ea43c23d28d2
Revision: 201016
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
138 |
return; |
19 | 139 |
delete data1; |
140 |
delete data2; |
|
141 |
||
142 |
} |
|
143 |
||
144 |
||
145 |
return ; |
|
146 |
} |
|
147 |
||
148 |
void CTestAsync6::HandleResponseL(const TDesC& /*aEntity*/,const TDesC& /*aKey*/, |
|
149 |
CSysData* aResponse, TInt32 /*aTransID*/, |
|
150 |
TSysRequest::TRequestType /*aType*/,TInt aError) |
|
151 |
{ |
|
152 |
||
153 |
if(aError == KErrNone) |
|
154 |
{ |
|
155 |
const CStatus* data1 = (CStatus*)aResponse; |
|
156 |
TInt statusval = data1->Status() ; |
|
157 |
||
158 |
if(statusval == 1) |
|
159 |
{ |
|
160 |
gripstatus -=1; |
|
161 |
} |
|
162 |
else |
|
163 |
{ |
|
164 |
gripstatus +=1; |
|
165 |
} |
|
166 |
||
167 |
if(statusval == (gripstatus) ) |
|
168 |
{ |
|
169 |
iResult = KErrNone; |
|
170 |
} |
|
171 |
else |
|
172 |
{ |
|
173 |
iResult = -1; |
|
174 |
} |
|
175 |
delete aResponse; |
|
176 |
||
177 |
} |
|
178 |
iWaitSchedular->AsyncStop(); |
|
179 |
} |
|
180 |
||
181 |
||
182 |
int GripNotification() |
|
183 |
{ |
|
184 |
__UHEAP_MARK; |
|
185 |
||
186 |
CTestAsync6* test = CTestAsync6::NewL(); |
|
187 |
||
188 |
test->Start(); |
|
189 |
TInt retval = test->Result(); |
|
190 |
// test->Cancel(); |
|
191 |
delete test; |
|
192 |
__UHEAP_MARKEND; |
|
193 |
||
194 |
return retval; |
|
195 |
} |
|
196 |