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