[Bluetooth][TCSACR-311] Add new StartLeScan API (#1506)
authorWootak <wootak.jung@samsung.com>
Thu, 2 Apr 2020 01:13:35 +0000 (10:13 +0900)
committerGitHub <noreply@github.com>
Thu, 2 Apr 2020 01:13:35 +0000 (10:13 +0900)
src/Tizen.Network.Bluetooth/Interop/Interop.Bluetooth.cs
src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothAdapter.cs
src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothEnumerations.cs
src/Tizen.Network.Bluetooth/Tizen.Network.Bluetooth/BluetoothLeAdapterImpl.cs

index d3bcaea..1c9cfad 100644 (file)
@@ -231,6 +231,9 @@ internal static partial class Interop
         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_le_stop_scan")]
         public static extern int StopScan();
 
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_le_set_scan_mode")]
+        public static extern int SetLeScanMode(BluetoothLeScanMode mode);
+
         [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_le_get_scan_result_service_uuids")]
         public static extern int GetScanResultServiceUuid(ref BluetoothLeScanDataStruct scanData,
             BluetoothLePacketType packetType, ref IntPtr uuids, ref int count);
index 2cb8354..12ff128 100644 (file)
@@ -638,6 +638,37 @@ namespace Tizen.Network.Bluetooth
         }
 
         /// <summary>
+        /// Starts the Bluetooth LE scan operation with scan mode.
+        /// </summary>
+        /// <remarks>
+        /// The Bluetooth must be enabled.
+        /// </remarks>The result of the operation StartLeScan.
+        /// <param name="mode">The LE scan mode.</param>
+        /// <since_tizen> 7 </since_tizen>
+        /// <feature>http://tizen.org/feature/network.bluetooth.le</feature>
+        /// <exception cref="NotSupportedException">Thrown when the Bluetooth LE is not supported.</exception>
+        /// <exception cref="InvalidOperationException">Thrown when the Bluetooth LE is not enabled
+        /// or the Start LE scan is failed.</exception>
+        /// <exception cref="PermissionDeniedException">Thrown when the permission is denied.</exception>
+        static public void StartLeScan(BluetoothLeScanMode mode)
+        {
+            if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
+            {
+                BluetoothLeImplAdapter.Instance.SetScanMode(mode);
+                int ret = BluetoothLeImplAdapter.Instance.StartScan();
+                if (ret != (int)BluetoothError.None)
+                {
+                    Log.Error(Globals.LogTag, "Failed to start the le scan operation, Error - " + (BluetoothError)ret);
+                    BluetoothErrorFactory.ThrowBluetoothException(ret);
+                }
+            }
+            else
+            {
+                BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
+            }
+        }
+
+        /// <summary>
         /// Stops the Bluetooth LE scan operation.
         /// </summary>
         /// <remarks>
index b3b6a66..a57f495 100644 (file)
@@ -1061,6 +1061,26 @@ namespace Tizen.Network.Bluetooth
     }
 
     /// <summary>
+    /// Enumeration for the Bluetooth LE scan mode.
+    /// </summary>
+    /// <since_tizen> 7 </since_tizen>
+    public enum BluetoothLeScanMode
+    {
+        /// <summary>
+        /// Balanced mode of power consumption and connection latency
+        /// </summary>
+        Balanced,
+        /// <summary>
+        /// Low connection latency but high power consumption
+        /// </summary>
+        LowLatency,
+        /// <summary>
+        /// Low power consumption but high connection latency
+        /// </summary>
+        LowEnergy
+    }
+
+    /// <summary>
     /// Enumeration for the integer type for GATT handle's values.
     /// </summary>
     /// <since_tizen> 3 </since_tizen>
index b15bb85..bfd7c2f 100644 (file)
@@ -201,6 +201,18 @@ namespace Tizen.Network.Bluetooth
             return ret;
         }
 
+        internal int SetScanMode(BluetoothLeScanMode mode)
+        {
+            int ret = (int)BluetoothError.None;
+
+            ret = Interop.Bluetooth.SetLeScanMode(mode);
+            if (ret != (int)BluetoothError.None) {
+                Log.Error (Globals.LogTag, "Failed to set LE scan mode - " + (BluetoothError)ret);
+                BluetoothErrorFactory.ThrowBluetoothException (ret);
+            }
+            return ret;
+        }
+
         internal IList<string> GetLeScanResultServiceUuids(BluetoothLeScanData scanData, BluetoothLePacketType packetType)
         {
             if (!BluetoothAdapter.IsBluetoothEnabled || !Globals.IsInitialize)