|
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: Handles Mediator pluging resolving and loading to new thread. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <e32base.h> |
|
21 |
|
22 #include "MediatorServerPluginHandler.h" |
|
23 #include "MediatorPluginBase.h" |
|
24 #include "MediatorUids.hrh" |
|
25 |
|
26 #include "MediatorDebug.h" |
|
27 #include "Debug.h" |
|
28 |
|
29 // CONSTANTS |
|
30 _LIT( KMediatorThreadName, "MediatorThread - " ); |
|
31 |
|
32 const TInt KMediatorHeapSize = 0x80000; |
|
33 |
|
34 |
|
35 // ============================ MEMBER FUNCTIONS =============================== |
|
36 |
|
37 // ----------------------------------------------------------------------------- |
|
38 // CMediatorServerPluginHandler::CMediatorServerPluginHandler |
|
39 // ----------------------------------------------------------------------------- |
|
40 // |
|
41 CMediatorServerPluginHandler::CMediatorServerPluginHandler() |
|
42 { |
|
43 } |
|
44 |
|
45 // ----------------------------------------------------------------------------- |
|
46 // CMediatorServerPluginHandler::ConstructL |
|
47 // ----------------------------------------------------------------------------- |
|
48 // |
|
49 void CMediatorServerPluginHandler::ConstructL() |
|
50 { |
|
51 iIdle = CIdle::NewL( CActive::EPriorityIdle ); |
|
52 iIdle->Start( TCallBack( LoadPlugins, this ) ); |
|
53 } |
|
54 |
|
55 // ----------------------------------------------------------------------------- |
|
56 // CMediatorServerPluginHandler::NewL |
|
57 // ----------------------------------------------------------------------------- |
|
58 // |
|
59 CMediatorServerPluginHandler* CMediatorServerPluginHandler::NewL() |
|
60 { |
|
61 CMediatorServerPluginHandler* self = new( ELeave ) CMediatorServerPluginHandler; |
|
62 |
|
63 CleanupStack::PushL( self ); |
|
64 self->ConstructL(); |
|
65 CleanupStack::Pop( self ); |
|
66 |
|
67 return self; |
|
68 } |
|
69 |
|
70 // ----------------------------------------------------------------------------- |
|
71 // CMediatorServerPluginHandler::~CMediatorServerPluginHandler |
|
72 // ----------------------------------------------------------------------------- |
|
73 // |
|
74 CMediatorServerPluginHandler::~CMediatorServerPluginHandler() |
|
75 { |
|
76 iPluginImplInfoArray.ResetAndDestroy(); |
|
77 delete iIdle; |
|
78 } |
|
79 |
|
80 // ----------------------------------------------------------------------------- |
|
81 // CMediatorEventConsumer::LoadPlugins |
|
82 // |
|
83 // (other items were commented in a header). |
|
84 // ----------------------------------------------------------------------------- |
|
85 // |
|
86 TInt CMediatorServerPluginHandler::LoadPlugins( TAny* aPtr ) |
|
87 { |
|
88 CMediatorServerPluginHandler* me = (CMediatorServerPluginHandler*) aPtr; |
|
89 TRAPD( error, me->LoadPluginsL() ); |
|
90 |
|
91 if ( error != KErrNone ) |
|
92 { |
|
93 ERROR_TRACE(Print(_L("CMediatorServerPluginHandler::LoadPlugins: error=%d\n"), error ) ); |
|
94 } |
|
95 |
|
96 return error; |
|
97 } |
|
98 |
|
99 // ----------------------------------------------------------------------------- |
|
100 // CMediatorEventConsumer::LoadPluginsL |
|
101 // |
|
102 // (other items were commented in a header). |
|
103 // ----------------------------------------------------------------------------- |
|
104 // |
|
105 void CMediatorServerPluginHandler::LoadPluginsL() |
|
106 { |
|
107 FindImplementationsL(); |
|
108 for ( TInt index = 0; index < iPluginImplInfoArray.Count(); index ++ ) |
|
109 { |
|
110 RMediatorDebug::LogPlugin(iPluginImplInfoArray[index]); |
|
111 StartThreadL( iPluginImplInfoArray[index]->ImplementationUid() ); |
|
112 } |
|
113 } |
|
114 |
|
115 // ----------------------------------------------------------------------------- |
|
116 // CMediatorServerPluginHandler::FindImplementationsL |
|
117 // |
|
118 // (other items were commented in a header). |
|
119 // ----------------------------------------------------------------------------- |
|
120 // |
|
121 void CMediatorServerPluginHandler::FindImplementationsL() |
|
122 { |
|
123 LOG(_L("[Mediator Server]\t CMediatorServerPluginHandler::FindImplementationsL")); |
|
124 |
|
125 // Mediator interface uid as argument |
|
126 TUid pluginInterfaceUid; |
|
127 pluginInterfaceUid.iUid = KMediatorPluginInterfaceUid; |
|
128 |
|
129 TEComResolverParams emptyParams; |
|
130 // List the plugins to array. Note ROM-only plugins are accepted! |
|
131 REComSession::ListImplementationsL( pluginInterfaceUid, |
|
132 emptyParams, |
|
133 KRomOnlyResolverUid, |
|
134 iPluginImplInfoArray ); |
|
135 |
|
136 } |
|
137 |
|
138 // ----------------------------------------------------------------------------- |
|
139 // CMediatorServerPluginHandler::ThreadEntryPoint |
|
140 // |
|
141 // (other items were commented in a header). |
|
142 // ----------------------------------------------------------------------------- |
|
143 // |
|
144 TInt CMediatorServerPluginHandler::ThreadEntryPoint( TAny* aParameter ) |
|
145 { |
|
146 TRACE(Print( _L("[Mediator Server]\t CMediatorServerPluginHandler::ThreadEntryPoint(0x%x)" ), &aParameter ) ); |
|
147 |
|
148 TInt err = KErrNone; |
|
149 |
|
150 //create cleanupstack |
|
151 CTrapCleanup* cleanup = CTrapCleanup::New(); // get clean-up stack |
|
152 if ( !cleanup ) |
|
153 { |
|
154 ERROR_LOG(_L("CMediatorServerPluginHandler::ThreadEntryPoint: KErrNoMemory\n")); |
|
155 err = KErrNoMemory; |
|
156 } |
|
157 |
|
158 if ( !err ) |
|
159 { |
|
160 // Read the parameters from started |
|
161 TMediatorThreadParam* parameters = ( TMediatorThreadParam* ) aParameter; |
|
162 TUid pluginUid = parameters->iMediatorPluginUid; |
|
163 |
|
164 // Just trap the leave in construction phase |
|
165 TRAP( err, DoStartThreadL( pluginUid ) ); |
|
166 |
|
167 if ( err != KErrNone ) |
|
168 { |
|
169 ERROR_TRACE(Print(_L("CMediatorServerPluginHandler::ThreadEntryPoint: pluginUid=0x%x, err=%d\n"), pluginUid.iUid, err ) ); |
|
170 } |
|
171 } |
|
172 |
|
173 delete cleanup; |
|
174 |
|
175 return KErrNone; |
|
176 } |
|
177 |
|
178 // ----------------------------------------------------------------------------- |
|
179 // CMediatorServerPluginHandler::StartThreadL |
|
180 // |
|
181 // (other items were commented in a header). |
|
182 // ----------------------------------------------------------------------------- |
|
183 // |
|
184 void CMediatorServerPluginHandler::StartThreadL( TUid aMediatorPluginUid ) |
|
185 { |
|
186 TRACE(Print( _L("[Mediator Server]\t CMediatorServerPluginHandler::StartThreadL(0x%x)" ), aMediatorPluginUid ) ); |
|
187 |
|
188 // Then create start parameters |
|
189 TMediatorThreadParam param; |
|
190 param.iMediatorPluginUid = aMediatorPluginUid; |
|
191 |
|
192 // Generate unique thread name |
|
193 HBufC* bufThreadName = HBufC::NewLC( KMediatorThreadName().Length() + KMaxUidName ); |
|
194 TPtr ptrThreadName = bufThreadName->Des(); |
|
195 ptrThreadName = KMediatorThreadName; |
|
196 ptrThreadName.Append( aMediatorPluginUid.Name() ); |
|
197 |
|
198 TRACE(Print( _L("[Mediator Server]\t CMediatorServerPluginHandler::StartThreadL(%S)" ), &ptrThreadName ) ); |
|
199 RThread newThread; |
|
200 |
|
201 User::LeaveIfError( newThread.Create( |
|
202 ptrThreadName, |
|
203 CMediatorServerPluginHandler::ThreadEntryPoint, |
|
204 KDefaultStackSize, |
|
205 KMinHeapSize, |
|
206 KMediatorHeapSize, |
|
207 ¶m ) ); |
|
208 |
|
209 CleanupStack::PopAndDestroy( bufThreadName ); |
|
210 |
|
211 // Rendezvous |
|
212 TRequestStatus status = KRequestPending; |
|
213 newThread.Rendezvous( status ); |
|
214 newThread.Resume(); |
|
215 User::WaitForRequest( status ); |
|
216 TRACE(Print( _L("[Mediator Server]\t Thread resumed with status %d" ), status.Int() ) ); |
|
217 |
|
218 newThread.Close(); |
|
219 } |
|
220 |
|
221 // ----------------------------------------------------------------------------- |
|
222 // CMediatorServerPluginHandler::DoStartThreadL |
|
223 // |
|
224 // (other items were commented in a header). |
|
225 // ----------------------------------------------------------------------------- |
|
226 // |
|
227 void CMediatorServerPluginHandler::DoStartThreadL( TUid aMediatorPluginUid ) |
|
228 { |
|
229 TRACE(Print( _L("[Mediator Server]\t CMediatorServerPluginHandler::DoStartThreadL(0x%x)" ), aMediatorPluginUid ) ); |
|
230 CActiveScheduler* scheduler = new (ELeave) CActiveScheduler; |
|
231 CleanupStack::PushL( scheduler ); |
|
232 CActiveScheduler::Install( scheduler ); |
|
233 |
|
234 CMediatorPluginBase* newPlugin = CMediatorPluginBase::NewL( aMediatorPluginUid ); |
|
235 CleanupStack::PushL( newPlugin ); |
|
236 RThread::Rendezvous( KErrNone ); |
|
237 CActiveScheduler::Start(); |
|
238 |
|
239 CleanupStack::PopAndDestroy( newPlugin ); |
|
240 CleanupStack::PopAndDestroy( scheduler ); |
|
241 |
|
242 } |
|
243 |
|
244 // End of File |