[NUI] TCSACR-226 code change (#1032)
[platform/core/csapi/tizenfx.git] / src / Tizen.Network.Bluetooth / Tizen.Network.Bluetooth / BluetoothAdapterImpl.cs
index 7adcffe..c5aaee3 100644 (file)
@@ -26,6 +26,8 @@ namespace Tizen.Network.Bluetooth
         internal static bool IsInitialize = false;
         internal static bool IsAudioInitialize = false;
         internal static bool IsHidInitialize = false;
+        internal static bool IsOppServerInitialized = false;
+        internal static bool IsOppClientInitialized = false;
     }
 
     internal partial class BluetoothAdapterImpl : IDisposable
@@ -394,6 +396,57 @@ namespace Tizen.Network.Bluetooth
             }
         }
 
+        internal void Enable()
+        {
+            if (Globals.IsInitialize)
+            {
+                int ret = Interop.Bluetooth.EnableAdapter();
+                if (ret != (int)BluetoothError.None)
+                {
+                    Log.Error(Globals.LogTag, "Failed to enable adapter, Error - " + (BluetoothError)ret);
+                    BluetoothErrorFactory.ThrowBluetoothException(ret);
+                }
+            }
+            else
+            {
+                BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotInitialized);
+            }
+        }
+
+        internal void Disable()
+        {
+            if (IsBluetoothEnabled)
+            {
+                int ret = Interop.Bluetooth.DisableAdapter();
+                if (ret != (int)BluetoothError.None)
+                {
+                    Log.Error(Globals.LogTag, "Failed to disable adapter, Error - " + (BluetoothError)ret);
+                    BluetoothErrorFactory.ThrowBluetoothException(ret);
+                }
+            }
+            else
+            {
+                BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
+            }
+        }
+
+        internal void SetVisibility(VisibilityMode mode, int timeout)
+        {
+            if (IsBluetoothEnabled)
+            {
+                int ret = Interop.Bluetooth.SetVisibility(mode, timeout);
+                if (ret != (int)BluetoothError.None)
+                {
+                    Log.Error(Globals.LogTag, "Failed to set visibility, Error - " + (BluetoothError)ret);
+                    BluetoothErrorFactory.ThrowBluetoothException(ret);
+                }
+            }
+            else
+            {
+                BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
+            }
+        }
+
         internal void StartDiscovery()
         {
             int ret = Interop.Bluetooth.StartDiscovery();
@@ -446,6 +499,7 @@ namespace Tizen.Network.Bluetooth
             }
             BluetoothDeviceStruct device = (BluetoothDeviceStruct)Marshal.PtrToStructure(deviceInfo, typeof(BluetoothDeviceStruct));
 
+            Interop.Bluetooth.FreeDeviceInfo(deviceInfo);
             return BluetoothUtils.ConvertStructToDeviceClass(device);
         }
 
@@ -596,7 +650,6 @@ namespace Tizen.Network.Bluetooth
             if (ret != (int)BluetoothError.None)
             {
                 Log.Error (Globals.LogTag, "Failed to deinitialize bluetooth, Error - " + (BluetoothError)ret);
-                BluetoothErrorFactory.ThrowBluetoothException (ret);
             }
             else
             {