19
|
1 |
/*
|
|
2 |
* Copyright (c) 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: Implementation of VoiceUIPluginHandler
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
// INCLUDE FILES
|
|
20 |
#include <ecom.h>
|
|
21 |
#include <nssvuipf.hrh>
|
|
22 |
#include "nssvoiceuipluginhandler.h"
|
|
23 |
#include "rubydebug.h"
|
|
24 |
#include <nssvoicestatus.h>
|
|
25 |
|
|
26 |
|
|
27 |
// CONSTANTS
|
|
28 |
const TUid KEventPluginUid = { KVuipfEventInterfaceUid };
|
|
29 |
const TUid KActionPluginUid = { KVuipfExecutionInterfaceUid };
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
// ============================ MEMBER FUNCTIONS ===============================
|
|
34 |
|
|
35 |
// -----------------------------------------------------------------------------
|
|
36 |
// CNssVoiceUIPluginHandler::CNssVoiceUIPluginHandler
|
|
37 |
// C++ default constructor can NOT contain any code, that
|
|
38 |
// might leave.
|
|
39 |
// -----------------------------------------------------------------------------
|
|
40 |
//
|
|
41 |
CNssVoiceUIPluginHandler::CNssVoiceUIPluginHandler()
|
|
42 |
{
|
|
43 |
// nothing
|
|
44 |
}
|
|
45 |
|
|
46 |
// -----------------------------------------------------------------------------
|
|
47 |
// CNssVoiceUIPluginHandler::ConstructL
|
|
48 |
// Symbian 2nd phase constructor can leave.
|
|
49 |
// -----------------------------------------------------------------------------
|
|
50 |
//
|
|
51 |
void CNssVoiceUIPluginHandler::ConstructL()
|
|
52 |
{
|
|
53 |
LoadPluginsL();
|
|
54 |
}
|
|
55 |
|
|
56 |
// -----------------------------------------------------------------------------
|
|
57 |
// CNssVoiceUIPluginHandler::NewL
|
|
58 |
// Two-phased constructor.
|
|
59 |
// -----------------------------------------------------------------------------
|
|
60 |
//
|
|
61 |
EXPORT_C CNssVoiceUIPluginHandler* CNssVoiceUIPluginHandler::NewL()
|
|
62 |
{
|
|
63 |
RUBY_DEBUG_BLOCK( "CNssVoiceUIPluginHandler::NewL()" );
|
|
64 |
CNssVoiceUIPluginHandler* self = new( ELeave ) CNssVoiceUIPluginHandler;
|
|
65 |
|
|
66 |
CleanupStack::PushL( self );
|
|
67 |
self->ConstructL();
|
|
68 |
CleanupStack::Pop( self );
|
|
69 |
|
|
70 |
return self;
|
|
71 |
}
|
|
72 |
|
|
73 |
|
|
74 |
// -----------------------------------------------------------------------------
|
|
75 |
// CNssVoiceUIPluginHandler::~CNssVoiceUIPluginHandler
|
|
76 |
// Destructor.
|
|
77 |
// -----------------------------------------------------------------------------
|
|
78 |
//
|
|
79 |
EXPORT_C CNssVoiceUIPluginHandler::~CNssVoiceUIPluginHandler()
|
|
80 |
{
|
|
81 |
UnloadPlugins();
|
|
82 |
RUBY_DEBUG0( "CNssVoiceUIPluginHandler::~CNssVoiceUIPluginHandler() end" );
|
|
83 |
}
|
|
84 |
|
|
85 |
|
|
86 |
// -----------------------------------------------------------------------------
|
|
87 |
// CNssVoiceUIPluginHandler::VoiceEvent
|
|
88 |
// Handle voice event
|
|
89 |
// -----------------------------------------------------------------------------
|
|
90 |
//
|
|
91 |
TInt CNssVoiceUIPluginHandler::VoiceEvent( TUid aEventUid )
|
|
92 |
{
|
|
93 |
RUBY_DEBUG1( "CNssVoiceUIPluginHandler::VoiceEvent(0x%x)", aEventUid.iUid );
|
|
94 |
CVoiceUiPluginBase* plugin = NULL;
|
|
95 |
CVoiceUiPluginBase* previousPlugin = NULL;
|
|
96 |
TInt highestPriority( KMinTInt );
|
|
97 |
|
|
98 |
RPointerArray<CVoiceUiPluginBase> usedPlugins;
|
|
99 |
// Select the suitable plug-in with highest priority
|
|
100 |
// In case of multiple plug-ins with same priority the first one is selected.
|
|
101 |
|
|
102 |
TInt status( KErrNoneEventNotConsumed );
|
|
103 |
|
|
104 |
// execute plug-ins until the event has been successfully processed
|
|
105 |
while ( status != KErrNone )
|
|
106 |
{
|
|
107 |
|
|
108 |
// Loop all plugins
|
|
109 |
for( TInt i( 0 ); i < iActionPlugins.Count(); i++ )
|
|
110 |
{
|
|
111 |
CVoiceUiPluginBase* tmpPlugin = iActionPlugins[i];
|
|
112 |
|
|
113 |
// Loop all supported events in the plugin
|
|
114 |
for ( TInt j( 0 ); j < tmpPlugin->EventUids().Count(); j++ )
|
|
115 |
{
|
|
116 |
RUBY_DEBUG2( "VoiceEvent Comparing event uid [0x%x] against plugin's [0x%x]",
|
|
117 |
aEventUid.iUid, tmpPlugin->EventUids()[j].iUid );
|
|
118 |
|
|
119 |
TVuipPriority priority = tmpPlugin->Priority();
|
|
120 |
if ( tmpPlugin->EventUids()[j] == aEventUid
|
|
121 |
&& priority > highestPriority )
|
|
122 |
{
|
|
123 |
|
|
124 |
// find the next plug-in in the order of priority
|
|
125 |
TBool alreadyUsed( EFalse );
|
|
126 |
TInt k( 0 );
|
|
127 |
while( k < usedPlugins.Count() && !alreadyUsed )
|
|
128 |
{
|
|
129 |
if ( usedPlugins[k] == tmpPlugin )
|
|
130 |
{
|
|
131 |
alreadyUsed = ETrue;
|
|
132 |
}
|
|
133 |
k++;
|
|
134 |
}
|
|
135 |
|
|
136 |
if ( !alreadyUsed )
|
|
137 |
{
|
|
138 |
plugin = tmpPlugin;
|
|
139 |
highestPriority = priority;
|
|
140 |
}
|
|
141 |
}
|
|
142 |
}
|
|
143 |
}
|
|
144 |
|
|
145 |
if ( plugin && plugin != previousPlugin )
|
|
146 |
{
|
|
147 |
// execute a plug-in
|
|
148 |
status = plugin->Execute( aEventUid );
|
|
149 |
previousPlugin = plugin;
|
|
150 |
}
|
|
151 |
else
|
|
152 |
{
|
|
153 |
// all plug-ins checked -> exit loop
|
|
154 |
RUBY_DEBUG0( "No plugin for the event");
|
|
155 |
break;
|
|
156 |
}
|
|
157 |
}
|
|
158 |
|
|
159 |
|
|
160 |
if ( status == KErrNoneForwardEvent )
|
|
161 |
{
|
|
162 |
status = KErrNoneEventNotConsumed;
|
|
163 |
}
|
|
164 |
|
|
165 |
usedPlugins.Reset();
|
|
166 |
usedPlugins.Close();
|
|
167 |
return status;
|
|
168 |
}
|
|
169 |
|
|
170 |
|
|
171 |
// -----------------------------------------------------------------------------
|
|
172 |
// CNssVoiceUIPluginHandler::LoadPluginsL
|
|
173 |
// Loads plug-ins
|
|
174 |
// -----------------------------------------------------------------------------
|
|
175 |
//
|
|
176 |
void CNssVoiceUIPluginHandler::LoadPluginsL()
|
|
177 |
{
|
|
178 |
RUBY_DEBUG_BLOCK( "CNssVoiceUIPluginHandler::LoadPluginsL()" );
|
|
179 |
TInt i( 0 );
|
|
180 |
RImplInfoPtrArray eventPluginArray;
|
|
181 |
CleanupClosePushL( eventPluginArray );
|
|
182 |
|
|
183 |
REComSession::ListImplementationsL( KEventPluginUid, eventPluginArray );
|
|
184 |
|
|
185 |
RUBY_DEBUG1( "CNssVoiceUIPluginHandler::LoadPluginsL() found %i event plugins",
|
|
186 |
eventPluginArray.Count() );
|
|
187 |
// load event plug-ins
|
|
188 |
for ( i = 0; i < eventPluginArray.Count(); i++ )
|
|
189 |
{
|
|
190 |
// Get Uid of plug-in
|
|
191 |
TUid id = eventPluginArray[i]->ImplementationUid();
|
|
192 |
|
|
193 |
// create plug-in
|
|
194 |
TUid dtorID;
|
|
195 |
CVoiceEventObserverPluginBase* tmpPlugin = NULL;
|
|
196 |
|
|
197 |
TRAPD( error,
|
|
198 |
tmpPlugin =
|
|
199 |
reinterpret_cast<CVoiceEventObserverPluginBase*>
|
|
200 |
( REComSession::CreateImplementationL( id, dtorID ) ) );
|
|
201 |
|
|
202 |
if ( error == KErrNone )
|
|
203 |
{
|
|
204 |
// initialize plug-in
|
|
205 |
TRAP( error, tmpPlugin->InitializeL( *this ) );
|
|
206 |
}
|
|
207 |
|
|
208 |
if ( error == KErrNone )
|
|
209 |
{
|
|
210 |
error = iEventPlugins.Append( tmpPlugin );
|
|
211 |
}
|
|
212 |
|
|
213 |
if ( error == KErrNone )
|
|
214 |
{
|
|
215 |
error = iEventPluginDtorIds.Append( dtorID );
|
|
216 |
}
|
|
217 |
|
|
218 |
if ( error != KErrNone )
|
|
219 |
{
|
|
220 |
REComSession::DestroyedImplementation( dtorID );
|
|
221 |
delete tmpPlugin;
|
|
222 |
tmpPlugin = NULL;
|
|
223 |
}
|
|
224 |
|
|
225 |
}
|
|
226 |
|
|
227 |
eventPluginArray.ResetAndDestroy();
|
|
228 |
|
|
229 |
CleanupStack::PopAndDestroy( &eventPluginArray );
|
|
230 |
|
|
231 |
RImplInfoPtrArray actionPluginArray;
|
|
232 |
CleanupClosePushL( actionPluginArray );
|
|
233 |
REComSession::ListImplementationsL( KActionPluginUid, actionPluginArray );
|
|
234 |
|
|
235 |
RUBY_DEBUG1( "CNssVoiceUIPluginHandler::LoadPluginsL() found %i VUI plugins",
|
|
236 |
actionPluginArray.Count() );
|
|
237 |
|
|
238 |
// load action plug-ins
|
|
239 |
for ( i = 0; i < actionPluginArray.Count(); i++ )
|
|
240 |
{
|
|
241 |
// Get Uid of plug-in
|
|
242 |
TUid id = actionPluginArray[i]->ImplementationUid();
|
|
243 |
|
|
244 |
// create plug-in
|
|
245 |
TUid dtorID;
|
|
246 |
CVoiceUiPluginBase* tmpPlugin = NULL;
|
|
247 |
|
|
248 |
TRAPD( error,
|
|
249 |
tmpPlugin =
|
|
250 |
reinterpret_cast<CVoiceUiPluginBase*>
|
|
251 |
( REComSession::CreateImplementationL( id,dtorID ) ) );
|
|
252 |
|
|
253 |
if ( error == KErrNone )
|
|
254 |
{
|
|
255 |
// initialize plug-in
|
|
256 |
TRAP( error, tmpPlugin->InitializeL() );
|
|
257 |
}
|
|
258 |
|
|
259 |
if ( error == KErrNone )
|
|
260 |
{
|
|
261 |
error = iActionPlugins.Append( tmpPlugin );
|
|
262 |
}
|
|
263 |
|
|
264 |
if ( error == KErrNone )
|
|
265 |
{
|
|
266 |
error = iActionPluginDtorIds.Append( dtorID );
|
|
267 |
}
|
|
268 |
|
|
269 |
if ( error != KErrNone )
|
|
270 |
{
|
|
271 |
REComSession::DestroyedImplementation( dtorID );
|
|
272 |
delete tmpPlugin;
|
|
273 |
tmpPlugin = NULL;
|
|
274 |
}
|
|
275 |
}
|
|
276 |
|
|
277 |
actionPluginArray.ResetAndDestroy();
|
|
278 |
CleanupStack::PopAndDestroy( &actionPluginArray );
|
|
279 |
|
|
280 |
}
|
|
281 |
|
|
282 |
// -----------------------------------------------------------------------------
|
|
283 |
// CNssVoiceUIPluginHandler::UnloadPlugins
|
|
284 |
// Unloads plug-ins
|
|
285 |
// -----------------------------------------------------------------------------
|
|
286 |
//
|
|
287 |
void CNssVoiceUIPluginHandler::UnloadPlugins()
|
|
288 |
{
|
|
289 |
TInt i( 0 );
|
|
290 |
iEventPlugins.ResetAndDestroy();
|
|
291 |
iEventPlugins.Close();
|
|
292 |
|
|
293 |
// notify ecom
|
|
294 |
for ( i = 0; i < iEventPluginDtorIds.Count(); i++ )
|
|
295 |
{
|
|
296 |
REComSession::DestroyedImplementation( iEventPluginDtorIds[i] );
|
|
297 |
}
|
|
298 |
|
|
299 |
iEventPluginDtorIds.Close();
|
|
300 |
iActionPlugins.ResetAndDestroy();
|
|
301 |
iActionPlugins.Close();
|
|
302 |
|
|
303 |
// notify ecom
|
|
304 |
for ( i = 0; i < iActionPluginDtorIds.Count(); i++ )
|
|
305 |
{
|
|
306 |
REComSession::DestroyedImplementation( iActionPluginDtorIds[i] );
|
|
307 |
}
|
|
308 |
iActionPluginDtorIds.Close();
|
|
309 |
|
|
310 |
// Release REComSession allocations.
|
|
311 |
REComSession::FinalClose();
|
|
312 |
}
|
|
313 |
|
|
314 |
// ========================== OTHER EXPORTED FUNCTIONS =========================
|
|
315 |
|
|
316 |
// -----------------------------------------------------------------------------
|
|
317 |
// For DLL goodness.
|
|
318 |
// -----------------------------------------------------------------------------
|
|
319 |
//
|
|
320 |
#ifndef EKA2
|
|
321 |
GLDEF_C TInt E32Dll( TDllReason /*aReason*/ )
|
|
322 |
{
|
|
323 |
return KErrNone;
|
|
324 |
}
|
|
325 |
#endif
|
|
326 |
|
|
327 |
// End of File
|