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 "tsysinfoservicetests.h" |
|
20 |
#include "sysinfoservice.h" |
|
33
50974a8b132e
Revision: 200945
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
21 |
#include "tautolocknotifier.h" |
19 | 22 |
#include "entitykeys.h" |
23 |
#include "watchtimer.h" |
|
24 |
#include <e32std.h> |
|
25 |
||
26 |
using namespace SysInfo; |
|
27 |
||
28 |
CAutoLockNotifier* CAutoLockNotifier::NewL(CStifLogger* aLog,TInt aDrvNo) |
|
29 |
{ |
|
30 |
CAutoLockNotifier* self = new(ELeave) CAutoLockNotifier(aLog,aDrvNo); |
|
31 |
self->ConstructL(); |
|
32 |
return self; |
|
33 |
} |
|
34 |
||
35 |
CAutoLockNotifier::~CAutoLockNotifier() |
|
36 |
{ |
|
37 |
Cancel(); |
|
38 |
if(iWaitSchedular->IsStarted()) |
|
39 |
iWaitSchedular->AsyncStop(); |
|
40 |
||
41 |
delete iTimer; |
|
42 |
delete iSysInfoService; |
|
43 |
delete iWaitSchedular; |
|
44 |
} |
|
45 |
||
46 |
void CAutoLockNotifier::ConstructL() |
|
47 |
{ |
|
48 |
iSysInfoService = CSysInfoService::NewL(); |
|
49 |
iWaitSchedular = new(ELeave) CActiveSchedulerWait(); |
|
50 |
iTimer = CWatchTimer::NewL(EPriorityNormal,this); |
|
51 |
CActiveScheduler::Add(this); |
|
52 |
} |
|
53 |
||
54 |
CAutoLockNotifier::CAutoLockNotifier(CStifLogger* aLog,TInt aAutoLockTime) : |
|
55 |
CActive(EPriorityStandard),iLog(aLog),iAutoLockTime(aAutoLockTime) |
|
56 |
{ |
|
57 |
} |
|
58 |
||
59 |
void CAutoLockNotifier::DoCancel() |
|
60 |
{ |
|
61 |
//TRAPD(err1,iSysInfoService->GetInfoL(req1)); |
|
62 |
} |
|
63 |
||
64 |
void CAutoLockNotifier::RunL() |
|
65 |
{ |
|
66 |
TestFuncL(); |
|
67 |
} |
|
68 |
||
69 |
void CAutoLockNotifier::Start() |
|
70 |
{ |
|
71 |
SetActive(); |
|
72 |
TRequestStatus* temp = &iStatus; |
|
73 |
User::RequestComplete(temp, KErrNone); |
|
74 |
iWaitSchedular->Start(); |
|
75 |
} |
|
76 |
||
77 |
TInt CAutoLockNotifier::Result() |
|
78 |
{ |
|
79 |
return iResult; |
|
80 |
} |
|
81 |
||
82 |
void CAutoLockNotifier::TestFuncL() |
|
83 |
{ |
|
84 |
CSysData* input = CStatus::NewL(iAutoLockTime); |
|
85 |
CleanupStack::PushL(input); |
|
86 |
TRAPD(err,iSysInfoService->SetInfoL(KDisplay,KAutoLockTime,input)); |
|
87 |
CleanupStack::PopAndDestroy(input); |
|
88 |
if (err) |
|
89 |
{ |
|
90 |
iLog->Log( _L("Error setting auto lock time: %d"),err ); |
|
91 |
} |
|
92 |
||
93 |
iLog->Log( _L("Auto Lock Time Set to %d Mins"),iAutoLockTime ); |
|
94 |
iSysInfoService->GetNotificationL(KDisplay,KAutoLockStatus,1,this); |
|
95 |
||
96 |
const TInt OneMin(60000000); |
|
97 |
iTimer->After(OneMin*iAutoLockTime*2); |
|
98 |
return ; |
|
99 |
} |
|
100 |
||
101 |
void CAutoLockNotifier::HandleResponseL(const TDesC& aEntity,const TDesC& aKey, |
|
102 |
CSysData* aOutput, TInt32 aTransID, TSysRequest::TRequestType /*aType*/,TInt aError) |
|
103 |
{ |
|
104 |
delete iTimer; |
|
105 |
iTimer = NULL; |
|
106 |
if( !(aEntity.Compare(KDisplay) || aKey.Compare(KAutoLockStatus)) ) |
|
107 |
{ |
|
108 |
if(!aError) |
|
109 |
{ |
|
110 |
if(!(aTransID == 1)) |
|
111 |
{ |
|
112 |
iLog->Log(_L("Incorrect TransactionID: %d"),aTransID); |
|
113 |
iResult = FAIL; |
|
114 |
} |
|
115 |
||
116 |
TInt AutoLockStatus = ((CStatus*)aOutput)->Status(); |
|
117 |
||
118 |
if(AutoLockStatus) |
|
119 |
iLog->Log(_L("Auto Lock Enabled")); |
|
120 |
else |
|
121 |
iLog->Log(_L("Auto Lock Disabled")); |
|
122 |
||
123 |
delete aOutput; |
|
124 |
iResult = PASS; |
|
125 |
} |
|
126 |
else |
|
127 |
{ |
|
128 |
iLog->Log(_L("Error Set in Response Error: %d "),aError); |
|
129 |
iResult = FAIL; |
|
130 |
} |
|
131 |
||
132 |
} |
|
133 |
//reset autolock time to 0 |
|
134 |
CSysData* input = CStatus::NewL(0); |
|
135 |
CleanupStack::PushL(input); |
|
136 |
TRAPD(err,iSysInfoService->SetInfoL(KDisplay,KAutoLockTime,input)); |
|
137 |
CleanupStack::PopAndDestroy(input); |
|
138 |
if (err) |
|
139 |
{ |
|
140 |
iLog->Log( _L("Error setting auto lock time: %d"),err ); |
|
141 |
} |
|
142 |
||
143 |
iWaitSchedular->AsyncStop(); |
|
144 |
||
145 |
} |
|
146 |
||
147 |
void CAutoLockNotifier::HandleTimeOut() |
|
148 |
{ |
|
149 |
iLog->Log(_L("TimeOut reached. Auto Lock Not Enabled..")); |
|
150 |
iSysInfoService->Cancel(1); |
|
151 |
iResult = FAIL; |
|
152 |
//reset autolock time to 0 |
|
153 |
CSysData* input = CStatus::NewL(0); |
|
154 |
CleanupStack::PushL(input); |
|
155 |
TRAPD(err,iSysInfoService->SetInfoL(KDisplay,KAutoLockTime,input)); |
|
156 |
CleanupStack::PopAndDestroy(input); |
|
157 |
if (err) |
|
158 |
{ |
|
159 |
iLog->Log( _L("Error setting auto lock time: %d"),err ); |
|
160 |
} |
|
161 |
iWaitSchedular->AsyncStop(); |
|
162 |
} |
|
163 |