Fix crashes 84/111684/3 accepted/tizen/common/20170124.181747 accepted/tizen/ivi/20170124.121049 accepted/tizen/mobile/20170124.121009 accepted/tizen/tv/20170124.121028 submit/tizen/20170123.231955
authorchanywa <cbible.kim@samsung.com>
Mon, 23 Jan 2017 10:58:35 +0000 (19:58 +0900)
committerchanywa <cbible.kim@samsung.com>
Mon, 23 Jan 2017 11:09:03 +0000 (20:09 +0900)
Change-Id: I296d9c698cec477138fda3cec68e7a11f5d661b9

Tizen.Location/Interop/Interop.Libraries.cs
Tizen.Location/Interop/Interop.Location.cs
Tizen.Location/Tizen.Location.project.json [changed mode: 0644->0755]
Tizen.Location/Tizen.Location/GpsSatellite.cs
Tizen.Location/Tizen.Location/Locator.cs
packaging/csapi-location.spec

index 211595b..7fd22e0 100755 (executable)
@@ -18,7 +18,7 @@ internal static partial class Interop
 {
     internal static partial class Libraries
     {
-        public const string Location = "libcapi-location-manager.so.0";
-        public const string Libc = "libc.so.6";
+        internal const string Location = "libcapi-location-manager.so.0";
+        internal const string Libc = "libc.so.6";
     }
 }
