17 #include <e32property.h> |
17 #include <e32property.h> |
18 |
18 |
19 #include "harvesterclient.h" |
19 #include "harvesterclient.h" |
20 #include "harvestercommon.h" |
20 #include "harvestercommon.h" |
21 #include "harvesterrequestqueue.h" |
21 #include "harvesterrequestqueue.h" |
22 #include "harvesternotificationqueue.h" |
|
23 #include "harvestereventobserverao.h" |
22 #include "harvestereventobserverao.h" |
24 #include "harvesterlog.h" |
23 #include "harvesterlog.h" |
25 #include "harvesterclientao.h" |
24 #include "harvesterclientao.h" |
26 #include "harvestersessionwatcher.h" |
25 #include "harvestersessionwatcher.h" |
27 #include "mdsutils.h" |
26 #include "mdsutils.h" |
56 OstTrace0( TRACE_NORMAL, RHARVESTERCLIENT_RHARVESTERCLIENT, "RHarvesterClient::RHarvesterClient" ); |
55 OstTrace0( TRACE_NORMAL, RHARVESTERCLIENT_RHARVESTERCLIENT, "RHarvesterClient::RHarvesterClient" ); |
57 |
56 |
58 iObserver = NULL; |
57 iObserver = NULL; |
59 iHEO = NULL; |
58 iHEO = NULL; |
60 iRequestQueue = NULL; |
59 iRequestQueue = NULL; |
61 iNotificationQueue = NULL; |
60 iHarvesterClientAO = NULL; |
|
61 iSessionWatcher = NULL; |
62 } |
62 } |
63 |
63 |
64 // ---------------------------------------------------------------------------------------- |
64 // ---------------------------------------------------------------------------------------- |
65 // Connect |
65 // Connect |
66 // ---------------------------------------------------------------------------------------- |
66 // ---------------------------------------------------------------------------------------- |
79 if ( error != KErrNone || value > KErrNone ) |
79 if ( error != KErrNone || value > KErrNone ) |
80 { |
80 { |
81 return KErrLocked; |
81 return KErrLocked; |
82 } |
82 } |
83 |
83 |
84 if( iRequestQueue ) |
84 if( iHarvesterClientAO ) |
85 { |
85 { |
86 return KErrAlreadyExists; |
86 return KErrAlreadyExists; |
87 } |
87 } |
88 |
88 |
|
89 TRAPD( err, iHarvesterClientAO = CHarvesterClientAO::NewL(*this) ); |
|
90 if ( err != KErrNone ) |
|
91 { |
|
92 WRITELOG( "RHarvesterClient::RHarvesterClient() - Couldn't create active object" ); |
|
93 return err; |
|
94 } |
|
95 |
89 // request processor |
96 // request processor |
90 TRAPD( err, iRequestQueue = CHarvesterRequestQueue::NewL() ) |
97 TRAP( err, iRequestQueue = CHarvesterRequestQueue::NewL() ) |
91 { |
98 { |
92 if ( err != KErrNone ) |
99 if ( err != KErrNone ) |
93 { |
100 { |
94 WRITELOG( "RHarvesterClient::RHarvesterClient() - Couldn't create harvester request queue" ); |
101 WRITELOG( "RHarvesterClient::RHarvesterClient() - Couldn't create harvester request queue" ); |
95 return err; |
102 delete iHarvesterClientAO; |
96 } |
103 iHarvesterClientAO = NULL; |
97 } |
|
98 |
|
99 // request processor |
|
100 TRAP( err, iNotificationQueue = CHarvesterNotificationQueue::NewL() ) |
|
101 { |
|
102 if ( err != KErrNone ) |
|
103 { |
|
104 WRITELOG( "RHarvesterClient::RHarvesterClient() - Couldn't create harvester notification queue" ); |
|
105 delete iRequestQueue; |
|
106 iRequestQueue = NULL; |
|
107 return err; |
104 return err; |
108 } |
105 } |
109 } |
106 } |
110 |
107 |
111 err = ::StartServer(); |
108 err = ::StartServer(); |
115 WRITELOG( "RHarvesterClient::Connect() - creating session" ); |
112 WRITELOG( "RHarvesterClient::Connect() - creating session" ); |
116 err = CreateSession( KHarvesterServerName, Version(), KDefaultMessageSlots ); |
113 err = CreateSession( KHarvesterServerName, Version(), KDefaultMessageSlots ); |
117 } |
114 } |
118 else |
115 else |
119 { |
116 { |
|
117 WRITELOG1( "RHarvesterClient::Connect() - Server is not running or could not be started, error &d", err ); |
120 delete iRequestQueue; |
118 delete iRequestQueue; |
121 iRequestQueue = NULL; |
119 iRequestQueue = NULL; |
122 delete iNotificationQueue; |
120 delete iHarvesterClientAO; |
123 iNotificationQueue = NULL; |
121 iHarvesterClientAO = NULL; |
124 } |
122 return err; |
125 |
123 } |
126 #ifdef _DEBUG |
124 |
127 if ( err != KErrNone ) |
125 if( err != KErrNone ) |
128 { |
126 { |
129 WRITELOG1( "RHarvesterClient::Connect() - Server is not running or could not be started, error &d", err ); |
127 WRITELOG1( "RHarvesterClient::Connect() - Session creation failed, error &d", err ); |
130 } |
128 delete iRequestQueue; |
131 else |
129 iRequestQueue = NULL; |
132 { |
130 delete iHarvesterClientAO; |
133 WRITELOG( "RHarvesterClient::Connect() - no errors" ); |
131 iHarvesterClientAO = NULL; |
134 } |
132 } |
|
133 |
|
134 iHEO = NULL; |
|
135 |
|
136 iSessionWatcher = NULL; |
|
137 |
135 WRITELOG( "RHarvesterClient::Connect() - end" ); |
138 WRITELOG( "RHarvesterClient::Connect() - end" ); |
136 #endif |
|
137 |
|
138 iHEO = NULL; |
|
139 |
|
140 iSessionWatcher = NULL; |
|
141 |
139 |
142 return err; |
140 return err; |
143 } |
141 } |
144 |
142 |
145 // ---------------------------------------------------------------------------------------- |
143 // ---------------------------------------------------------------------------------------- |
184 OstTrace0( TRACE_NORMAL, RHARVESTERCLIENT_CLOSE, "RHarvesterClient::Close" ); |
182 OstTrace0( TRACE_NORMAL, RHARVESTERCLIENT_CLOSE, "RHarvesterClient::Close" ); |
185 |
183 |
186 delete iSessionWatcher; |
184 delete iSessionWatcher; |
187 iSessionWatcher = NULL; |
185 iSessionWatcher = NULL; |
188 |
186 |
189 // cancels Harvest Complete request if it exist at server |
187 WRITELOG( "RHarvesterClient::Close() - cancelling pending harvesting requests" ); |
|
188 if( iRequestQueue && iRequestQueue->RequestsPending() ) |
|
189 { |
|
190 iRequestQueue->Cancel(); |
|
191 } |
|
192 |
|
193 WRITELOG( "RHarvesterClient::Close() - removing harvester client observer" ); |
|
194 if( iObserver ) |
|
195 { |
|
196 RemoveObserver( iObserver ); |
|
197 } |
190 UnregisterHarvestComplete(); |
198 UnregisterHarvestComplete(); |
191 delete iNotificationQueue; |
|
192 iNotificationQueue = NULL; |
|
193 |
199 |
194 WRITELOG( "RHarvesterClient::Close() - UnregisterHarvest done" ); |
200 WRITELOG( "RHarvesterClient::Close() - UnregisterHarvest done" ); |
195 |
201 |
|
202 WRITELOG( "RHarvesterClient::Close() - forcing remaining harvesting requests" ); |
196 if( iRequestQueue && iRequestQueue->RequestsPending() ) |
203 if( iRequestQueue && iRequestQueue->RequestsPending() ) |
197 { |
204 { |
198 iRequestQueue->Cancel(); |
205 WRITELOG( "RHarvesterClient::Close() - Pending harvesting requests detected -> ForceHarvest" ); |
199 iRequestQueue->ForceRequests(); |
206 iRequestQueue->ForceRequests(); |
200 } |
207 } |
|
208 |
|
209 WRITELOG( "RHarvesterClient::Close() - ForceHarvest done" ); |
201 |
210 |
202 delete iRequestQueue; |
211 delete iRequestQueue; |
203 iRequestQueue = NULL; |
212 iRequestQueue = NULL; |
204 |
213 |
205 delete iHEO; |
214 delete iHEO; |
206 iHEO = NULL; |
215 iHEO = NULL; |
207 |
216 |
|
217 WRITELOG( "RHarvesterClient::Close() - deleting harvester client AO" ); |
|
218 delete iHarvesterClientAO; |
|
219 iHarvesterClientAO = NULL; |
|
220 |
208 WRITELOG( "RHarvesterClient::Close() - Closing session" ); |
221 WRITELOG( "RHarvesterClient::Close() - Closing session" ); |
209 |
222 |
210 RSessionBase::Close(); |
223 RSessionBase::Close(); |
211 } |
224 } |
212 |
225 |
217 EXPORT_C void RHarvesterClient::SetObserver( MHarvestObserver* aObserver ) |
230 EXPORT_C void RHarvesterClient::SetObserver( MHarvestObserver* aObserver ) |
218 { |
231 { |
219 WRITELOG( "RHarvesterClient::SetObserver()" ); |
232 WRITELOG( "RHarvesterClient::SetObserver()" ); |
220 OstTrace0( TRACE_NORMAL, RHARVESTERCLIENT_SETOBSERVER, "RHarvesterClient::SetObserver" ); |
233 OstTrace0( TRACE_NORMAL, RHARVESTERCLIENT_SETOBSERVER, "RHarvesterClient::SetObserver" ); |
221 |
234 |
|
235 if ( iHarvesterClientAO ) |
|
236 { |
|
237 iHarvesterClientAO->SetObserver( aObserver ); |
|
238 } |
222 iObserver = aObserver; |
239 iObserver = aObserver; |
223 iNotificationQueue->SetObserver( iObserver ); |
|
224 } |
240 } |
225 |
241 |
226 // ---------------------------------------------------------------------------------------- |
242 // ---------------------------------------------------------------------------------------- |
227 // RemoveObserver |
243 // RemoveObserver |
228 // ---------------------------------------------------------------------------------------- |
244 // ---------------------------------------------------------------------------------------- |
230 EXPORT_C void RHarvesterClient::RemoveObserver( MHarvestObserver* aObserver ) |
246 EXPORT_C void RHarvesterClient::RemoveObserver( MHarvestObserver* aObserver ) |
231 { |
247 { |
232 WRITELOG( "RHarvesterClient::RemoveObserver()" ); |
248 WRITELOG( "RHarvesterClient::RemoveObserver()" ); |
233 OstTrace0( TRACE_NORMAL, RHARVESTERCLIENT_REMOVEOBSERVER, "RHarvesterClient::RemoveObserver" ); |
249 OstTrace0( TRACE_NORMAL, RHARVESTERCLIENT_REMOVEOBSERVER, "RHarvesterClient::RemoveObserver" ); |
234 |
250 |
235 if ( aObserver == iObserver ) |
251 if ( aObserver == iObserver && iObserver ) |
236 { |
252 { |
237 WRITELOG( "RHarvesterClient::RemoveObserver() - deleting observer" ); |
253 WRITELOG( "RHarvesterClient::RemoveObserver() - deleting observer" ); |
|
254 |
|
255 if ( iHarvesterClientAO ) |
|
256 { |
|
257 WRITELOG( "RHarvesterClient::RemoveObserver() - calling iHarvesterClientAO->RemoveObserver" ); |
|
258 iHarvesterClientAO->RemoveObserver( aObserver ); |
|
259 } |
|
260 |
238 iObserver = NULL; |
261 iObserver = NULL; |
239 iNotificationQueue->SetObserver( iObserver ); |
|
240 } |
262 } |
241 } |
263 } |
242 |
264 |
243 // ---------------------------------------------------------------------------------------- |
265 // ---------------------------------------------------------------------------------------- |
244 // AddHarvesterEventObserver |
266 // AddHarvesterEventObserver |
303 } |
325 } |
304 return; |
326 return; |
305 } |
327 } |
306 |
328 |
307 CHarvesterRequestActive* harvestFileActive( NULL ); |
329 CHarvesterRequestActive* harvestFileActive( NULL ); |
308 TRAP( err, harvestFileActive = CHarvesterRequestActive::NewL( *this, (TInt)EHarvestFile, aURI, |
330 TRAP( err, harvestFileActive = CHarvesterRequestActive::NewL( *this, iObserver, (TInt)EHarvestFile, aURI, |
309 paramBuf, aAddLocation, iRequestQueue ) ); |
331 paramBuf, aAddLocation, iRequestQueue ) ); |
310 if( err ) |
332 if( err ) |
311 { |
333 { |
312 WRITELOG1( "RHarvesterClient::HarvestFile() - cannot create harvesting request, error: %d", err ); |
334 WRITELOG1( "RHarvesterClient::HarvestFile() - cannot create harvesting request, error: %d", err ); |
313 if( iObserver ) |
335 if( iObserver ) |
380 } |
402 } |
381 return; |
403 return; |
382 } |
404 } |
383 |
405 |
384 CHarvesterRequestActive* harvestFileActive( NULL ); |
406 CHarvesterRequestActive* harvestFileActive( NULL ); |
385 TRAP( err, harvestFileActive = CHarvesterRequestActive::NewL( *this, (TInt)EHarvestFile, aURI, |
407 TRAP( err, harvestFileActive = CHarvesterRequestActive::NewL( *this, iObserver, (TInt)EHarvestFile, aURI, |
386 paramBuf, aAddLocation, iRequestQueue ) ); |
408 paramBuf, aAddLocation, iRequestQueue ) ); |
387 if( err ) |
409 if( err ) |
388 { |
410 { |
389 WRITELOG1( "RHarvesterClient::HarvestFile() - cannot create harvesting request, error: %d", err ); |
411 WRITELOG1( "RHarvesterClient::HarvestFile() - cannot create harvesting request, error: %d", err ); |
390 if( iObserver ) |
412 if( iObserver ) |
461 // ---------------------------------------------------------------------------------------- |
483 // ---------------------------------------------------------------------------------------- |
462 // RegisterHarvestComplete |
484 // RegisterHarvestComplete |
463 // ---------------------------------------------------------------------------------------- |
485 // ---------------------------------------------------------------------------------------- |
464 // |
486 // |
465 void RHarvesterClient::RegisterHarvestComplete(TDes& aURI, TRequestStatus& aStatus) |
487 void RHarvesterClient::RegisterHarvestComplete(TDes& aURI, TRequestStatus& aStatus) |
466 { |
488 { |
467 TIpcArgs ipcArgs( &aURI ); |
489 TIpcArgs ipcArgs( &aURI ); |
468 OstTrace0( TRACE_NORMAL, RHARVESTERCLIENT_REGISTERHARVESTCOMPLETE, "RHarvesterClient::RegisterHarvestComplete" ); |
490 OstTrace0( TRACE_NORMAL, RHARVESTERCLIENT_REGISTERHARVESTCOMPLETE, "RHarvesterClient::RegisterHarvestComplete" ); |
469 |
491 |
470 if( !iHandle ) |
492 if( !iHandle ) |
471 { |
493 { |
491 |
513 |
492 // ---------------------------------------------------------------------------------------- |
514 // ---------------------------------------------------------------------------------------- |
493 // HarvestFile |
515 // HarvestFile |
494 // ---------------------------------------------------------------------------------------- |
516 // ---------------------------------------------------------------------------------------- |
495 // |
517 // |
496 void RHarvesterClient::HarvestFile( TInt& aService, TIpcArgs& aArgs, TRequestStatus& aStatus, TDesC& aUri ) |
518 void RHarvesterClient::HarvestFile( TInt& aService, TIpcArgs& aArgs, TRequestStatus& aStatus ) |
497 { |
519 { |
498 // send to server harvesting complete observer |
520 // send to server harvesting complete observer |
499 if( iObserver ) |
521 if( iObserver && iHarvesterClientAO ) |
500 { |
522 { |
501 CHarvesterClientAO* harvestNotificationRequest( NULL ); |
523 iHarvesterClientAO->Active(); |
502 TRAPD( err, harvestNotificationRequest = CHarvesterClientAO::NewL(*this, iNotificationQueue ) ); |
|
503 if( err ) |
|
504 { |
|
505 WRITELOG1( "RHarvesterClient::HarvestFile() - cannot issue harvesting notitification request, error: %d", err ); |
|
506 iObserver->HarvestingComplete( const_cast<TDesC&>(aUri), KErrCompletion ); |
|
507 delete harvestNotificationRequest; |
|
508 harvestNotificationRequest = NULL; |
|
509 } |
|
510 else |
|
511 { |
|
512 TRAP( err, iNotificationQueue->AddRequestL( harvestNotificationRequest ) ); |
|
513 if( err ) |
|
514 { |
|
515 iObserver->HarvestingComplete( const_cast<TDesC&>(aUri), KErrCompletion ); |
|
516 delete harvestNotificationRequest; |
|
517 harvestNotificationRequest = NULL; |
|
518 } |
|
519 else |
|
520 { |
|
521 harvestNotificationRequest->SetObserver( iObserver ); |
|
522 harvestNotificationRequest->Active( aUri ); |
|
523 } |
|
524 } |
|
525 } |
524 } |
526 SendReceive( aService, aArgs, aStatus ); |
525 SendReceive( aService, aArgs, aStatus ); |
527 } |
526 } |
528 |
527 |
529 // ---------------------------------------------------------------------------------------- |
528 // ---------------------------------------------------------------------------------------- |