|
1 /* |
|
2 * Copyright (c) 2006-2009 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: A Server class for LocationManagerServer. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <e32debug.h> |
|
19 #include <w32std.h> |
|
20 |
|
21 #include "clocationmanagerserver.h" |
|
22 #include "clocationmanagersession.h" |
|
23 |
|
24 #include "locationtraildefs.h" |
|
25 #include "locationmanagerdebug.h" |
|
26 |
|
27 #include "mdesession.h" |
|
28 #include "mdenamespacedef.h" |
|
29 #include "mdeobjectdef.h" |
|
30 #include "mdepropertydef.h" |
|
31 #include "mdcserializationbuffer.h" |
|
32 |
|
33 using namespace MdeConstants; |
|
34 |
|
35 // -------------------------------------------------------------------------- |
|
36 // RunServerL |
|
37 // Initialize and run the server. |
|
38 // -------------------------------------------------------------------------- |
|
39 // |
|
40 static void RunServerL() |
|
41 { |
|
42 User::LeaveIfError( RThread().RenameMe( KLocServerName ) ); |
|
43 |
|
44 CActiveScheduler* scheduler = new (ELeave) CActiveScheduler; |
|
45 CleanupStack::PushL( scheduler ); |
|
46 CActiveScheduler::Install( scheduler ); |
|
47 |
|
48 CLocationManagerServer* server = CLocationManagerServer::NewLC(); |
|
49 |
|
50 RProcess::Rendezvous( KErrNone ); |
|
51 |
|
52 CActiveScheduler::Start(); |
|
53 |
|
54 CleanupStack::PopAndDestroy(server); |
|
55 CleanupStack::PopAndDestroy(scheduler); |
|
56 } |
|
57 |
|
58 // -------------------------------------------------------------------------- |
|
59 // E32Main |
|
60 // Server process entry-point. |
|
61 // -------------------------------------------------------------------------- |
|
62 // |
|
63 TInt E32Main() |
|
64 { |
|
65 CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
66 TInt ret( KErrNoMemory ); |
|
67 if( cleanup ) |
|
68 { |
|
69 TRAP( ret, RunServerL() ); |
|
70 delete cleanup; |
|
71 } |
|
72 return ret; |
|
73 } |
|
74 |
|
75 // -------------------------------------------------------------------------- |
|
76 // CLocationManagerServer::NewLC |
|
77 // 2-phased constructor. |
|
78 // -------------------------------------------------------------------------- |
|
79 // |
|
80 CLocationManagerServer* CLocationManagerServer::NewLC() |
|
81 { |
|
82 CLocationManagerServer* self = new (ELeave) CLocationManagerServer(); |
|
83 CleanupStack::PushL(self); |
|
84 self->ConstructL(); |
|
85 return self; |
|
86 } |
|
87 |
|
88 // -------------------------------------------------------------------------- |
|
89 // CLocationManagerServer::CLocationManagerServer() |
|
90 // C++ constructor. |
|
91 // -------------------------------------------------------------------------- |
|
92 // |
|
93 CLocationManagerServer::CLocationManagerServer() |
|
94 : CPolicyServer( CActive::EPriorityStandard, |
|
95 KLocationManagerPolicy, |
|
96 ESharableSessions ), |
|
97 iTimer( NULL ), |
|
98 iSessionReady( EFalse ), |
|
99 iTagId( 0 ), |
|
100 iLocManStopDelay( 0 ), |
|
101 iCaptureSetting( RLocationTrail::EOff ), |
|
102 iRemoveLocation( EFalse ) |
|
103 { |
|
104 } |
|
105 |
|
106 // -------------------------------------------------------------------------- |
|
107 // CLocationManagerServer::ConstructL |
|
108 // 2nd phase constructor. |
|
109 // -------------------------------------------------------------------------- |
|
110 // |
|
111 void CLocationManagerServer::ConstructL() |
|
112 { |
|
113 LOG ("CLocationManagerServer::ConstructL() begin"); |
|
114 |
|
115 StartL( KLocServerName ); |
|
116 |
|
117 RProcess process; |
|
118 process.SetPriority( EPriorityBackground ); |
|
119 process.Close(); |
|
120 |
|
121 iASW = new (ELeave) CActiveSchedulerWait(); |
|
122 iMdeSession = CMdESession::NewL( *this ); |
|
123 iLocationRecord = CLocationRecord::NewL(); |
|
124 iTrackLog = CTrackLog::NewL(); |
|
125 |
|
126 iASW->Start(); |
|
127 |
|
128 iLocationRecord->SetObserver( this ); |
|
129 |
|
130 iLocationRecord->SetAddObserver( iTrackLog ); |
|
131 |
|
132 iTrackLog->AddGpxObserver( this ); |
|
133 |
|
134 CRepository* repository = CRepository::NewLC( KRepositoryUid ); |
|
135 TInt err = repository->Get( KLocationTrailShutdownTimer, iLocManStopDelay ); |
|
136 CleanupStack::PopAndDestroy( repository ); |
|
137 |
|
138 LOG1("CLocationManagerServer::ConstructL, iLocManStopDelay:%d", iLocManStopDelay); |
|
139 |
|
140 if ( err != KErrNone ) |
|
141 { |
|
142 LOG1("CLocationManagerServer::ConstructL, iLocManStopDelay err:%d", err); |
|
143 iLocManStopDelay = KLocationTrailShutdownDelay; |
|
144 } |
|
145 |
|
146 LOG ("CLocationManagerServer::ConstructL() end"); |
|
147 } |
|
148 |
|
149 // -------------------------------------------------------------------------- |
|
150 // CLocationManagerServer::~CLocationManagerServer() |
|
151 // C++ destructor. |
|
152 // -------------------------------------------------------------------------- |
|
153 // |
|
154 CLocationManagerServer::~CLocationManagerServer() |
|
155 { |
|
156 delete iLocationRecord; |
|
157 delete iTrackLog; |
|
158 delete iTimer; |
|
159 //delete iRelationQuery; |
|
160 delete iASW; |
|
161 delete iMdeSession; |
|
162 |
|
163 iTargetObjectIds.Close(); |
|
164 CancelRequests(iNotifReqs); |
|
165 iNotifReqs.Close(); |
|
166 CancelRequests(iLocationReqs); |
|
167 iLocationReqs.Close(); |
|
168 CancelRequests(iTrackLogNotifyReqs); |
|
169 iTrackLogNotifyReqs.Close(); |
|
170 CancelCopyRequests(iCopyReqs); |
|
171 iCopyReqs.Close(); |
|
172 iSessionCount = 0; |
|
173 } |
|
174 // -------------------------------------------------------------------------- |
|
175 // CLocationManagerServer::CompleteRequests() |
|
176 // -------------------------------------------------------------------------- |
|
177 // |
|
178 void CLocationManagerServer::CancelRequests(RArray<RMessage2>& aMessageList) |
|
179 { |
|
180 const TInt count = aMessageList.Count(); |
|
181 |
|
182 for ( TInt i(0) ; i < count; i++ ) |
|
183 { |
|
184 RMessage2& msg = aMessageList[i]; |
|
185 |
|
186 if( !msg.IsNull() ) |
|
187 { |
|
188 msg.Complete( KErrCancel ); |
|
189 } |
|
190 } |
|
191 aMessageList.Reset(); |
|
192 } |
|
193 |
|
194 void CLocationManagerServer::CancelCopyRequests(RArray<TMessageQuery>& aMessageList) |
|
195 { |
|
196 const TInt count = aMessageList.Count(); |
|
197 |
|
198 for ( TInt i(0) ; i < count; i++ ) |
|
199 { |
|
200 const RMessage2& msg = aMessageList[i].iMessage; |
|
201 |
|
202 if( !msg.IsNull() ) |
|
203 { |
|
204 msg.Complete( KErrCancel ); |
|
205 } |
|
206 } |
|
207 aMessageList.Reset(); |
|
208 } |
|
209 |
|
210 |
|
211 void CLocationManagerServer::HandleSessionOpened(CMdESession& /*aSession*/, TInt aError) |
|
212 { |
|
213 if ( iASW->IsStarted() ) |
|
214 { |
|
215 iASW->AsyncStop(); |
|
216 } |
|
217 |
|
218 if ( KErrNone == aError ) |
|
219 { |
|
220 iSessionReady = ETrue; |
|
221 TRAP_IGNORE( iTrackLog->StartRecoveryL() ); |
|
222 iLocationRecord->SetMdeSession( iMdeSession ); |
|
223 } |
|
224 else |
|
225 { |
|
226 iSessionReady = EFalse; |
|
227 delete iMdeSession; |
|
228 iMdeSession = NULL; |
|
229 } |
|
230 } |
|
231 |
|
232 void CLocationManagerServer::HandleSessionError(CMdESession& /*aSession*/, TInt /*aError*/) |
|
233 { |
|
234 iSessionReady = EFalse; |
|
235 delete iMdeSession; |
|
236 iMdeSession = NULL; |
|
237 |
|
238 if ( iASW->IsStarted() ) |
|
239 { |
|
240 iASW->AsyncStop(); |
|
241 } |
|
242 } |
|
243 |
|
244 TBool CLocationManagerServer::IsSessionReady() |
|
245 { |
|
246 return iSessionReady; |
|
247 } |
|
248 |
|
249 // -------------------------------------------------------------------------- |
|
250 // CLocationManagerServer::NewSessionL |
|
251 // from CServer2, creates a new session. |
|
252 // -------------------------------------------------------------------------- |
|
253 // |
|
254 CSession2* CLocationManagerServer::NewSessionL( const TVersion& aVersion, |
|
255 const RMessage2& /*aMsg*/ ) const |
|
256 { |
|
257 TBool supported = User::QueryVersionSupported( TVersion( |
|
258 KLocationManagerServerMajor, |
|
259 KLocationManagerServerMinor, |
|
260 KLocationManagerServerBuild ), |
|
261 aVersion ); |
|
262 if( !supported ) |
|
263 { |
|
264 User::Leave( KErrNotSupported ); |
|
265 } |
|
266 |
|
267 return new (ELeave) CLocationManagerSession(); |
|
268 } |
|
269 |
|
270 // -------------------------------------------------------------------------- |
|
271 // CLocationManagerServer::AddSession |
|
272 // -------------------------------------------------------------------------- |
|
273 // |
|
274 void CLocationManagerServer::AddSession() |
|
275 { |
|
276 iSessionCount++; |
|
277 } |
|
278 |
|
279 // -------------------------------------------------------------------------- |
|
280 // CLocationManagerServer::RemoveSession |
|
281 // -------------------------------------------------------------------------- |
|
282 // |
|
283 void CLocationManagerServer::RemoveSession() |
|
284 { |
|
285 iSessionCount--; |
|
286 if ( !iSessionCount ) |
|
287 { |
|
288 CActiveScheduler::Stop(); |
|
289 } |
|
290 } |
|
291 |
|
292 // -------------------------------------------------------------------------- |
|
293 // CLocationManagerServer::StartGPSPositioningL |
|
294 // -------------------------------------------------------------------------- |
|
295 // |
|
296 void CLocationManagerServer::StartGPSPositioningL( RLocationTrail::TTrailCaptureSetting aCaptureSetting ) |
|
297 { |
|
298 if ( aCaptureSetting == RLocationTrail::EOff ) |
|
299 { |
|
300 return; |
|
301 } |
|
302 |
|
303 iCaptureSetting = aCaptureSetting; |
|
304 |
|
305 RLocationTrail::TTrailState state; |
|
306 GetLocationTrailState( state ); |
|
307 if ( state != RLocationTrail::ETrailStopped && state != RLocationTrail::ETrailStopping ) |
|
308 { |
|
309 User::Leave( KErrAlreadyExists ); |
|
310 } |
|
311 if ( iTimer ) |
|
312 { |
|
313 delete iTimer; |
|
314 iTimer = NULL; |
|
315 } |
|
316 |
|
317 iLocationRecord->StartL( aCaptureSetting ); |
|
318 } |
|
319 |
|
320 // -------------------------------------------------------------------------- |
|
321 // CLocationManagerServer::StopGPSPositioning |
|
322 // -------------------------------------------------------------------------- |
|
323 // |
|
324 void CLocationManagerServer::StopGPSPositioningL() |
|
325 { |
|
326 iCaptureSetting = RLocationTrail::EOff; |
|
327 |
|
328 RLocationTrail::TTrailState state; |
|
329 GetLocationTrailState( state ); |
|
330 if( state == RLocationTrail::ETrailStarted || state == RLocationTrail::ETrailStarting ) |
|
331 { |
|
332 iLocationRecord->Stop(); |
|
333 } |
|
334 else if ( state != RLocationTrail::ETrailStopped && state != RLocationTrail::ETrailStopping ) |
|
335 { |
|
336 if ( iLocationRecord->RemappingNeeded() ) |
|
337 { |
|
338 TRAPD( error, iTimer = CPeriodic::NewL( CActive::EPriorityStandard ) ); |
|
339 if ( error != KErrNone ) |
|
340 { |
|
341 // If timer can't be created we stop the location trail immediately. |
|
342 iLocationRecord->Stop(); |
|
343 StopTrackLogL(); |
|
344 return; |
|
345 } |
|
346 iLocationRecord->SetStateToStopping(); |
|
347 iTimer->Start( iLocManStopDelay * 1000000, 0, TCallBack( PositioningStopTimeout, this ) ); |
|
348 } |
|
349 else |
|
350 { |
|
351 iLocationRecord->Stop(); |
|
352 } |
|
353 } |
|
354 |
|
355 // Always stop tracklog. |
|
356 StopTrackLogL(); |
|
357 } |
|
358 |
|
359 // -------------------------------------------------------------------------- |
|
360 // CLocationUtilityServer::StopRecording |
|
361 // -------------------------------------------------------------------------- |
|
362 // |
|
363 void CLocationManagerServer::StopRecording() |
|
364 { |
|
365 iLocationRecord->Stop(); |
|
366 delete iTimer; |
|
367 iTimer = NULL; |
|
368 } |
|
369 |
|
370 // -------------------------------------------------------------------------- |
|
371 // CLocationUtilityServer::PositioningStopTimeout |
|
372 // -------------------------------------------------------------------------- |
|
373 // |
|
374 TInt CLocationManagerServer::PositioningStopTimeout( TAny* aAny ) |
|
375 { |
|
376 CLocationManagerServer* self = STATIC_CAST( CLocationManagerServer*, aAny ); |
|
377 self->StopRecording(); |
|
378 |
|
379 return KErrNone; |
|
380 } |
|
381 |
|
382 // -------------------------------------------------------------------------- |
|
383 // CLocationManagerServer::GetLocationTrailState |
|
384 // -------------------------------------------------------------------------- |
|
385 // |
|
386 void CLocationManagerServer::GetLocationTrailState( RLocationTrail::TTrailState& aState ) |
|
387 { |
|
388 iLocationRecord->LocationTrailState( aState ); |
|
389 } |
|
390 |
|
391 // -------------------------------------------------------------------------- |
|
392 // CLocationManagerServer::AddNotificationRequestL |
|
393 // -------------------------------------------------------------------------- |
|
394 // |
|
395 void CLocationManagerServer::AddNotificationRequestL( const RMessage2& aNotifReq ) |
|
396 { |
|
397 LOG( "CLocationManagerServer::AddNotificationRequestL(), begin" ); |
|
398 iNotifReqs.AppendL( aNotifReq ); |
|
399 LOG( "CLocationManagerServer::AddNotificationRequestL(), end" ); |
|
400 } |
|
401 |
|
402 // -------------------------------------------------------------------------- |
|
403 // CLocationManagerServer::AddTrackLogNotificationRequestL |
|
404 // -------------------------------------------------------------------------- |
|
405 // |
|
406 void CLocationManagerServer::AddTrackLogNotificationRequestL( const RMessage2& aNotifReq ) |
|
407 { |
|
408 iTrackLogNotifyReqs.AppendL( aNotifReq ); |
|
409 } |
|
410 |
|
411 // -------------------------------------------------------------------------- |
|
412 // CLocationManagerServer::CancelNotificationRequest |
|
413 // -------------------------------------------------------------------------- |
|
414 // |
|
415 void CLocationManagerServer::CancelNotificationRequest( const TInt aHandle ) |
|
416 { |
|
417 LOG( "CLocationManagerServer::CancelNotificationRequest(), begin" ); |
|
418 |
|
419 const TInt count = iNotifReqs.Count(); |
|
420 for ( TInt i = count; --i >= 0; ) |
|
421 { |
|
422 RMessage2& msg = iNotifReqs[i]; |
|
423 |
|
424 if( msg.IsNull() ) |
|
425 { |
|
426 iNotifReqs.Remove(i); |
|
427 continue; |
|
428 } |
|
429 |
|
430 if ( msg.Handle() == aHandle ) |
|
431 { |
|
432 msg.Complete( KErrCancel ); |
|
433 iNotifReqs.Remove(i); |
|
434 break; |
|
435 } |
|
436 } |
|
437 LOG( "CLocationManagerServer::CancelNotificationRequest(), end" ); |
|
438 } |
|
439 |
|
440 // -------------------------------------------------------------------------- |
|
441 // CLocationManagerServer::GetLocationByTimeL |
|
442 // -------------------------------------------------------------------------- |
|
443 // |
|
444 void CLocationManagerServer::GetLocationByTimeL( const TTime& aTimeStamp, |
|
445 TLocationData& aLocationData, |
|
446 TLocTrailState& aState ) |
|
447 { |
|
448 iLocationRecord->GetLocationByTimeL( aTimeStamp, |
|
449 aLocationData, |
|
450 aState ); |
|
451 } |
|
452 |
|
453 // -------------------------------------------------------------------------- |
|
454 // CLocationManagerServer::RequestCurrentLocationL |
|
455 // -------------------------------------------------------------------------- |
|
456 // |
|
457 void CLocationManagerServer::RequestCurrentLocationL( const RMessage2& aCurrLocReq ) |
|
458 { |
|
459 iLocationReqs.AppendL( aCurrLocReq ); |
|
460 iLocationRecord->RequestLocationL(); |
|
461 } |
|
462 |
|
463 // -------------------------------------------------------------------------- |
|
464 // CLocationManagerServer::CancelLocationRequest |
|
465 // -------------------------------------------------------------------------- |
|
466 // |
|
467 void CLocationManagerServer::CancelLocationRequest( const TInt aHandle ) |
|
468 { |
|
469 LOG( "CLocationManagerServer::CancelLocationRequest(), begin" ); |
|
470 |
|
471 const TInt count = iLocationReqs.Count(); |
|
472 for ( TInt i = count; --i >= 0; ) |
|
473 { |
|
474 RMessage2& msg = iLocationReqs[i]; |
|
475 |
|
476 if( msg.IsNull() ) |
|
477 { |
|
478 iLocationReqs.Remove(i); |
|
479 continue; |
|
480 } |
|
481 |
|
482 if ( msg.Handle() == aHandle ) |
|
483 { |
|
484 msg.Complete( KErrCancel ); |
|
485 iLocationReqs.Remove(i); |
|
486 break; |
|
487 } |
|
488 } |
|
489 if ( !iLocationReqs.Count() ) |
|
490 { |
|
491 iLocationRecord->CancelLocationRequest(); |
|
492 } |
|
493 LOG( "CLocationManagerServer::CancelLocationRequest(), end" ); |
|
494 } |
|
495 |
|
496 // -------------------------------------------------------------------------- |
|
497 // CLocationManagerServer::GetCurrentCellId |
|
498 // -------------------------------------------------------------------------- |
|
499 // |
|
500 void CLocationManagerServer::GetCurrentNetworkInfo( CTelephony::TNetworkInfoV1& aNetworkInfo ) |
|
501 { |
|
502 iLocationRecord->GetNetworkInfo( aNetworkInfo ); |
|
503 } |
|
504 |
|
505 // -------------------------------------------------------------------------- |
|
506 // CLocationManagerServer::LocationTrailStateChange |
|
507 // -------------------------------------------------------------------------- |
|
508 // |
|
509 void CLocationManagerServer::LocationTrailStateChange() |
|
510 { |
|
511 LOG( "CLocationManagerServer::LocationTrailStateChange(), begin" ); |
|
512 |
|
513 for ( TInt i = iNotifReqs.Count(); --i >= 0; ) |
|
514 { |
|
515 RMessage2& msg = iNotifReqs[i]; |
|
516 |
|
517 if( !msg.IsNull() ) |
|
518 { |
|
519 msg.Complete( KErrNone ); |
|
520 } |
|
521 } |
|
522 iNotifReqs.Reset(); |
|
523 LOG( "CLocationManagerServer::LocationTrailStateChange(), end" ); |
|
524 } |
|
525 |
|
526 // -------------------------------------------------------------------------- |
|
527 // CLocationManagerServer::CurrentLocation |
|
528 // -------------------------------------------------------------------------- |
|
529 // |
|
530 void CLocationManagerServer::CurrentLocation( const TPositionSatelliteInfo& aSatelliteInfo, |
|
531 const CTelephony::TNetworkInfoV1& aNetworkInfo, |
|
532 const TInt aError ) |
|
533 { |
|
534 LOG( "CLocationManagerServer::CurrentLocation(), begin" ); |
|
535 const TInt KParamLocationData = 0; |
|
536 |
|
537 TLocationData locationData; |
|
538 aSatelliteInfo.GetPosition( locationData.iPosition ); |
|
539 aSatelliteInfo.GetCourse( locationData.iCourse ); |
|
540 locationData.iNetworkInfo = aNetworkInfo; |
|
541 locationData.iSatellites = aSatelliteInfo.NumSatellitesUsed(); |
|
542 |
|
543 TPckg<TLocationData> wrapLocationData( locationData ); |
|
544 |
|
545 if ( aError == KErrNone ) |
|
546 { |
|
547 for ( TInt i = iLocationReqs.Count(); --i >= 0; ) |
|
548 { |
|
549 RMessage2& msg = iLocationReqs[i]; |
|
550 |
|
551 if( !msg.IsNull() ) |
|
552 { |
|
553 TInt err = msg.Write( KParamLocationData, wrapLocationData ); |
|
554 LOG1( "CLocationManagerServer::CurrentLocation() location data written with error:%d", err); |
|
555 msg.Complete( err ); |
|
556 } |
|
557 } |
|
558 } |
|
559 else |
|
560 { |
|
561 for ( TInt i = iLocationReqs.Count(); --i >= 0; ) |
|
562 { |
|
563 RMessage2& msg = iLocationReqs[i]; |
|
564 |
|
565 LOG1( "CLocationManagerServer::CurrentLocation() completed with error:%d", aError); |
|
566 |
|
567 if( !msg.IsNull() ) |
|
568 { |
|
569 msg.Complete( aError ); |
|
570 } |
|
571 } |
|
572 } |
|
573 |
|
574 iLocationReqs.Reset(); |
|
575 |
|
576 LOG( "CLocationManagerServer::CurrentLocation(), end" ); |
|
577 } |
|
578 |
|
579 void CLocationManagerServer::GPSSignalQualityChanged( const TPositionSatelliteInfo& aSatelliteInfo ) |
|
580 { |
|
581 LOG( "CLocationManagerServer::GPSSignalQualityChanged" ); |
|
582 const TInt KFixParam = 0; |
|
583 const TInt KPositionInfoParam = 1; |
|
584 const TInt KEventTypeParam = 2; |
|
585 TBool fix( ETrue ); |
|
586 TPosition tmpPosition; |
|
587 TEventTypes eventType = ESignalChanged; |
|
588 |
|
589 TPckg<TPositionSatelliteInfo> wrapSatelliteInfo( aSatelliteInfo ); |
|
590 TPckg<TBool> wrapFix( fix ); |
|
591 TPckg<TEventTypes> wrapEventType( eventType ); |
|
592 |
|
593 aSatelliteInfo.GetPosition( tmpPosition ); |
|
594 if ( Math::IsNaN( tmpPosition.Latitude() ) || Math::IsNaN( tmpPosition.Longitude() ) ) |
|
595 { |
|
596 fix = EFalse; |
|
597 LOG( "CLocationManagerServer::GPSSignalQualityChanged - no GPS fix"); |
|
598 } |
|
599 |
|
600 TInt error( KErrNone ); |
|
601 const TInt count = iTrackLogNotifyReqs.Count(); |
|
602 for ( TInt i( count ); --i >= 0; ) |
|
603 { |
|
604 RMessage2& msg = iTrackLogNotifyReqs[i]; |
|
605 |
|
606 if( !msg.IsNull() ) |
|
607 { |
|
608 LOG1( "CLocationManagerServer::GPSSignalQualityChanged request %d", i ); |
|
609 error = msg.Write( KFixParam, wrapFix ); |
|
610 if( KErrNone == error ) |
|
611 { |
|
612 error = msg.Write( KPositionInfoParam, wrapSatelliteInfo ); |
|
613 if( KErrNone == error ) |
|
614 { |
|
615 error = msg.Write( KEventTypeParam, wrapEventType ); |
|
616 } |
|
617 } |
|
618 LOG1( "CLocationManagerServer::GPSSignalQualityChanged error: %d", error ); |
|
619 msg.Complete( error ); |
|
620 } |
|
621 } |
|
622 iTrackLogNotifyReqs.Reset(); |
|
623 } |
|
624 |
|
625 |
|
626 |
|
627 void CLocationManagerServer::CancelTrackLogNotificationRequest( const TInt aHandle ) |
|
628 { |
|
629 LOG( "CLocationManagerServer::CancelTrackLogNotificationRequest(), begin" ); |
|
630 |
|
631 const TInt count = iTrackLogNotifyReqs.Count(); |
|
632 for ( TInt i(count); --i >= 0; ) |
|
633 { |
|
634 RMessage2& msg = iTrackLogNotifyReqs[i]; |
|
635 |
|
636 if( msg.IsNull() ) |
|
637 { |
|
638 iTrackLogNotifyReqs.Remove(i); |
|
639 continue; |
|
640 } |
|
641 |
|
642 if ( msg.Handle() == aHandle ) |
|
643 { |
|
644 msg.Complete( KErrCancel ); |
|
645 iTrackLogNotifyReqs.Remove(i); |
|
646 break; |
|
647 } |
|
648 } |
|
649 |
|
650 LOG( "CLocationManagerServer::CancelTrackLogNotificationRequest(), end" ); |
|
651 } |
|
652 |
|
653 void CLocationManagerServer::CreateLocationObjectL( const TLocationData& aLocationData, |
|
654 const TUint& aObjectId ) |
|
655 { |
|
656 if ( !IsSessionReady() ) |
|
657 { |
|
658 User::Leave( KErrNotReady ); |
|
659 } |
|
660 |
|
661 iLocationRecord->CreateLocationObjectL( aLocationData, aObjectId ); |
|
662 } |
|
663 |
|
664 void CLocationManagerServer::LocationSnapshotL( const TUint& aObjectId ) |
|
665 { |
|
666 if ( !IsSessionReady() ) |
|
667 { |
|
668 User::Leave( KErrNotReady ); |
|
669 } |
|
670 iLocationRecord->LocationSnapshotL( aObjectId ); |
|
671 } |
|
672 |
|
673 // -------------------------------------------------------------------------- |
|
674 // CLocationManagerServer::RemoveLocationObjectL |
|
675 // -------------------------------------------------------------------------- |
|
676 // |
|
677 void CLocationManagerServer::RemoveLocationObjectL(TUint& aObjectId) |
|
678 { |
|
679 if ( !IsSessionReady() ) |
|
680 { |
|
681 User::Leave( KErrNotReady ); |
|
682 } |
|
683 |
|
684 CMdENamespaceDef& namespaceDef = iMdeSession->GetDefaultNamespaceDefL(); |
|
685 |
|
686 iRelationQuery = iMdeSession->NewRelationQueryL( namespaceDef, this ); |
|
687 iRelationQuery->SetResultMode( EQueryResultModeId ); |
|
688 iRelationQuery->Conditions().SetOperator( ELogicConditionOperatorAnd ); |
|
689 |
|
690 CMdERelationCondition& filterCondLeft = iRelationQuery->Conditions().AddRelationConditionL( |
|
691 ERelationConditionSideLeft ); |
|
692 |
|
693 // The left object in relation must have this ID. |
|
694 filterCondLeft.LeftL().AddObjectConditionL( aObjectId ); |
|
695 |
|
696 // Right object in relation must be a location object. |
|
697 CMdERelationCondition& filterCondRight = iRelationQuery->Conditions().AddRelationConditionL( |
|
698 ERelationConditionSideRight ); |
|
699 CMdEObjectDef& rightObjDef = namespaceDef.GetObjectDefL( Location::KLocationObject ); |
|
700 filterCondRight.RightL().AddObjectConditionL( rightObjDef ); |
|
701 |
|
702 iRemoveLocation = ETrue; |
|
703 iRelationQuery->FindL( 1, 1 ); |
|
704 } |
|
705 |
|
706 void CLocationManagerServer::CopyLocationObjectL( TItemId aSource, |
|
707 const RArray<TItemId>& aTargets, TMessageQuery& aMessageQuery ) |
|
708 { |
|
709 if( aTargets.Count() <= 0 ) |
|
710 { |
|
711 aMessageQuery.iMessage.Complete( KErrNotFound ); |
|
712 return; |
|
713 } |
|
714 |
|
715 if ( !IsSessionReady() ) |
|
716 { |
|
717 User::Leave( KErrNotReady ); |
|
718 } |
|
719 |
|
720 CMdENamespaceDef& namespaceDef = iMdeSession->GetDefaultNamespaceDefL(); |
|
721 |
|
722 TMdEObject obj; |
|
723 iMdeSession->CheckObjectL( obj, aSource, &namespaceDef ); |
|
724 |
|
725 aMessageQuery.iQuery = iMdeSession->NewRelationQueryL( namespaceDef, this ); |
|
726 aMessageQuery.iQuery->SetResultMode( EQueryResultModeItem ); |
|
727 aMessageQuery.iQuery->Conditions().SetOperator( ELogicConditionOperatorAnd ); |
|
728 |
|
729 CMdERelationCondition& filterCondLeft = aMessageQuery.iQuery->Conditions() |
|
730 .AddRelationConditionL( ERelationConditionSideLeft ); |
|
731 |
|
732 // The left object in relation must have this ID. |
|
733 filterCondLeft.LeftL().AddObjectConditionL( aSource ); |
|
734 |
|
735 // Right object in relation must be a location object. |
|
736 CMdERelationCondition& filterCondRight = aMessageQuery.iQuery->Conditions() |
|
737 .AddRelationConditionL( ERelationConditionSideRight ); |
|
738 CMdEObjectDef& rightObjDef = namespaceDef.GetObjectDefL( Location::KLocationObject ); |
|
739 filterCondRight.RightL().AddObjectConditionL( rightObjDef ); |
|
740 |
|
741 if( iTargetObjectIds.Count() <= 0 ) |
|
742 { |
|
743 TInt err = 0; |
|
744 const TInt count = aTargets.Count(); |
|
745 for( TInt i = 0 ; i < count ; i++ ) |
|
746 { |
|
747 TRAP( err, iMdeSession->CheckObjectL( obj, aTargets[i], &namespaceDef ) ); |
|
748 if ( err == KErrNone ) |
|
749 { |
|
750 iTargetObjectIds.AppendL( aTargets[i] ); |
|
751 } |
|
752 } |
|
753 } |
|
754 |
|
755 iCopyReqs.AppendL( aMessageQuery ); |
|
756 |
|
757 if ( iTargetObjectIds.Count() > 0 ) |
|
758 { |
|
759 aMessageQuery.iQuery->FindL( 1, 1 ); |
|
760 } |
|
761 else |
|
762 { |
|
763 aMessageQuery.iMessage.Complete( KErrNotFound ); |
|
764 iCopyReqs.Remove( iCopyReqs.Find( aMessageQuery ) ); |
|
765 } |
|
766 } |
|
767 |
|
768 void CLocationManagerServer::CopyLocationObjectL( const TDesC& aSource, |
|
769 const RArray<TPtrC>& aTargets, TMessageQuery& aQuery ) |
|
770 { |
|
771 CMdENamespaceDef& namespaceDef = iMdeSession->GetDefaultNamespaceDefL(); |
|
772 TMdEObject obj; |
|
773 iMdeSession->CheckObjectL( obj, aSource, &namespaceDef ); |
|
774 TItemId source = obj.Id(); |
|
775 const TInt count = aTargets.Count(); |
|
776 TInt err = 0; |
|
777 for( TInt i = 0; i < count; i++ ) |
|
778 { |
|
779 TRAP(err, iMdeSession->CheckObjectL( obj, aTargets[i], &namespaceDef )); |
|
780 if( err == KErrNone ) |
|
781 { |
|
782 iTargetObjectIds.AppendL( obj.Id() ); |
|
783 } |
|
784 } |
|
785 |
|
786 CopyLocationObjectL( source, iTargetObjectIds, aQuery ); |
|
787 } |
|
788 |
|
789 void CLocationManagerServer::HandleQueryNewResults( CMdEQuery& /*aQuery*/, |
|
790 TInt /*aFirstNewItemIndex*/, TInt /*aNewItemCount*/ ) |
|
791 { |
|
792 } |
|
793 |
|
794 void CLocationManagerServer::HandleQueryCompleted( CMdEQuery& aQuery, TInt aError ) |
|
795 { |
|
796 if ( iRemoveLocation ) |
|
797 { |
|
798 if( aQuery.Count() > 0 && aError == KErrNone ) |
|
799 { |
|
800 TRAPD( err, iMdeSession->RemoveRelationL( aQuery.ResultId( 0 ), &aQuery.NamespaceDef() ) ); |
|
801 if ( err != KErrNone ) |
|
802 { |
|
803 LOG1( "CLocationManagerServer::HandleQueryCompleted error: %d", err ); |
|
804 } |
|
805 } |
|
806 |
|
807 iRemoveLocation = EFalse; |
|
808 } |
|
809 else |
|
810 { |
|
811 // When results CopyLocationL handles completion of message |
|
812 if( aQuery.Count() > 0 && aError == KErrNone ) |
|
813 { |
|
814 TRAP_IGNORE( CopyLocationL( aQuery ) ); |
|
815 } |
|
816 // otherwise find correct message and complete it |
|
817 else |
|
818 { |
|
819 for ( TInt i = iCopyReqs.Count() - 1; i >= 0; --i ) |
|
820 { |
|
821 if ( iCopyReqs[i].iQuery == &aQuery ) |
|
822 { |
|
823 if( aError == KErrNone ) |
|
824 { |
|
825 aError = KErrNotFound; |
|
826 } |
|
827 iCopyReqs[i].iMessage.Complete( aError ); |
|
828 delete iCopyReqs[i].iQuery; |
|
829 iCopyReqs.Remove( i ); |
|
830 break; |
|
831 } |
|
832 } |
|
833 } |
|
834 } |
|
835 |
|
836 iTargetObjectIds.Reset(); |
|
837 } |
|
838 |
|
839 void CLocationManagerServer::CopyLocationL( CMdEQuery& aQuery ) |
|
840 { |
|
841 CMdEObjectDef& locationDef = aQuery.NamespaceDef().GetObjectDefL( Location::KLocationObject ); |
|
842 |
|
843 CMdERelation& result = static_cast<CMdERelation&>( aQuery.ResultItem( 0 ) ); |
|
844 TItemId rightId = result.RightObjectId(); |
|
845 CMdEObject* sourceLocation = iMdeSession->GetObjectL( rightId, locationDef ); |
|
846 CleanupStack::PushL( sourceLocation ); |
|
847 |
|
848 // "contains" relation definition |
|
849 CMdERelationDef& containsRelDef = aQuery.NamespaceDef().GetRelationDefL( |
|
850 Relations::KContainsLocation ); |
|
851 |
|
852 const TInt count = iTargetObjectIds.Count(); |
|
853 for( TInt i=0;i<count;i++ ) |
|
854 { |
|
855 CMdERelation* relationObject = iMdeSession->NewRelationLC( containsRelDef, iTargetObjectIds[i], |
|
856 rightId, 0 ); |
|
857 |
|
858 iMdeSession->AddRelationL( *relationObject ); |
|
859 |
|
860 CleanupStack::PopAndDestroy( relationObject ); |
|
861 } |
|
862 CleanupStack::PopAndDestroy( sourceLocation ); |
|
863 |
|
864 for ( TInt i = iCopyReqs.Count() - 1; i >= 0; --i ) |
|
865 { |
|
866 if ( iCopyReqs[i].iQuery == &aQuery ) |
|
867 { |
|
868 iCopyReqs[i].iMessage.Complete( KErrNone ); |
|
869 delete iCopyReqs[i].iQuery; |
|
870 iCopyReqs.Remove( i ); |
|
871 break; |
|
872 } |
|
873 } |
|
874 } |
|
875 |
|
876 void CLocationManagerServer::InitCopyLocationByIdL( const RMessage2& aMessage ) |
|
877 { |
|
878 const TInt KParamSourceId = 0; |
|
879 const TInt KParamTargetIds = 1; |
|
880 TItemId sourceId = 0; |
|
881 RArray<TItemId> targetIds; |
|
882 CleanupClosePushL(targetIds); |
|
883 |
|
884 // read TUint& aSourceId from request |
|
885 TPckg<TItemId> locSourceId( sourceId ); |
|
886 aMessage.ReadL(KParamSourceId, locSourceId); |
|
887 |
|
888 const TInt KParamTargetIdsLength = aMessage.GetDesLength( KParamTargetIds ); |
|
889 LOG1("CLocationManagerServer::InitCopyLocationL KParamTargetIdsLength:%d", KParamTargetIdsLength); |
|
890 if ( KParamTargetIdsLength > 0 ) |
|
891 { |
|
892 HBufC8* paramBuf = HBufC8::NewLC( KParamTargetIdsLength ); |
|
893 TPtr8 ptr( paramBuf->Des() ); |
|
894 aMessage.ReadL( KParamTargetIds, ptr ); |
|
895 |
|
896 DeserializeArrayL( ptr, targetIds ); |
|
897 |
|
898 TMessageQuery q( NULL, aMessage ); |
|
899 |
|
900 LOG1("CLocationManagerServer::InitCopyLocationL ID count:%d", targetIds.Count()); |
|
901 |
|
902 CopyLocationObjectL( sourceId, targetIds, q ); |
|
903 |
|
904 CleanupStack::PopAndDestroy(paramBuf); |
|
905 } |
|
906 CleanupStack::PopAndDestroy(&targetIds); |
|
907 } |
|
908 |
|
909 void CLocationManagerServer::InitCopyLocationByURIL( const RMessage2& aMessage ) |
|
910 { |
|
911 LOG( "CLocationManagerSession::CopyLocationDataByUriL begin" ); |
|
912 const TInt KParamSourceUri = 0; |
|
913 const TInt KParamTargetUris = 1; |
|
914 |
|
915 const TInt KParamSourceLength = aMessage.GetDesLength(KParamSourceUri); |
|
916 if (KParamSourceLength > 0) |
|
917 { |
|
918 // read TDesC& aSourceURI from request |
|
919 HBufC* sourceUriBuf = HBufC::NewLC( KParamSourceLength ); |
|
920 TPtr ptrSource( sourceUriBuf->Des() ); |
|
921 aMessage.ReadL( KParamSourceUri, ptrSource ); |
|
922 |
|
923 const TInt KParamTargetUrisLength = aMessage.GetDesLength( KParamTargetUris ); |
|
924 LOG1("CLocationManagerSession::CopyLocationDataByUriL KParamTargetUrisLength:%d", KParamTargetUrisLength); |
|
925 if ( KParamTargetUrisLength > 0 ) |
|
926 { |
|
927 RArray<TPtrC> targetUris; |
|
928 CleanupClosePushL(targetUris); |
|
929 |
|
930 CMdCSerializationBuffer* uriBuffer = CMdCSerializationBuffer::NewLC( aMessage, KParamTargetUris ); |
|
931 |
|
932 TInt32 uriCount = 0; |
|
933 uriBuffer->ReceiveL( uriCount ); |
|
934 |
|
935 targetUris.ReserveL( uriCount ); |
|
936 |
|
937 // deserialize URIs |
|
938 for( TInt i = 0; i < uriCount; i++ ) |
|
939 { |
|
940 targetUris.Append( uriBuffer->ReceivePtr16L() ); |
|
941 } |
|
942 |
|
943 LOG1("CLocationManagerSession::CopyLocationDataByUriL ID count:%d", targetUris.Count()); |
|
944 |
|
945 TMessageQuery q( NULL, aMessage ); |
|
946 |
|
947 CopyLocationObjectL( sourceUriBuf->Des(), targetUris, q ); |
|
948 |
|
949 CleanupStack::PopAndDestroy( uriBuffer ); |
|
950 CleanupStack::PopAndDestroy( &targetUris ); |
|
951 } |
|
952 CleanupStack::PopAndDestroy( sourceUriBuf ); |
|
953 } |
|
954 |
|
955 LOG( "CLocationManagerSession::CopyLocationDataByUriL end" ); |
|
956 } |
|
957 |
|
958 TItemId CLocationManagerServer::StartTrackLogL() |
|
959 { |
|
960 if ( iTrackLog->IsRecording() ) |
|
961 { |
|
962 User::Leave( KErrInUse ); |
|
963 } |
|
964 |
|
965 iTagId = CreateTrackLogTagL(); |
|
966 iTrackLog->StartRecordingL( iTagId ); |
|
967 |
|
968 StartListeningObjectCreationsL(); |
|
969 StartListeningTagRemovalsL(); |
|
970 |
|
971 CompleteNotifyRequest( EStarted, KErrNone ); |
|
972 |
|
973 return iTagId; |
|
974 } |
|
975 |
|
976 void CLocationManagerServer::StopTrackLogL() |
|
977 { |
|
978 if ( iTrackLog->IsRecording() ) |
|
979 { |
|
980 iTrackLog->StopRecordingL(); |
|
981 |
|
982 CompleteNotifyRequest( EStopped, KErrNone ); |
|
983 |
|
984 // stop observers |
|
985 TRAP_IGNORE( iMdeSession->RemoveObjectObserverL( *this, &iMdeSession->GetDefaultNamespaceDefL()) ); |
|
986 TRAP_IGNORE( iMdeSession->RemoveObjectObserverL( *this, &iMdeSession->GetDefaultNamespaceDefL()) ); |
|
987 } |
|
988 } |
|
989 |
|
990 void CLocationManagerServer::CompleteNotifyRequest( TEventTypes aEventType, TInt aError ) |
|
991 { |
|
992 const TInt KEventTypeParam = 2; |
|
993 TPckg<TEventTypes> wrapEventType( aEventType ); |
|
994 |
|
995 const TInt count = iTrackLogNotifyReqs.Count(); |
|
996 for ( TInt i( count ); --i >= 0; ) |
|
997 { |
|
998 RMessage2& msg = iTrackLogNotifyReqs[i]; |
|
999 |
|
1000 if( !msg.IsNull() ) |
|
1001 { |
|
1002 msg.Write( KEventTypeParam, wrapEventType ); |
|
1003 msg.Complete( aError ); |
|
1004 } |
|
1005 } |
|
1006 iTrackLogNotifyReqs.Reset(); |
|
1007 } |
|
1008 |
|
1009 void CLocationManagerServer::IsTrackLogRecording( TBool &aRec ) |
|
1010 { |
|
1011 aRec = iTrackLog->IsRecording(); |
|
1012 } |
|
1013 |
|
1014 void CLocationManagerServer::GpxFileCreated( const TDesC& aFileName, TItemId aTagId, |
|
1015 TReal32 aLength, TTime aStart, TTime aEnd ) |
|
1016 { |
|
1017 TRAP_IGNORE( CreateTrackLogL( aTagId, aFileName, aLength, aStart, aEnd ) ); |
|
1018 } |
|
1019 |
|
1020 TItemId CLocationManagerServer::CreateTrackLogTagL() |
|
1021 { |
|
1022 if ( !IsSessionReady() ) |
|
1023 { |
|
1024 User::Leave( KErrNotReady ); |
|
1025 } |
|
1026 |
|
1027 CMdEObjectDef& trackLogTagDef = iMdeSession->GetDefaultNamespaceDefL() |
|
1028 .GetObjectDefL( Tag::KTagObject ); |
|
1029 |
|
1030 CMdEObject* trackLogTag = iMdeSession->NewObjectLC( trackLogTagDef, KNullDesC ); |
|
1031 |
|
1032 // Mandatory parameters for any object. |
|
1033 CMdEPropertyDef& creationDef = trackLogTagDef.GetPropertyDefL( Object::KCreationDateProperty ); |
|
1034 CMdEPropertyDef& modifiedDef = trackLogTagDef.GetPropertyDefL( Object::KLastModifiedDateProperty ); |
|
1035 CMdEPropertyDef& sizeDef = trackLogTagDef.GetPropertyDefL( Object::KSizeProperty ); |
|
1036 CMdEPropertyDef& itemTypeDef = trackLogTagDef.GetPropertyDefL( Object::KItemTypeProperty ); |
|
1037 |
|
1038 TTime timestamp( 0 ); |
|
1039 timestamp.UniversalTime(); |
|
1040 |
|
1041 // required object properties |
|
1042 trackLogTag->AddTimePropertyL( creationDef, timestamp ); |
|
1043 trackLogTag->AddTimePropertyL( modifiedDef, timestamp ); |
|
1044 trackLogTag->AddUint32PropertyL( sizeDef, 0 ); |
|
1045 trackLogTag->AddTextPropertyL( itemTypeDef, Tag::KTagItemType ); |
|
1046 |
|
1047 TItemId tagId = iMdeSession->AddObjectL( *trackLogTag ); |
|
1048 |
|
1049 CleanupStack::PopAndDestroy( trackLogTag ); |
|
1050 |
|
1051 return tagId; |
|
1052 } |
|
1053 |
|
1054 void CLocationManagerServer::CreateTrackLogL( TItemId aTagId, const TDesC& aUri, TReal32 aLength, |
|
1055 TTime aStart, TTime aEnd ) |
|
1056 { |
|
1057 if ( !IsSessionReady() ) |
|
1058 { |
|
1059 User::Leave( KErrNotReady ); |
|
1060 } |
|
1061 |
|
1062 CMdEObjectDef& trackLogDef = iMdeSession->GetDefaultNamespaceDefL().GetObjectDefL( |
|
1063 TrackLog::KTrackLogObject ); |
|
1064 |
|
1065 CMdEObject* trackLog = iMdeSession->NewObjectLC( trackLogDef, aUri ); |
|
1066 |
|
1067 // Mandatory parameters for any object. |
|
1068 CMdEPropertyDef& creationDef = trackLogDef.GetPropertyDefL( Object::KCreationDateProperty ); |
|
1069 CMdEPropertyDef& modifiedDef = trackLogDef.GetPropertyDefL( Object::KLastModifiedDateProperty ); |
|
1070 CMdEPropertyDef& sizeDef = trackLogDef.GetPropertyDefL( Object::KSizeProperty ); |
|
1071 CMdEPropertyDef& itemTypeDef = trackLogDef.GetPropertyDefL( Object::KItemTypeProperty ); |
|
1072 |
|
1073 // Tracklog specific properties. |
|
1074 CMdEPropertyDef& lengthDef = trackLogDef.GetPropertyDefL( TrackLog::KLengthProperty ); |
|
1075 CMdEPropertyDef& startTimeDef = trackLogDef.GetPropertyDefL( TrackLog::KStartTimeProperty ); |
|
1076 CMdEPropertyDef& stopTimeDef = trackLogDef.GetPropertyDefL( TrackLog::KStopTimeProperty ); |
|
1077 |
|
1078 TTime timestamp( 0 ); |
|
1079 timestamp.UniversalTime(); |
|
1080 |
|
1081 trackLog->AddTimePropertyL( creationDef, timestamp ); |
|
1082 trackLog->AddTimePropertyL( modifiedDef, timestamp ); |
|
1083 trackLog->AddUint32PropertyL( sizeDef, 0 ); |
|
1084 trackLog->AddTextPropertyL( itemTypeDef, TrackLog::KTrackLogItemType ); |
|
1085 trackLog->AddUint32PropertyL( lengthDef, TUint32( aLength )); |
|
1086 trackLog->AddTimePropertyL( startTimeDef, aStart ); |
|
1087 trackLog->AddTimePropertyL( stopTimeDef, aEnd ); |
|
1088 |
|
1089 TItemId trackLogId = iMdeSession->AddObjectL( *trackLog ); |
|
1090 |
|
1091 CMdERelationDef& containsRelDef = iMdeSession->GetDefaultNamespaceDefL().GetRelationDefL( |
|
1092 Relations::KContains ); |
|
1093 |
|
1094 CMdERelation* relationObject = iMdeSession->NewRelationLC( containsRelDef, aTagId, |
|
1095 trackLogId, 0 ); |
|
1096 |
|
1097 iMdeSession->AddRelationL( *relationObject ); |
|
1098 |
|
1099 CleanupStack::PopAndDestroy( relationObject ); |
|
1100 CleanupStack::PopAndDestroy( trackLog ); |
|
1101 } |
|
1102 |
|
1103 TInt CLocationManagerServer::GetTrackLogStatus( TBool& aRecording, TPositionSatelliteInfo& aFixQuality) |
|
1104 { |
|
1105 if ( !iTrackLog ) |
|
1106 { |
|
1107 return KErrNotFound; |
|
1108 } |
|
1109 |
|
1110 iTrackLog->GetStatus( aRecording, aFixQuality ); |
|
1111 |
|
1112 return KErrNone; |
|
1113 } |
|
1114 |
|
1115 TInt CLocationManagerServer::DeleteTrackLogL( const TDesC& aUri ) |
|
1116 { |
|
1117 LOG( "CLocationManagerServer::DeleteTrackLogL enter" ); |
|
1118 |
|
1119 // remove tracklog mde object |
|
1120 CMdEObject* mdeObject = iMdeSession->GetObjectL( aUri ); |
|
1121 if ( mdeObject ) |
|
1122 { |
|
1123 TItemId objectId = mdeObject->Id(); |
|
1124 delete mdeObject; |
|
1125 |
|
1126 TTime time( 0 ); |
|
1127 CMdENamespaceDef& nsDef = iMdeSession->GetDefaultNamespaceDefL(); |
|
1128 CMdEEventDef& eventDef = nsDef.GetEventDefL( MdeConstants::Events::KDeleted ); |
|
1129 |
|
1130 iMdeSession->RemoveObjectL( aUri, &nsDef ); |
|
1131 time.UniversalTime(); |
|
1132 CMdEEvent* event = iMdeSession->NewEventL( eventDef, objectId, time,NULL,NULL ); |
|
1133 CleanupStack::PushL( event ); |
|
1134 |
|
1135 iMdeSession->AddEventL( *event ); |
|
1136 CleanupStack::PopAndDestroy( event ); |
|
1137 } |
|
1138 |
|
1139 // remove file from filesystem |
|
1140 RFs fs; |
|
1141 TInt err; |
|
1142 err = fs.Connect(); |
|
1143 if ( err == KErrNone ) |
|
1144 { |
|
1145 err = fs.Delete( aUri ); |
|
1146 fs.Close(); |
|
1147 } |
|
1148 |
|
1149 LOG( "CLocationManagerServer::DeleteTrackLogL return" ); |
|
1150 |
|
1151 return err; |
|
1152 } |
|
1153 |
|
1154 TInt CLocationManagerServer::TrackLogName( TFileName& aFileName ) |
|
1155 { |
|
1156 if ( iTrackLog->IsRecording() ) |
|
1157 { |
|
1158 iTrackLog->GetTrackLogName(aFileName); |
|
1159 return KErrNone; |
|
1160 } |
|
1161 return KErrNotFound; |
|
1162 } |
|
1163 |
|
1164 void CLocationManagerServer::GetCaptureSetting( RLocationTrail::TTrailCaptureSetting& aCaptureSetting ) |
|
1165 { |
|
1166 aCaptureSetting = iCaptureSetting; |
|
1167 } |
|
1168 |
|
1169 void CLocationManagerServer::HandleObjectNotification( CMdESession& /*aSession*/, |
|
1170 TObserverNotificationType aType, |
|
1171 const RArray<TItemId>& aObjectIdArray ) |
|
1172 { |
|
1173 // If notification type is remove then someone has deleted a tracklog tag. |
|
1174 if ( aType == ENotifyRemove ) |
|
1175 { |
|
1176 iTrackLog->CancelRecording(); |
|
1177 return; |
|
1178 } |
|
1179 |
|
1180 TRAP_IGNORE( LinkObjectToTrackLogTagL( aObjectIdArray ) ); |
|
1181 } |
|
1182 |
|
1183 void CLocationManagerServer::StartListeningTagRemovalsL() |
|
1184 { |
|
1185 if ( !IsSessionReady() ) |
|
1186 { |
|
1187 User::Leave( KErrNotReady ); |
|
1188 } |
|
1189 |
|
1190 // start listening to mde track log tag removals |
|
1191 CMdELogicCondition* condition = CMdELogicCondition::NewL( ELogicConditionOperatorAnd ); |
|
1192 CleanupStack::PushL( condition ); |
|
1193 iMdeSession->AddObjectObserverL( *this, condition, ENotifyRemove, |
|
1194 &iMdeSession->GetDefaultNamespaceDefL() ); |
|
1195 CleanupStack::Pop( condition ); |
|
1196 } |
|
1197 |
|
1198 void CLocationManagerServer::StartListeningObjectCreationsL() |
|
1199 { |
|
1200 if ( !IsSessionReady() ) |
|
1201 { |
|
1202 User::Leave( KErrNotReady ); |
|
1203 } |
|
1204 |
|
1205 CMdELogicCondition* condition = CMdELogicCondition::NewL( ELogicConditionOperatorAnd ); |
|
1206 CleanupStack::PushL( condition ); |
|
1207 |
|
1208 CMdEObjectDef& objDef = iMdeSession->GetDefaultNamespaceDefL().GetObjectDefL( |
|
1209 MediaObject::KMediaObject ); |
|
1210 |
|
1211 CMdEPropertyDef& originDef = objDef.GetPropertyDefL( Object::KOriginProperty ); |
|
1212 condition->AddPropertyConditionL( originDef, TMdEUintEqual( Object::ECamera )); |
|
1213 |
|
1214 CleanupStack::Pop( condition ); |
|
1215 iMdeSession->AddObjectObserverL( *this, condition, ENotifyAdd | ENotifyModify, |
|
1216 &iMdeSession->GetDefaultNamespaceDefL() ); |
|
1217 |
|
1218 } |
|
1219 |
|
1220 void CLocationManagerServer::LinkObjectToTrackLogTagL( const RArray<TItemId>& aObjectIdArray ) |
|
1221 { |
|
1222 CMdERelationDef& containsRelDef = iMdeSession->GetDefaultNamespaceDefL() |
|
1223 .GetRelationDefL( Relations::KContains ); |
|
1224 |
|
1225 const TInt count = aObjectIdArray.Count(); |
|
1226 for ( TInt i( 0 ); i < count; i++ ) |
|
1227 { |
|
1228 CMdERelation* relationObject = iMdeSession->NewRelationLC( containsRelDef, |
|
1229 aObjectIdArray[i], iTagId, 0 ); |
|
1230 |
|
1231 iMdeSession->AddRelationL( *relationObject ); |
|
1232 |
|
1233 CleanupStack::PopAndDestroy( relationObject ); |
|
1234 } |
|
1235 } |
|
1236 |
|
1237 void CLocationManagerServer::AddGpxObserver( MGpxConversionObserver* aObserver ) |
|
1238 { |
|
1239 iTrackLog->AddGpxObserver( aObserver ); |
|
1240 } |
|
1241 // End of file |