1 /* |
|
2 * Copyright (c) 2006-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 "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: Speech synthesis server |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef SPEECHSYNTHESISSERVER_H |
|
20 #define SPEECHSYNTHESISSERVER_H |
|
21 |
|
22 // INCLUDES |
|
23 |
|
24 #include <e32base.h> |
|
25 #include <nssttsutility.h> |
|
26 #include <speechsynthesis.h> |
|
27 |
|
28 #include "speechsynthesisclientserver.h" |
|
29 #include "speechsynthesisserverutilities.h" |
|
30 |
|
31 |
|
32 // DEFINITION OF SERVER POLICY |
|
33 |
|
34 // Total number of ranges |
|
35 const TUint KSpeechSynthesisRangeCount = 4; |
|
36 |
|
37 // Definition of the ranges of IPC numbers |
|
38 const TInt KSpeechSynthesisRanges[KSpeechSynthesisRangeCount] = |
|
39 { |
|
40 0, // Messages 0..19 |
|
41 ESetAudioPriority, // Message 20 |
|
42 ESetAudioOutput, // Message 21 |
|
43 ESetAudioOutput+1 // Messages 22.. |
|
44 }; |
|
45 |
|
46 // Policy to implement for the above range |
|
47 const TUint8 KSpeechSynthesisElementsIndex[KSpeechSynthesisRangeCount] = |
|
48 { |
|
49 CPolicyServer::EAlwaysPass, // Applies to 0th range |
|
50 0, // Applies to 1st range |
|
51 CPolicyServer::ECustomCheck, // Applies to 2nd range |
|
52 CPolicyServer::EAlwaysPass, // Applies to 3rd range |
|
53 }; |
|
54 |
|
55 // Specific capability checks |
|
56 const CPolicyServer::TPolicyElement KSpeechSynthesisElements[] = |
|
57 { |
|
58 // Only clients having Nokia VID capability passes this policy element. |
|
59 { _INIT_SECURITY_POLICY_V0( VID_DEFAULT ), CPolicyServer::EFailClient }, |
|
60 }; |
|
61 |
|
62 // Package all the above together into a policy |
|
63 const CPolicyServer::TPolicy KSpeechSynthesisPolicy = |
|
64 { |
|
65 CPolicyServer::EAlwaysPass, // Specifies all connect attempts should pass |
|
66 KSpeechSynthesisRangeCount, // Number of ranges |
|
67 KSpeechSynthesisRanges, // Ranges array |
|
68 KSpeechSynthesisElementsIndex, // Elements<->ranges index |
|
69 KSpeechSynthesisElements, // Array of elements |
|
70 }; |
|
71 |
|
72 |
|
73 // ---------------------------------------------------------------------------- |
|
74 // CSpeechSynthesisServer |
|
75 // Server implementation |
|
76 // ---------------------------------------------------------------------------- |
|
77 class CSpeechSynthesisServer : public CPolicyServer, |
|
78 public MConfigurationObserver, |
|
79 public MTtsClientUtilityObserver |
|
80 { |
|
81 |
|
82 public: // New functions |
|
83 |
|
84 /** |
|
85 * 2nd phase constructor |
|
86 */ |
|
87 static CServer2* NewLC(); |
|
88 |
|
89 /** |
|
90 * Destructor |
|
91 */ |
|
92 virtual ~CSpeechSynthesisServer(); |
|
93 |
|
94 /** |
|
95 * Add new sessios |
|
96 */ |
|
97 void AddSession(); |
|
98 |
|
99 /** |
|
100 * Remove session |
|
101 */ |
|
102 void DropSession(); |
|
103 |
|
104 /** |
|
105 * Reserve server for aSession |
|
106 */ |
|
107 void ReserveL( MSpeechSynthesisServerObserver* aSession ); |
|
108 void ReserveL( MSpeechSynthesisServerObserver* aSession, TInt aPriority ); |
|
109 |
|
110 /** |
|
111 * Release server to be used by other sessions |
|
112 */ |
|
113 void Release( const MSpeechSynthesisServerObserver* aSession ); |
|
114 |
|
115 /** |
|
116 * Used to ask server's default settings |
|
117 */ |
|
118 void GetDefaultSettingsL( TVoice& aVoice, |
|
119 TInt& aSpeakingRate, TInt& aMaxSpeakingRate, |
|
120 TInt& aVolume, TInt& aMaxVolume, |
|
121 TInt& aAudioPriority, TInt& aAudioPreference, |
|
122 TInt& aAudioOutput ); |
|
123 |
|
124 /** |
|
125 * Used to ask server's default voice |
|
126 */ |
|
127 void GetDefaultVoiceL( TVoice& aVoice ); |
|
128 |
|
129 /** |
|
130 * Prime the synthesizer |
|
131 * |
|
132 * @param aText Text to be synthesized |
|
133 * |
|
134 */ |
|
135 void PrimeL( const TDesC& aText ); |
|
136 |
|
137 /** |
|
138 * Prime the synthesizer |
|
139 * |
|
140 * @param aText Text to be synthesized |
|
141 * @param aFile Open handle to file |
|
142 * |
|
143 */ |
|
144 void PrimeL( const TDesC& aText, const RFile& aFile ); |
|
145 |
|
146 /** |
|
147 * Synthesize text |
|
148 */ |
|
149 void Synthesize(); |
|
150 |
|
151 /** |
|
152 * Stop synthesis |
|
153 */ |
|
154 void Stop(); |
|
155 |
|
156 /** |
|
157 * Pause synthesis |
|
158 */ |
|
159 void Pause(); |
|
160 |
|
161 /** |
|
162 * Get available languages |
|
163 * |
|
164 * @param aLanguages Contains supported languages after function call |
|
165 */ |
|
166 void GetSupportedLanguagesL( RArray<TLanguage>& aLanguages ); |
|
167 |
|
168 /** |
|
169 * Get available voices |
|
170 * |
|
171 * @param aLanguage Language |
|
172 * @param aVoices Contains voices after the function call |
|
173 */ |
|
174 void GetSupportedVoicesL( TLanguage aLanguage, RArray<TVoice>& aVoices ); |
|
175 |
|
176 /** |
|
177 * Change voice. |
|
178 * |
|
179 * @param aVoice New voice |
|
180 * @param aSpeakingRate Speaking rate to be used |
|
181 */ |
|
182 void SetVoiceL( const TVoice aVoice, TInt aSpeakingRate ); |
|
183 |
|
184 /** |
|
185 * Change volume. |
|
186 * |
|
187 * @param aVolume New volume |
|
188 */ |
|
189 void SetVolume( TInt aVolume ); |
|
190 |
|
191 /** |
|
192 * Set audio priority |
|
193 * |
|
194 * @param aPriority New priority |
|
195 * @param aPreference New preference |
|
196 */ |
|
197 void SetAudioPriorityL( TInt aPriority, TInt aPreference ); |
|
198 |
|
199 /** |
|
200 * Set audio output |
|
201 */ |
|
202 void SetAudioOutputL( TInt aAudioOutput ); |
|
203 |
|
204 /** |
|
205 * Custom command |
|
206 * |
|
207 * @param aCommand A custom command |
|
208 * @param aValue Value |
|
209 * @return Error code |
|
210 */ |
|
211 TInt CustomCommand( TInt aCommand, TInt aValue ); |
|
212 |
|
213 /** |
|
214 * Checks if given voice exists |
|
215 * |
|
216 * @param aVoice Voice to be checked |
|
217 * @return ETrue if voice exists, EFalse otherwise |
|
218 */ |
|
219 TBool IsVoiceValidL( const TVoice& aVoice ); |
|
220 |
|
221 /* |
|
222 * Returns pointer to the previous session. Plugin is closed if it doesn't |
|
223 * match new session in order to avoid using settings from other session. |
|
224 */ |
|
225 const MSpeechSynthesisServerObserver* PreviousSession(); |
|
226 |
|
227 /* |
|
228 * Closes open plugin |
|
229 */ |
|
230 void ClosePlugin(); |
|
231 |
|
232 public: // From base class MConfigurationObserver |
|
233 |
|
234 /** |
|
235 * This is called when installation or removal of SIS package is detected |
|
236 */ |
|
237 void McoConfigurationChanged(); |
|
238 |
|
239 public: // From base class MTtsClientUtilityObserver |
|
240 |
|
241 /** |
|
242 * Called when asynchronous custom command finishes. |
|
243 */ |
|
244 void MapcCustomCommandEvent( TInt aEvent, TInt aError ); |
|
245 |
|
246 /** |
|
247 * Callback when initialized |
|
248 */ |
|
249 void MapcInitComplete( TInt aError, const TTimeIntervalMicroSeconds& aDuration ); |
|
250 |
|
251 /** |
|
252 * Callback when playback finished |
|
253 */ |
|
254 void MapcPlayComplete( TInt aError ); |
|
255 |
|
256 public: |
|
257 |
|
258 /** |
|
259 * Callback function called when server has been idle certain time. |
|
260 */ |
|
261 static TInt ClosePlugin( TAny* aAny ); |
|
262 |
|
263 private: |
|
264 |
|
265 // Constructor |
|
266 CSpeechSynthesisServer(); |
|
267 |
|
268 // 2nd phase constructor |
|
269 void ConstructL(); |
|
270 |
|
271 // Create new session |
|
272 CSession2* NewSessionL( const TVersion& aVersion, |
|
273 const RMessage2& aMessage ) const; |
|
274 |
|
275 // Custom access policy check |
|
276 TCustomResult CustomSecurityCheckL( const RMessage2& aMsg, |
|
277 TInt& aAction, |
|
278 TSecurityInfo& aMissing ); |
|
279 |
|
280 // Updates configuration if needed |
|
281 void UpdateSynthesisConfigurationIfNeededL(); |
|
282 |
|
283 // Updates configuration |
|
284 void UpdateSynthesisConfigurationL(); |
|
285 |
|
286 private: |
|
287 |
|
288 // Pointer to active session observer, not owned. |
|
289 MSpeechSynthesisServerObserver* iSession; |
|
290 |
|
291 // Pointer to previous session observer, not owned. |
|
292 MSpeechSynthesisServerObserver* iPreviousSession; |
|
293 |
|
294 // Pointer to tts, owned. |
|
295 CTtsUtility* iTtsUtility; |
|
296 |
|
297 // Object used to stop the server when it has been idle for a while. |
|
298 // Owned |
|
299 CShutdown* iShutdown; |
|
300 |
|
301 // Object for closing tts plugin when server has been idle some time. |
|
302 // Frees memory and lets tts components to be removed. |
|
303 CPeriodic* iPluginCloser; |
|
304 |
|
305 // SIS package installer listener, owned. |
|
306 CConfigurationListener* iConfigurationListener; |
|
307 |
|
308 // MMC status listener, owned. |
|
309 CMMCListener* iMMCListener; |
|
310 |
|
311 // Supported voice configurations |
|
312 RArray<TVoiceConfiguration> iTtsVoiceConfigs; |
|
313 |
|
314 // Uid of open tts plugin |
|
315 TUid iOpenTtsPlugin; |
|
316 |
|
317 // Number of sessions using this server |
|
318 TInt iSessionCount; |
|
319 |
|
320 // |
|
321 TInt iSessionPriority; |
|
322 |
|
323 // Default settings |
|
324 TVoice iDefaultVoice; |
|
325 TInt iDefaultSpeakingRate; |
|
326 TInt iDefaultVolume; |
|
327 TInt iDefaultMaxVolume; |
|
328 TInt iDefaultAudioPriority; |
|
329 TInt iDefaultAudioPreference; |
|
330 |
|
331 // If ETrue updates to voice configuration and |
|
332 // default settings are needed. |
|
333 TBool iUpdateNeeded; |
|
334 }; |
|
335 |
|
336 #endif // SPEECHSYNTHESISSERVER_H |
|