|
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 UID |
|
107 // --------------------------------------------------------------------------- |
|
108 // |
|
109 TAny* CPluginManager::GetImplementation( TUid aUid ) |
|
110 { |
|
111 TInt32 key = aUid.iUid; |
|
112 TAny* ret= NULL; |
|
113 TAny** imp= NULL; |
|
114 imp = iPluginMap.Find( key ); |
|
115 if ( imp ) |
|
116 { |
|
117 ret = *imp; |
|
118 } |
|
119 return ret; |
|
120 } |
|
121 |
|
122 // --------------------------------------------------------------------------- |
|
123 // Retuns a plugin by index |
|
124 // --------------------------------------------------------------------------- |
|
125 // |
|
126 TAny* CPluginManager::GetImplementation( TInt aIndex ) |
|
127 { |
|
128 TAny* ret= NULL; |
|
129 THashMapIter<TInt32, TAny*> iter( iPluginMap ); |
|
130 TAny*const* ptr = iter.NextValue(); |
|
131 for ( TInt i( 0 ); ptr; i++ ) |
|
132 { |
|
133 if ( i == aIndex ) |
|
134 { |
|
135 ret = *ptr; |
|
136 break; |
|
137 } |
|
138 ptr = iter.NextValue(); |
|
139 } |
|
140 return ret; |
|
141 } |
|
142 |
|
143 // --------------------------------------------------------------------------- |
|
144 // Returns the count of the plug-ins. |
|
145 // --------------------------------------------------------------------------- |
|
146 // |
|
147 TInt CPluginManager::GetCount() |
|
148 { |
|
149 return iPluginMap.Count(); |
|
150 } |
|
151 |
|
152 // --------------------------------------------------------------------------- |
|
153 // Loads the plugins. |
|
154 // --------------------------------------------------------------------------- |
|
155 // |
|
156 void CPluginManager::LoadPluginsL() |
|
157 { |
|
158 MPX_DEBUG1("CPluginManager::LoadPluginsL <---"); |
|
159 // Read info about all implementations into infoArray |
|
160 RImplInfoPtrArray infoArray; |
|
161 CleanupResetAndDestroyPushL( infoArray ); |
|
162 |
|
163 REComSession::ListImplementationsL( iUid, infoArray ); |
|
164 for ( TInt i = 0; i < infoArray.Count(); i++ ) |
|
165 { |
|
166 TUid current_plugin = infoArray[i]->ImplementationUid(); |
|
167 TAny* plug( NULL ); |
|
168 TUid temp; |
|
169 TInt err( KErrNone ); |
|
170 TRAP( err, plug = REComSession::CreateImplementationL( |
|
171 current_plugin, |
|
172 temp, |
|
173 iParameter ) ); |
|
174 if ( err == KErrNone && plug ) |
|
175 { |
|
176 CleanupStack::PushL( plug ); |
|
177 TInt32 key = current_plugin.iUid; |
|
178 iPluginMap.InsertL( key, plug ); |
|
179 CleanupStack::Pop( plug ); |
|
180 } |
|
181 } |
|
182 |
|
183 CleanupStack::PopAndDestroy( &infoArray ); |
|
184 MPX_DEBUG1("CPluginManager::LoadPluginsL --->"); |
|
185 } |
|
186 |
|
187 // --------------------------------------------------------------------------- |
|
188 // Unloads the plgugins. |
|
189 // --------------------------------------------------------------------------- |
|
190 // |
|
191 void CPluginManager::CleanPluginsTable() |
|
192 { |
|
193 MPX_DEBUG1("CPluginManager::CleanPluginsTable <---"); |
|
194 THashMapIter<TInt32, TAny*> iter( iPluginMap ); |
|
195 TAny*const* ptr = iter.NextValue(); |
|
196 CBase* plug( NULL ); |
|
197 const TInt32* pluginUid( NULL ); |
|
198 while ( ptr ) |
|
199 { |
|
200 plug = static_cast<CBase*>( *ptr ); |
|
201 delete plug; |
|
202 plug = NULL; |
|
203 pluginUid = iter.CurrentKey(); |
|
204 REComSession::DestroyedImplementation( TUid::Uid( *pluginUid ) ); |
|
205 ptr = iter.NextValue(); |
|
206 pluginUid = NULL; |
|
207 } |
|
208 MPX_DEBUG1("CPluginManager::CleanPluginsTable --->"); |
|
209 } |
|
210 |
|
211 // --------------------------------------------------------------------------- |
|
212 //From CActive |
|
213 // --------------------------------------------------------------------------- |
|
214 // |
|
215 void CPluginManager::RunL() |
|
216 { |
|
217 MPX_DEBUG1("CPluginManager::RunL <---"); |
|
218 CleanPluginsTable(); |
|
219 iPluginMap.Close(); |
|
220 iContentPublisher->ResetL(); |
|
221 LoadPluginsL(); |
|
222 iSession->NotifyOnChange( iStatus ); |
|
223 SetActive(); |
|
224 MPX_DEBUG1("CPluginManager::RunL --->"); |
|
225 } |
|
226 |
|
227 // --------------------------------------------------------------------------- |
|
228 //From CActive |
|
229 // --------------------------------------------------------------------------- |
|
230 // |
|
231 void CPluginManager::DoCancel() |
|
232 { |
|
233 MPX_DEBUG1("CPluginManager::DoCancel <---"); |
|
234 iSession->CancelNotifyOnChange( iStatus ); |
|
235 MPX_DEBUG1("CPluginManager::DoCancel --->"); |
|
236 } |
|
237 |
|
238 // --------------------------------------------------------------------------- |
|
239 //From CActive |
|
240 // --------------------------------------------------------------------------- |
|
241 // |
|
242 TInt CPluginManager::RunError( TInt /*aError*/ ) |
|
243 { |
|
244 MPX_DEBUG1("CPluginManager::RunError <---"); |
|
245 MPX_DEBUG1("CPluginManager::RunError --->"); |
|
246 return KErrNone; |
|
247 } |
|
248 |
|
249 // End of File |
|
250 |