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