|
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 the License "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 starter, this is run in separate thread from engine* |
|
15 */ |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 #include "CCseSchedulerPluginStarter.h" |
|
23 #include "CseDebug.h" // Debug macros |
|
24 #include <ipvideo/CCseScheduledProgram.h> // Represent one schedule in database |
|
25 #include <ipvideo/CCseSchedulerPluginIF.h> |
|
26 #include "CCseSchedulerThreadPacket.h" |
|
27 #include "CCseSemaphoreController.h" |
|
28 |
|
29 // EXTERNAL DATA STRUCTURES |
|
30 // None. |
|
31 |
|
32 // EXTERNAL FUNCTION PROTOTYPES |
|
33 // None. |
|
34 |
|
35 // CONSTANTS |
|
36 // None |
|
37 |
|
38 // MACROS |
|
39 // None. |
|
40 |
|
41 // LOCAL CONSTANTS AND MACROS |
|
42 // None |
|
43 |
|
44 // MODULE DATA STRUCTURES |
|
45 // None. |
|
46 |
|
47 // LOCAL FUNCTION PROTOTYPES |
|
48 // None. |
|
49 |
|
50 |
|
51 // ============================ MEMBER FUNCTIONS =============================== |
|
52 |
|
53 // ----------------------------------------------------------------------------- |
|
54 // CCseSchedulerPluginStarter::CCseSchedulerPluginStarter |
|
55 // C++ default constructor can NOT contain any code, that might leave. |
|
56 // ----------------------------------------------------------------------------- |
|
57 // |
|
58 CCseSchedulerPluginStarter::CCseSchedulerPluginStarter ( CCseSchedulerThreadPacket* aThreadPacket ) : |
|
59 iThreadPacket( aThreadPacket ), |
|
60 iPluginRdyToTakedown( EFalse ) |
|
61 { |
|
62 CSELOGSTRING_HIGH_LEVEL(">>>CCseSchedulerPluginStarter::CCseSchedulerPluginStarter"); |
|
63 |
|
64 CSELOGSTRING_HIGH_LEVEL("<<<CCseSchedulerPluginStarter::CCseSchedulerPluginStarter"); |
|
65 } |
|
66 |
|
67 // ----------------------------------------------------------------------------- |
|
68 // CCseSchedulerPluginStarter::NewL |
|
69 // Two-phased constructor. |
|
70 // ----------------------------------------------------------------------------- |
|
71 // |
|
72 CCseSchedulerPluginStarter* CCseSchedulerPluginStarter::NewL( CCseSchedulerThreadPacket* aThreadPacket ) |
|
73 { |
|
74 CSELOGSTRING_HIGH_LEVEL(">>>CCseSchedulerPluginStarter::NewL"); |
|
75 |
|
76 CCseSchedulerPluginStarter* self = new( ELeave ) CCseSchedulerPluginStarter( aThreadPacket ); |
|
77 CleanupStack::PushL( self ); |
|
78 self->ConstructL(); |
|
79 CleanupStack::Pop( self ); |
|
80 |
|
81 CSELOGSTRING_HIGH_LEVEL("<<<CCseSchedulerPluginStarter::NewL"); |
|
82 return self; |
|
83 } |
|
84 |
|
85 // ----------------------------------------------------------------------------- |
|
86 // CCseSchedulerPluginStarter::ConstructL |
|
87 // Symbian 2nd phase constructor can leave. |
|
88 // ----------------------------------------------------------------------------- |
|
89 // |
|
90 void CCseSchedulerPluginStarter::ConstructL() |
|
91 { |
|
92 CSELOGSTRING_HIGH_LEVEL(">>>CCseSchedulerPluginStarter::ConstructL"); |
|
93 |
|
94 iCompletitionBreaker = CIdle::NewL( CActive::EPriorityLow ); |
|
95 // Start completition breaker. This time we do not inform about completition of |
|
96 // plugin but we break call chain and start running plugin from RunL |
|
97 iCompletitionBreaker->Start(TCallBack( PluginCompleteCallback, this )); |
|
98 |
|
99 iSemaphoreMonitor = CCseSemaphoreController::NewL( iThreadPacket->ShutdownSemaphore(), |
|
100 *this ); |
|
101 |
|
102 CSELOGSTRING_HIGH_LEVEL("<<<CCseSchedulerPluginStarter::ConstructL"); |
|
103 } |
|
104 |
|
105 // ----------------------------------------------------------------------------- |
|
106 // CCseSchedulerEngineBackdoorClient::~CCseSchedulerPluginStarter |
|
107 // Destructor. |
|
108 // ----------------------------------------------------------------------------- |
|
109 // |
|
110 CCseSchedulerPluginStarter::~CCseSchedulerPluginStarter() |
|
111 { |
|
112 CSELOGSTRING_HIGH_LEVEL(">>>CCseSchedulerPluginStarter::~CCseSchedulerPluginStarter"); |
|
113 |
|
114 delete iCompletitionBreaker; |
|
115 delete iPlugin; |
|
116 iPlugin = NULL; |
|
117 REComSession::FinalClose(); |
|
118 |
|
119 delete iSemaphoreMonitor; |
|
120 iSemaphoreMonitor = NULL; |
|
121 |
|
122 // We DO NOT destroy thread packet, we just null the pointer. |
|
123 // Information is still needed on other side after thread dies |
|
124 iThreadPacket = NULL; |
|
125 |
|
126 CSELOGSTRING_HIGH_LEVEL("<<<CCseSchedulerPluginStarter::~CCseSchedulerPluginStarter"); |
|
127 } |
|
128 |
|
129 // ----------------------------------------------------------------------------- |
|
130 // CCseSchedulerPluginStarter::StartThread |
|
131 // |
|
132 // ----------------------------------------------------------------------------- |
|
133 // |
|
134 TInt CCseSchedulerPluginStarter::StartThread( TAny* aParam ) |
|
135 { |
|
136 CSELOGSTRING_HIGH_LEVEL(">>>CCseSchedulerPluginStarter::RunPlugin"); |
|
137 |
|
138 TInt err( KErrNone ); |
|
139 |
|
140 //create cleanupstack |
|
141 CTrapCleanup* cleanup = CTrapCleanup::New(); // get clean-up stack |
|
142 if (!cleanup) |
|
143 { |
|
144 err = KErrNoMemory; |
|
145 } |
|
146 if (!err) |
|
147 { |
|
148 TRAP(err, DoStartThreadL( aParam )); |
|
149 } |
|
150 delete cleanup; |
|
151 |
|
152 CSELOGSTRING_HIGH_LEVEL("<<<CCseSchedulerPluginStarter::RunPlugin"); |
|
153 return err; |
|
154 } |
|
155 |
|
156 // ----------------------------------------------------------------------------- |
|
157 // CCseSchedulerPluginStarter::DoStartThreadL |
|
158 // |
|
159 // ----------------------------------------------------------------------------- |
|
160 // |
|
161 void CCseSchedulerPluginStarter::DoStartThreadL( TAny* aParam ) |
|
162 { |
|
163 CSELOGSTRING_HIGH_LEVEL(">>>CCseSchedulerPluginStarter::DoStartThreadL"); |
|
164 |
|
165 CCseSchedulerThreadPacket* threadPacket = static_cast<CCseSchedulerThreadPacket*>(aParam); |
|
166 |
|
167 CActiveScheduler* scheduler = new ( ELeave ) CActiveScheduler; |
|
168 |
|
169 // If schedule doesn't exist there is really nothing we can do |
|
170 if( scheduler ) |
|
171 { |
|
172 CleanupStack::PushL( scheduler ); // |->1 |
|
173 CActiveScheduler::Install( scheduler ); |
|
174 |
|
175 // Create the starter |
|
176 CCseSchedulerPluginStarter* starter = CCseSchedulerPluginStarter::NewL( threadPacket ); |
|
177 CleanupStack::PushL(starter); // |->2 |
|
178 |
|
179 // Ready to run |
|
180 CActiveScheduler::Start(); |
|
181 |
|
182 CSELOGSTRING_HIGH_LEVEL("CCseSchedulerPluginStarter::DoStartThreadL - Out from CActiveScheduler::Start!"); |
|
183 |
|
184 // Cleanup the server and scheduler |
|
185 CleanupStack::PopAndDestroy( starter ); // 2<-| |
|
186 CleanupStack::PopAndDestroy( scheduler ); // 1<-| |
|
187 |
|
188 threadPacket->ShutdownCompleteSemaphore().Signal(); |
|
189 } |
|
190 else |
|
191 { |
|
192 CSELOGSTRING_HIGH_LEVEL("CCseSchedulerPluginStarter::DoStartThreadL - No schedule available, GTFO"); |
|
193 } |
|
194 |
|
195 CSELOGSTRING_HIGH_LEVEL("<<<CCseSchedulerPluginStarter::DoStartThreadL"); |
|
196 } |
|
197 |
|
198 // ----------------------------------------------------------------------------- |
|
199 // CCseSchedulerPluginStarter::RunPluginL |
|
200 // |
|
201 // ----------------------------------------------------------------------------- |
|
202 // |
|
203 void CCseSchedulerPluginStarter::RunPluginL( ) |
|
204 { |
|
205 CSELOGSTRING_HIGH_LEVEL(">>>CCseSchedulerPluginStarter::RunPluginL"); |
|
206 |
|
207 // Create plugin |
|
208 TUid pluginUid = TUid::Uid( iThreadPacket->Schedule()->PluginUid() ); |
|
209 |
|
210 iPlugin = CCseSchedulerPluginIF::NewL( pluginUid ); |
|
211 |
|
212 iPlugin->RunTaskL( *iThreadPacket->Schedule(), this ); |
|
213 |
|
214 CSELOGSTRING_HIGH_LEVEL("<<<CCseSchedulerPluginStarter::RunPluginL"); |
|
215 } |
|
216 |
|
217 // ----------------------------------------------------------------------------- |
|
218 // CCseSchedulerPluginStarter::PluginCompleted |
|
219 // |
|
220 // ----------------------------------------------------------------------------- |
|
221 // |
|
222 void CCseSchedulerPluginStarter::PluginCompleted( TInt aCompletitionCode ) |
|
223 { |
|
224 CSELOGSTRING2_HIGH_LEVEL( |
|
225 ">>>CCseSchedulerPluginStarter::PluginCompleted - Code: %d", aCompletitionCode); |
|
226 |
|
227 // Start taking down The Thread |
|
228 // Start Completition breaker if not already active to break call chain. |
|
229 // Set plugin completition value |
|
230 iThreadPacket->SetResultCode( aCompletitionCode ); |
|
231 |
|
232 iPluginRdyToTakedown = ETrue; |
|
233 |
|
234 if( !iCompletitionBreaker->IsActive() ) |
|
235 { |
|
236 iCompletitionBreaker->Start(TCallBack( PluginCompleteCallback, this )); |
|
237 } |
|
238 else |
|
239 { |
|
240 CSELOGSTRING_HIGH_LEVEL( |
|
241 "CCseSchedulerPluginStarter::PluginCompleted:Breaker already running!"); |
|
242 } |
|
243 |
|
244 CSELOGSTRING_HIGH_LEVEL("<<<CCseSchedulerPluginStarter::PluginCompleted"); |
|
245 } |
|
246 |
|
247 // ----------------------------------------------------------------------------- |
|
248 // CCseSchedulerPluginStarter::PluginCompleteCallback |
|
249 // ----------------------------------------------------------------------------- |
|
250 // |
|
251 TInt CCseSchedulerPluginStarter::PluginCompleteCallback( TAny* aPtr ) |
|
252 { |
|
253 CSELOGSTRING_HIGH_LEVEL(">>>PluginCompleteCallback::ScheduleCompleteCallback"); |
|
254 CSELOGSTRING_HIGH_LEVEL("<<<PluginCompleteCallback::ScheduleCompleteCallback"); |
|
255 return static_cast<CCseSchedulerPluginStarter*>( aPtr )->HandlePluginCompleteCallback(); |
|
256 } |
|
257 |
|
258 // ----------------------------------------------------------------------------- |
|
259 // CCseSchedulerUserInformer::HandlePluginCompleteCallback |
|
260 // ----------------------------------------------------------------------------- |
|
261 // |
|
262 TInt CCseSchedulerPluginStarter::HandlePluginCompleteCallback() |
|
263 { |
|
264 CSELOGSTRING_HIGH_LEVEL(">>>CCseSchedulerPluginStarter::HandleScheduleCompleteCallback "); |
|
265 |
|
266 if( iPluginRdyToTakedown ) |
|
267 { |
|
268 // First clear flag |
|
269 iPluginRdyToTakedown = EFalse; |
|
270 // Takedown thread |
|
271 CActiveScheduler::Stop(); |
|
272 } |
|
273 else |
|
274 { |
|
275 // First start monitor |
|
276 iSemaphoreMonitor->Start(); |
|
277 // Plugin ready to be run |
|
278 TRAPD( err, RunPluginL() ); |
|
279 if ( err != KErrNone ) |
|
280 { |
|
281 // Run plugin leaved for some reason. Set error code and get outta here! |
|
282 iThreadPacket->SetResultCode( err ); |
|
283 iPluginRdyToTakedown = ETrue; |
|
284 iCompletitionBreaker->Start(TCallBack( PluginCompleteCallback, this )); |
|
285 } |
|
286 } |
|
287 |
|
288 CSELOGSTRING_HIGH_LEVEL("<<<CCseSchedulerPluginStarter::HandleScheduleCompleteCallback "); |
|
289 return EFalse; |
|
290 } |
|
291 |
|
292 // ----------------------------------------------------------------------------- |
|
293 // CCseSchedulerUserInformer::SemaphoreSignalled |
|
294 // ----------------------------------------------------------------------------- |
|
295 // |
|
296 void CCseSchedulerPluginStarter::SemaphoreSignalled() |
|
297 { |
|
298 CSELOGSTRING_HIGH_LEVEL(">>>CCseSchedulerPluginStarter::SemaphoreSignalled"); |
|
299 |
|
300 delete iPlugin; |
|
301 iPlugin = NULL; |
|
302 |
|
303 CActiveScheduler::Stop(); |
|
304 |
|
305 CSELOGSTRING_HIGH_LEVEL("<<<CCseSchedulerPluginStarter::SemaphoreSignalled"); |
|
306 } |
|
307 |
|
308 // End of file. |