[UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
internal delegate void BtGattServerAttMtuChangedCallback(IntPtr clientHandle, ref AttMtuInfoStruct mtuInfo, IntPtr userData);
+ [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
+ internal delegate void BtClientServiceChangedCallback(IntPtr clientHandle, BluetoothGattServiceChangeType changeType, string serviceUuid, IntPtr userData);
+
// Gatt Attribute
[DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_destroy")]
[DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_characteristic_foreach_descriptors")]
internal static extern int BtGattCharacteristicForeachDescriptors(BluetoothGattAttributeHandle characteristicHandle, BtGattForeachCallback callback, IntPtr userData);
+ [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_client_set_service_changed_cb")]
+ internal static extern int BtGattClientSetServiceChangedCallback(BluetoothGattClientHandle clientHandle, BtClientServiceChangedCallback cb, IntPtr userData);
+
+ [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_client_unset_service_changed_cb")]
+ internal static extern int BtGattClientUnsetServiceChangedCallback(BluetoothGattClientHandle clientHandle);
+
[DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_client_set_characteristic_value_changed_cb")]
internal static extern int BtGattClientSetCharacteristicValueChangedCallback(BluetoothGattAttributeHandle characteristicHandle, BtClientCharacteristicValueChangedCallback cb, IntPtr userData);
[DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_server_notify_characteristic_changed_value")]
internal static extern int BtGattServerNotify(BluetoothGattAttributeHandle characteristicHandle, BtGattServerNotificationSentCallback callback, string clientAddress, IntPtr userData);
+
+ [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_server_get_device_mtu")]
+ internal static extern int BtGattServerGetDeviceMtu(string remoteAddress, out int mtu);
}
}
}
/// <summary>
+ /// Enumeration for the GATT service change type.
+ /// </summary>
+ /// <since_tizen> 9 </since_tizen>
+ public enum BluetoothGattServiceChangeType
+ {
+ /// <summary>
+ /// Service added.
+ /// </summary>
+ Added = 0,
+ /// <summary>
+ /// Service removed.
+ /// </summary>
+ Removed,
+ }
+
+ /// <summary>
/// Enumeration for the Bluetooth HID header type.
/// </summary>
/// <since_tizen> 6 </since_tizen>
}
/// <summary>
+ /// An extended EventArgs class contains the service changed information.
+ /// </summary>
+ /// <since_tizen> 9 </since_tizen>
+ public class ServiceChangedEventArgs : EventArgs
+ {
+ internal ServiceChangedEventArgs(BluetoothGattServiceChangeType changeType, string serviceUuid)
+ {
+ ChangeType = changeType;
+ ServiceUuid = serviceUuid;
+ }
+
+ /// <summary>
+ /// The service changed type.
+ /// </summary>
+ /// <since_tizen> 9 </since_tizen>
+ public BluetoothGattServiceChangeType ChangeType { get; }
+
+ /// <summary>
+ /// The service UUID.
+ /// </summary>
+ /// <since_tizen> 9 </since_tizen>
+ public string ServiceUuid { get; }
+ }
+
+ /// <summary>
/// An extended EventArgs class contains the changed attribute value.
/// </summary>
/// <since_tizen> 3 </since_tizen>
}
/// <summary>
+ /// Gets the value of the ATT MTU(Maximum Transmission Unit) for the connection.
+ /// </summary>
+ /// <param name="clientAddress">The remote device address.</param>
+ /// <feature>http://tizen.org/feature/network.bluetooth.le.gatt.server</feature>
+ /// <returns>The MTU value</returns>
+ /// <exception cref="NotSupportedException">Thrown when the BT/BLE is not supported.</exception>
+ /// <exception cref="InvalidOperationException">Thrown when the BT/BLE is not enabled
+ /// or when the remote device is disconnected, or when other specific error occurs.</exception>
+ /// <since_tizen> 9 </since_tizen>
+ public int GetAttMtu(string clientAddress)
+ {
+ return _impl.GetAttMtu(clientAddress);
+ }
+
/// The AttMtuChanged event is raised when the MTU value changed.
/// </summary>
/// <since_tizen> 9 </since_tizen>
_remoteAddress = remoteAddress;
StaticConnectionStateChanged += OnConnectionStateChanged;
_impl.AttMtuChanged += OnAttMtuChanged;
+ _impl.ServiceChanged += OnServiceChanged;
}
private void OnAttMtuChanged(object s, AttMtuChangedEventArgs e)
AttMtuChanged?.Invoke(this, e);
}
+ private void OnServiceChanged(object s, ServiceChangedEventArgs e)
+ {
+ ServiceChanged?.Invoke(this, e);
+ }
+
/// <summary>
/// Creates the Bluetooth GATT client.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public event EventHandler<AttMtuChangedEventArgs> AttMtuChanged;
+ /// <summary>
+ /// The ServiceChanged event is raised when the service is changed from the remote device(GATT server).
+ /// </summary>
+ /// <feature>http://tizen.org/feature/network.bluetooth.le.gatt.client</feature>
+ /// <since_tizen> 9 </since_tizen>
+ public event EventHandler<ServiceChangedEventArgs> ServiceChanged;
+
internal bool Isvalid()
{
return _impl.GetHandle().IsInvalid == false;
return task.Task;
}
+ internal int GetAttMtu(string clientAddress)
+ {
+ int err = Interop.Bluetooth.BtGattServerGetDeviceMtu(clientAddress, out int mtu);
+ if (err.IsFailed())
+ {
+ GattUtil.Error(err, "Failed to get MTU value");
+ BluetoothErrorFactory.ThrowBluetoothException(err);
+ }
+ return mtu;
+ }
+
internal event EventHandler<AttMtuChangedEventArgs> AttMtuChanged
{
add
private Interop.Bluetooth.BtGattForeachCallback _serviceForeachCallback;
private Interop.Bluetooth.BtGattClientAttMtuChangedCallback _attMtuChangedCallback;
private event EventHandler<AttMtuChangedEventArgs> _attMtuChanged;
+ private Interop.Bluetooth.BtClientServiceChangedCallback _serviceChangedCallback;
+ private event EventHandler<ServiceChangedEventArgs> _serviceChanged;
internal BluetoothGattClientImpl(string remoteAddress)
{
}
}
+ internal event EventHandler<ServiceChangedEventArgs> ServiceChanged
+ {
+ add
+ {
+ if (_serviceChanged == null)
+ {
+ RegisterServiceChangedEvent();
+ }
+ _serviceChanged += value;
+ }
+ remove
+ {
+ _serviceChanged -= value;
+ if (_serviceChanged == null)
+ {
+ UnregisterServiceChangedEvent();
+ }
+ }
+ }
+
+ private void RegisterServiceChangedEvent()
+ {
+ _serviceChangedCallback = (IntPtr clientHandle, BluetoothGattServiceChangeType changeType, string serviceUuid, IntPtr userData) =>
+ {
+ _serviceChanged?.Invoke(null, new ServiceChangedEventArgs(changeType, serviceUuid));
+ };
+ int ret = Interop.Bluetooth.BtGattClientSetServiceChangedCallback(_handle, _serviceChangedCallback, IntPtr.Zero);
+ if (ret != (int)BluetoothError.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to set service changed callback, Error - " + (BluetoothError)ret);
+ }
+ }
+
+ private void UnregisterServiceChangedEvent()
+ {
+ int ret = Interop.Bluetooth.BtGattClientUnsetServiceChangedCallback(_handle);
+ if (ret != (int)BluetoothError.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to unset service changed callback, Error - " + (BluetoothError)ret);
+ }
+ }
+
internal BluetoothGattClientHandle GetHandle()
{
return _handle;