|
1 /* |
|
2 * Copyright (c) 2006 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 which hides the dynamic loading of nssttsutility.dll |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <e32std.h> |
|
21 #include <nssttsutilitybase.h> |
|
22 #include "rubydebug.h" |
|
23 #include "nssvasttsutilitywrapper.h" |
|
24 |
|
25 // CONSTANTS |
|
26 // DLL name |
|
27 _LIT( KUtilityFilename, "nssttsutility.dll" ); |
|
28 // CreateInstanceL function ordinal number |
|
29 const TInt KFunctionOrdinal = 1; |
|
30 |
|
31 // ================= MEMBER FUNCTIONS ======================= |
|
32 |
|
33 // --------------------------------------------------------- |
|
34 // CNssTtsUtilityWrapper::NewL |
|
35 // Two-phased constructor |
|
36 // --------------------------------------------------------- |
|
37 // |
|
38 CNssTtsUtilityWrapper* CNssTtsUtilityWrapper::NewL( MTtsClientUtilityObserver& aObserver, |
|
39 TInt aPriority, |
|
40 TMdaPriorityPreference aPref ) |
|
41 { |
|
42 CNssTtsUtilityWrapper* self = new ( ELeave ) CNssTtsUtilityWrapper( |
|
43 aObserver, aPriority, aPref ); |
|
44 CleanupStack::PushL( self ); |
|
45 self->ConstructL(); |
|
46 CleanupStack::Pop( self ); |
|
47 return self; |
|
48 } |
|
49 |
|
50 // --------------------------------------------------------- |
|
51 // CNssTtsUtilityWrapper::~CNssTtsUtilityWrapper |
|
52 // Destructor |
|
53 // --------------------------------------------------------- |
|
54 // |
|
55 CNssTtsUtilityWrapper::~CNssTtsUtilityWrapper() |
|
56 { |
|
57 RUBY_DEBUG0( "CNssTtsUtilityWrapper::~CNssTtsUtilityWrapper" ); |
|
58 if ( IsActive() ) |
|
59 { |
|
60 Cancel(); |
|
61 } |
|
62 delete iUtility; |
|
63 // Close RLibrary handle |
|
64 iLib.Close(); |
|
65 } |
|
66 |
|
67 // --------------------------------------------------------- |
|
68 // CNssTtsUtilityWrapper::CNssTtsUtilityWrapper |
|
69 // C++ constructor |
|
70 // --------------------------------------------------------- |
|
71 // |
|
72 CNssTtsUtilityWrapper::CNssTtsUtilityWrapper( MTtsClientUtilityObserver& aObserver, |
|
73 TInt aPriority, |
|
74 TMdaPriorityPreference aPref ) : |
|
75 CActive( EPriorityStandard ), |
|
76 iObserver( aObserver ), |
|
77 iPriority( aPriority ), |
|
78 iPref( aPref ) |
|
79 { |
|
80 // Nothing |
|
81 } |
|
82 |
|
83 // --------------------------------------------------------- |
|
84 // CNssTtsUtilityWrapper::ConstructL |
|
85 // Second phase constructor |
|
86 // --------------------------------------------------------- |
|
87 // |
|
88 void CNssTtsUtilityWrapper::ConstructL() |
|
89 { |
|
90 RUBY_DEBUG_BLOCK( "CNssTtsUtilityWrapper::ConstructL" ); |
|
91 |
|
92 // Load a DLL based on name with RLibrary |
|
93 User::LeaveIfError( iLib.Load( KUtilityFilename ) ); |
|
94 |
|
95 // Find the TAny* CreateInstanceL() function |
|
96 TLibraryFunction entry = iLib.Lookup( KFunctionOrdinal ); |
|
97 if ( !entry ) |
|
98 { |
|
99 User::Leave( KErrNotFound ); |
|
100 } |
|
101 |
|
102 // Call CreateInstanceL |
|
103 // Cannot use static_cast since entry() call returns TInt |
|
104 iUtility = ( MTtsUtilityBase* ) entry(); |
|
105 |
|
106 // Do the 2nd phase construction |
|
107 iUtility->CreateInstanceSecondPhaseL( *this ); |
|
108 |
|
109 CActiveScheduler::Add( this ); |
|
110 } |
|
111 |
|
112 // --------------------------------------------------------- |
|
113 // CNssTtsUtilityWrapper::AddStyleL |
|
114 // Forwards call to TTS Utility |
|
115 // --------------------------------------------------------- |
|
116 // |
|
117 TTtsStyleID CNssTtsUtilityWrapper::AddStyleL( const TTtsStyle& aStyle ) |
|
118 { |
|
119 return iUtility->AddStyleL( aStyle ); |
|
120 } |
|
121 |
|
122 // --------------------------------------------------------- |
|
123 // CNssTtsUtilityWrapper::OpenAndPlayParsedTextL |
|
124 // Forwards call to TTS Utility |
|
125 // --------------------------------------------------------- |
|
126 // |
|
127 void CNssTtsUtilityWrapper::OpenAndPlayParsedTextL( CTtsParsedText& aText, |
|
128 TInt /*aPriority*/, |
|
129 TMdaPriorityPreference /*aPref*/ ) |
|
130 { |
|
131 iUtility->OpenAndPlayParsedTextL( aText ); |
|
132 } |
|
133 |
|
134 // --------------------------------------------------------- |
|
135 // CNssTtsUtilityWrapper::Stop |
|
136 // Forwards call to TTS Utility |
|
137 // --------------------------------------------------------- |
|
138 // |
|
139 void CNssTtsUtilityWrapper::Stop() |
|
140 { |
|
141 iUtility->Stop(); |
|
142 } |
|
143 |
|
144 // --------------------------------------------------------- |
|
145 // CNssTtsUtilityWrapper::Play |
|
146 // Forwards call to TTS Utility |
|
147 // --------------------------------------------------------- |
|
148 // |
|
149 void CNssTtsUtilityWrapper::Play() |
|
150 { |
|
151 iUtility->Play(); |
|
152 } |
|
153 |
|
154 // --------------------------------------------------------- |
|
155 // CNssTtsUtilityWrapper::Close |
|
156 // Forwards call to TTS Utility |
|
157 // --------------------------------------------------------- |
|
158 // |
|
159 void CNssTtsUtilityWrapper::Close() |
|
160 { |
|
161 iUtility->Close(); |
|
162 } |
|
163 |
|
164 // --------------------------------------------------------- |
|
165 // CNssTtsUtilityWrapper::MapcCustomCommandEvent |
|
166 // Callback from TTS Utility |
|
167 // --------------------------------------------------------- |
|
168 // |
|
169 void CNssTtsUtilityWrapper::MapcCustomCommandEvent( TInt /*aEvent*/, |
|
170 TInt /*aError*/ ) |
|
171 { |
|
172 // Nothing |
|
173 } |
|
174 |
|
175 // --------------------------------------------------------- |
|
176 // CNssTtsUtilityWrapper::MapcInitComplete |
|
177 // Callback from TTS Utility |
|
178 // --------------------------------------------------------- |
|
179 // |
|
180 void CNssTtsUtilityWrapper::MapcInitComplete( TInt aError, |
|
181 const TTimeIntervalMicroSeconds& aDuration ) |
|
182 { |
|
183 RUBY_DEBUG1( "CNssTtsUtilityWrapper::MapcInitComplete, aError[%d]", aError ); |
|
184 iError = aError; |
|
185 iDuration = aDuration; |
|
186 iState = EInitComplete; |
|
187 Ready(); |
|
188 } |
|
189 |
|
190 // --------------------------------------------------------- |
|
191 // CNssTtsUtilityWrapper::MapcPlayComplete |
|
192 // Callback from TTS Utility |
|
193 // --------------------------------------------------------- |
|
194 // |
|
195 void CNssTtsUtilityWrapper::MapcPlayComplete( TInt aError ) |
|
196 { |
|
197 RUBY_DEBUG1( "CNssTtsUtilityWrapper::MapcPlayComplete, aError[%d]", aError ); |
|
198 iError = aError; |
|
199 iState = EPlayComplete; |
|
200 Ready(); |
|
201 } |
|
202 |
|
203 // --------------------------------------------------------- |
|
204 // CNssTtsUtilityWrapper::Ready |
|
205 // Sets active object ready to be run |
|
206 // --------------------------------------------------------- |
|
207 // |
|
208 void CNssTtsUtilityWrapper::Ready() |
|
209 { |
|
210 if ( !IsActive() ) |
|
211 { |
|
212 SetActive(); |
|
213 TRequestStatus* stat = &iStatus; |
|
214 User::RequestComplete( stat, KErrNone ); |
|
215 } |
|
216 } |
|
217 |
|
218 // --------------------------------------------------------- |
|
219 // CNssTtsUtilityWrapper::RunL |
|
220 // From CActive |
|
221 // --------------------------------------------------------- |
|
222 // |
|
223 void CNssTtsUtilityWrapper::RunL() |
|
224 { |
|
225 // Forwards callback to other parts of VAS |
|
226 RUBY_DEBUG_BLOCK( "CNssTtsUtilityWrapper::RunL" ); |
|
227 switch ( iState ) |
|
228 { |
|
229 case EInitComplete: |
|
230 iObserver.MapcInitComplete( iError, iDuration ); |
|
231 break; |
|
232 |
|
233 case EPlayComplete: |
|
234 iObserver.MapcPlayComplete( iError ); |
|
235 break; |
|
236 |
|
237 default: |
|
238 RUBY_ERROR1( "CNssTtsUtilityWrapper::RunL unexpected state %d", iState ); |
|
239 break; |
|
240 } |
|
241 } |
|
242 |
|
243 // --------------------------------------------------------- |
|
244 // CNssSiUtilityWrapper::DoCancel |
|
245 // From CActive |
|
246 // --------------------------------------------------------- |
|
247 // |
|
248 void CNssTtsUtilityWrapper::DoCancel() |
|
249 { |
|
250 // Nothing |
|
251 } |
|
252 |
|
253 // End of file |