\ No newline at end of file
index 9998fbf..f1172b1 100755 (executable)
@@ -23,147 +23,160 @@ internal static partial class Interop
     internal static partial class Locator
     {
         [DllImport(Libraries.Location, EntryPoint = "location_manager_create")]
-        public static extern int Create(int locationMethod, out IntPtr handle);
+        internal static extern int Create(int locationMethod, out IntPtr handle);
 
         [DllImport(Libraries.Location, EntryPoint = "location_manager_destroy")]
-        public static extern int Destroy(IntPtr handle);
+        internal static extern int Destroy(IntPtr handle);
 
         [DllImport(Libraries.Location, EntryPoint = "location_manager_start")]
-        public static extern int Start(IntPtr handle);
+        internal static extern int Start(IntPtr handle);
 
         [DllImport(Libraries.Location, EntryPoint = "location_manager_stop")]
-        public static extern int Stop(IntPtr handle);
+        internal static extern int Stop(IntPtr handle);
 
         [DllImport(Libraries.Location, EntryPoint = "location_manager_enable_mock_location")]
-        public static extern int EnableMock(bool enable);
+        internal static extern int EnableMock(bool enable);
 
         [DllImport(Libraries.Location, EntryPoint = "location_manager_set_mock_location")]
-        public static extern int SetMockLocation(IntPtr handle, double latitude, double longitude, double altitude, double speed, double direction, double accuracy);
+        internal static extern int SetMockLocation(IntPtr handle, double latitude, double longitude, double altitude, double speed, double direction, double accuracy);
 
         [DllImport(Libraries.Location, EntryPoint = "location_manager_clear_mock_location")]
-        public static extern int ClearMock(IntPtr handle);
+        internal static extern int ClearMock(IntPtr handle);
 
         [DllImport(Libraries.Location, EntryPoint = "location_manager_get_method")]
-        public static extern int GetLocationType(IntPtr handle, out LocationType method);
+        internal static extern int GetLocationType(IntPtr handle, out LocationType method);
 
         [DllImport(Libraries.Location, EntryPoint = "location_manager_get_location")]
-        public static extern int GetLocation(IntPtr handle, out double altitude, out double latitude, out double longitude, out double climb, out double direction, out double speed, out LocationAccuracy level, out double horizontal, out double vertical, out int timestamp);
+        internal static extern int GetLocation(IntPtr handle, out double altitude, out double latitude, out double longitude, out double climb, out double direction, out double speed, out LocationAccuracy level, out double horizontal, out double vertical, out int timestamp);
 
         [DllImport(Libraries.Location, EntryPoint = "location_manager_get_last_location")]
-        public static extern int GetLastLocation(IntPtr handle, out double altitude, out double latitude, out double longitude, out double climb, out double direction, out double speed, out LocationAccuracy level, out double horizontal, out double vertical, out int timestamp);
+        internal static extern int GetLastLocation(IntPtr handle, out double altitude, out double latitude, out double longitude, out double climb, out double direction, out double speed, out LocationAccuracy level, out double horizontal, out double vertical, out int timestamp);
 
         [DllImport(Libraries.Location, EntryPoint = "location_manager_add_boundary")]
-        public static extern int AddBoundary(IntPtr managerHandle, IntPtr boundsHandle);
+        internal static extern int AddBoundary(IntPtr managerHandle, IntPtr boundsHandle);
 
         [DllImport(Libraries.Location, EntryPoint = "location_manager_remove_boundary")]
-        public static extern int RemoveBoundary(IntPtr managerHandle, IntPtr boundsHandle);
+        internal static extern int RemoveBoundary(IntPtr managerHandle, IntPtr boundsHandle);
     }
 
     internal static partial class LocatorHelper
     {
         [DllImport(Libraries.Location, EntryPoint = "location_manager_is_enabled_method")]
-        public static extern int IsEnabled(int locationMethod, out bool status);
+        internal static extern int IsEnabled(int locationMethod, out bool status);
 
         [DllImport(Libraries.Location, EntryPoint = "location_manager_is_supported_method")]
-        public static extern bool IsSupported(int locationMethod);
+        internal static extern bool IsSupported(int locationMethod);
     }
 
     internal static partial class Location
     {
         [DllImport(Libraries.Location, EntryPoint = "location_manager_get_distance")]
-        public static extern int GetDistanceBetween(double startLatitude, double startLongitude, double endLatitude, double endLongitude, out double distance);
+        internal static extern int GetDistanceBetween(double startLatitude, double startLongitude, double endLatitude, double endLongitude, out double distance);
     }
 
     internal static partial class LocatorEvent
     {
-        public delegate void ServiceStatechangedCallback(ServiceState state, IntPtr userData);
-        public delegate void ZonechangedCallback(BoundaryState state, double latitude, double longitude, double altitude, int timesatmp, IntPtr userData);
-        public delegate void SettingchangedCallback(LocationType method, bool enable, IntPtr userData);
-        public delegate void LocationchangedCallback(double latitude, double longitude, double altitude, double speed, double direction, double horizontalAcc, int timeStamp, IntPtr userData);
-        public delegate void LocationUpdatedCallback(LocationError error, double latitude, double longitude, double altitude, int timestamp, double speed, double direction, double climb, IntPtr userData);
+        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+        internal delegate void ServiceStatechangedCallback(ServiceState state, IntPtr userData);
+
+        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+        internal delegate void ZonechangedCallback(BoundaryState state, double latitude, double longitude, double altitude, int timesatmp, IntPtr userData);
+
+        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+        internal delegate void SettingchangedCallback(LocationType method, bool enable, IntPtr userData);
+
+        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+        internal delegate void LocationchangedCallback(double latitude, double longitude, double altitude, double speed, double direction, double horizontalAcc, int timeStamp, IntPtr userData);
+
+        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+        internal delegate void LocationUpdatedCallback(LocationError error, double latitude, double longitude, double altitude, int timestamp, double speed, double direction, double climb, IntPtr userData);
 
         [DllImport(Libraries.Location, EntryPoint = "location_manager_set_service_state_changed_cb")]
-        public static extern int SetServiceStateChangedCallback(IntPtr handle, ServiceStatechangedCallback callback, IntPtr userData);
+        internal static extern int SetServiceStateChangedCallback(IntPtr handle, ServiceStatechangedCallback callback, IntPtr userData);
 
         [DllImport(Libraries.Location, EntryPoint = "location_manager_unset_service_state_changed_cb")]
-        public static extern int UnSetServiceStateChangedCallback(IntPtr handle);
+        internal static extern int UnSetServiceStateChangedCallback(IntPtr handle);
 
         [DllImport(Libraries.Location, EntryPoint = "location_manager_set_zone_changed_cb")]
-        public static extern int SetZoneChangedCallback(IntPtr handle, ZonechangedCallback callback, IntPtr userData);
+        internal static extern int SetZoneChangedCallback(IntPtr handle, ZonechangedCallback callback, IntPtr userData);
 
         [DllImport(Libraries.Location, EntryPoint = "location_manager_unset_zone_changed_cb")]
-        public static extern int UnSetZoneChangedCallback(IntPtr handle);
+        internal static extern int UnSetZoneChangedCallback(IntPtr handle);
 
         [DllImport(Libraries.Location, EntryPoint = "location_manager_set_setting_changed_cb")]
-        public static extern int SetSettingChangedCallback(int method, SettingchangedCallback callback, IntPtr userData);
+        internal static extern int SetSettingChangedCallback(int method, SettingchangedCallback callback, IntPtr userData);
 
         [DllImport(Libraries.Location, EntryPoint = "location_manager_unset_setting_changed_cb")]
-        public static extern int UnSetSettingChangedCallback(int method);
+        internal static extern int UnSetSettingChangedCallback(int method);
 
         [DllImport(Libraries.Location, EntryPoint = "location_manager_set_distance_based_location_changed_cb")]
-        public static extern int SetDistanceBasedLocationChangedCallback(IntPtr handle, LocationchangedCallback callback, int interval, double distance, IntPtr userData);
+        internal static extern int SetDistanceBasedLocationChangedCallback(IntPtr handle, LocationchangedCallback callback, int interval, double distance, IntPtr userData);
 
         [DllImport(Libraries.Location, EntryPoint = "location_manager_unset_distance_based_location_changed_cb")]
-        public static extern int UnSetDistanceBasedLocationChangedCallback(IntPtr handle);
+        internal static extern int UnSetDistanceBasedLocationChangedCallback(IntPtr handle);
 
         [DllImport(Libraries.Location, EntryPoint = "location_manager_set_location_changed_cb")]
-        public static extern int SetLocationChangedCallback(IntPtr handle, LocationchangedCallback callback, int interval, IntPtr userData);
+        internal static extern int SetLocationChangedCallback(IntPtr handle, LocationchangedCallback callback, int interval, IntPtr userData);
 
         [DllImport(Libraries.Location, EntryPoint = "location_manager_unset_location_changed_cb")]
-        public static extern int UnSetLocationChangedCallback(IntPtr handle);
+        internal static extern int UnSetLocationChangedCallback(IntPtr handle);
 
         [DllImport(Libraries.Location, EntryPoint = "location_manager_request_single_location")]
-        public static extern int GetSingleLocation(IntPtr handle, int timeout, LocationUpdatedCallback callback, IntPtr userData);
+        internal static extern int GetSingleLocation(IntPtr handle, int timeout, LocationUpdatedCallback callback, IntPtr userData);
     }
 
     internal static partial class LocationBoundary
     {
-        public delegate bool PolygonCoordinatesCallback(Coordinate coordinates, IntPtr userData);
+        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+        internal delegate bool PolygonCoordinatesCallback(Coordinate coordinates, IntPtr userData);
 
         [DllImport(Libraries.Location, EntryPoint = "location_bounds_create_rect")]
-        public static extern int CreateRectangularBoundary(Coordinate topLeft, Coordinate bottomLeft, out IntPtr boundsHandle);
+        internal static extern int CreateRectangularBoundary(Coordinate topLeft, Coordinate bottomLeft, out IntPtr boundsHandle);
 
         [DllImport(Libraries.Location, EntryPoint = "location_bounds_create_circle")]
-        public static extern int CreateCircleBoundary(Coordinate center, double radius, out IntPtr boundsHandle);
+        internal static extern int CreateCircleBoundary(Coordinate center, double radius, out IntPtr boundsHandle);
 
         [DllImport(Libraries.Location, EntryPoint = "location_bounds_create_polygon")]
-        public static extern int CreatePolygonBoundary(IntPtr list, int listLength, out IntPtr boundsHandle);
+        internal static extern int CreatePolygonBoundary(IntPtr list, int listLength, out IntPtr boundsHandle);
 
         [DllImport(Libraries.Location, EntryPoint = "location_bounds_get_rect_coords")]
-        public static extern int GetRectangleCoordinates(IntPtr handle, out Coordinate topLeft, out Coordinate bottomRight);
+        internal static extern int GetRectangleCoordinates(IntPtr handle, out Coordinate topLeft, out Coordinate bottomRight);
 
         [DllImport(Libraries.Location, EntryPoint = "location_bounds_get_circle_coords")]
-        public static extern int GetCircleCoordinates(IntPtr handle, out Coordinate center, out double radius);
+        internal static extern int GetCircleCoordinates(IntPtr handle, out Coordinate center, out double radius);
 
         [DllImport(Libraries.Location, EntryPoint = "location_bounds_foreach_polygon_coords")]
-        public static extern int GetForEachPolygonCoordinates(IntPtr handle, PolygonCoordinatesCallback callback, IntPtr userData);
+        internal static extern int GetForEachPolygonCoordinates(IntPtr handle, PolygonCoordinatesCallback callback, IntPtr userData);
 
         [DllImport(Libraries.Location, EntryPoint = "location_bounds_contains_coordinates")]
-        public static extern bool IsValidCoordinates(IntPtr handle, Coordinate coordinate);
+        internal static extern bool IsValidCoordinates(IntPtr handle, Coordinate coordinate);
 
         [DllImport(Libraries.Location, EntryPoint = "location_bounds_destroy")]
-        public static extern int DestroyBoundary(IntPtr handle);
+        internal static extern int DestroyBoundary(IntPtr handle);
     }
 
     internal static partial class GpsSatellite
     {
-        public delegate void SatelliteStatuschangedCallback(uint numActive, uint numInView, int timeStamp, IntPtr userData);
-        public delegate bool SatelliteStatusinfomationCallback(uint azimuth, uint elevation, uint prn, uint snr, bool isActive, IntPtr userData);
+        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+        internal delegate void SatelliteStatuschangedCallback(uint numActive, uint numInView, int timeStamp, IntPtr userData);
+
+        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+        internal delegate bool SatelliteStatusinfomationCallback(uint azimuth, uint elevation, uint prn, uint snr, bool isActive, IntPtr userData);
 
         [DllImport(Libraries.Location, EntryPoint = "gps_status_get_nmea")]
-        public static extern int GetNMEAData(IntPtr handle, out string nmea);
+        internal static extern int GetNMEAData(IntPtr handle, out string nmea);
 
         [DllImport(Libraries.Location, EntryPoint = "gps_status_get_satellite")]
-        public static extern int GetSatelliteStatus(IntPtr handle, out uint numberOfActive, out uint numberInView, out int timestamp);
+        internal static extern int GetSatelliteStatus(IntPtr handle, out uint numberOfActive, out uint numberInView, out int timestamp);
 
         [DllImport(Libraries.Location, EntryPoint = "gps_status_set_satellite_updated_cb")]
-        public static extern int SetSatelliteStatusChangedCallback(IntPtr handle, SatelliteStatuschangedCallback callback, int interval, IntPtr userData);
+        internal static extern int SetSatelliteStatusChangedCallback(IntPtr handle, SatelliteStatuschangedCallback callback, int interval, IntPtr userData);
 
         [DllImport(Libraries.Location, EntryPoint = "gps_status_unset_satellite_updated_cb")]
-        public static extern int UnSetSatelliteStatusChangedCallback(IntPtr handle);
+        internal static extern int UnSetSatelliteStatusChangedCallback(IntPtr handle);
 
         [DllImport(Libraries.Location, EntryPoint = "gps_status_foreach_satellites_in_view")]
-        public static extern int GetForEachSatelliteInView(IntPtr handle, SatelliteStatusinfomationCallback callback, IntPtr userData);
+        internal static extern int GetForEachSatelliteInView(IntPtr handle, SatelliteStatusinfomationCallback callback, IntPtr userData);
     }
 
     internal static DateTime ConvertDateTime(int timestamp)
