|
1 /* |
|
2 * Copyright (c) 2002-2005 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 "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: Hardware Resource Manager stub plugins light plugin |
|
15 * implementation. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #include "LightPlugin.h" |
|
21 #include <hwrmlightcommands.h> |
|
22 #include "PluginTimer.h" |
|
23 #include "Trace.h" |
|
24 |
|
25 #ifdef PUBLISH_STATE_INFO |
|
26 const TUid KPSUidHWResourceNotification = {0x101F7A01}; // HWRM private PS Uid |
|
27 #endif // PUBLISH_STATE_INFO |
|
28 |
|
29 CLightPlugin* CLightPlugin::NewL() |
|
30 { |
|
31 CLightPlugin* self = new(ELeave) CLightPlugin(); |
|
32 CleanupStack::PushL(self); |
|
33 self->ConstructL(); |
|
34 CleanupStack::Pop(); |
|
35 return self; |
|
36 } |
|
37 |
|
38 CLightPlugin::~CLightPlugin() |
|
39 { |
|
40 iTimers.ResetAndDestroy(); |
|
41 #ifdef PUBLISH_STATE_INFO |
|
42 for ( TInt i=0; i< KHWRMLightMaxTargets; i++ ) |
|
43 { |
|
44 iCmdProperty[i].Close(); |
|
45 iDataProperty[i].Close(); |
|
46 } |
|
47 iIntensityProperty.Close(); |
|
48 iSensitivityProperty.Close(); |
|
49 #endif // PUBLISH_STATE_INFO |
|
50 } |
|
51 |
|
52 CLightPlugin::CLightPlugin() |
|
53 { |
|
54 } |
|
55 |
|
56 void CLightPlugin::ConstructL() |
|
57 { |
|
58 #ifdef PUBLISH_STATE_INFO |
|
59 TInt currentTarget(0x00010000); |
|
60 for ( TInt i=0; i< KHWRMLightMaxTargets; i++ ) |
|
61 { |
|
62 RProperty::Define(KPSUidHWResourceNotification, (KHWRMTestLightCommand | currentTarget), RProperty::EInt); |
|
63 RProperty::Define(KPSUidHWResourceNotification, (KHWRMTestLightDataPckg | currentTarget), RProperty::EByteArray, 512); |
|
64 iCmdProperty[i].Attach(KPSUidHWResourceNotification, (KHWRMTestLightCommand | currentTarget)); |
|
65 iDataProperty[i].Attach(KPSUidHWResourceNotification, (KHWRMTestLightDataPckg | currentTarget)); |
|
66 currentTarget <<= 1; |
|
67 } |
|
68 |
|
69 RProperty::Define(KPSUidHWResourceNotification, KHWRMTestLightIntensityValue, RProperty::EInt); |
|
70 RProperty::Define(KPSUidHWResourceNotification, KHWRMTestLightSensitivityValue, RProperty::EInt); |
|
71 iIntensityProperty.Attach(KPSUidHWResourceNotification, KHWRMTestLightIntensityValue); |
|
72 iSensitivityProperty.Attach(KPSUidHWResourceNotification, KHWRMTestLightSensitivityValue); |
|
73 #endif // PUBLISH_STATE_INFO |
|
74 } |
|
75 |
|
76 |
|
77 void CLightPlugin::ProcessCommandL( const TInt aCommandId, |
|
78 const TUint8 aTransId, |
|
79 #ifdef PUBLISH_STATE_INFO |
|
80 TDesC8& aData ) |
|
81 #else |
|
82 TDesC8& /*aData*/ ) |
|
83 #endif // PUBLISH_STATE_INFO |
|
84 { |
|
85 COMPONENT_TRACE((_L("HWRM LightPlugin: Processing command: 0x%x, TransId: 0x%x"), aCommandId, aTransId)); |
|
86 |
|
87 #ifdef PUBLISH_STATE_INFO |
|
88 TInt targetMask(0); |
|
89 #endif // PUBLISH_STATE_INFO |
|
90 switch ( aCommandId ) |
|
91 { |
|
92 case HWRMLightCommand::ELightsOnCmdId: |
|
93 { |
|
94 COMPONENT_TRACE(_L("HWRM LightPlugin: Processed ELightsOnCmdId")); |
|
95 #ifdef PUBLISH_STATE_INFO |
|
96 HWRMLightCommand::TLightsOnCmdPackage pckg; |
|
97 pckg.Copy(aData); |
|
98 HWRMLightCommand::TLightsOnData data = pckg(); |
|
99 if ( data.iIntensity == KHWRMDefaultIntensity ) |
|
100 { |
|
101 data.iIntensity = iDefaultIntensity; |
|
102 } |
|
103 |
|
104 targetMask = data.iTarget << 16; |
|
105 HWRMLightCommand::TLightsOnCmdPackage pckg2(data); |
|
106 PublishStateInfo(targetMask, aCommandId, pckg2); |
|
107 #endif // PUBLISH_STATE_INFO |
|
108 } |
|
109 break; |
|
110 case HWRMLightCommand::ELightsOnSensorCmdId: |
|
111 { |
|
112 COMPONENT_TRACE(_L("HWRM LightPlugin: Processed ELightsOnSensorCmdId")); |
|
113 #ifdef PUBLISH_STATE_INFO |
|
114 HWRMLightCommand::TLightsOnSensorCmdPackage pckg; |
|
115 pckg.Copy(aData); |
|
116 HWRMLightCommand::TLightsOnSensorData data = pckg(); |
|
117 |
|
118 targetMask = data.iTarget << 16; |
|
119 PublishStateInfo(targetMask, aCommandId, pckg); |
|
120 #endif // PUBLISH_STATE_INFO |
|
121 } |
|
122 break; |
|
123 case HWRMLightCommand::ELightsBlinkCmdId: |
|
124 { |
|
125 COMPONENT_TRACE(_L("HWRM LightPlugin: Processed ELightsBlinkCmdId")); |
|
126 #ifdef PUBLISH_STATE_INFO |
|
127 HWRMLightCommand::TLightsBlinkCmdPackage pckg; |
|
128 pckg.Copy(aData); |
|
129 HWRMLightCommand::TLightsBlinkData data = pckg(); |
|
130 if ( data.iIntensity == KHWRMDefaultIntensity ) |
|
131 { |
|
132 data.iIntensity = iDefaultIntensity; |
|
133 } |
|
134 |
|
135 targetMask = data.iTarget << 16; |
|
136 HWRMLightCommand::TLightsBlinkCmdPackage pckg2(data); |
|
137 PublishStateInfo(targetMask, aCommandId, pckg2); |
|
138 #endif // PUBLISH_STATE_INFO |
|
139 } |
|
140 break; |
|
141 case HWRMLightCommand::ELightsOffCmdId: |
|
142 { |
|
143 COMPONENT_TRACE(_L("HWRM LightPlugin: Processed ELightsOffCmdId")); |
|
144 #ifdef PUBLISH_STATE_INFO |
|
145 HWRMLightCommand::TLightsOffCmdPackage pckg; |
|
146 pckg.Copy(aData); |
|
147 HWRMLightCommand::TLightsOffData data = pckg(); |
|
148 |
|
149 targetMask = data.iTarget << 16; |
|
150 PublishStateInfo(targetMask, aCommandId, pckg); |
|
151 #endif // PUBLISH_STATE_INFO |
|
152 } |
|
153 break; |
|
154 case HWRMLightCommand::ESetLightsIntensityCmdId: |
|
155 { |
|
156 COMPONENT_TRACE(_L("HWRM LightPlugin: Processed ESetLightsIntensityCmdId")); |
|
157 #ifdef PUBLISH_STATE_INFO |
|
158 HWRMLightCommand::TLightsIntensityCmdPackage pckg; |
|
159 pckg.Copy(aData); |
|
160 HWRMLightCommand::TLightsIntensityData data = pckg(); |
|
161 |
|
162 iDefaultIntensity = data.iIntensity; |
|
163 COMPONENT_TRACE( (_L("HWRM LightPlugin: Intensity: %d"), iDefaultIntensity)); |
|
164 |
|
165 // Currently only general intensity is supported, so ignore target parameter, |
|
166 // it is always all supported targets |
|
167 iIntensityProperty.Set(iDefaultIntensity); |
|
168 |
|
169 #endif // PUBLISH_STATE_INFO |
|
170 } |
|
171 break; |
|
172 case HWRMLightCommand::ESetLightsSensorSensitivityCmdId: |
|
173 { |
|
174 COMPONENT_TRACE(_L("HWRM LightPlugin: Processed ESetLightsSensorSensitivityCmdId")); |
|
175 #ifdef PUBLISH_STATE_INFO |
|
176 HWRMLightCommand::TLightsSensorSensitivityCmdPackage pckg; |
|
177 pckg.Copy(aData); |
|
178 TInt data = pckg(); |
|
179 |
|
180 iSensitivityProperty.Set(data); |
|
181 #endif // PUBLISH_STATE_INFO |
|
182 } |
|
183 break; |
|
184 default : |
|
185 { |
|
186 COMPONENT_TRACE((_L("HWRM LightPlugin: Unknown Command: 0x%x"), aCommandId)); |
|
187 } |
|
188 break; |
|
189 } |
|
190 TInt retval(KErrNone); |
|
191 TInt timeout(500); // microseconds |
|
192 |
|
193 // create new timer |
|
194 CPluginTimer* timer = CPluginTimer::NewL(timeout, iResponseCallback, aCommandId, aTransId, retval, this); |
|
195 CleanupStack::PushL(timer); |
|
196 iTimers.AppendL(timer); |
|
197 CleanupStack::Pop(timer); |
|
198 } |
|
199 |
|
200 #ifdef PUBLISH_STATE_INFO |
|
201 void CLightPlugin::PublishStateInfo(TInt aTargetMask, |
|
202 const TInt aCommandId, |
|
203 TDesC8& aData ) |
|
204 { |
|
205 // publish |
|
206 TInt currentTarget(0x10000); |
|
207 for ( TInt i=0; i< KHWRMLightMaxTargets; i++ ) |
|
208 { |
|
209 if ( aTargetMask & currentTarget ) |
|
210 { |
|
211 iCmdProperty[i].Set(aCommandId); |
|
212 iDataProperty[i].Set(aData); |
|
213 } |
|
214 currentTarget <<= 1; |
|
215 } |
|
216 } |
|
217 #endif // PUBLISH_STATE_INFO |
|
218 |
|
219 void CLightPlugin::CancelCommandL( const TUint8 aTransId, |
|
220 #if defined(_DEBUG) && defined(COMPONENT_TRACE_FLAG) |
|
221 const TInt aCommandId) |
|
222 #else |
|
223 const TInt /*aCommandId*/) |
|
224 #endif |
|
225 { |
|
226 COMPONENT_TRACE((_L("HWRM LightPlugin: Cancelling command: 0x%x, TransId: 0x%x"), aCommandId, aTransId)); |
|
227 COMPONENT_TRACE((_L("HWRM LightPlugin: Cancelling command - iTimers.Count(): %d "), iTimers.Count())); |
|
228 |
|
229 for( TInt i = 0; i < iTimers.Count(); i++ ) |
|
230 { |
|
231 if ( iTimers[i]->TransId() == aTransId ) |
|
232 { |
|
233 delete iTimers[i]; |
|
234 iTimers.Remove(i); |
|
235 COMPONENT_TRACE((_L("HWRM LightPlugin: Cancelling command - Removed command: 0x%x, TransId: 0x%x"), aCommandId, aTransId)); |
|
236 break; |
|
237 } |
|
238 } |
|
239 } |
|
240 |
|
241 void CLightPlugin::GenericTimerFired(MHWRMPluginCallback* aService, |
|
242 TInt aCommandId, |
|
243 TUint8 aTransId, |
|
244 TInt aRetVal) |
|
245 { |
|
246 COMPONENT_TRACE((_L("HWRM LightPlugin: GenericTimerFired (0x%x, 0x%x, %d)"), aCommandId, aTransId, aRetVal)); |
|
247 |
|
248 __ASSERT_ALWAYS(aService != NULL, User::Invariant() ); |
|
249 |
|
250 HWRMLightCommand::TErrorCodeResponsePackage retvalPackage(aRetVal); |
|
251 |
|
252 TRAPD(err, aService->ProcessResponseL(aCommandId, aTransId, retvalPackage)); |
|
253 |
|
254 if ( err != KErrNone ) |
|
255 { |
|
256 COMPONENT_TRACE((_L("HWRM LightPlugin: Error in ProcessResponseL: %d"), err)); |
|
257 } |
|
258 |
|
259 // delete obsolete timers |
|
260 for( TInt i = (iTimers.Count()-1); i > -1 ; i-- ) |
|
261 { |
|
262 if ( !iTimers[i]->IsActive() ) |
|
263 { |
|
264 delete iTimers[i]; |
|
265 iTimers.Remove(i); |
|
266 COMPONENT_TRACE((_L("HWRM LightPlugin: GenericTimerFired - Removed obsolete timer"))); |
|
267 } |
|
268 } |
|
269 } |
|
270 |