internal static extern int SetAudioConnectionStateChangedCallback(AudioConnectionStateChangedCallback audioStateChangedCb, IntPtr userData);
[DllImport(Libraries.Bluetooth, EntryPoint = "bt_audio_unset_connection_state_changed_cb")]
internal static extern int UnsetAudioConnectionStateChangedCallback();
+ [DllImport(Libraries.Bluetooth, EntryPoint = "bt_audio_select_role")]
+ internal static extern int SelectAudioRole(BluetoothAudioRole role);
[DllImport(Libraries.Bluetooth, EntryPoint = "bt_ag_open_sco")]
internal static extern int OpenAgSco();
[DllImport(Libraries.Bluetooth, EntryPoint = "bt_ag_close_sco")]
[UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
internal delegate void BtGattClientAttMtuChangedCallback(IntPtr clientHandle, ref AttMtuInfoStruct mtuInfo, IntPtr userData);
+ [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
+ internal delegate void BtGattServerAttMtuChangedCallback(IntPtr clientHandle, ref AttMtuInfoStruct mtuInfo, IntPtr userData);
+
// Gatt Attribute
[DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_destroy")]
[DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_set_float_value")]
internal static extern int BtGattSetFloatValue(BluetoothGattAttributeHandle gattHandle, int type, int mantissa, int exponent, int offset);
+ [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_get_uuid_specification_name")]
+ internal static extern int BtGattGetUuidSpecificationName(string uuid, out string name);
+
// GATT Descriptor
[DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_descriptor_create")]
[DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_server_deinitialize")]
internal static extern int BtGattServerDeinitialize();
+ [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_server_set_att_mtu_changed_cb")]
+ internal static extern int BtGattServerSetMtuChangedCallback(BluetoothGattServerHandle serverHandle, BtGattServerAttMtuChangedCallback callback, IntPtr userData);
+
+ [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_server_unset_att_mtu_changed_cb")]
+ internal static extern int BtGattServerUnsetMtuChangedCallback(BluetoothGattServerHandle serverHandle);
+
[DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_server_set_read_value_requested_cb")]
internal static extern int BtGattServerSetReadValueRequestedCallback(BluetoothGattAttributeHandle gattHandle, BtGattServerReadValueRequestedCallback callback, IntPtr userData);
BluetoothAdapterImpl.Instance.DestroyServerSocket(socket);
}
}
+
+ /// <summary>
+ /// Select the A2DP source/sink role.
+ /// </summary>
+ /// <param name="role">The A2DP source/sink role.</param>
+ /// <since_tizen> 9 </since_tizen>
+ /// <feature>http://tizen.org/feature/network.bluetooth</feature>
+ /// <feature>http://tizen.org/feature/network.bluetooth.audio.call</feature>
+ /// <feature>http://tizen.org/feature/network.bluetooth.audio.media</feature>
+ /// <privilege>http://tizen.org/privilege/bluetooth</privilege>
+ /// <exception cref="NotSupportedException">Thrown when the Bluetooth is not supported.</exception>
+ /// <exception cref="InvalidOperationException">Thrown when the method is failed with message.</exception>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ static public void SelectRole(BluetoothAudioRole role)
+ {
+ BluetoothAudioImpl.Instance.SelectRole(role);
+ }
+
+ /// <summary>
+ /// Gets the name of the specification UUID.
+ /// </summary>
+ /// <param name="uuid">The UUID.</param>
+ /// <since_tizen> 9 </since_tizen>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ static public string GetUuidSpecificationName(string uuid)
+ {
+ return BluetoothAdapterImpl.Instance.GetUuidSpecificationName(uuid);
+ }
}
}
}
}
+ internal string GetUuidSpecificationName(string uuid)
+ {
+ int ret = Interop.Bluetooth.BtGattGetUuidSpecificationName(uuid, out string name);
+ if (ret != (int)BluetoothError.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to get uuid specification name, Error - " + (BluetoothError)ret);
+ BluetoothErrorFactory.ThrowBluetoothException(ret);
+ }
+ return name;
+ }
+
internal static BluetoothAdapterImpl Instance
{
get
}
}
+ internal void SelectRole(BluetoothAudioRole role)
+ {
+ if (Globals.IsAudioInitialize)
+ {
+ int ret = Interop.Bluetooth.SelectAudioRole(role);
+ if (ret != (int)BluetoothError.None && ret != (int)BluetoothError.AlreadyDone)
+ {
+ Log.Error(Globals.LogTag, "Failed to select audio role, Error - " + (BluetoothError)ret);
+ BluetoothErrorFactory.ThrowBluetoothException(ret);
+ }
+ }
+ else
+ {
+ BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotInitialized);
+ }
+ }
+
internal static BluetoothAudioImpl Instance
{
get
}
/// <summary>
+ /// Enumeration for the Bluetooth audio role.
+ /// </summary>
+ /// <since_tizen> 9 </since_tizen>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public enum BluetoothAudioRole
+ {
+ /// <summary>
+ /// The source role.
+ /// </summary>
+ Source = 0,
+ /// <summary>
+ /// The sink role.
+ /// </summary>
+ Sink,
+ }
+
+ /// <summary>
/// Enumeration for the Bluetooth service class types.
/// </summary>
/// <since_tizen> 3 </since_tizen>
e.Server = this;
NotificationSent?.Invoke(this, e);
};
+ _impl.AttMtuChanged += OnAttMtuChanged;
+ }
+
+ private void OnAttMtuChanged(object s, AttMtuChangedEventArgs e)
+ {
+ AttMtuChanged?.Invoke(this, e);
}
/// <summary>
_impl.SendResponse(requestId, (int)type, status, value, offset);
}
+ /// <summary>
+ /// The AttMtuChanged event is raised when the MTU value changed.
+ /// </summary>
+ /// <since_tizen> 9 </since_tizen>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public event EventHandler<AttMtuChangedEventArgs> AttMtuChanged;
+
internal bool IsValid()
{
return _impl.GetHandle().IsInvalid == false;
Dictionary<int, TaskCompletionSource<bool>> _sendIndicationTaskSource = new Dictionary<int, TaskCompletionSource<bool>>();
private Interop.Bluetooth.BtGattServerNotificationSentCallback _sendIndicationCallback;
private Interop.Bluetooth.BtGattForeachCallback _serviceForeachCallback;
+ private Interop.Bluetooth.BtGattServerAttMtuChangedCallback _attMtuChangedCallback;
+ private event EventHandler<AttMtuChangedEventArgs> _attMtuChanged;
internal BluetoothGattServerImpl()
{
return task.Task;
}
+ internal event EventHandler<AttMtuChangedEventArgs> AttMtuChanged
+ {
+ add
+ {
+ if (_attMtuChanged == null)
+ {
+ RegisterMtuChangedEvent();
+ }
+ _attMtuChanged += value;
+ }
+ remove
+ {
+ _attMtuChanged -= value;
+ if (_attMtuChanged == null)
+ {
+ UnregisterMtuChangedEvent();
+ }
+ }
+ }
+
+ private void RegisterMtuChangedEvent()
+ {
+ _attMtuChangedCallback = (IntPtr clientHandle, ref AttMtuInfoStruct mtuInfoStruct, IntPtr userData) =>
+ {
+ _attMtuChanged?.Invoke(null, new AttMtuChangedEventArgs(mtuInfoStruct.RemoteAddress, mtuInfoStruct.Mtu));
+ };
+ int ret = Interop.Bluetooth.BtGattServerSetMtuChangedCallback(_handle, _attMtuChangedCallback, IntPtr.Zero);
+ if (ret != (int)BluetoothError.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to set MTU changed callback, Error - " + (BluetoothError)ret);
+ }
+ }
+
+ private void UnregisterMtuChangedEvent()
+ {
+ int ret = Interop.Bluetooth.BtGattServerUnsetMtuChangedCallback(_handle);
+ if (ret != (int)BluetoothError.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to unset MTU changed callback, Error - " + (BluetoothError)ret);
+ }
+ }
+
internal BluetoothGattServerHandle GetHandle()
{
return _handle;