old mode 100644 (file)
new mode 100755 (executable)
index 55ec093..ed54b3e
@@ -1,9 +1,9 @@
-{
-  "dependencies": {
-    "NETStandard.Library": "1.6.0",
-    "Tizen": "1.0.2"
-  },
-  "frameworks": {
-    "netstandard1.3": {}
-  }
-}
+{\r
+  "dependencies": {\r
+    "NETStandard.Library": "1.6.1",\r
+    "Tizen": "1.0.2"\r
+  },\r
+  "frameworks": {\r
+    "netstandard1.3": {}\r
+  }\r
+}
\ No newline at end of file
index 21a91cd..6bbec8b 100755 (executable)
@@ -30,6 +30,9 @@ namespace Tizen.Location
         private EventHandler<SatelliteStatusChangedEventArgs> _satelliteStatusChanged;
         private IntPtr _handle = IntPtr.Zero;
 
+        private Interop.GpsSatellite.SatelliteStatuschangedCallback _satelliteStatuschangedCallback;
+        private Interop.GpsSatellite.SatelliteStatusinfomationCallback _satelliteStatusinfomationCallback;
+
         /// <summary>
         /// The time interval between callback updates.
         /// Should be in the range [1~120] seconds.
@@ -167,13 +170,18 @@ namespace Tizen.Location
         {
             List<SatelliteInformation> satelliteList = new List<SatelliteInformation>();
             Log.Info(Globals.LogTag, "Getting the list of satellites");
-            Interop.GpsSatellite.SatelliteStatusinfomationCallback callback = (uint azimuth, uint elevation, uint prn, uint snr, bool isActive, IntPtr userData) =>
+
+            if (_satelliteStatusinfomationCallback == null)
             {
-                SatelliteInformation satellite = new SatelliteInformation(azimuth, elevation, prn, snr, isActive);
-                satelliteList.Add(satellite);
-                return true;
-            };
-            int ret = Interop.GpsSatellite.GetForEachSatelliteInView(_handle, callback, IntPtr.Zero);
+                _satelliteStatusinfomationCallback = (azimuth, elevation, prn, snr, isActive, userData) =>
+                {
+                    SatelliteInformation satellite = new SatelliteInformation(azimuth, elevation, prn, snr, isActive);
+                    satelliteList.Add(satellite);
+                    return true;
+                };
+            }
+
+            int ret = Interop.GpsSatellite.GetForEachSatelliteInView(_handle, _satelliteStatusinfomationCallback, IntPtr.Zero);
             if (((LocationError)ret != LocationError.None))
             {
                 Log.Error(Globals.LogTag, "Error getting the satellite" + (LocationError)ret);
@@ -237,9 +245,24 @@ namespace Tizen.Location
         private void SetSatelliteStatusChangeCallback()
         {
             Log.Info(Globals.LogTag, "SetSatelliteStatusChangeCallback");
+            if (_satelliteStatuschangedCallback == null)
+            {
+                _satelliteStatuschangedCallback = (numActive, numInView, timestamp, userData) =>
+                {
+                    Log.Info(Globals.LogTag, "Inside SatelliteStatusChangedCallback");
+                    DateTime timeStamp = DateTime.Now;
+
+                    if (timestamp != 0)
+                    {
+                        DateTime start = DateTime.SpecifyKind(new DateTime(1970, 1, 1).AddSeconds(timestamp), DateTimeKind.Utc);
+                        timeStamp = start.ToLocalTime();
+                    }
+                    _satelliteStatusChanged?.Invoke(_handle, new SatelliteStatusChangedEventArgs(numActive, numInView, timeStamp));
+                };
+            }
+
             GCHandle handle = GCHandle.Alloc(this);
-            int ret = Interop.GpsSatellite.SetSatelliteStatusChangedCallback(_handle, SatelliteStatusChangedCallback, _interval, GCHandle.ToIntPtr(handle));
-            /* int ret = Interop.GpsSatellite.SetSatelliteStatusChangedCallback(_handle, SatelliteStatusChangedCallback, _interval, IntPtr.Zero); */
+            int ret = Interop.GpsSatellite.SetSatelliteStatusChangedCallback(_handle, _satelliteStatuschangedCallback, _interval, GCHandle.ToIntPtr(handle));
             if (((LocationError)ret != LocationError.None))
             {
                 Log.Error(Globals.LogTag, "Error in setting satellite status changed callback," + (LocationError)ret);
@@ -257,20 +280,6 @@ namespace Tizen.Location
                 throw LocationErrorFactory.ThrowLocationException(ret);
             }
         }
-
-        private void SatelliteStatusChangedCallback(uint numActive, uint numInView, int timestamp, IntPtr userData)
-        {
-            Log.Info(Globals.LogTag, "Inside SatelliteStatusChangedCallback");
-            DateTime timeStamp = DateTime.Now;
-
-            if (timestamp != 0)
-            {
-                DateTime start = DateTime.SpecifyKind(new DateTime(1970, 1, 1).AddSeconds(timestamp), DateTimeKind.Utc);
-                timeStamp = start.ToLocalTime();
-            }
-
-            _satelliteStatusChanged?.Invoke(_handle, new SatelliteStatusChangedEventArgs(numActive, numInView, timeStamp));
-        }
     }
 
     /// <summary>
