locationmanager/server/src/clocationmanagerserver.cpp
changeset 23 33ae025ac1e8
parent 21 50bf9db68373
child 25 8e4539ab1889
--- a/locationmanager/server/src/clocationmanagerserver.cpp	Fri Apr 16 15:23:55 2010 +0300
+++ b/locationmanager/server/src/clocationmanagerserver.cpp	Mon May 03 12:55:01 2010 +0300
@@ -155,6 +155,14 @@
         iLocManStopRemapDelay = KLocationTrailRemapShutdownDelay;
         }
     
+    TRAPD( error, iTimer = CPeriodic::NewL( CActive::EPriorityUserInput ) );    
+    if ( error != KErrNone )
+        {
+        LOG("CLocationManagerServer::ConstructL - iTimer not created");
+        iTimer = NULL;
+        }  
+    
+    
     LOG ("CLocationManagerServer::ConstructL() end");
     }
 
@@ -326,8 +334,7 @@
     
     if ( iTimer )
     	{
-    	delete iTimer;
-    	iTimer = NULL;
+    	iTimer->Cancel();
     	}
     
     iLocationRecord->StartL( aCaptureSetting );
@@ -348,19 +355,26 @@
      
     if( state != RLocationTrail::ETrailStopped && state != RLocationTrail::ETrailStopping )
         {
-        TRAPD( error, iTimer = CPeriodic::NewL( CActive::EPriorityUserInput ) );
-        
-        if ( error != KErrNone )
+        if(!iTimer)
             {
-            // If timer can't be created we stop the location trail immediately.
+            TRAPD( error, iTimer = CPeriodic::NewL( CActive::EPriorityUserInput ) );    
+            if ( error != KErrNone )
+                {
+                LOG("CLocationManagerServer::StopGPSPositioningL() - iTimer not created");
+                iTimer = NULL;
+                }
+            }        
+        if(iTimer)
+            {
+			iTimer->Cancel();
+            iLocationRecord->SetStateToStopping();
+            iTimer->Start( iLocManStopDelay * 1000000, 0, TCallBack( CheckForRemappingCallback, this ) );
+            }
+        else
+            {
             iLocationRecord->Stop();
-            StopTrackLogL();
-            return;
-            }   
-        
-        iLocationRecord->SetStateToStopping();
-        iTimer->Start( iLocManStopDelay * 1000000, 0, TCallBack( CheckForRemappingCallback, this ) );
-    	}
+            }
+        }
     
     // Always stop tracklog.
     StopTrackLogL();
@@ -375,8 +389,11 @@
     LOG( "CLocationManagerServer::StopRecording()" );    
     iWaitForPositioningStopTimeout = EFalse;
     iLocationRecord->Stop();		
-	delete iTimer;
-	iTimer = NULL;
+	if(iTimer)
+	    {
+        iTimer->Cancel();
+	    }
+	
 	}
 
 // --------------------------------------------------------------------------