|
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: tsysinfoaccessorystatus |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "tsysmanualtest.h" |
|
20 #include "sysinfoservice.h" |
|
21 #include "tasyncaccandvibra.h" |
|
22 #include "watchtimer.h" |
|
23 #include "entitykeys.h" |
|
24 |
|
25 using namespace SysInfo; |
|
26 |
|
27 |
|
28 CTestAccAndVibraNot* CTestAccAndVibraNot::NewL(CStifLogger* aLog) |
|
29 { |
|
30 CTestAccAndVibraNot* self = new(ELeave) CTestAccAndVibraNot(aLog); |
|
31 self->ConstructL(); |
|
32 return self; |
|
33 } |
|
34 |
|
35 CTestAccAndVibraNot::~CTestAccAndVibraNot() |
|
36 { |
|
37 Cancel(); |
|
38 |
|
39 if(iWaitScheduler->IsStarted()) |
|
40 iWaitScheduler->AsyncStop(); |
|
41 |
|
42 if(iSysInfoService) |
|
43 delete iSysInfoService; |
|
44 |
|
45 if(iWaitScheduler) |
|
46 delete iWaitScheduler; |
|
47 } |
|
48 |
|
49 void CTestAccAndVibraNot::ConstructL() |
|
50 { |
|
51 CActiveScheduler::Add(this); |
|
52 iSysInfoService = CSysInfoService::NewL(); |
|
53 iWaitScheduler = new(ELeave) CActiveSchedulerWait(); |
|
54 } |
|
55 |
|
56 CTestAccAndVibraNot::CTestAccAndVibraNot(CStifLogger* aLog) : |
|
57 CActive(EPriorityStandard),iResult(-1),iLog(aLog),iCount(0) |
|
58 { |
|
59 } |
|
60 |
|
61 void CTestAccAndVibraNot::DoCancel() |
|
62 { |
|
63 |
|
64 } |
|
65 |
|
66 void CTestAccAndVibraNot::RunL() |
|
67 { |
|
68 TestFunc(); |
|
69 } |
|
70 |
|
71 void CTestAccAndVibraNot::Start() |
|
72 { |
|
73 |
|
74 SetActive(); |
|
75 TRequestStatus* temp = &iStatus; |
|
76 User::RequestComplete(temp, KErrNone); |
|
77 iWaitScheduler->Start(); |
|
78 } |
|
79 |
|
80 TInt CTestAccAndVibraNot::Result() |
|
81 { |
|
82 return iResult; |
|
83 } |
|
84 |
|
85 void CTestAccAndVibraNot::TestSetup(TInt aVibraStatus) |
|
86 { |
|
87 CStatus *vibStatus = CStatus::NewL(aVibraStatus) ; |
|
88 iSysInfoService->SetInfoL(KGeneral,KVibraActive,vibStatus) ; |
|
89 delete vibStatus ; |
|
90 } |
|
91 |
|
92 void CTestAccAndVibraNot::TestFunc() |
|
93 { |
|
94 TestSetup(0) ; |
|
95 TRAPD(err1,iSysInfoService->GetNotificationL(KGeneral,KAccessoryStatus,1000,this)); |
|
96 TRAPD(err2,iSysInfoService->GetNotificationL(KGeneral,KVibraActive,1001,this)); |
|
97 |
|
98 if((KErrNone == err1) && (KErrNone == err2)) |
|
99 { |
|
100 TestSetup(1) ; |
|
101 } |
|
102 else |
|
103 { |
|
104 iWaitScheduler->AsyncStop(); |
|
105 TestSetup(0) ; |
|
106 } |
|
107 return ; |
|
108 } |
|
109 |
|
110 void CTestAccAndVibraNot::HandleResponseL(const TDesC& /*aEntity*/,const TDesC& /*aKey*/, |
|
111 CSysData* aResponse, TInt32 aTransID, |
|
112 TSysRequest::TRequestType /*aType*/, TInt aError) |
|
113 { |
|
114 |
|
115 if(aError == KErrNone) |
|
116 { |
|
117 if(aTransID == 1000) |
|
118 { |
|
119 const CAccessoryInfo* accInfo= (CAccessoryInfo*)aResponse; |
|
120 |
|
121 TBuf<50> acctype ; |
|
122 TBuf<50> accConnState; |
|
123 acctype.AppendNum( accInfo->AccessoryType() ); |
|
124 accConnState.AppendNum( accInfo->ConnectionState() ); |
|
125 iLog->Log(_L("Accessory Type:")); |
|
126 iLog->Log(acctype); |
|
127 |
|
128 iLog->Log(_L("Accessory Connection State:")); |
|
129 iLog->Log(accConnState); |
|
130 |
|
131 iResult = KErrNone; |
|
132 } |
|
133 |
|
134 else if(aTransID == 1001) |
|
135 { |
|
136 TInt expVibStatus = 1 ; |
|
137 |
|
138 const CStatus* data = (CStatus*)aResponse ; |
|
139 TInt vibStatus = data->Status() ; |
|
140 |
|
141 if(vibStatus == expVibStatus) |
|
142 { |
|
143 iResult = KErrNone ; |
|
144 } |
|
145 iLog->Log(_L8("PredicitiveText status : %d"),vibStatus) ; |
|
146 |
|
147 } |
|
148 iCount++ ; |
|
149 delete aResponse ; |
|
150 } |
|
151 |
|
152 if(iCount == 2) |
|
153 { |
|
154 iWaitScheduler->AsyncStop(); |
|
155 TestSetup(0) ; |
|
156 } |
|
157 |
|
158 } |
|
159 |
|
160 |
|
161 TInt TestAccAndVibraNot(CStifLogger* aLog) |
|
162 { |
|
163 |
|
164 __UHEAP_MARK ; |
|
165 |
|
166 CTestAccAndVibraNot* test = CTestAccAndVibraNot::NewL(aLog); |
|
167 aLog->Log(_L8("Accessory and Vibration Status Notifications")) ; |
|
168 test->Start(); |
|
169 TInt retval = test->Result(); |
|
170 delete test; |
|
171 |
|
172 __UHEAP_MARKEND ; |
|
173 return retval; |
|
174 } |
|
175 |