index 7604c20..8d6a5d0 100755 (executable)
@@ -47,6 +47,12 @@ namespace Tizen.Location
         private int _requestId = 0;
         private Dictionary<IntPtr, Interop.LocatorEvent.LocationUpdatedCallback> _callback_map = new Dictionary<IntPtr, Interop.LocatorEvent.LocationUpdatedCallback>();
 
+        private Interop.LocatorEvent.ServiceStatechangedCallback _serviceStateChangedCallback;
+        private Interop.LocatorEvent.ZonechangedCallback _zoneChangedCallback;
+        private Interop.LocatorEvent.SettingchangedCallback _settingChangedCallback;
+        private Interop.LocatorEvent.LocationchangedCallback _distanceBasedLocationChangedCallback;
+        private Interop.LocatorEvent.LocationchangedCallback _locationChangedCallback;
+
         private EventHandler<ZoneChangedEventArgs> _zoneChanged;
         private EventHandler<ServiceStateChangedEventArgs> _serviceStateChanged;
         private EventHandler<SettingChangedEventArgs> _settingChanged;
@@ -514,7 +520,16 @@ namespace Tizen.Location
         private void SetServiceStateChangedCallback()
         {
             Log.Info(Globals.LogTag, "Calling Interop.LocatorEvent.SetServiceStateChangedCallback");
-            int ret = Interop.LocatorEvent.SetServiceStateChangedCallback(_handle, ServiceStateChangedCallback, IntPtr.Zero);
+            if (_serviceStateChangedCallback == null)
+            {
+                _serviceStateChangedCallback = (state, userData) =>
+                {
+                    Log.Info(Globals.LogTag, "Inside ServiceStateChangedCallback");
+                    _serviceStateChanged?.Invoke(this, new ServiceStateChangedEventArgs(state));
+                };
+            }
+
+            int ret = Interop.LocatorEvent.SetServiceStateChangedCallback(_handle, _serviceStateChangedCallback, IntPtr.Zero);
             if (((LocationError)ret != LocationError.None))
             {
                 Log.Error(Globals.LogTag, "Error in Setting Service State Changed Callback," + (LocationError)ret);
@@ -533,12 +548,6 @@ namespace Tizen.Location
             }
         }
 
