|
1 /* |
|
2 * Copyright (c) 2009 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: Class for producing haptics tacticon. |
|
15 * Part of: Tacticon Server |
|
16 */ |
|
17 |
|
18 #include <f32file.h> |
|
19 #include <hwrmhaptics.h> |
|
20 #include <centralrepository.h> |
|
21 #include <ecom/implementationproxy.h> |
|
22 |
|
23 #include "tacticonhapticsplayer.h" |
|
24 #include "tacticonprivatecrkeys.h" |
|
25 #include "tacticontrace.h" |
|
26 #include "osttracedefinitions.h" |
|
27 #ifdef OST_TRACE_COMPILER_IN_USE |
|
28 #include "tacticonhapticsplayertraces.h" |
|
29 #endif |
|
30 |
|
31 |
|
32 // Tacticons |
|
33 _LIT8( KPositiveTacticon, "PositiveTacticon"); |
|
34 _LIT8( KNegativeTacticon, "NegativeTacticon"); |
|
35 _LIT8( KNeutralTacticon, "NeutralTacticon" ); |
|
36 |
|
37 |
|
38 // max length of tacticon names defined above |
|
39 const TInt KTacticonNameMaxLen = 128; |
|
40 |
|
41 // --------------------------------------------------------------------------- |
|
42 // Constructor. |
|
43 // --------------------------------------------------------------------------- |
|
44 // |
|
45 CTacticonHapticsPlayer::CTacticonHapticsPlayer( CRepository& aRepository ) : |
|
46 iRepository(aRepository) |
|
47 { |
|
48 |
|
49 } |
|
50 |
|
51 // --------------------------------------------------------------------------- |
|
52 // 2nd phase constructor. |
|
53 // --------------------------------------------------------------------------- |
|
54 // |
|
55 void CTacticonHapticsPlayer::ConstructL() |
|
56 { |
|
57 TRACE( "CTacticonHapticsPlayer::ConstructL - Begin" ); |
|
58 iHaptics = CHWRMHaptics::NewL( NULL, NULL ); |
|
59 |
|
60 TUint32 suppMask( 0 ); |
|
61 User::LeaveIfError( iHaptics->SupportedActuators( suppMask ) ); |
|
62 |
|
63 CRepository* playerRepository = CRepository::NewL( KCRUidTacticon ); |
|
64 CleanupStack::PushL( playerRepository ); |
|
65 TInt actuatorType( 0 ); |
|
66 playerRepository->Get( KActuatorType, actuatorType ); |
|
67 CleanupStack::PopAndDestroy( playerRepository ); |
|
68 TRACE2( "CTacticonHapticsPlayer::ConstructL - ActuatorType: %d", actuatorType ); |
|
69 if ( actuatorType & suppMask ) |
|
70 { |
|
71 // supported actuator, use this |
|
72 iHaptics->OpenActuatorL( ( THWRMLogicalActuators )actuatorType ); |
|
73 } |
|
74 else |
|
75 { |
|
76 TRACE3( "CTacticonHapticsPlayer::ConstructL - ActuatorType is not supported: %d/%d", |
|
77 actuatorType, |
|
78 suppMask ); |
|
79 // suggested actuator is not supported, use default one |
|
80 iHaptics->OpenActuatorL( EHWRMLogicalActuatorAny ); |
|
81 } |
|
82 |
|
83 User::LeaveIfError( iHaptics->SetDeviceProperty( |
|
84 CHWRMHaptics::EHWRMHapticsLicensekey, |
|
85 KNullDesC8() ) ); |
|
86 TInt strength( 0 ); |
|
87 User::LeaveIfError( iRepository.Get( KTacticonStrength, strength ) ); |
|
88 iStrength = strength * 100; // strength is in percents |
|
89 |
|
90 iHaptics->SetDeviceProperty( CHWRMHaptics::EHWRMHapticsStrength, |
|
91 iStrength ); |
|
92 TRACE2( "CTacticonHapticsPlayer::ConstructL - Set strength: %d", iStrength ); |
|
93 |
|
94 TFileName ivtFile; |
|
95 User::LeaveIfError( iRepository.Get( KTacticonIVTFile, ivtFile ) ); |
|
96 TRACE2( "CTacticonHapticsPlayer::ConstructL - Loading IVT file: %S", &ivtFile ); |
|
97 |
|
98 HBufC8* ivtBuf = IVTBufAllocL( ivtFile ); |
|
99 CleanupStack::PushL( ivtBuf ); |
|
100 User::LeaveIfError( iHaptics->LoadEffectData( *ivtBuf, iIVTHandle ) ); |
|
101 CleanupStack::PopAndDestroy( ivtBuf ); |
|
102 |
|
103 iCenRepNotifier = CCenRepNotifyHandler::NewL( *this, iRepository ); |
|
104 iCenRepNotifier->StartListeningL(); |
|
105 |
|
106 TRACE( "CTacticonHapticsPlayer::ConstructL - End" ); |
|
107 } |
|
108 |
|
109 // --------------------------------------------------------------------------- |
|
110 // 2-phased constructor. |
|
111 // --------------------------------------------------------------------------- |
|
112 // |
|
113 CTacticonHapticsPlayer* CTacticonHapticsPlayer::NewL( CRepository& aRepository ) |
|
114 { |
|
115 CTacticonHapticsPlayer* self = |
|
116 new ( ELeave ) CTacticonHapticsPlayer( aRepository ); |
|
117 CleanupStack::PushL( self ); |
|
118 self->ConstructL(); |
|
119 CleanupStack::Pop( self ); |
|
120 return self; |
|
121 } |
|
122 |
|
123 // --------------------------------------------------------------------------- |
|
124 // Destructor. |
|
125 // --------------------------------------------------------------------------- |
|
126 // |
|
127 CTacticonHapticsPlayer::~CTacticonHapticsPlayer() |
|
128 { |
|
129 delete iCenRepNotifier; |
|
130 delete iHaptics; |
|
131 } |
|
132 |
|
133 // --------------------------------------------------------------------------- |
|
134 // Load IVT file. |
|
135 // --------------------------------------------------------------------------- |
|
136 // |
|
137 HBufC8* CTacticonHapticsPlayer::IVTBufAllocL( const TDesC& aFileName ) |
|
138 { |
|
139 RFs fs; |
|
140 User::LeaveIfError( fs.Connect() ); |
|
141 CleanupClosePushL( fs ); |
|
142 |
|
143 RFile file; |
|
144 User::LeaveIfError( file.Open( fs, aFileName, EFileRead ) ); |
|
145 CleanupClosePushL( file ); |
|
146 |
|
147 TInt fileSize( 0 ); |
|
148 file.Size( fileSize ); |
|
149 |
|
150 HBufC8* ivtFileBuf = HBufC8::NewLC( fileSize ); |
|
151 TPtr8 dataBufPtr = ivtFileBuf->Des(); |
|
152 |
|
153 User::LeaveIfError( file.Read( dataBufPtr ) ); |
|
154 |
|
155 CleanupStack::Pop( ivtFileBuf ); |
|
156 CleanupStack::PopAndDestroy( &file ); |
|
157 CleanupStack::PopAndDestroy( &fs ); |
|
158 return ivtFileBuf; |
|
159 } |
|
160 |
|
161 // --------------------------------------------------------------------------- |
|
162 // Check if there's a change in tacticon settings and set new values if needed. |
|
163 // --------------------------------------------------------------------------- |
|
164 // |
|
165 void CTacticonHapticsPlayer::DoHandleNotifyGenericL( TUint32 aId ) |
|
166 { |
|
167 switch ( aId ) |
|
168 { |
|
169 case KTacticonStrength: |
|
170 { |
|
171 // Strength value in settings is multiplied by 100 to scale value |
|
172 // suitable for haptics. |
|
173 TInt strength(0); |
|
174 iRepository.Get( KTacticonStrength, strength ); |
|
175 |
|
176 iStrength = strength * 100; |
|
177 iHaptics->SetDeviceProperty( CHWRMHaptics::EHWRMHapticsStrength, |
|
178 iStrength ); |
|
179 } |
|
180 break; |
|
181 case KTacticonIVTFile: |
|
182 { |
|
183 TFileName ivtFile; |
|
184 iRepository.Get( KTacticonIVTFile, ivtFile ); |
|
185 ChangeIVTFileL( ivtFile ); |
|
186 } |
|
187 break; |
|
188 default: |
|
189 break; |
|
190 } |
|
191 } |
|
192 |
|
193 // --------------------------------------------------------------------------- |
|
194 // From MCenRepNotifyHandlerCallback. |
|
195 // --------------------------------------------------------------------------- |
|
196 // |
|
197 void CTacticonHapticsPlayer::HandleNotifyGeneric( TUint32 aId ) |
|
198 { |
|
199 TRAP_IGNORE( DoHandleNotifyGenericL( aId ) ); |
|
200 } |
|
201 |
|
202 // --------------------------------------------------------------------------- |
|
203 // Load new effect file. |
|
204 // --------------------------------------------------------------------------- |
|
205 // |
|
206 void CTacticonHapticsPlayer::ChangeIVTFileL( const TDesC& aFileName ) |
|
207 { |
|
208 iHaptics->DeleteEffectData( iIVTHandle ); |
|
209 |
|
210 HBufC8* ivtBuf = IVTBufAllocL( aFileName ); |
|
211 |
|
212 iHaptics->LoadEffectData( *ivtBuf, iIVTHandle ); |
|
213 |
|
214 delete ivtBuf; |
|
215 } |
|
216 |
|
217 // --------------------------------------------------------------------------- |
|
218 // Play tacticon. |
|
219 // --------------------------------------------------------------------------- |
|
220 // |
|
221 void CTacticonHapticsPlayer::PlayTacticon( TTacticonType aTacticon ) |
|
222 { |
|
223 TRACE2( "CTacticonHapticsPlayer::PlayTacticon(%d) - Begin", aTacticon ); |
|
224 |
|
225 TBuf8<KTacticonNameMaxLen> name; |
|
226 switch( aTacticon ) |
|
227 { |
|
228 case EPositiveTacticon: |
|
229 name = KPositiveTacticon; |
|
230 break; |
|
231 case ENegativeTacticon: |
|
232 name = KNegativeTacticon; |
|
233 break; |
|
234 case ENeutralTacticon: |
|
235 name = KNeutralTacticon; |
|
236 break; |
|
237 default: |
|
238 return; |
|
239 } |
|
240 TInt effectIndex(0); |
|
241 iHaptics->GetEffectIndexFromName( iIVTHandle, name, effectIndex ); |
|
242 |
|
243 OstTrace1( TACTICON_PERFORMANCE, TACTICON_HAPTICS_PLAYER_PLAY_TACTICON_1, |
|
244 "e_TACTICON_HAPTICS_PLAYER_PLAY_TACTICON 1 0x%x", aTacticon ); |
|
245 |
|
246 TInt effectHandle(0); |
|
247 iHaptics->PlayEffect( iIVTHandle, effectIndex, effectHandle ); |
|
248 |
|
249 OstTrace1( TACTICON_PERFORMANCE, TACTICON_HAPTICS_PLAYER_PLAY_TACTICON_0, |
|
250 "e_TACTICON_HAPTICS_PLAYER_PLAY_TACTICON 0 0x%x", aTacticon ); |
|
251 |
|
252 TRACE( "CTacticonHapticsPlayer::PlayTacticon(%d) - End" ); |
|
253 } |
|
254 |
|
255 // --------------------------------------------------------------------------- |
|
256 // Stop playing tacticon. |
|
257 // --------------------------------------------------------------------------- |
|
258 // |
|
259 void CTacticonHapticsPlayer::StopTacticon() |
|
260 { |
|
261 OstTrace0( TACTICON_PERFORMANCE, TACTICON_HAPTICS_PLAYER_STOP_TACTICON_1, |
|
262 "e_TACTICON_HAPTICS_PLAYER_STOP_TACTICON 1" ); |
|
263 |
|
264 iHaptics->StopAllPlayingEffects(); |
|
265 |
|
266 OstTrace0( TACTICON_PERFORMANCE, TACTICON_HAPTICS_PLAYER_STOP_TACTICON_0, |
|
267 "e_TACTICON_HAPTICS_PLAYER_STOP_TACTICON 0" ); |
|
268 } |
|
269 |
|
270 //--------------------------------------------------------------------------- |
|
271 // ImplementationTable[] |
|
272 // |
|
273 //--------------------------------------------------------------------------- |
|
274 // |
|
275 const TImplementationProxy ImplementationTable[] = |
|
276 { |
|
277 IMPLEMENTATION_PROXY_ENTRY( 0x2001FE51, CTacticonHapticsPlayer::NewL ) |
|
278 }; |
|
279 |
|
280 //--------------------------------------------------------------------------- |
|
281 // TImplementationProxy* ImplementationGroupProxy() |
|
282 // |
|
283 //--------------------------------------------------------------------------- |
|
284 // |
|
285 EXPORT_C const TImplementationProxy* ImplementationGroupProxy( TInt& aTableCount ) |
|
286 { |
|
287 aTableCount = sizeof( ImplementationTable ) / sizeof( TImplementationProxy ); |
|
288 return ImplementationTable; |
|
289 } |
|
290 |
|
291 // End of file |