From: kj7.sung Date: Mon, 10 Jul 2017 05:02:50 +0000 (+0900) Subject: [TCSACR-65] Add properties to support batch mode X-Git-Tag: submit/trunk/20170823.075128~103^2~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f5fe84f0f4412ce57698c0c3629c9ad8182ec83c;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git [TCSACR-65] Add properties to support batch mode Change-Id: I5d26a601bbbc2ffb5cfdf84d3d42060660ddd7b9 Signed-off-by: kj7.sung --- diff --git a/src/Tizen.Location/Interop/Interop.Location.cs b/src/Tizen.Location/Interop/Interop.Location.cs index f890450..ad4466c 100755 --- a/src/Tizen.Location/Interop/Interop.Location.cs +++ b/src/Tizen.Location/Interop/Interop.Location.cs @@ -34,6 +34,12 @@ internal static partial class Interop [DllImport(Libraries.Location, EntryPoint = "location_manager_stop")] internal static extern int Stop(IntPtr handle); + [DllImport(Libraries.Location, EntryPoint = "location_manager_start_batch")] + internal static extern int StartBatch(IntPtr handle); + + [DllImport(Libraries.Location, EntryPoint = "location_manager_stop_batch")] + internal static extern int StopBatch(IntPtr handle); + [DllImport(Libraries.Location, EntryPoint = "location_manager_is_enabled_mock_location")] internal static extern int IsEnabledMock(out bool status); @@ -91,6 +97,12 @@ internal static partial class Interop [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); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate void LocationBatchCallback(int batch_size, IntPtr userData); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate void LocationBatchGetCallback(double latitude, double longitude, double altitude, double speed, double direction, double horizontal, double vertical, int timeStamp, IntPtr userData); + [DllImport(Libraries.Location, EntryPoint = "location_manager_set_service_state_changed_cb")] internal static extern int SetServiceStateChangedCallback(IntPtr handle, ServiceStatechangedCallback callback, IntPtr userData); @@ -121,6 +133,15 @@ internal static partial class Interop [DllImport(Libraries.Location, EntryPoint = "location_manager_unset_location_changed_cb")] internal static extern int UnSetLocationChangedCallback(IntPtr handle); + [DllImport(Libraries.Location, EntryPoint = "location_manager_set_location_batch_cb")] + internal static extern int SetLocationBatchCallback(IntPtr handle, LocationBatchCallback callback, int batchInterval, int batchPeriod, IntPtr userData); + + [DllImport(Libraries.Location, EntryPoint = "location_manager_unset_location_batch_cb")] + internal static extern int UnSetLocationBatchCallback(IntPtr handle); + + [DllImport(Libraries.Location, EntryPoint = "location_manager_foreach_location_batch")] + internal static extern int GetLocationBatch(IntPtr handle, LocationBatchGetCallback callback, IntPtr userData); + [DllImport(Libraries.Location, EntryPoint = "location_manager_request_single_location")] internal static extern int GetSingleLocation(IntPtr handle, int timeout, LocationUpdatedCallback callback, IntPtr userData); } diff --git a/src/Tizen.Location/Tizen.Location/Locator.cs b/src/Tizen.Location/Tizen.Location/Locator.cs index fc3337c..3c8a85d 100755 --- a/src/Tizen.Location/Tizen.Location/Locator.cs +++ b/src/Tizen.Location/Tizen.Location/Locator.cs @@ -37,6 +37,8 @@ namespace Tizen.Location { private int _interval = 1; private int _stayInterval = 120; + private int _batchInterval = 0; + private int _batchPeriod = 0; private int _requestId = 0; private double _distance = 120.0; private bool _isEnableMock = false; @@ -52,6 +54,8 @@ namespace Tizen.Location private Interop.LocatorEvent.SettingchangedCallback _settingChangedCallback; private Interop.LocatorEvent.LocationchangedCallback _distanceBasedLocationChangedCallback; private Interop.LocatorEvent.LocationchangedCallback _locationChangedCallback; + private Interop.LocatorEvent.LocationBatchCallback _locationBatchCallback; + private Interop.LocatorEvent.LocationBatchGetCallback _locationBatchGetCallback; private EventHandler _zoneChanged; private EventHandler _serviceStateChanged; @@ -149,6 +153,64 @@ namespace Tizen.Location } /// + /// The time interval between position collection in batch mode. + /// Should be in the range [1~255] seconds. + /// + /// 3 + /// Thrown when an invalid argument is used. + /// Thrown when the location is not supported. + public int BatchInterval + { + get + { + Log.Info(Globals.LogTag, "Getting the Batch Interval"); + return _batchInterval; + } + set + { + Log.Info(Globals.LogTag, "Setting the Batch Interval"); + if (value > 0 && value <= 255) + { + _batchInterval = value; + } + else + { + Log.Error(Globals.LogTag, "Error setting Callback Interval"); + throw LocationErrorFactory.ThrowLocationException((int)LocationError.InvalidParameter); + } + } + } + + /// + /// The time interval between batch callback updates. The BatchPeriod should be greater than or equal to the BatchInterval. If BatchPeriod is zero or smaller than BatchInterval, then batch mode will not working. + /// Should be in the range [0~60000] seconds. + /// + /// 3 + /// Thrown when an invalid argument is used. + /// Thrown when the location is not supported. + public int BatchPeriod + { + get + { + Log.Info(Globals.LogTag, "Getting the Batch Period"); + return _batchPeriod; + } + set + { + Log.Info(Globals.LogTag, "Setting the Batch Period"); + if (value >= 0 && value <= 60000) + { + _batchPeriod = value; + } + else + { + Log.Error(Globals.LogTag, "Error setting Batch Period"); + throw LocationErrorFactory.ThrowLocationException((int)LocationError.InvalidParameter); + } + } + } + + /// /// The distance between callback updates. /// Should be in the range [1-120] meters. /// @@ -264,11 +326,23 @@ namespace Tizen.Location public void Start() { Log.Info(Globals.LogTag, "Starting Location Manager"); - int ret = Interop.Locator.Start(_handle); - if (((LocationError)ret != LocationError.None)) + if (_batchPeriod > 0 && _batchPeriod > _batchInterval) { - Log.Error(Globals.LogTag, "Error Starting Location Manager," + (LocationError)ret); - throw LocationErrorFactory.ThrowLocationException(ret); + int ret = Interop.Locator.StartBatch(_handle); + if (((LocationError)ret != LocationError.None)) + { + Log.Error(Globals.LogTag, "Error Starting Location Batch mode," + (LocationError)ret); + throw LocationErrorFactory.ThrowLocationException(ret); + } + } + else + { + int ret = Interop.Locator.Start(_handle); + if (((LocationError)ret != LocationError.None)) + { + Log.Error(Globals.LogTag, "Error Starting Location Manager," + (LocationError)ret); + throw LocationErrorFactory.ThrowLocationException(ret); + } } _isStarted = true; } @@ -785,20 +859,36 @@ namespace Tizen.Location Log.Info(Globals.LogTag, "Adding LocationChanged EventHandler"); if (_locationChanged == null) { - Log.Info(Globals.LogTag, "Calling function SetLocationChangedCallback"); - SetLocationChangedCallback(); + if (_batchPeriod > 0 && _batchPeriod > _batchInterval) + { + Log.Info(Globals.LogTag, "Calling function SetLocationBatchCallback"); + SetLocationBatchCallback(); + } + else + { + Log.Info(Globals.LogTag, "Calling function SetLocationChangedCallback"); + SetLocationChangedCallback(); + } } _locationChanged += value; } remove { - Log.Info(Globals.LogTag, "Adding LocationChanged EventHandler"); + Log.Info(Globals.LogTag, "Removing LocationChanged EventHandler"); _locationChanged -= value; if (_locationChanged == null) { - Log.Info(Globals.LogTag, "calling function UnSetLocationChangedCallback"); - UnSetLocationChangedCallback(); + if (_batchPeriod > 0 && _batchPeriod > _batchInterval) + { + Log.Info(Globals.LogTag, "Calling function UnSetLocationBatchCallback"); + UnSetLocationBatchCallback(); + } + else + { + Log.Info(Globals.LogTag, "Calling function UnSetLocationChangedCallback"); + UnSetLocationChangedCallback(); + } } } } @@ -835,5 +925,50 @@ namespace Tizen.Location throw LocationErrorFactory.ThrowLocationException(ret); } } + + private void SetLocationBatchCallback() + { + Log.Info(Globals.LogTag, "Calling SetLocationBatchCallback"); + int ret; + if (_locationBatchCallback == null) { + _locationBatchCallback = (batch_size, userData) => + { + Log.Info(Globals.LogTag, "LocationBatchCallback has been called, size : " + batch_size); + + _locationBatchGetCallback = (latitude, longitude, altitude, speed, direction, horizontal, vertical, timestamp, batchUserData) => + { + Log.Info(Globals.LogTag, "GetLocationBatch has been called"); + Location location = new Location(latitude, longitude, altitude, speed, direction, horizontal, timestamp); + _location = location; + _locationChanged?.Invoke(this, new LocationChangedEventArgs(location)); + }; + + ret = Interop.LocatorEvent.GetLocationBatch(_handle, _locationBatchGetCallback, IntPtr.Zero); + if (((LocationError)ret != LocationError.None)) + { + Log.Error(Globals.LogTag, "Error in Setting location batch Callback," + (LocationError)ret); + throw LocationErrorFactory.ThrowLocationException(ret); + } + }; + } + + ret = Interop.LocatorEvent.SetLocationBatchCallback(_handle, _locationBatchCallback, _batchInterval, _batchPeriod, IntPtr.Zero); + if (((LocationError)ret != LocationError.None)) + { + Log.Error(Globals.LogTag, "Error in Setting location batch Callback," + (LocationError)ret); + throw LocationErrorFactory.ThrowLocationException(ret); + } + } + + private void UnSetLocationBatchCallback() + { + Log.Info(Globals.LogTag, "Calling UnSetLocationBatchCallback"); + int ret = Interop.LocatorEvent.UnSetLocationBatchCallback(_handle); + if (((LocationError)ret != LocationError.None)) + { + Log.Error(Globals.LogTag, "Error in UnSetting location batch Callback," + (LocationError)ret); + throw LocationErrorFactory.ThrowLocationException(ret); + } + } } }