-        private void ServiceStateChangedCallback(ServiceState state, IntPtr userData)
-        {
-            Log.Info(Globals.LogTag, "Inside ServiceStateChangedCallback");
-            _serviceStateChanged?.Invoke(this, new ServiceStateChangedEventArgs(state));
-        }
-
         /// <summary>
         /// (event) ZoneChanged is  invoked when the previously set boundary area is entered or left.
         /// </summary>
@@ -572,7 +581,22 @@ namespace Tizen.Location
         private void SetZoneChangedCallback()
         {
             Log.Info(Globals.LogTag, "Inside SetZoneChangedCallback");
-            int ret = Interop.LocatorEvent.SetZoneChangedCallback(_handle, ZoneChangedCallback, IntPtr.Zero);
+            if (_zoneChangedCallback == null)
+            {
+                _zoneChangedCallback = (state, latitude, longitude, altitude, timestamp, userData) =>
+                {
+                    Log.Info(Globals.LogTag, "Inside ZoneChangedCallback");
+                    DateTime timeStamp = DateTime.Now;
+                    if (timestamp != 0)
+                    {
+                        DateTime start = DateTime.SpecifyKind(new DateTime(1970, 1, 1).AddSeconds(timestamp), DateTimeKind.Utc);
+                        timeStamp = start.ToLocalTime();
+                    }
+                    _zoneChanged?.Invoke(this, new ZoneChangedEventArgs(state, latitude, longitude, altitude, timeStamp));
+                };
+            }
+
+            int ret = Interop.LocatorEvent.SetZoneChangedCallback(_handle, _zoneChangedCallback, IntPtr.Zero);
             if (((LocationError)ret != LocationError.None))
             {
                 Log.Error(Globals.LogTag, "Error in Setting Zone Changed Callback," + (LocationError)ret);
@@ -590,18 +614,6 @@ namespace Tizen.Location
             }
         }
 
