using System.Collections.Concurrent;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
+using System.Reflection;
+using System.ComponentModel;
namespace Tizen.Network.Bluetooth
{
/// 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>
+ /// 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>
/// The name of the device.
/// </summary>
+ /// <since_tizen> 3 </since_tizen>
public string Name
{
get
/// <summary>
/// The strength indicator of received signal of the device.
/// </summary>
+ /// <since_tizen> 3 </since_tizen>
public int Rssi
{
get
/// <summary>
/// The class of the device.
/// </summary>
+ /// <since_tizen> 3 </since_tizen>
public BluetoothClass Class
{
get
/// <summary>
/// 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 the device.
/// </summary>
+ /// <since_tizen> 3 </since_tizen>
public bool IsPaired
{
get
/// <summary>
/// The connection state of the device.
/// </summary>
+ /// <since_tizen> 3 </since_tizen>
public bool IsConnected
{
get
/// <summary>
/// The authorization state of the device.
/// </summary>
+ /// <since_tizen> 3 </since_tizen>
public bool IsAuthorized
{
get
/// <summary>
/// The Bluetooth appearance.
/// </summary>
+ /// <since_tizen> 3 </since_tizen>
public BluetoothAppearanceType AppearanceType
{
get
/// <summary>
/// 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>
/// 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>
/// The BondDestroyed event is raised when the bond is destroyed.
/// </summary>
+ /// <since_tizen> 3 </since_tizen>
public event EventHandler<BondDestroyedEventArgs> BondDestroyed
{
add
/// <summary>
/// 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>
/// 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>
/// The ConnectionStateChanged event is raised when the connection state is changed.
/// </summary>
+ /// <since_tizen> 3 </since_tizen>
public event EventHandler<DeviceConnectionStateChangedEventArgs> ConnectionStateChanged
{
add
/// </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>
/// <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();
/// </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)
/// <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)
/// <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)
/// <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;
/// </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");
/// <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);
/// <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)
/// <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"))
+ try
{
- BluetoothAvrcp avrcp = new BluetoothAvrcp();
- profile = (avrcp as T);
- }
- else if (type.Equals("Tizen.Network.Bluetooth.BluetoothHid"))
- {
- BluetoothHid hid = new BluetoothHid();
- profile = (hid as T);
- }
-
- else if (type.Equals("Tizen.Network.Bluetooth.BluetoothOppClient"))
- {
- BluetoothOppClient oppClient = new BluetoothOppClient();
- profile = (oppClient 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>
/// </summary>
/// <returns>The IBluetoothClientSocket instance.</returns>
/// <param name="serviceUuid">The UUID of the service.</param>
+ /// <since_tizen> 3 </since_tizen>
public IBluetoothClientSocket CreateSocket(string serviceUuid)
{
BluetoothSocket clientSocket = new BluetoothSocket();