[Location]Modified Stop() for StopBatch() functionality (#775)
authorsovalin <40753917+sovalin@users.noreply.github.com>
Mon, 15 Apr 2019 06:41:05 +0000 (12:11 +0530)
committerchanywa <cbible.kim@samsung.com>
Mon, 15 Apr 2019 06:41:05 +0000 (15:41 +0900)
* Modified code for StopBatch()

Signed-off-by: Susnata Sovalin <s.sovalin@samsung.com>
* Modified code for StopBatch()

Signed-off-by: Susnata Sovalin <s.sovalin@samsung.com>
* Modified code for StopBatch()

Signed-off-by: Susnata Sovalin <s.sovalin@samsung.com>
* Modified code for StopBatch()

Signed-off-by: Susnata Sovalin <s.sovalin@samsung.com>
src/Tizen.Location/Tizen.Location/Locator.cs

index 8a0c764..cfc54c1 100755 (executable)
@@ -43,6 +43,7 @@ namespace Tizen.Location
         private double _distance = 120.0;
         private bool _isEnableMock = false;
         private bool _disposed = false;
+        private bool _isBatchStarted;
         private IntPtr _handle;
         private LocationType _locationType;
         private Location _location = null;
@@ -321,7 +322,8 @@ namespace Tizen.Location
         public void Start()
         {
             Log.Info(Globals.LogTag, "Starting Location Manager");
-            if (_batchPeriod > 0 && _batchPeriod > _batchInterval)
+            _isBatchStarted = (_batchPeriod > 0 ) && (_batchPeriod > _batchInterval);
+            if (_isBatchStarted)
             {
                 int ret = Interop.Locator.StartBatch(_handle);
                 if (((LocationError)ret != LocationError.None))
@@ -352,13 +354,25 @@ namespace Tizen.Location
         public void Stop()
         {
             Log.Info(Globals.LogTag, "Stopping Location Manager");
-            int ret = Interop.Locator.Stop(_handle);
-            if (((LocationError)ret != LocationError.None))
+            if (_isBatchStarted)
             {
-                Log.Error(Globals.LogTag, "Error stopping Location Manager," + (LocationError)ret);
-                throw LocationErrorFactory.ThrowLocationException(ret);
+                int ret = Interop.Locator.StopBatch(_handle);
+                if (((LocationError)ret != LocationError.None))
+                {
+                    Log.Error(Globals.LogTag, "Error Stopping Location Batch mode," + (LocationError)ret);
+                    throw LocationErrorFactory.ThrowLocationException(ret);
+                }
             }
-       }
+            else
+            {
+                int ret = Interop.Locator.Stop(_handle);
+                if (((LocationError)ret != LocationError.None))
+                {
+                    Log.Error(Globals.LogTag, "Error stopping Location Manager," + (LocationError)ret);
+                    throw LocationErrorFactory.ThrowLocationException(ret);
+                }
+            } 
+        }
 
         /// <summary>
         /// Sets a mock location for the given location method.