|
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 vibra plugin |
|
15 * implementation. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #include "VibraPlugin.h" |
|
21 #include "PluginTimer.h" |
|
22 #include <hwrmvibracommands.h> |
|
23 #include "Trace.h" |
|
24 |
|
25 |
|
26 #ifdef PUBLISH_STATE_INFO |
|
27 const TUid KPSUidHWResourceNotification = {0x101F7A01}; // HWRM private PS Uid |
|
28 #endif // PUBLISH_STATE_INFO |
|
29 |
|
30 |
|
31 CVibraPlugin* CVibraPlugin::NewL() |
|
32 { |
|
33 CVibraPlugin* self = new(ELeave) CVibraPlugin(); |
|
34 CleanupStack::PushL(self); |
|
35 self->ConstructL(); |
|
36 CleanupStack::Pop(); |
|
37 return self; |
|
38 } |
|
39 |
|
40 CVibraPlugin::~CVibraPlugin() |
|
41 { |
|
42 iTimers.ResetAndDestroy(); |
|
43 #ifdef PUBLISH_STATE_INFO |
|
44 iCmdProperty.Close(); |
|
45 iDataProperty.Close(); |
|
46 #endif // PUBLISH_STATE_INFO |
|
47 } |
|
48 |
|
49 CVibraPlugin::CVibraPlugin() |
|
50 { |
|
51 } |
|
52 |
|
53 void CVibraPlugin::ConstructL() |
|
54 { |
|
55 #ifdef PUBLISH_STATE_INFO |
|
56 RProperty::Define(KPSUidHWResourceNotification, KHWRMTestVibraCommand, RProperty::EInt); |
|
57 RProperty::Define(KPSUidHWResourceNotification, KHWRMTestVibraDataPckg, RProperty::EByteArray, 512); |
|
58 iCmdProperty.Attach(KPSUidHWResourceNotification, KHWRMTestVibraCommand); |
|
59 iDataProperty.Attach(KPSUidHWResourceNotification, KHWRMTestVibraDataPckg); |
|
60 #endif // PUBLISH_STATE_INFO |
|
61 } |
|
62 |
|
63 |
|
64 void CVibraPlugin::ProcessCommandL( const TInt aCommandId, |
|
65 const TUint8 aTransId, |
|
66 #ifdef PUBLISH_STATE_INFO |
|
67 TDesC8& aData ) |
|
68 #else |
|
69 TDesC8& /*aData*/ ) |
|
70 #endif // PUBLISH_STATE_INFO |
|
71 { |
|
72 COMPONENT_TRACE((_L("HWRM VibraPlugin: Processing command: 0x%x, TransId: 0x%x"), aCommandId, aTransId)); |
|
73 |
|
74 switch ( aCommandId ) |
|
75 { |
|
76 case HWRMVibraCommand::EStartVibraCmdId: |
|
77 { |
|
78 COMPONENT_TRACE(_L("HWRM VibraPlugin: Processed EStartVibraCmdId")); |
|
79 } |
|
80 break; |
|
81 case HWRMVibraCommand::EStartVibraWithDefaultSettingsCmdId: |
|
82 { |
|
83 COMPONENT_TRACE(_L("HWRM VibraPlugin: Processed EStartVibraWithDefaultSettingsCmdId")); |
|
84 } |
|
85 break; |
|
86 case HWRMVibraCommand::EPulseVibraCmdId: |
|
87 { |
|
88 COMPONENT_TRACE(_L("HWRM VibraPlugin: Processed EPulseVibraCmdId")); |
|
89 } |
|
90 break; |
|
91 case HWRMVibraCommand::EStopVibraCmdId: |
|
92 { |
|
93 COMPONENT_TRACE(_L("HWRM VibraPlugin: Processed EStopVibraCmdId")); |
|
94 } |
|
95 break; |
|
96 |
|
97 default : |
|
98 { |
|
99 COMPONENT_TRACE((_L("HWRM VibraPlugin: Unknown Command: 0x%x"), aCommandId)); |
|
100 } |
|
101 break; |
|
102 } |
|
103 |
|
104 TInt retval(KErrNone); |
|
105 TInt timeout(500); // microseconds |
|
106 |
|
107 #ifdef PUBLISH_STATE_INFO |
|
108 // publish |
|
109 iCmdProperty.Set(aCommandId); |
|
110 iDataProperty.Set(aData); |
|
111 #endif // PUBLISH_STATE_INFO |
|
112 |
|
113 // create new timer |
|
114 CPluginTimer* timer = CPluginTimer::NewL(timeout, iResponseCallback, aCommandId, aTransId, retval, this); |
|
115 CleanupStack::PushL(timer); |
|
116 iTimers.AppendL(timer); |
|
117 CleanupStack::Pop(timer); |
|
118 } |
|
119 |
|
120 void CVibraPlugin::CancelCommandL( const TUint8 aTransId, |
|
121 #if defined(_DEBUG) && defined(COMPONENT_TRACE_FLAG) |
|
122 const TInt aCommandId) |
|
123 #else |
|
124 const TInt /*aCommandId*/) |
|
125 #endif |
|
126 { |
|
127 COMPONENT_TRACE((_L("HWRM VibraPlugin: Cancelling command: 0x%x, TransId: 0x%x"), aCommandId, aTransId)); |
|
128 COMPONENT_TRACE((_L("HWRM VibraPlugin: Cancelling command - iTimers.Count(): %d "), iTimers.Count())); |
|
129 |
|
130 for( TInt i = 0; i < iTimers.Count(); i++ ) |
|
131 { |
|
132 if ( iTimers[i]->TransId() == aTransId ) |
|
133 { |
|
134 delete iTimers[i]; |
|
135 iTimers.Remove(i); |
|
136 COMPONENT_TRACE((_L("HWRM VibraPlugin: Cancelling command - Removed command: 0x%x, TransId: 0x%x"), aCommandId, aTransId)); |
|
137 break; |
|
138 } |
|
139 } |
|
140 } |
|
141 |
|
142 void CVibraPlugin::GenericTimerFired(MHWRMPluginCallback* aService, |
|
143 TInt aCommandId, |
|
144 const TUint8 aTransId, |
|
145 TInt aRetVal) |
|
146 { |
|
147 COMPONENT_TRACE((_L("HWRM VibraPlugin: GenericTimerFired (0x%x, 0x%x, %d)"), aCommandId, aTransId, aRetVal)); |
|
148 |
|
149 __ASSERT_ALWAYS(aService != NULL, User::Invariant() ); |
|
150 |
|
151 HWRMVibraCommand::TErrorCodeResponsePackage retvalPackage(aRetVal); |
|
152 |
|
153 TRAPD(err, aService->ProcessResponseL(aCommandId, aTransId, retvalPackage)); |
|
154 |
|
155 if ( err != KErrNone ) |
|
156 { |
|
157 COMPONENT_TRACE((_L("HWRM VibraPlugin: Error in ProcessResponseL: %d"), err)); |
|
158 } |
|
159 |
|
160 // delete obsolete timers |
|
161 for( TInt i = (iTimers.Count()-1); i > -1 ; i-- ) |
|
162 { |
|
163 if ( !iTimers[i]->IsActive() ) |
|
164 { |
|
165 delete iTimers[i]; |
|
166 iTimers.Remove(i); |
|
167 COMPONENT_TRACE((_L("HWRM VibraPlugin: GenericTimerFired - Removed obsolete timer"))); |
|
168 } |
|
169 } |
|
170 |
|
171 } |