2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 using System.Collections.Generic;
19 using System.Runtime.InteropServices;
21 using System.Threading.Tasks;
23 namespace Tizen.Network.Bluetooth
26 /// The Bluetooth GATT server.
28 public class BluetoothGattServer
30 private static BluetoothGattServer _instance;
31 private BluetoothGattServerImpl _impl;
32 private BluetoothGattServer()
34 _impl = new BluetoothGattServerImpl();
38 /// (event) This event is called when the indication acknowledgement is received for each notified client.
40 public event EventHandler<NotificationSentEventArg> NotificationSent
44 _impl._notificationSent += value;
48 _impl._notificationSent -= value;
53 /// Creates the Bluetooth GATT server.
55 /// <returns></returns>
56 /// <exception cref="System.NotSupportedException">Thrown when the BT/BTLE is not supported.</exception>
57 /// <exception cref="System.InvalidOperationException">Thrown when the create GATT server fails.</exception>
58 public static BluetoothGattServer CreateServer()
60 if (_instance == null)
62 BluetoothGattServer server = new BluetoothGattServer();
72 /// Registers the server along with the GATT services of the application it is hosting.
74 /// <exception cref="System.NotSupportedException">Thrown when the BT/BTLE is not supported.</exception>
75 /// <exception cref="System.InvalidOperationException">Thrown when the register server application fails.</exception>
82 /// Registers a specified service to this server.
84 /// <param name="service">The service, which needs to be registered with this server.</param>
85 /// <exception cref="System.NotSupportedException">Thrown when the BT/BTLE is not supported.</exception>
86 /// <exception cref="System.InvalidOperationException">Thrown when the register service fails.</exception>
87 public void RegisterGattService(BluetoothGattService service)
89 if (service.IsRegistered())
91 BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.InvalidParameter);
93 _impl.RegisterGattService(this, service);
97 /// Unregisters a specified service from this server.
99 /// <param name="service">The service, which needs to be unregistered from this server.</param>
101 /// Once unregistered, the service object will become invalid and should not be used to access sevices or any children attribute's methods/members.
103 /// <exception cref="System.NotSupportedException">Thrown when the BT/BTLE is not supported.</exception>
104 /// <exception cref="System.InvalidOperationException">Thrown when the unregister service fails.</exception>
105 public void UnregisterGattService(BluetoothGattService service)
107 if (service.GetGattServer() != this)
109 BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.InvalidParameter);
112 _impl.UnregisterGattService(service);
116 /// Unregisters all services from this server.
119 /// Once unregistered, servicees will become invalid and should not be used to access sevices or any children attribute's methods/members.
121 /// <exception cref="System.NotSupportedException">Thrown when the BT/BTLE is not supported.</exception>
122 /// <exception cref="System.InvalidOperationException">Thrown when the unregister all services fail.</exception>
123 public void UnregisterGattServices()
125 _impl.UnregisterAllGattServices(this);
129 /// Gets service with given UUID that belongs to this server.
131 /// <param name="uuid">The UUID for the service to get.</param>
132 /// <returns>The Service with the given UUID if it exists, null otherwise.</returns>
133 public BluetoothGattService GetService(string uuid)
135 return _impl.GetService(this, uuid);
139 /// Gets the list of services that belongs to this server.
141 /// <returns>The list of services that belongs to this server.</returns>
142 public IEnumerable<BluetoothGattService> GetServices()
144 return _impl.GetServices(this);
148 /// Sends indication for the value change of the characteristic to the remote devices.
150 /// <param name="characteristic">The characteristic whose the value is changed.</param>
151 /// <param name="clientAddress">The remote device address to send, notify, or indicate and if set to NULL, then notify/indicate all is enabled.</param>
152 /// <exception cref="System.InvalidOperationException">Thrown when the BT/BTLE is not enabled
153 /// or when the remote device is disconnected, or when service is not registered, or when the CCCD is not enabled.</exception>
154 public async Task<bool> SendIndicationAsync(BluetoothGattCharacteristic characteristic, string clientAddress)
156 return await _impl.SendIndicationAsync(this, characteristic, clientAddress);
160 /// Sends the notification for the value change of the characteristic to the remote devices.
162 /// <param name="characteristic">The characteristic, which has a changed value.</param>
163 /// <param name="clientAddress">The remote device address to send, notify, or indicate and if set to NULL, then notify/indicate all is enabled.</param>
164 /// <exception cref="System.InvalidOperationException">Thrown when the BT/BTLE is not enabled
165 /// or when the remote device is disconnected, or when service is not registered, or when the CCCD is not enabled.</exception>
166 public void SendNotification(BluetoothGattCharacteristic characteristic, string clientAddress)
168 _impl.SendNotification(characteristic, clientAddress);
172 /// Sends a response to the remote device as a result of a read/write request.
174 /// <param name="requestId">The identification of a read/write request.</param>
175 /// <param name="type">The request type for read/write.</param>
176 /// <param name="status">The error value in case of failure, 0 for success.</param>
177 /// <param name="value">The value to be sent.</param>
178 /// <param name="offset">The offset from where the value is read.</param>
179 /// <exception cref="System.InvalidOperationException">Thrown when the BT/BTLE is not enabled
180 /// or when the remote device is disconnected, or the send response procedure fails.</exception>
181 public void SendResponse(int requestId, BluetoothGattRequestType type, int status, byte[] value, int offset)
183 _impl.SendResponse(requestId, (int)type, status, value, offset);
186 internal bool IsValid()
188 return _impl.GetHandle().IsInvalid == false;
193 /// The Bluetooth GATT client.
195 public class BluetoothGattClient
197 private BluetoothGattClientImpl _impl;
198 private string _remoteAddress = string.Empty;
200 internal BluetoothGattClient(string remoteAddress)
202 _impl = new BluetoothGattClientImpl(remoteAddress);
203 _remoteAddress = remoteAddress;
206 internal static BluetoothGattClient CreateClient(string remoteAddress)
208 BluetoothGattClient client = new BluetoothGattClient(remoteAddress);
209 return client.Isvalid() ? client : null;
212 public void DestroyClient()
214 _impl.GetHandle().Dispose();
218 /// The address of the remote device.
220 /// <exception cref="System.InvalidOperationException">Thrown when the BT/BTLE is not enabled
221 /// or when the remote device is disconnected.</exception>
222 public string RemoteAddress
226 if (string.IsNullOrEmpty(_remoteAddress))
228 _remoteAddress = _impl.GetRemoteAddress();
230 return _remoteAddress;
235 /// Gets the service with the given UUID that belongs to the remote device.
237 /// <param name="uuid">The UUID for the service to get.</param>
238 /// <returns>The service with the given UUID if it exists, null otherwise.</returns>
239 /// <exception cref="System.InvalidOperationException">Thrown when the BT/BTLE is not enabled
240 /// or when the remote device is disconnected, or when the get service fails.</exception>
241 public BluetoothGattService GetService(string uuid)
243 return _impl.GetService(this, uuid);
247 /// Gets list of services that belongs to the remote device.
249 /// <returns>The list of services that belongs to the remote device.</returns>
250 /// <exception cref="System.InvalidOperationException">Thrown when the BT/BTLE is not enabled
251 /// or when the remote device is disconnected, or when the get service fails.</exception>
252 public IEnumerable<BluetoothGattService> GetServices()
254 return _impl.GetServices(this);
258 /// Reads the value of a given characteristic from the remote device asynchronously.
260 /// <param name="characteristic">The characteristic to be read.</param>
261 /// <returns>true on success, false otherwise.</returns>
262 /// <exception cref="System.InvalidOperationException">Thrown when the BT/BTLE is not enabled
263 /// or when the remote device is disconnected, or when the read attribute value fails.</exception>
264 public async Task<bool> ReadValueAsync(BluetoothGattCharacteristic characteristic)
266 return await _impl.ReadValueAsyncTask(characteristic.GetHandle());
270 /// Reads the value of the given descriptor from the remote device asynchronously.
272 /// <param name="descriptor">The descriptor to be read.</param>
273 /// <returns>true on success, false otherwise.</returns>
274 /// <exception cref="System.InvalidOperationException">Thrown when the BT/BTLE is not enabled
275 /// or when the remote device is disconnected, or when the read attribute value fails.</exception>
276 public async Task<bool> ReadValueAsync(BluetoothGattDescriptor descriptor)
278 return await _impl.ReadValueAsyncTask(descriptor.GetHandle());
282 /// Writes the value of a given characteristic to the remote device asynchronously.
284 /// <param name="characteristic">The characteristic to be written.</param>
285 /// <returns>true on success, false otherwise.</returns>
286 /// <exception cref="System.InvalidOperationException">Thrown when the BT/BTLE is not enabled
287 /// or when the remote device is disconnected or when the write attribute value fails.</exception>
288 public async Task<bool> WriteValueAsync(BluetoothGattCharacteristic characteristic)
290 return await _impl.WriteValueAsyncTask(characteristic.GetHandle());
294 /// Writes the value of the given descriptor to the remote device asynchronously.
296 /// <param name="descriptor">The descriptor to be written.</param>
297 /// <returns>true on success, false otherwise.</returns>
298 /// <exception cref="System.InvalidOperationException">Thrown when the BT/BTLE is not enabled
299 /// or when the remote device is disconnected, or when the write attribute value fails.</exception>
300 public async Task<bool> WriteValueAsync(BluetoothGattDescriptor descriptor)
302 return await _impl.WriteValueAsyncTask(descriptor.GetHandle());
305 internal bool Isvalid()
307 return _impl.GetHandle().IsInvalid == false;
312 /// The Bluetooth GATT service.
314 public class BluetoothGattService
316 private BluetoothGattServiceImpl _impl;
317 private BluetoothGattClient _parentClient = null;
318 private BluetoothGattServer _parentServer = null;
319 private BluetoothGattService _parentService = null;
324 /// <param name="uuid">The UUID of the service.</param>
325 /// <param name="type">The type of service.</param>
326 /// <exception cref="System.InvalidOperationException">Thrown when the create GATT service procedure fails.</exception>
327 public BluetoothGattService(string uuid, BluetoothGattServiceType type)
330 _impl = new BluetoothGattServiceImpl(uuid, type);
333 internal BluetoothGattService(BluetoothGattServiceImpl impl, string uuid)
340 /// Specification name from the UUID.
342 public string Uuid { get; }
345 /// Adds a characteristic to this service.
347 /// <param name="characteristic">The characteristic to be added.</param>
348 /// <returns>true on success, false otherwise.</returns>
349 /// <exception cref="System.InvalidOperationException">Thrown when the add GATT characteristic procedure fails.</exception>
350 public void AddCharacteristic(BluetoothGattCharacteristic characteristic)
352 if (GetGattClient() != null)
354 BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotSupported);
357 if (characteristic.GetService() != null)
359 BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.InvalidParameter);
362 _impl.AddCharacteristic(characteristic);
363 characteristic.SetParent(this);
367 /// Gets the characteristic with the given UUID that belongs to this service.
369 /// <param name="uuid">The UUID for the characteristic to get.</param>
370 /// <returns>The characteristic with a given UUID if it exists, null otherwise.</returns>
371 public BluetoothGattCharacteristic GetCharacteristic(string uuid)
373 return _impl.GetCharacteristic(this, uuid);
377 /// Gets list of the characteristic that belongs to this service.
379 /// <returns>The list of the characteristic that belongs to this service.</returns>
380 public IEnumerable<BluetoothGattCharacteristic> GetCharacteristics()
382 return _impl.GetCharacteristics(this);
386 /// Includes a service to this service.
388 /// <param name="service">The service to be included.</param>
389 /// <returns>true on success, false otherwise</returns>
390 /// <exception cref="System.InvalidOperationException">Thrown when the add GATT service procedure fails.</exception>///
391 public void AddService(BluetoothGattService service)
393 if (GetGattClient() != null)
395 BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotSupported);
398 if (service.IsRegistered())
400 BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.InvalidParameter);
403 _impl.AddIncludeService(service);
404 service.SetParent(this);
408 /// Gets the included service.
410 /// <param name="uuid">The UUID for the service to get.</param>
411 /// <returns>The service with a given UUID if it exists, null otherwise.</returns>
412 public BluetoothGattService GetIncludeService(string uuid)
414 return _impl.GetIncludeService(this, uuid);
418 /// Gets the included service list of this service.
420 /// <returns>The included service list of this service.</returns>
421 public IEnumerable<BluetoothGattService> GetIncludeServices()
423 return _impl.GetIncludeServices(this);
427 /// Gets the server instance which the specified service belongs to.
429 /// <returns>The server instance which the specified service belongs to.</returns>
430 public BluetoothGattServer GetGattServer()
432 return _parentServer;
436 /// Gets the client instance which the specified service belongs to.
438 /// <returns>The client instance which the specified service belongs to.</returns>
439 public BluetoothGattClient GetGattClient()
441 return _parentClient;
444 internal BluetoothGattAttributeHandle GetHandle()
446 return _impl.GetHandle();
449 internal void SetParent(BluetoothGattService parent)
453 _parentService = parent;
454 _impl.ReleaseHandleOwnership();
458 internal void SetParent(BluetoothGattClient parent)
462 _parentClient = parent;
463 _impl.ReleaseHandleOwnership();
467 internal void SetParent(BluetoothGattServer parent)
471 _parentServer = parent;
472 _impl.ReleaseHandleOwnership();
476 internal void UnregisterService()
478 _parentServer = null;
479 _parentClient = null;
480 _parentService = null;
483 internal bool IsRegistered()
485 return _parentClient != null || _parentServer != null || _parentService != null;
490 /// The Bluetooth GATT characteristic.
492 public class BluetoothGattCharacteristic : BluetoothGattAttribute
494 private BluetoothGattCharacteristicImpl _impl;
495 private BluetoothGattService _parent = null;
497 private Interop.Bluetooth.BtClientCharacteristicValueChangedCallback _characteristicValueChangedCallback;
498 private Interop.Bluetooth.BtGattServerNotificationStateChangeCallback _notificationStateChangedCallback;
500 private EventHandler<ValueChangedEventArgs> _characteristicValueChanged;
501 internal EventHandler<NotificationStateChangedEventArg> _notificationStateChanged;
506 /// <param name="uuid">The UUID of the characterstic.param>
507 /// <param name="permissions">Permissions for the characterstic.</param>
508 /// <param name="properties">Properties set for the characterstic.</param>
509 /// <param name="value">The value associated with the characterstic.</param>
510 /// <remarks>throws in case of internal error.</remarks>
511 /// <exception cref="System.InvalidOperationException">Thrown when the create GATT characteristics procedure fails.</exception>
512 public BluetoothGattCharacteristic(string uuid, BluetoothGattPermission permissions, BluetoothGattProperty properties, byte[] value) : base(uuid, permissions)
514 _impl = new BluetoothGattCharacteristicImpl(uuid, permissions, properties, value);
517 internal BluetoothGattCharacteristic(BluetoothGattCharacteristicImpl impl, string uuid, BluetoothGattPermission permission) : base(uuid, permission)
523 /// The CharacteristicValueChanged event is raised when the server notifies for change in this characteristic value.
526 /// Adding the event handle on characteristic on the server side will not have any effect.
528 public event EventHandler<ValueChangedEventArgs> ValueChanged
534 if (_characteristicValueChanged == null)
536 _characteristicValueChangedCallback = (gattHandle, characteristicValue, len, userData) =>
538 _characteristicValueChanged?.Invoke(this, new ValueChangedEventArgs(characteristicValue));
541 _impl.SetCharacteristicValueChangedEvent(_characteristicValueChangedCallback);
543 _characteristicValueChanged = value;
550 _characteristicValueChanged = null;
551 if (_characteristicValueChanged == null)
553 _impl.UnsetCharacteristicValueChangedEvent();
561 /// The NotificationStateChanged event is called when the client enables or disables the Notification/Indication for particular characteristics.
564 /// Adding event handle on the characteristic on the client side will not have any effect.
566 public event EventHandler<NotificationStateChangedEventArg> NotificationStateChanged
572 if (_notificationStateChangedCallback == null)
574 _notificationStateChangedCallback = (notify, serverHandle, characteristicHandle, userData) =>
576 _notificationStateChanged?.Invoke(this, new NotificationStateChangedEventArg(Server, notify));
579 _impl.SetNotificationStateChangedEvent(_notificationStateChangedCallback);
582 _notificationStateChanged = value;
589 _notificationStateChanged = null;
590 // CAPI does not allow unsetting ReadValueRequestedEventCallback.
596 /// The property for this characteristic.
598 public BluetoothGattProperty Properties
602 return _impl.GetProperties();
608 _impl.SetProperties(value);
614 /// The write type to be used for write operations.
616 public BluetoothGattWriteType WriteType
620 return _impl.GetWriteType();
624 _impl.SetWriteType(value);
628 internal override BluetoothGattClient Client
632 return _parent?.GetGattClient();
636 internal override BluetoothGattServer Server
640 return _parent?.GetGattServer();
644 internal override BluetoothGattAttributeImpl Impl
653 /// Adds a descriptor to this characteristic.
655 /// <param name="descriptor">The descriptor to be added.</param>
656 /// <returns>true on success, false otherwise.</returns>
657 /// <exception cref="System.InvalidOperationException">Thrown when the add GATT descriptor procedure fails.</exception>
658 public void AddDescriptor(BluetoothGattDescriptor descriptor)
662 BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotSupported);
665 if (descriptor.GetCharacteristic() != null)
667 BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.InvalidParameter);
670 _impl.AddDescriptor(descriptor);
671 descriptor.SetParent(this);
675 /// Gets the descriptor with the given UUID that belongs to this characteristic.
677 /// <param name="uuid">The UUID for the descriptor to get.</param>
678 /// <returns>The descriptor with a given UUID if it exists, null otherwise.</returns>
679 public BluetoothGattDescriptor GetDescriptor(string uuid)
681 return _impl.GetDescriptor(this, uuid);
685 /// Gets the list of descriptors that belongs to this characteristic.
687 /// <returns>The list of descriptors that belongs to this characteristic.</returns>
688 public IEnumerable<BluetoothGattDescriptor> GetDescriptors()
690 return _impl.GetDescriptors(this);
694 /// Gets the service instance, which the specified characterstic belongs to.
696 /// <returns>The characteristic instance, the specified characterstic belongs to.</returns>
697 public BluetoothGattService GetService()
702 internal void SetParent(BluetoothGattService parent)
707 ReleaseHandleOwnership();
713 /// The Bluetooth GATT descriptor.
715 public class BluetoothGattDescriptor : BluetoothGattAttribute
717 private BluetoothGattCharacteristic _parent = null;
718 private BluetoothGattDescriptorImpl _impl;
723 /// <param name="uuid">The UUID of the descriptor.</param>
724 /// <param name="permisions">Permissions for the descriptor.</param>
725 /// <param name="value">The value associated with the descriptor.</param>
726 /// <remarks>throws in case of internal error.</remarks>
727 /// <exception cref="System.InvalidOperationException">Thrown when the create GATT descriptor procedure fails.</exception>
728 public BluetoothGattDescriptor(string uuid, BluetoothGattPermission permisions, byte[] value) : base (uuid, permisions)
730 _impl = new BluetoothGattDescriptorImpl(uuid, permisions, value);
733 internal BluetoothGattDescriptor(BluetoothGattDescriptorImpl impl, string uuid, BluetoothGattPermission permission) : base(uuid, permission)
738 internal override BluetoothGattClient Client
742 return _parent?.Client;
746 internal override BluetoothGattServer Server
750 return _parent?.Server;
754 internal override BluetoothGattAttributeImpl Impl
763 /// Gets the characteristic instance, which the specified descriptor belongs to.
765 /// <returns>The characteristic instance, the specified descriptor belongs to.</returns>
766 public BluetoothGattCharacteristic GetCharacteristic()
771 internal void SetParent(BluetoothGattCharacteristic parent)
776 ReleaseHandleOwnership();
782 /// The Bluetooth GATT attribute.
784 public abstract class BluetoothGattAttribute
786 private Interop.Bluetooth.BtGattServerReadValueRequestedCallback _readValueRequestedCallback;
787 private Interop.Bluetooth.BtGattServerWriteValueRequestedCallback _writeValueRequestedCallback;
789 private EventHandler<ReadRequestedEventArgs> _readValueRequested;
790 private EventHandler<WriteRequestedEventArgs> _writeValueRequested;
792 public BluetoothGattAttribute(string uuid, BluetoothGattPermission permission)
795 Permissions = permission;
801 /// This event is called when the client request to read the value of a characteristic or a descriptor.
803 /// <exception cref="System.InvalidOperationException">Thrown when the set read value requested callback procedure fails.</exception>
804 public event EventHandler<ReadRequestedEventArgs> ReadRequested
808 if (Server == null) return;
809 if (_readValueRequestedCallback == null)
811 _readValueRequestedCallback = (clientAddress, requestId, serverHandle, gattHandle, offset, userData) =>
813 _readValueRequested?.Invoke(this, new ReadRequestedEventArgs(Server, clientAddress, requestId, offset));
815 Impl.SetReadValueRequestedEventCallback(_readValueRequestedCallback);
817 _readValueRequested = value;
821 if (Server == null) return;
822 _readValueRequested = null;
823 // CAPI does not allow unsetting ReadValueRequestedEventCallback.
828 /// This event is called when a value of a characteristic or a descriptor has been changed by a client.
830 /// <exception cref="System.InvalidOperationException">Thrown when the set write value requested callback procedure fails.</exception>
831 public event EventHandler<WriteRequestedEventArgs> WriteRequested
835 if (Server == null) return;
836 if (_writeValueRequested == null)
838 _writeValueRequestedCallback = (clientAddress, requestId, serverHandle, gattHandle, offset, response_needed, valueToWrite, len, userData) =>
840 _writeValueRequested?.Invoke(this, new WriteRequestedEventArgs(Server, clientAddress, requestId, valueToWrite, offset, response_needed));
842 Impl.SetWriteValueRequestedEventCallback(_writeValueRequestedCallback);
844 _writeValueRequested = value;
848 if (Server == null) return;
849 _writeValueRequested = null;
850 // CAPI does not allow unsetting ReadValueRequestedEventCallback.
855 /// The attribute's UUID.
857 public string Uuid { get; }
860 /// Permissions for this attribute.
862 public BluetoothGattPermission Permissions { get; }
865 /// The value of this descriptor.
871 return Impl.GetValue();
875 Impl.SetValue(value);
879 internal abstract BluetoothGattClient Client { get; }
880 internal abstract BluetoothGattServer Server { get; }
881 internal abstract BluetoothGattAttributeImpl Impl { get; }
884 /// Returns a string value at the specified offset.
886 /// <param name="offset"></param>
887 /// <returns>The string value at specified offset.</returns>
888 public string GetValue(int offset)
890 return Impl.GetValue(offset);
894 /// Sets the string value as a specified offset.
896 /// <param name="value">value to set</param>
897 /// <exception cref="InvalidOperationException">Throws exception if the value is null.</exception>
898 public void SetValue(string value)
900 if (string.IsNullOrEmpty(value))
901 GattUtil.ThrowForError((int)BluetoothError.InvalidParameter, "value should not be null");
903 byte[] val = Encoding.UTF8.GetBytes(value);
908 /// Returns a value at specified offset as the int value of the specified type.
910 /// <param name="type">The type of the int value.</param>
911 /// <param name="An offset">An offset in the attribute value buffer.</param>
912 /// <returns>The int value at given offset.</returns>
913 /// <exception cref="InvalidOperationException">Throws exception if (offset + size of int value) is greater than the length of the value buffer.</exception>
914 public int GetValue(IntDataType type, int offset)
916 return Impl.GetValue(type, offset);
920 /// Updates a value at the specified offset by the int value of the specified type.
922 /// <param name="type">The type of the int value.</param>
923 /// <param name="value">The value to set.</param>
924 /// <param name="offset">An offset in the attribute value buffer.</param>
925 /// <exception cref="InvalidOperationException">Throws exception if (offset + size of int value) is greater than the length of the value buffer.</exception>
926 public void SetValue(IntDataType type, int value, int offset)
928 Impl.SetValue(type, value, offset);
932 /// Returns a value at the specified offset as the float value of the specified type.
934 /// <param name="type">The type of the float value.</param>
935 /// <param name="offset">An offset in the attribute value buffer.</param>
936 /// <returns>The float value at given offset.</returns>
937 /// <exception cref="InvalidOperationException">Throws exception if (offset + size of float value) is greater than the length of the value buffer.</exception>
938 public float GetValue(FloatDataType type, int offset)
940 return Impl.GetValue(type, offset);
944 /// Updates the value at the specified offset by the float value of the specified type.
946 /// <param name="type">The type of the float value.</param>
947 /// <param name="mantissa">The mantissa of the float value.</param>
948 /// <param name="exponent">An exponent of the float value.</param>
949 /// <param name="offset">An offset in the attribute value buffer.</param>
950 /// <exception cref="InvalidOperationException">Throws exception if (offset + size of float value) is greater than the length of the value buffer.</exception>
951 public void SetValue(FloatDataType type, int mantissa, int exponent, int offset)
953 Impl.SetValue(type, mantissa, exponent, offset);
956 internal void ReleaseHandleOwnership()
958 Impl.ReleaseHandleOwnership();
961 internal BluetoothGattAttributeHandle GetHandle()
963 return Impl.GetHandle();