30
|
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:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
#include <ecom/ecom.h>
|
|
20 |
#include <mmf/common/mmfcontrollerpluginresolver.h>
|
|
21 |
#include "cpluginvalidator.h"
|
|
22 |
|
|
23 |
// ======== MEMBER FUNCTIONS ========
|
|
24 |
|
|
25 |
// ----------------------------------------------------------------------------
|
|
26 |
//
|
|
27 |
// ----------------------------------------------------------------------------
|
|
28 |
//
|
|
29 |
EXPORT_C CPluginValidator* CPluginValidator::NewL( TUid aUid,
|
|
30 |
TAny *aParameter )
|
|
31 |
{
|
|
32 |
CPluginValidator* self = CPluginValidator::NewLC( aUid , aParameter );
|
|
33 |
CleanupStack::Pop( self );
|
|
34 |
return self;
|
|
35 |
}
|
|
36 |
|
|
37 |
// ----------------------------------------------------------------------------
|
|
38 |
//
|
|
39 |
// ----------------------------------------------------------------------------
|
|
40 |
//
|
|
41 |
EXPORT_C CPluginValidator* CPluginValidator::NewLC( TUid aUid,
|
|
42 |
TAny *aParameter )
|
|
43 |
{
|
|
44 |
CPluginValidator* self = new( ELeave ) CPluginValidator( aUid,
|
|
45 |
aParameter );
|
|
46 |
CleanupStack::PushL( self );
|
|
47 |
self->ConstructL();
|
|
48 |
return self;
|
|
49 |
}
|
|
50 |
|
|
51 |
// ----------------------------------------------------------------------------
|
|
52 |
//
|
|
53 |
// ----------------------------------------------------------------------------
|
|
54 |
//
|
|
55 |
EXPORT_C TAny* CPluginValidator::GetImplementation( TUid aUid )
|
|
56 |
{
|
|
57 |
TPluginInfo pluginInfo;
|
|
58 |
pluginInfo.iImplementationUid = aUid;
|
|
59 |
TInt index = iPluginArray.Find( pluginInfo,
|
|
60 |
TIdentityRelation< TPluginInfo >(UidMatch) );
|
|
61 |
return GetImplementation( index );
|
|
62 |
}
|
|
63 |
|
|
64 |
// ----------------------------------------------------------------------------
|
|
65 |
//
|
|
66 |
// ----------------------------------------------------------------------------
|
|
67 |
//
|
|
68 |
EXPORT_C TAny* CPluginValidator::GetImplementation( TInt aIndex )
|
|
69 |
{
|
|
70 |
TAny* ret( NULL );
|
|
71 |
if (( aIndex != KErrNotFound ) && ( aIndex < iPluginArray.Count() ))
|
|
72 |
{
|
|
73 |
ret= iPluginArray[aIndex].iPlugin;
|
|
74 |
}
|
|
75 |
return ret;
|
|
76 |
}
|
|
77 |
|
|
78 |
// ----------------------------------------------------------------------------
|
|
79 |
//
|
|
80 |
// ----------------------------------------------------------------------------
|
|
81 |
//
|
|
82 |
EXPORT_C TInt CPluginValidator::GetCount( )
|
|
83 |
{
|
|
84 |
return iPluginArray.Count();
|
|
85 |
}
|
|
86 |
|
|
87 |
// ---------------------------------------------------------------------------
|
|
88 |
// destructor
|
|
89 |
// ---------------------------------------------------------------------------
|
|
90 |
CPluginValidator::~CPluginValidator()
|
|
91 |
{
|
|
92 |
Cancel();
|
|
93 |
CleanPluginsTable();
|
|
94 |
iPluginArray.Close( );
|
|
95 |
if( iSession )
|
|
96 |
{
|
|
97 |
iSession->Close();
|
|
98 |
}
|
|
99 |
REComSession::FinalClose( );
|
|
100 |
}
|
|
101 |
|
|
102 |
// ----------------------------------------------------------------------------
|
|
103 |
//
|
|
104 |
// ----------------------------------------------------------------------------
|
|
105 |
//
|
|
106 |
void CPluginValidator::RunL()
|
|
107 |
{
|
|
108 |
ManagePluginsL();
|
|
109 |
iSession->NotifyOnChange( iStatus );
|
|
110 |
SetActive();
|
|
111 |
}
|
|
112 |
|
|
113 |
// ----------------------------------------------------------------------------
|
|
114 |
//
|
|
115 |
// ----------------------------------------------------------------------------
|
|
116 |
//
|
|
117 |
void CPluginValidator::DoCancel()
|
|
118 |
{
|
|
119 |
iSession->CancelNotifyOnChange( iStatus );
|
|
120 |
}
|
|
121 |
|
|
122 |
// ----------------------------------------------------------------------------
|
|
123 |
//
|
|
124 |
// ----------------------------------------------------------------------------
|
|
125 |
//
|
|
126 |
TInt CPluginValidator::RunError( TInt /*aError*/)
|
|
127 |
{
|
|
128 |
return KErrNone;
|
|
129 |
}
|
|
130 |
// ----------------------------------------------------------------------------
|
|
131 |
//
|
|
132 |
// ----------------------------------------------------------------------------
|
|
133 |
//
|
|
134 |
CPluginValidator::CPluginValidator( TUid aUid, TAny* aParameter ):
|
|
135 |
CActive(EPriorityStandard),
|
|
136 |
iUid( aUid ),
|
|
137 |
iParameter( aParameter )
|
|
138 |
{
|
|
139 |
|
|
140 |
}
|
|
141 |
|
|
142 |
// ----------------------------------------------------------------------------
|
|
143 |
//
|
|
144 |
// ----------------------------------------------------------------------------
|
|
145 |
//
|
|
146 |
void CPluginValidator::ConstructL()
|
|
147 |
{
|
|
148 |
iSession = &REComSession::OpenL();
|
|
149 |
ManagePluginsL();
|
|
150 |
iSession->NotifyOnChange( iStatus );
|
|
151 |
CActiveScheduler::Add( this );
|
|
152 |
SetActive();
|
|
153 |
}
|
|
154 |
|
|
155 |
// ----------------------------------------------------------------------------
|
|
156 |
//
|
|
157 |
// ----------------------------------------------------------------------------
|
|
158 |
//
|
|
159 |
TBool CPluginValidator::PresentInArrayL( TPluginInfo aPluginInfo,
|
|
160 |
const RImplInfoPtrArray& aInfoArray )
|
|
161 |
{
|
|
162 |
TBool result(EFalse);
|
|
163 |
for ( TInt i = 0; i< aInfoArray.Count(); i++ )
|
|
164 |
{
|
|
165 |
if ( aPluginInfo.iImplementationUid.iUid ==
|
|
166 |
aInfoArray[i]->ImplementationUid().iUid)
|
|
167 |
{
|
|
168 |
result = ETrue;
|
|
169 |
break;
|
|
170 |
}
|
|
171 |
}
|
|
172 |
return result;
|
|
173 |
}
|
|
174 |
|
|
175 |
// ----------------------------------------------------------------------------
|
|
176 |
//
|
|
177 |
// ----------------------------------------------------------------------------
|
|
178 |
//
|
|
179 |
void CPluginValidator::DestroyPlugin( TInt aIndex )
|
|
180 |
{
|
|
181 |
CBase* plugin = static_cast<CBase*>( iPluginArray[aIndex].iPlugin );
|
|
182 |
delete plugin;
|
|
183 |
REComSession::DestroyedImplementation(
|
|
184 |
iPluginArray[aIndex].iDtor_ID_Key );
|
|
185 |
}
|
|
186 |
|
|
187 |
// ----------------------------------------------------------------------------
|
|
188 |
//
|
|
189 |
// ----------------------------------------------------------------------------
|
|
190 |
//
|
|
191 |
void CPluginValidator::CleanPluginsTable()
|
|
192 |
{
|
|
193 |
for ( TInt i = 0; i < iPluginArray.Count(); i++ )
|
|
194 |
{
|
|
195 |
DestroyPlugin( i );
|
|
196 |
}
|
|
197 |
}
|
|
198 |
|
|
199 |
// ----------------------------------------------------------------------------
|
|
200 |
//
|
|
201 |
// ----------------------------------------------------------------------------
|
|
202 |
//
|
|
203 |
void CPluginValidator::ManagePluginsL()
|
|
204 |
{
|
|
205 |
// Read info about all implementations into infoArray
|
|
206 |
RImplInfoPtrArray infoArray;
|
|
207 |
CleanupResetAndDestroyPushL( infoArray );
|
|
208 |
|
|
209 |
REComSession::ListImplementationsL( iUid , infoArray );
|
|
210 |
TPluginInfo pluginInfo;
|
|
211 |
//Load new plugins
|
|
212 |
for ( TInt i = 0; i < infoArray.Count( ); i++ )
|
|
213 |
{
|
|
214 |
pluginInfo.iImplementationUid = infoArray[i]->ImplementationUid( );
|
|
215 |
pluginInfo.iVersion = infoArray[i]->Version();
|
|
216 |
|
|
217 |
TInt index = iPluginArray.Find( pluginInfo,
|
|
218 |
TIdentityRelation< TPluginInfo >(UidMatch) );
|
|
219 |
|
|
220 |
if ( index == KErrNotFound )
|
|
221 |
{
|
|
222 |
//plugin wasn't present, we load it now
|
|
223 |
LoadPluginL( pluginInfo );
|
|
224 |
}
|
|
225 |
else if ( pluginInfo.iVersion > iPluginArray[index].iVersion )
|
|
226 |
{
|
|
227 |
//plugin was present but it is a newer version,
|
|
228 |
//remove old and load a new one
|
|
229 |
DestroyPlugin( index );
|
|
230 |
iPluginArray.Remove( index );
|
|
231 |
LoadPluginL( pluginInfo );
|
|
232 |
}
|
|
233 |
}
|
|
234 |
//Remove old plugins
|
|
235 |
for ( TInt i = iPluginArray.Count() - 1 ; i >= 0; i-- )
|
|
236 |
{
|
|
237 |
pluginInfo = iPluginArray[i];
|
|
238 |
if ( !PresentInArrayL( pluginInfo, infoArray ) )
|
|
239 |
{
|
|
240 |
DestroyPlugin( i );
|
|
241 |
iPluginArray.Remove( i );
|
|
242 |
}
|
|
243 |
}
|
|
244 |
CleanupStack::PopAndDestroy( &infoArray );
|
|
245 |
}
|
|
246 |
|
|
247 |
// ----------------------------------------------------------------------------
|
|
248 |
//
|
|
249 |
// ----------------------------------------------------------------------------
|
|
250 |
//
|
|
251 |
void CPluginValidator::LoadPluginL( TPluginInfo& aPluginInfo )
|
|
252 |
{
|
|
253 |
TAny* plug ( NULL );
|
|
254 |
TInt err( KErrNone );
|
|
255 |
TRAP( err, plug = REComSession::CreateImplementationL(
|
|
256 |
aPluginInfo.iImplementationUid,
|
|
257 |
aPluginInfo.iDtor_ID_Key, iParameter ) );
|
|
258 |
if( err==KErrNone && plug )
|
|
259 |
{
|
|
260 |
CleanupStack::PushL( plug );
|
|
261 |
aPluginInfo.iPlugin = plug;
|
|
262 |
iPluginArray.AppendL( aPluginInfo );
|
|
263 |
CleanupStack::Pop( plug );
|
|
264 |
}
|
|
265 |
}
|
|
266 |
|