-        private void ZoneChangedCallback(BoundaryState state, double latitude, double longitude, double altitude, int timestamp, IntPtr userData)
-        {
-            Log.Info(Globals.LogTag, "Inside ZoneChangedCallback");
-            DateTime timeStamp = DateTime.Now;
-            if (timestamp != 0)
-            {
-                DateTime start = DateTime.SpecifyKind(new DateTime(1970, 1, 1).AddSeconds(timestamp), DateTimeKind.Utc);
-                timeStamp = start.ToLocalTime();
-            }
-            _zoneChanged?.Invoke(this, new ZoneChangedEventArgs(state, latitude, longitude, altitude, timeStamp));
-        }
-
         /// <summary>
         /// (event) SetttingChanged is raised when the location setting is changed.
         /// </summary>
@@ -636,7 +648,16 @@ namespace Tizen.Location
         private void SetSettingChangedCallback()
         {
             Log.Info(Globals.LogTag, "Calling SetSettingChangedCallback");
-            int ret = Interop.LocatorEvent.SetSettingChangedCallback((int)_locationType, SettingChangedCallback, IntPtr.Zero);
+            if (_settingChangedCallback == null)
+            {
+                _settingChangedCallback = (method, enable, userData) =>
+                {
+                    Log.Info(Globals.LogTag, "Calling SettingChangedCallback");
+                    _settingChanged?.Invoke(this, new SettingChangedEventArgs(method, enable));
+                };
+            }
+
+            int ret = Interop.LocatorEvent.SetSettingChangedCallback((int)_locationType, _settingChangedCallback, IntPtr.Zero);
             if (((LocationError)ret != LocationError.None))
             {
                 Log.Error(Globals.LogTag, "Error in Setting Changed Callback," + (LocationError)ret);
@@ -655,12 +676,6 @@ namespace Tizen.Location
             }
         }
 
