Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.Network.Bluetooth / Tizen.Network.Bluetooth / BluetoothHid.cs
1 using System;
2
3 namespace Tizen.Network.Bluetooth
4 {
5     /// <summary>
6     /// A class which is used to handle the connection to Bluetooth HID like keyboards and mouse.
7     /// </summary>
8     /// <privilege> http://tizen.org/privilege/bluetooth </privilege>
9     public class BluetoothHid : BluetoothProfile
10     {
11         internal BluetoothHid()
12         {
13         }
14
15         /// <summary>
16         /// The HidConnectionStateChanged event is called when the HID host connection state is changed.
17         /// </summary>
18         public event EventHandler<HidConnectionStateChangedEventArgs> HidConnectionStateChanged
19         {
20             add
21             {
22                 BluetoothHidImpl.Instance.HidConnectionStateChanged += value;
23             }
24             remove
25             {
26                 BluetoothHidImpl.Instance.HidConnectionStateChanged -= value;
27             }
28         }
29
30         /// <summary>
31         /// Connects the remote device with the HID service.
32         /// </summary>
33         /// <remarks>
34         /// The device must be bonded with the remote device by CreateBond().
35         /// If connection request succeeds, the HidConnectionStateChanged event will be invoked.
36         /// </remarks>
37         /// <exception cref="System.InvalidOperationException">Thrown when the Bluetooth is not enabled
38         /// or when the connection attempt to the remote device fails.</exception>
39         public void Connect()
40         {
41             if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
42             {
43                 int ret = BluetoothHidImpl.Instance.Connect(RemoteAddress);
44                 if (ret != (int)BluetoothError.None)
45                 {
46                     Log.Error(Globals.LogTag, "Failed to Connect - " + (BluetoothError)ret);
47                     BluetoothErrorFactory.ThrowBluetoothException(ret);
48                 }
49             }
50             else
51             {
52                 BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
53             }
54         }
55
56         /// <summary>
57         /// Disconnects the remote device with the HID service.
58         /// </summary>
59         /// <exception cref="System.InvalidOperationException">Thrown when the Bluetooth is not enabled
60         /// or when the disconnection attempt to the remote device fails.</exception>
61         public void Disconnect()
62         {
63             if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
64             {
65                 int ret = BluetoothHidImpl.Instance.Disconnect(RemoteAddress);
66                 if (ret != (int)BluetoothError.None)
67                 {
68                     Log.Error(Globals.LogTag, "Failed to Disconnect - " + (BluetoothError)ret);
69                     BluetoothErrorFactory.ThrowBluetoothException(ret);
70                 }
71             }
72             else
73             {
74                 BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
75             }
76         }
77     }
78 }
79