53
|
1 |
/*
|
|
2 |
* Copyright (c) 2008-2008 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: Plugin manager, responsible to load the plugins.
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include <mpxlog.h> // MPX_DEBUG
|
|
19 |
#include <ecom/ecom.h>
|
|
20 |
// for CeanupResetAndDestroyPushL
|
|
21 |
#include <mmf/common/mmfcontrollerpluginresolver.h>
|
|
22 |
|
|
23 |
#include "musiccontentpublisher.h"
|
|
24 |
#include "pluginmanager.h"
|
|
25 |
|
|
26 |
// ======== MEMBER FUNCTIONS ========
|
|
27 |
|
|
28 |
// ---------------------------------------------------------------------------
|
|
29 |
// Constructor
|
|
30 |
// ---------------------------------------------------------------------------
|
|
31 |
//
|
|
32 |
CPluginManager::CPluginManager( TUid aUid,
|
|
33 |
TAny* aParameter,
|
|
34 |
CMusicContentPublisher* aContentPublisher) :
|
|
35 |
CActive( EPriorityStandard ),
|
|
36 |
iUid( aUid ),
|
|
37 |
iParameter( aParameter ),
|
|
38 |
iContentPublisher(aContentPublisher)
|
|
39 |
{
|
|
40 |
}
|
|
41 |
|
|
42 |
// ---------------------------------------------------------------------------
|
|
43 |
//
|
|
44 |
// ---------------------------------------------------------------------------
|
|
45 |
//
|
|
46 |
void CPluginManager::ConstructL()
|
|
47 |
{
|
|
48 |
MPX_DEBUG1("CPluginManager::ConstructL <---");
|
|
49 |
iSession = &REComSession::OpenL();
|
|
50 |
LoadPluginsL();
|
|
51 |
iSession->NotifyOnChange( iStatus );
|
|
52 |
CActiveScheduler::Add( this );
|
|
53 |
SetActive();
|
|
54 |
MPX_DEBUG1("CPluginManager::ConstructL --->");
|
|
55 |
}
|
|
56 |
|
|
57 |
// ---------------------------------------------------------------------------
|
|
58 |
// Two-phased constructor.
|
|
59 |
// ---------------------------------------------------------------------------
|
|
60 |
//
|
|
61 |
CPluginManager* CPluginManager::NewL( TUid aUid,
|
|
62 |
TAny *aParameter,
|
|
63 |
CMusicContentPublisher* aContentPublisher )
|
|
64 |
{
|
|
65 |
CPluginManager* self = CPluginManager::NewLC( aUid,
|
|
66 |
aParameter,
|
|
67 |
aContentPublisher );
|
|
68 |
CleanupStack::Pop( self );
|
|
69 |
return self;
|
|
70 |
}
|
|
71 |
|
|
72 |
// ---------------------------------------------------------------------------
|
|
73 |
// Two-phased constructor.
|
|
74 |
// ---------------------------------------------------------------------------
|
|
75 |
//
|
|
76 |
CPluginManager* CPluginManager::NewLC( TUid aUid,
|
|
77 |
TAny *aParameter,
|
|
78 |
CMusicContentPublisher* aContentPublisher )
|
|
79 |
{
|
|
80 |
CPluginManager* self = new( ELeave ) CPluginManager( aUid,
|
|
81 |
aParameter,
|
|
82 |
aContentPublisher );
|
|
83 |
CleanupStack::PushL( self );
|
|
84 |
self->ConstructL();
|
|
85 |
return self;
|
|
86 |
}
|
|
87 |
|
|
88 |
// ---------------------------------------------------------------------------
|
|
89 |
// destructor
|
|
90 |
// ---------------------------------------------------------------------------
|
|
91 |
CPluginManager::~CPluginManager()
|
|
92 |
{
|
|
93 |
MPX_DEBUG1("CPluginManager::~CPluginManager <---");
|
|
94 |
Cancel();
|
|
95 |
CleanPluginsTable();
|
|
96 |
iPluginMap.Close();
|
|
97 |
if ( iSession )
|
|
98 |
{
|
|
99 |
iSession->Close();
|
|
100 |
}
|
|
101 |
REComSession::FinalClose();
|
|
102 |
MPX_DEBUG1("CPluginManager::~CPluginManager --->");
|
|
103 |
}
|
|
104 |
|
|
105 |
// ---------------------------------------------------------------------------
|
|
106 |
// Retuns a plugin by Implementation UID
|
|
107 |
// ---------------------------------------------------------------------------
|
|
108 |
//
|
|
109 |
TAny* CPluginManager::GetImplementation( TUid aUid )
|
|
110 |
{
|
|
111 |
TAny* ret= NULL;
|
|
112 |
THashMapIter<TInt32, TAny*> iter( iPluginMap );
|
|
113 |
const TInt32* pluginInstanceKey( NULL );
|
|
114 |
TAny*const* ptr = iter.NextValue();
|
|
115 |
while ( ptr )
|
|
116 |
{
|
|
117 |
pluginInstanceKey = iter.CurrentKey();
|
|
118 |
if (REComSession::GetImplementationUidL( TUid::Uid( *pluginInstanceKey ) ) == aUid)
|
|
119 |
{
|
|
120 |
ret = *ptr;
|
|
121 |
break;
|
|
122 |
}
|
|
123 |
ptr = iter.NextValue();
|
|
124 |
}
|
|
125 |
return ret;
|
|
126 |
}
|
|
127 |
|
|
128 |
// ---------------------------------------------------------------------------
|
|
129 |
// Retuns a plugin by index
|
|
130 |
// ---------------------------------------------------------------------------
|
|
131 |
//
|
|
132 |
TAny* CPluginManager::GetImplementation( TInt aIndex )
|
|
133 |
{
|
|
134 |
TAny* ret= NULL;
|
|
135 |
THashMapIter<TInt32, TAny*> iter( iPluginMap );
|
|
136 |
TAny*const* ptr = iter.NextValue();
|
|
137 |
for ( TInt i( 0 ); ptr; i++ )
|
|
138 |
{
|
|
139 |
if ( i == aIndex )
|
|
140 |
{
|
|
141 |
ret = *ptr;
|
|
142 |
break;
|
|
143 |
}
|
|
144 |
ptr = iter.NextValue();
|
|
145 |
}
|
|
146 |
return ret;
|
|
147 |
}
|
|
148 |
|
|
149 |
// ---------------------------------------------------------------------------
|
|
150 |
// Returns the count of the plug-ins.
|
|
151 |
// ---------------------------------------------------------------------------
|
|
152 |
//
|
|
153 |
TInt CPluginManager::GetCount()
|
|
154 |
{
|
|
155 |
return iPluginMap.Count();
|
|
156 |
}
|
|
157 |
|
|
158 |
// ---------------------------------------------------------------------------
|
|
159 |
// Loads the plugins.
|
|
160 |
// ---------------------------------------------------------------------------
|
|
161 |
//
|
|
162 |
void CPluginManager::LoadPluginsL()
|
|
163 |
{
|
|
164 |
MPX_DEBUG1("CPluginManager::LoadPluginsL <---");
|
|
165 |
// Read info about all implementations into infoArray
|
|
166 |
RImplInfoPtrArray infoArray;
|
|
167 |
CleanupResetAndDestroyPushL( infoArray );
|
|
168 |
|
|
169 |
REComSession::ListImplementationsL( iUid, infoArray );
|
|
170 |
for ( TInt i = 0; i < infoArray.Count(); i++ )
|
|
171 |
{
|
|
172 |
TUid current_plugin = infoArray[i]->ImplementationUid();
|
|
173 |
TAny* plug( NULL );
|
|
174 |
TUid instanceKey;
|
|
175 |
TInt err( KErrNone );
|
|
176 |
TRAP( err, plug = REComSession::CreateImplementationL(
|
|
177 |
current_plugin,
|
|
178 |
instanceKey,
|
|
179 |
iParameter ) );
|
|
180 |
if ( err == KErrNone && plug )
|
|
181 |
{
|
|
182 |
CleanupStack::PushL( plug );
|
|
183 |
TInt32 key = instanceKey.iUid;
|
|
184 |
iPluginMap.InsertL( key, plug );
|
|
185 |
CleanupStack::Pop( plug );
|
|
186 |
}
|
|
187 |
}
|
|
188 |
|
|
189 |
CleanupStack::PopAndDestroy( &infoArray );
|
|
190 |
MPX_DEBUG1("CPluginManager::LoadPluginsL --->");
|
|
191 |
}
|
|
192 |
|
|
193 |
// ---------------------------------------------------------------------------
|
|
194 |
// Unloads the plgugins.
|
|
195 |
// ---------------------------------------------------------------------------
|
|
196 |
//
|
|
197 |
void CPluginManager::CleanPluginsTable()
|
|
198 |
{
|
|
199 |
MPX_DEBUG1("CPluginManager::CleanPluginsTable <---");
|
|
200 |
THashMapIter<TInt32, TAny*> iter( iPluginMap );
|
|
201 |
TAny*const* ptr = iter.NextValue();
|
|
202 |
CBase* plug( NULL );
|
|
203 |
const TInt32* pluginInstanceKey( NULL );
|
|
204 |
while ( ptr )
|
|
205 |
{
|
|
206 |
plug = static_cast<CBase*>( *ptr );
|
|
207 |
delete plug;
|
|
208 |
plug = NULL;
|
|
209 |
pluginInstanceKey = iter.CurrentKey();
|
|
210 |
REComSession::DestroyedImplementation( TUid::Uid( *pluginInstanceKey ) );
|
|
211 |
ptr = iter.NextValue();
|
|
212 |
pluginInstanceKey = NULL;
|
|
213 |
}
|
|
214 |
MPX_DEBUG1("CPluginManager::CleanPluginsTable --->");
|
|
215 |
}
|
|
216 |
|
|
217 |
// ---------------------------------------------------------------------------
|
|
218 |
//From CActive
|
|
219 |
// ---------------------------------------------------------------------------
|
|
220 |
//
|
|
221 |
void CPluginManager::RunL()
|
|
222 |
{
|
|
223 |
MPX_DEBUG1("CPluginManager::RunL <---");
|
|
224 |
CleanPluginsTable();
|
|
225 |
iPluginMap.Close();
|
|
226 |
iContentPublisher->ResetL();
|
|
227 |
LoadPluginsL();
|
|
228 |
iSession->NotifyOnChange( iStatus );
|
|
229 |
SetActive();
|
|
230 |
MPX_DEBUG1("CPluginManager::RunL --->");
|
|
231 |
}
|
|
232 |
|
|
233 |
// ---------------------------------------------------------------------------
|
|
234 |
//From CActive
|
|
235 |
// ---------------------------------------------------------------------------
|
|
236 |
//
|
|
237 |
void CPluginManager::DoCancel()
|
|
238 |
{
|
|
239 |
MPX_DEBUG1("CPluginManager::DoCancel <---");
|
|
240 |
iSession->CancelNotifyOnChange( iStatus );
|
|
241 |
MPX_DEBUG1("CPluginManager::DoCancel --->");
|
|
242 |
}
|
|
243 |
|
|
244 |
// ---------------------------------------------------------------------------
|
|
245 |
//From CActive
|
|
246 |
// ---------------------------------------------------------------------------
|
|
247 |
//
|
|
248 |
TInt CPluginManager::RunError( TInt /*aError*/ )
|
|
249 |
{
|
|
250 |
MPX_DEBUG1("CPluginManager::RunError <---");
|
|
251 |
MPX_DEBUG1("CPluginManager::RunError --->");
|
|
252 |
return KErrNone;
|
|
253 |
}
|
|
254 |
|
|
255 |
// End of File
|
|
256 |
|