-        private void SettingChangedCallback(LocationType method, bool enable, IntPtr userData)
-        {
-            Log.Info(Globals.LogTag, "Calling SettingChangedCallback");
-            _settingChanged?.Invoke(this, new SettingChangedEventArgs(method, enable));
-        }
-
         /// <summary>
         /// (event) DistanceBasedLocationChanged is raised with updated location information.
         /// The callback will be invoked at minimum interval or minimum distance with updated position information.
@@ -672,7 +687,7 @@ namespace Tizen.Location
             add
             {
                 Log.Info(Globals.LogTag, "Adding DistanceBasedLocationChanged EventHandler");
-                if (_distanceBasedLocationChanged == null)
+                //if (_distanceBasedLocationChanged == null)
                 {
                     Log.Info(Globals.LogTag, "Calling function SetDistanceBasedLocationChangedCallback");
                     SetDistanceBasedLocationChangedCallback();
@@ -695,7 +710,18 @@ namespace Tizen.Location
         private void SetDistanceBasedLocationChangedCallback()
         {
             Log.Info(Globals.LogTag, "SetDistanceBasedLocationChangedCallback");
-            int ret = Interop.LocatorEvent.SetDistanceBasedLocationChangedCallback(_handle, DistanceBasedLocationChangedCallback, _stayInterval, _distance, IntPtr.Zero);
+            if (_distanceBasedLocationChangedCallback == null) {
+                _distanceBasedLocationChangedCallback = (latitude, longitude, altitude, speed, direction, horizontalAccuracy, timestamp, userData) =>
+                {
+                    Log.Info(Globals.LogTag, "DistanceBasedLocationChangedCallback #1");
+                    Location location = new Location(latitude, longitude, altitude, horizontalAccuracy, direction, speed, timestamp);
+                    Log.Info(Globals.LogTag, "DistanceBasedLocationChangedCallback #2");
+                    _distanceBasedLocationChanged?.Invoke(this, new LocationChangedEventArgs(location));
+                    Log.Info(Globals.LogTag, "DistanceBasedLocationChangedCallback #3");
+                };
+            }
+            
+            int ret = Interop.LocatorEvent.SetDistanceBasedLocationChangedCallback(_handle, _distanceBasedLocationChangedCallback, _stayInterval, _distance, IntPtr.Zero);
             if (((LocationError)ret != LocationError.None))
             {
                 Log.Error(Globals.LogTag, "Error in Setting Distance based location changed Callback," + (LocationError)ret);
@@ -712,13 +738,7 @@ namespace Tizen.Location
                 Log.Error(Globals.LogTag, "Error in UnSetting Distance based location changed Callback," + (LocationError)ret);
                 throw LocationErrorFactory.ThrowLocationException(ret);
             }
-        }
-
-        private void DistanceBasedLocationChangedCallback(double latitude, double longitude, double altitude, double speed, double direction, double horizontalAccuracy, int timestamp, IntPtr userData)
-        {
-            Log.Info(Globals.LogTag, "DistanceBasedLocationChangedCallback");
-            Location location = new Location(latitude, longitude, altitude, horizontalAccuracy, direction, speed, timestamp);
-            _distanceBasedLocationChanged?.Invoke(this, new LocationChangedEventArgs(location));
+            _distanceBasedLocationChanged = null;
         }
 
         /// <summary>
@@ -755,7 +775,18 @@ namespace Tizen.Location
         private void SetLocationChangedCallback()
         {
             Log.Info(Globals.LogTag, "Calling SetLocationChangedCallback");
-            int ret = Interop.LocatorEvent.SetLocationChangedCallback(_handle, LocationChangedCallback, _interval, IntPtr.Zero);
+
+            if (_locationChangedCallback == null) {
+                _locationChangedCallback = (latitude, longitude, altitude, speed, direction, horizontalAccuracy, timestamp, userData) =>
+                {
+                    Log.Info(Globals.LogTag, "LocationChangedCallback has been called");
+                    Location location = new Location(latitude, longitude, altitude, horizontalAccuracy, direction, speed, timestamp);
+                    _location = location;
+                    _locationChanged?.Invoke(this, new LocationChangedEventArgs(location));
+                };
+            }
+
+            int ret = Interop.LocatorEvent.SetLocationChangedCallback(_handle, _locationChangedCallback, _interval, IntPtr.Zero);
             if (((LocationError)ret != LocationError.None))
             {
                 Log.Error(Globals.LogTag, "Error in Setting location changed Callback," + (LocationError)ret);
@@ -773,13 +804,5 @@ namespace Tizen.Location
                 throw LocationErrorFactory.ThrowLocationException(ret);
             }
         }
-
-        private void LocationChangedCallback(double latitude, double longitude, double altitude, double speed, double direction, double horizontalAccuracy, int timestamp, IntPtr userData)
-        {
-            Log.Info(Globals.LogTag, "LocationChangedCallback has been called");
-            Location location = new Location(latitude, longitude, altitude, horizontalAccuracy, direction, speed, timestamp);
-            _location = location;
-            _locationChanged?.Invoke(this, new LocationChangedEventArgs(location));
-        }
     }
 }
index cf69381..735128b 100755 (executable)
@@ -1,6 +1,6 @@
 Name:       csapi-location
 Summary:    Tizen Location API for C#
-Version:    1.0.3
+Version:    1.0.4
 Release:    1
 Group:      Development/Libraries
 License:    Apache-2.0