using System.Collections.Concurrent;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
+using System.Reflection;
+using System.ComponentModel;
namespace Tizen.Network.Bluetooth
{
/// <summary>
- /// A class which is used to handle the connection with other devices and set authorization of other devices.<br>
+ /// This class is used to handle the connection with other devices and set authorization of other devices.<br/>
/// The BluetoothDevice class is used to search for services available on remote devices.
/// </summary>
/// <privilege> http://tizen.org/privilege/bluetooth </privilege>
+ /// <since_tizen> 3 </since_tizen>
public class BluetoothDevice
{
private event EventHandler<BondCreatedEventArgs> _bondCreated;
private Interop.Bluetooth.AuthorizationChangedCallback _authorizationChangedCallback;
private Interop.Bluetooth.ServiceSearchedCallback _serviceSearchedCallback;
private Interop.Bluetooth.DeviceConnectionStateChangedCallback _connectionChangedCallback;
+ private Interop.Bluetooth.ConnectedProfileCallback _connectedProfileCallback;
internal string RemoteDeviceAddress;
internal string RemoteDeviceName;
}
/// <summary>
- /// Address of device.
+ /// The constructor
/// </summary>
+ /// <since_tizen> 9 </since_tizen>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public BluetoothDevice(BluetoothLeDevice leDevice)
+ {
+ RemoteDeviceAddress = leDevice?.RemoteAddress;
+ }
+
+ /// <summary>
+ /// The address of the device.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
public string Address
{
get
}
}
/// <summary>
- /// Name of device.
+ /// The name of the device.
/// </summary>
+ /// <since_tizen> 3 </since_tizen>
public string Name
{
get
}
}
/// <summary>
- /// Strength indicator of received signal of device.
+ /// The strength indicator of received signal of the device.
/// </summary>
+ /// <since_tizen> 3 </since_tizen>
public int Rssi
{
get
}
}
/// <summary>
- /// Class of device.
+ /// The class of the device.
/// </summary>
+ /// <since_tizen> 3 </since_tizen>
public BluetoothClass Class
{
get
}
}
/// <summary>
- /// Service UUID list of device.
+ /// The service UUID list of the device.
/// </summary>
+ /// <since_tizen> 3 </since_tizen>
public IEnumerable<string> ServiceUuidList
{
get
/// <summary>
/// The number of services.
/// </summary>
+ /// <since_tizen> 3 </since_tizen>
public int ServiceCount
{
get
}
}
/// <summary>
- /// The paired state of device.
+ /// The paired state of the device.
/// </summary>
+ /// <since_tizen> 3 </since_tizen>
public bool IsPaired
{
get
}
}
/// <summary>
- /// The connection state of device.
+ /// The connection state of the device.
/// </summary>
+ /// <since_tizen> 3 </since_tizen>
public bool IsConnected
{
get
}
}
/// <summary>
- /// The authorization state of device.
+ /// The authorization state of the device.
/// </summary>
+ /// <since_tizen> 3 </since_tizen>
public bool IsAuthorized
{
get
}
}
/// <summary>
- /// Bluetooth Appearance.
+ /// The Bluetooth appearance.
/// </summary>
+ /// <since_tizen> 3 </since_tizen>
public BluetoothAppearanceType AppearanceType
{
get
}
/// <summary>
- /// The length of manufacturer data.
+ /// The length of the manufacturer data.
/// </summary>
+ /// <since_tizen> 3 </since_tizen>
public int ManufacturerDataLength
{
get
/// <summary>
/// The manufacturer data.
/// </summary>
+ /// <since_tizen> 3 </since_tizen>
public string ManufacturerData
{
get
}
/// <summary>
- /// (event) BondCreated is raised when process of creating bond is finished.
+ /// The BondCreated event is raised when the process of creating the bond is finished.
/// </summary>
+ /// <since_tizen> 3 </since_tizen>
public event EventHandler<BondCreatedEventArgs> BondCreated
{
add
}
/// <summary>
- /// (event) BondDestroyed is raised when the bond is destroyed.
+ /// The BondDestroyed event is raised when the bond is destroyed.
/// </summary>
+ /// <since_tizen> 3 </since_tizen>
public event EventHandler<BondDestroyedEventArgs> BondDestroyed
{
add
}
/// <summary>
- /// (event) AuthorizationChanged is raised when the authorization of device is changed.
+ /// The AuthorizationChanged event is raised when the authorization of the device is changed.
/// </summary>
+ /// <since_tizen> 3 </since_tizen>
public event EventHandler<AuthorizationChangedEventArgs> AuthorizationChanged
{
add
}
/// <summary>
- /// (event) ServiceSearched is raised when the process of service searched is finished.
+ /// The ServiceSearched event is raised when the process of service searched is finished.
/// </summary>
+ /// <since_tizen> 3 </since_tizen>
public event EventHandler<ServiceSearchedEventArgs> ServiceSearched
{
add
}
/// <summary>
- /// (event) ConnectionStateChanged is raised when the connection state is changed.
+ /// The ConnectionStateChanged event is raised when the connection state is changed.
/// </summary>
+ /// <since_tizen> 3 </since_tizen>
public event EventHandler<DeviceConnectionStateChangedEventArgs> ConnectionStateChanged
{
add
}
/// <summary>
- /// Creates a bond with remote Bluetooth device.
+ /// Creates a bond with the remote Bluetooth device.
/// </summary>
/// <remarks>
- /// The Bluetooth must be enabled and remote device must be discoverable by StartDiscovery().The bond can be destroyed by DestroyBond().
- /// The bonding request can be cancelled by CancelBonding().If this succeeds, BondCreated event will be invoked.
+ /// The Bluetooth must be enabled and the remote device must be discoverable by StartDiscovery(). The bond can be destroyed by DestroyBond().
+ /// The bonding request can be cancelled by CancelBonding(). If this succeeds, the BondCreated event will be invoked.
/// </remarks>
+ /// <exception cref="InvalidOperationException">Thrown when the BT/BTLE is not enabled
+ /// or when the create bonding process to the remote device fails.</exception>
+ /// <since_tizen> 3 </since_tizen>
public void CreateBond()
{
if (BluetoothAdapter.IsBluetoothEnabled)
/// <remarks>
/// Bonding must be in progress by CreateBond().
/// </remarks>
+ /// <exception cref="InvalidOperationException">Thrown when the BT/BTLE is not enabled
+ /// or when the cancel bonding procedure to remote device fails.</exception>
+ /// <since_tizen> 3 </since_tizen>
public void CancelBonding()
{
int ret = Interop.Bluetooth.CancelBonding();
/// </summary>
/// <remarks>
/// The Bluetooth must be enabled and the bond must be created by CreateBond().
- /// If this succeeds, BondDestroyed event will be invoked.
+ /// If this succeeds, the BondDestroyed event will be invoked.
/// </remarks>
+ /// <exception cref="InvalidOperationException">Thrown when the BT/BTLE is not enabled
+ /// or when the destroy bonding procedure fails.</exception>
+ /// <since_tizen> 3 </since_tizen>
public void DestroyBond()
{
if (BluetoothAdapter.IsBluetoothEnabled)
/// <remarks>
/// The Bluetooth must be enabled and the bond must be created by CreateBond().
/// </remarks>
- /// <param name="aliasName">Alias name of remote device.</param>
+ /// <param name="aliasName">The alias name of the remote device.</param>
+ /// <exception cref="InvalidOperationException">Thrown when the BT/BTLE is not enabled
+ /// or when the set alias name to remote device fails.</exception>
+ /// <since_tizen> 3 </since_tizen>
public void SetAlias(string aliasName)
{
if (BluetoothAdapter.IsBluetoothEnabled)
/// </summary>
/// <remarks>
/// The Bluetooth must be enabled and the bond must be created by CreateBond().
- /// If this succeeds, AuthorizationChanged event will be invoked.
+ /// If this succeeds, the AuthorizationChanged event will be invoked.
/// </remarks>
- /// <param name="authorizationState">Authorization state.</param>
+ /// <param name="authorizationState">The authorization state.</param>
+ /// <exception cref="InvalidOperationException">Thrown when the BT/BTLE is not enabled
+ /// or when the set authorization to remote device fails.</exception>
+ /// <since_tizen> 3 </since_tizen>
public void SetAuthorization(BluetoothAuthorizationType authorizationState)
{
if (BluetoothAdapter.IsBluetoothEnabled)
}
/// <summary>
- /// Gets the mask from UUID.
+ /// Gets the mask from the UUID.
/// </summary>
/// <returns>The service mask list converted from the given UUID list.</returns>
- /// <param name="uuids">Uuid list of the device.</param>
+ /// <param name="uuids">The UUID list of the device.</param>
+ /// <exception cref="InvalidOperationException">Thrown when the BT/BTLE is not enabled
+ /// or when the get Mask from UUID fails.</exception>
+ /// <since_tizen> 3 </since_tizen>
public BluetoothServiceClassType GetMaskFromUuid(string[] uuids)
{
BluetoothServiceClassType serviceMask;
/// Starts the search for services supported by the specified device.
/// </summary>
/// <remarks>
- /// The Bluetooth must be enabled and remote device must be discoverable by StartDiscovery().The bond must be created by CreateBond().
- /// If this succeeds, ServiceSearched will be invoked.
+ /// The Bluetooth must be enabled and remote device must be discoverable by StartDiscovery(). The bond must be created by CreateBond().
+ /// If this succeeds, the ServiceSearched event will be invoked.
/// </remarks>
+ /// <exception cref="InvalidOperationException">Thrown when the BT/BTLE is not enabled
+ /// or when the remote device service search fails.</exception>
+ /// <since_tizen> 3 </since_tizen>
public void StartServiceSearch()
{
Log.Info(Globals.LogTag, "startservicesearch entry");
/// The Bluetooth must be enabled.
/// </remarks>
/// <returns>The connected Bluetooth profiles.</returns>
+ /// <exception cref="InvalidOperationException">Thrown when the BT/BTLE is not enabled
+ /// or when there is no BT connection.</exception>
+ /// <since_tizen> 3 </since_tizen>
public IEnumerable<BluetoothProfileType> GetConnectedProfiles()
{
if (BluetoothAdapter.IsBluetoothEnabled)
{
List<BluetoothProfileType> profileList = new List<BluetoothProfileType>();
- Interop.Bluetooth.ConnectedProfileCallback callback = (int profile, IntPtr userData) =>
+ _connectedProfileCallback = (int profile, IntPtr userData) =>
{
if (!profile.Equals(null))
{
}
return true;
};
- int ret = Interop.Bluetooth.GetConnectedProfiles(RemoteDeviceAddress, callback, IntPtr.Zero);
+ int ret = Interop.Bluetooth.GetConnectedProfiles(RemoteDeviceAddress, _connectedProfileCallback, IntPtr.Zero);
if (ret != (int)BluetoothError.None)
{
Log.Error(Globals.LogTag, "Failed to get connected profiles, Error - " + (BluetoothError)ret);
/// <remarks>
/// The Bluetooth must be enabled.
/// </remarks>
- /// <returns><c>true</c> if profile is connected; otherwise, <c>false</c>.</returns>
- /// <param name="profileType">Bluetooth Profile type.</param>
+ /// <returns><c>true</c> if profile is connected, otherwise <c>false</c>.</returns>
+ /// <param name="profileType">The Bluetooth profile type.</param>
+ /// <exception cref="InvalidOperationException">Thrown when the BT/BTLE is not enabled
+ /// or when there is no BT connection.</exception>
+ /// <since_tizen> 3 </since_tizen>
public bool IsProfileConnected(BluetoothProfileType profileType)
{
if (BluetoothAdapter.IsBluetoothEnabled)
}
/// <summary>
- /// Returns the instance of Bluetooth profile type.
+ /// Returns the instance of the Bluetooth profile type.
/// </summary>
/// <remarks>
/// The Bluetooth must be enabled.
/// </remarks>
+ /// <returns>The profile instance.</returns>
+ /// <since_tizen> 3 </since_tizen>
public T GetProfile<T>() where T : BluetoothProfile
{
- /*
- * FIXME: Find a proper way for dynamic allocation.
- */
- T profile = null;
- String type = typeof(T).ToString();
- if (type.Equals("Tizen.Network.Bluetooth.BluetoothAudio"))
- {
- BluetoothAudio audio = new BluetoothAudio();
- profile = (audio as T);
- }
- else if (type.Equals("Tizen.Network.Bluetooth.BluetoothAvrcp"))
- {
- BluetoothAvrcp avrcp = new BluetoothAvrcp();
- profile = (avrcp as T);
- }
- else if (type.Equals("Tizen.Network.Bluetooth.BluetoothHid"))
+ try
{
- BluetoothHid hid = new BluetoothHid();
- profile = (hid as T);
+ // TODO : Need to check capability of supporting profiles
+ var profile = (T)Activator.CreateInstance(typeof(T), true);
+ profile.RemoteAddress = RemoteDeviceAddress;
+ return profile;
}
-
- if (profile != null)
+ catch (TargetInvocationException err)
{
- profile.RemoteAddress = RemoteDeviceAddress;
+ throw err.InnerException;
}
- return profile;
}
/// <summary>
/// Creates the client socket.
/// </summary>
/// <returns>The IBluetoothClientSocket instance.</returns>
- /// <param name="serviceUuid">The UUID of service.</param>
+ /// <param name="serviceUuid">The UUID of the service.</param>
+ /// <since_tizen> 3 </since_tizen>
public IBluetoothClientSocket CreateSocket(string serviceUuid)
{
BluetoothSocket clientSocket = new BluetoothSocket();