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 |
||
20 |
#include "sysinfoservice.h" |
|
21 |
#include"entitykeys.h" |
|
22 |
||
33
50974a8b132e
Revision: 200945
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
23 |
#include <ir_sock.h> |
19 | 24 |
#include <e32property.h> |
25 |
||
26 |
using namespace SysInfo; |
|
27 |
||
28 |
class CInfraredTestAsync : public CActive ,public ISystemObserver |
|
29 |
{ |
|
30 |
public: |
|
31 |
static CInfraredTestAsync* NewL(); |
|
32 |
~CInfraredTestAsync(); |
|
33 |
void Start(); |
|
34 |
TInt Result(); |
|
35 |
||
36 |
void HandleResponseL(const TDesC& aEntity,const TDesC& aKey, |
|
37 |
CSysData* aResponse, TInt32 aTransID, |
|
38 |
TSysRequest::TRequestType aType, TInt aError=KErrNone); |
|
39 |
||
40 |
private: |
|
41 |
void ConstructL(); |
|
42 |
CInfraredTestAsync(); |
|
43 |
||
44 |
virtual void DoCancel(); |
|
45 |
virtual void RunL(); |
|
46 |
||
47 |
||
48 |
void TestFunc(); |
|
49 |
||
50 |
||
51 |
||
52 |
private: |
|
53 |
CActiveSchedulerWait* iWaitSchedular; |
|
54 |
CSysInfoService* iSysInfoService; |
|
55 |
TInt infraredStatus ; |
|
56 |
TInt iResult; |
|
57 |
}; |
|
58 |
||
59 |
CInfraredTestAsync* CInfraredTestAsync::NewL() |
|
60 |
{ |
|
61 |
CInfraredTestAsync* self = new(ELeave) CInfraredTestAsync(); |
|
62 |
self->ConstructL(); |
|
63 |
return self; |
|
64 |
} |
|
65 |
||
66 |
CInfraredTestAsync::~CInfraredTestAsync() |
|
67 |
{ |
|
68 |
Cancel(); |
|
69 |
||
70 |
if(iWaitSchedular->IsStarted()) |
|
71 |
iWaitSchedular->AsyncStop(); |
|
72 |
||
73 |
if(iSysInfoService) |
|
74 |
delete iSysInfoService; |
|
75 |
||
76 |
if(iWaitSchedular) |
|
77 |
delete iWaitSchedular; |
|
78 |
} |
|
79 |
||
80 |
void CInfraredTestAsync::ConstructL() |
|
81 |
{ |
|
82 |
CActiveScheduler::Add(this); |
|
83 |
iSysInfoService = CSysInfoService::NewL(); |
|
84 |
iWaitSchedular = new(ELeave) CActiveSchedulerWait(); |
|
85 |
} |
|
86 |
||
87 |
CInfraredTestAsync::CInfraredTestAsync() : |
|
88 |
CActive(EPriorityStandard),iResult(KErrNone) |
|
89 |
{ |
|
90 |
} |
|
91 |
||
92 |
void CInfraredTestAsync::DoCancel() |
|
93 |
{ |
|
94 |
||
95 |
||
96 |
} |
|
97 |
||
98 |
void CInfraredTestAsync::RunL() |
|
99 |
{ |
|
100 |
TestFunc(); |
|
101 |
} |
|
102 |
||
103 |
void CInfraredTestAsync::Start() |
|
104 |
{ |
|
105 |
||
106 |
SetActive(); |
|
107 |
TRequestStatus* temp = &iStatus; |
|
108 |
User::RequestComplete(temp, KErrNone); |
|
109 |
iWaitSchedular->Start(); |
|
110 |
} |
|
111 |
||
112 |
TInt CInfraredTestAsync::Result() |
|
113 |
{ |
|
114 |
return iResult; |
|
115 |
} |
|
116 |
||
117 |
void CInfraredTestAsync::TestFunc() |
|
118 |
{ |
|
119 |
||
120 |
TRAPD(err1,iSysInfoService->GetNotificationL(KConnectivity,KInfraRed,8877,this)); |
|
121 |
iResult = err1; |
|
122 |
||
123 |
if(err1 == KErrNone) |
|
124 |
{ |
|
125 |
CSysData* data1 = NULL; |
|
126 |
||
127 |
TRAPD(err2,iSysInfoService->GetInfoL(KConnectivity,KInfraRed,data1)); |
|
128 |
iResult =err2; |
|
129 |
TInt newIRstatus; |
|
130 |
if(err2 == KErrNone) |
|
131 |
{ |
|
132 |
infraredStatus = ((CStatus*)data1)->Status(); |
|
133 |
CStatus* data2 = NULL; |
|
134 |
||
135 |
if(infraredStatus == EUnknown || infraredStatus ==EOff ) |
|
136 |
{ |
|
137 |
infraredStatus = EOff; |
|
138 |
newIRstatus = EOn; |
|
139 |
data2 = CStatus::NewL(newIRstatus); |
|
140 |
} |
|
141 |
else |
|
142 |
{ |
|
143 |
newIRstatus = EOff; |
|
144 |
data2 = CStatus::NewL(newIRstatus); |
|
145 |
} |
|
146 |
// TRAPD(err3,iSysInfoService->SetInfoL(KConnectivity,KInfraRed,data2)); |
|
147 |
TInt err3(KErrNone); |
|
148 |
if(newIRstatus == EOn) |
|
149 |
err3= RProperty::Set(KIrdaPropertyCategory, |
|
150 |
KIrdaStatus,TIrdaStatusCodes::EIrLoaded); |
|
151 |
else if(newIRstatus == EOff) |
|
152 |
err3 = RProperty::Set(KIrdaPropertyCategory, |
|
153 |
KIrdaStatus,TIrdaStatusCodes::EIrUnloaded); |
|
154 |
else |
|
155 |
err3 = KErrArgument; |
|
156 |
||
157 |
iResult =err3; |
|
158 |
||
159 |
delete data2; |
|
160 |
} |
|
161 |
delete data1; |
|
162 |
||
163 |
} |
|
164 |
return ; |
|
165 |
} |
|
166 |
||
167 |
void CInfraredTestAsync::HandleResponseL(const TDesC& /*aEntity*/,const TDesC& /*aKey*/, |
|
168 |
CSysData* aResponse, TInt32 /*aTransID*/, |
|
169 |
TSysRequest::TRequestType /*aType*/,TInt aError) |
|
170 |
{ |
|
171 |
if(aError == KErrNone) |
|
172 |
{ |
|
173 |
const CStatus* data1 = (CStatus*)aResponse; |
|
174 |
TInt newIRstatus; |
|
175 |
if((data1->Status() ) == (!infraredStatus) ) |
|
176 |
{ |
|
177 |
iResult = KErrNone; |
|
178 |
||
179 |
if((data1->Status()) == EOn) |
|
180 |
{ |
|
181 |
newIRstatus = EOff; |
|
182 |
} |
|
183 |
else |
|
184 |
{ |
|
185 |
newIRstatus = EOn; |
|
186 |
} |
|
187 |
||
188 |
// TRAPD(err3,iSysInfoService->SetInfoL(KConnectivity,KInfraRed,data2)); |
|
189 |
TInt err3(KErrNone); |
|
190 |
if(newIRstatus == EOn) |
|
191 |
err3= RProperty::Set(KIrdaPropertyCategory, |
|
192 |
KIrdaStatus,TIrdaStatusCodes::EIrLoaded); |
|
193 |
else if(newIRstatus == EOff) |
|
194 |
err3 = RProperty::Set(KIrdaPropertyCategory, |
|
195 |
KIrdaStatus,TIrdaStatusCodes::EIrUnloaded); |
|
196 |
else |
|
197 |
err3 = KErrArgument; |
|
198 |
iResult = err3; |
|
199 |
} |
|
200 |
else |
|
201 |
{ |
|
202 |
iResult = -1; |
|
203 |
} |
|
204 |
delete aResponse; |
|
205 |
data1 = NULL; |
|
206 |
} |
|
207 |
iWaitSchedular->AsyncStop(); |
|
208 |
} |
|
209 |
||
210 |
||
211 |
int IRNotification(int, char**) |
|
212 |
{ |
|
213 |
__UHEAP_MARK; |
|
214 |
CInfraredTestAsync* test = CInfraredTestAsync::NewL(); |
|
215 |
||
216 |
test->Start(); |
|
217 |
TInt retval = test->Result(); |
|
218 |
delete test; |
|
219 |
||
220 |
__UHEAP_MARKEND; |
|
221 |
return retval; |
|
222 |
} |
|
223 |