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="NotSupportedException">Thrown when the BT/BTLE is not supported.</exception>
57 /// <exception cref="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="NotSupportedException">Thrown when the BT/BTLE is not supported.</exception>
75 /// <exception cref="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="NotSupportedException">Thrown when the BT/BTLE is not supported.</exception>
86 /// <exception cref="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="NotSupportedException">Thrown when the BT/BTLE is not supported.</exception>
104 /// <exception cref="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="NotSupportedException">Thrown when the BT/BTLE is not supported.</exception>
122 /// <exception cref="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="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="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="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;
213 /// Destroy Bluetooth GATT client
215 public void DestroyClient()
217 _impl.GetHandle().Dispose();
221 /// The address of the remote device.
223 /// <exception cref="InvalidOperationException">Thrown when the BT/BTLE is not enabled
224 /// or when the remote device is disconnected.</exception>
225 public string RemoteAddress
229 if (string.IsNullOrEmpty(_remoteAddress))
231 _remoteAddress = _impl.GetRemoteAddress();
233 return _remoteAddress;
238 /// Gets the service with the given UUID that belongs to the remote device.
240 /// <param name="uuid">The UUID for the service to get.</param>
241 /// <returns>The service with the given UUID if it exists, null otherwise.</returns>
242 /// <exception cref="InvalidOperationException">Thrown when the BT/BTLE is not enabled
243 /// or when the remote device is disconnected, or when the get service fails.</exception>
244 public BluetoothGattService GetService(string uuid)
246 return _impl.GetService(this, uuid);
250 /// Gets list of services that belongs to the remote device.
252 /// <returns>The list of services that belongs to the remote device.</returns>
253 /// <exception cref="InvalidOperationException">Thrown when the BT/BTLE is not enabled
254 /// or when the remote device is disconnected, or when the get service fails.</exception>
255 public IEnumerable<BluetoothGattService> GetServices()
257 return _impl.GetServices(this);
261 /// Reads the value of a given characteristic from the remote device asynchronously.
263 /// <param name="characteristic">The characteristic to be read.</param>
264 /// <returns>true on success, false otherwise.</returns>
265 /// <exception cref="InvalidOperationException">Thrown when the BT/BTLE is not enabled
266 /// or when the remote device is disconnected, or when the read attribute value fails.</exception>
267 public async Task<bool> ReadValueAsync(BluetoothGattCharacteristic characteristic)
269 return await _impl.ReadValueAsyncTask(characteristic.GetHandle());
273 /// Reads the value of the given descriptor from the remote device asynchronously.
275 /// <param name="descriptor">The descriptor to be read.</param>
276 /// <returns>true on success, false otherwise.</returns>
277 /// <exception cref="InvalidOperationException">Thrown when the BT/BTLE is not enabled
278 /// or when the remote device is disconnected, or when the read attribute value fails.</exception>
279 public async Task<bool> ReadValueAsync(BluetoothGattDescriptor descriptor)
281 return await _impl.ReadValueAsyncTask(descriptor.GetHandle());
285 /// Writes the value of a given characteristic to the remote device asynchronously.
287 /// <param name="characteristic">The characteristic to be written.</param>
288 /// <returns>true on success, false otherwise.</returns>
289 /// <exception cref="InvalidOperationException">Thrown when the BT/BTLE is not enabled
290 /// or when the remote device is disconnected or when the write attribute value fails.</exception>
291 public async Task<bool> WriteValueAsync(BluetoothGattCharacteristic characteristic)
293 return await _impl.WriteValueAsyncTask(characteristic.GetHandle());
297 /// Writes the value of the given descriptor to the remote device asynchronously.
299 /// <param name="descriptor">The descriptor to be written.</param>
300 /// <returns>true on success, false otherwise.</returns>
301 /// <exception cref="InvalidOperationException">Thrown when the BT/BTLE is not enabled
302 /// or when the remote device is disconnected, or when the write attribute value fails.</exception>
303 public async Task<bool> WriteValueAsync(BluetoothGattDescriptor descriptor)
305 return await _impl.WriteValueAsyncTask(descriptor.GetHandle());
308 internal bool Isvalid()
310 return _impl.GetHandle().IsInvalid == false;
315 /// The Bluetooth GATT service.
317 public class BluetoothGattService
319 private BluetoothGattServiceImpl _impl;
320 private BluetoothGattClient _parentClient = null;
321 private BluetoothGattServer _parentServer = null;
322 private BluetoothGattService _parentService = null;
327 /// <param name="uuid">The UUID of the service.</param>
328 /// <param name="type">The type of service.</param>
329 /// <exception cref="InvalidOperationException">Thrown when the create GATT service procedure fails.</exception>
330 public BluetoothGattService(string uuid, BluetoothGattServiceType type)
333 _impl = new BluetoothGattServiceImpl(uuid, type);
336 internal BluetoothGattService(BluetoothGattServiceImpl impl, string uuid)
343 /// Specification name from the UUID.
345 public string Uuid { get; }
348 /// Adds a characteristic to this service.
350 /// <param name="characteristic">The characteristic to be added.</param>
351 /// <returns>true on success, false otherwise.</returns>
352 /// <exception cref="InvalidOperationException">Thrown when the add GATT characteristic procedure fails.</exception>
353 public void AddCharacteristic(BluetoothGattCharacteristic characteristic)
355 if (GetGattClient() != null)
357 BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotSupported);
360 if (characteristic.GetService() != null)
362 BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.InvalidParameter);
365 _impl.AddCharacteristic(characteristic);
366 characteristic.SetParent(this);
370 /// Gets the characteristic with the given UUID that belongs to this service.
372 /// <param name="uuid">The UUID for the characteristic to get.</param>
373 /// <returns>The characteristic with a given UUID if it exists, null otherwise.</returns>
374 public BluetoothGattCharacteristic GetCharacteristic(string uuid)
376 return _impl.GetCharacteristic(this, uuid);
380 /// Gets list of the characteristic that belongs to this service.
382 /// <returns>The list of the characteristic that belongs to this service.</returns>
383 public IEnumerable<BluetoothGattCharacteristic> GetCharacteristics()
385 return _impl.GetCharacteristics(this);
389 /// Includes a service to this service.
391 /// <param name="service">The service to be included.</param>
392 /// <returns>true on success, false otherwise</returns>
393 /// <exception cref="InvalidOperationException">Thrown when the add GATT service procedure fails.</exception>///
394 public void AddService(BluetoothGattService service)
396 if (GetGattClient() != null)
398 BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotSupported);
401 if (service.IsRegistered())
403 BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.InvalidParameter);
406 _impl.AddIncludeService(service);
407 service.SetParent(this);
411 /// Gets the included service.
413 /// <param name="uuid">The UUID for the service to get.</param>
414 /// <returns>The service with a given UUID if it exists, null otherwise.</returns>
415 public BluetoothGattService GetIncludeService(string uuid)
417 return _impl.GetIncludeService(this, uuid);
421 /// Gets the included service list of this service.
423 /// <returns>The included service list of this service.</returns>
424 public IEnumerable<BluetoothGattService> GetIncludeServices()
426 return _impl.GetIncludeServices(this);
430 /// Gets the server instance which the specified service belongs to.
432 /// <returns>The server instance which the specified service belongs to.</returns>
433 public BluetoothGattServer GetGattServer()
435 return _parentServer;
439 /// Gets the client instance which the specified service belongs to.
441 /// <returns>The client instance which the specified service belongs to.</returns>
442 public BluetoothGattClient GetGattClient()
444 return _parentClient;
447 internal BluetoothGattAttributeHandle GetHandle()
449 return _impl.GetHandle();
452 internal void SetParent(BluetoothGattService parent)
456 _parentService = parent;
457 _impl.ReleaseHandleOwnership();
461 internal void SetParent(BluetoothGattClient parent)
465 _parentClient = parent;
466 _impl.ReleaseHandleOwnership();
470 internal void SetParent(BluetoothGattServer parent)
474 _parentServer = parent;
475 _impl.ReleaseHandleOwnership();
479 internal void UnregisterService()
481 _parentServer = null;
482 _parentClient = null;
483 _parentService = null;
486 internal bool IsRegistered()
488 return _parentClient != null || _parentServer != null || _parentService != null;
493 /// The Bluetooth GATT characteristic.
495 public class BluetoothGattCharacteristic : BluetoothGattAttribute
497 private BluetoothGattCharacteristicImpl _impl;
498 private BluetoothGattService _parent = null;
500 private Interop.Bluetooth.BtClientCharacteristicValueChangedCallback _characteristicValueChangedCallback;
501 private Interop.Bluetooth.BtGattServerNotificationStateChangeCallback _notificationStateChangedCallback;
503 private EventHandler<ValueChangedEventArgs> _characteristicValueChanged;
504 internal EventHandler<NotificationStateChangedEventArg> _notificationStateChanged;
509 /// <param name="uuid">The UUID of the characterstic.</param>
510 /// <param name="permissions">Permissions for the characterstic.</param>
511 /// <param name="properties">Properties set for the characterstic.</param>
512 /// <param name="value">The value associated with the characterstic.</param>
513 /// <remarks>throws in case of internal error.</remarks>
514 /// <exception cref="InvalidOperationException">Thrown when the create GATT characteristics procedure fails.</exception>
515 public BluetoothGattCharacteristic(string uuid, BluetoothGattPermission permissions, BluetoothGattProperty properties, byte[] value) : base(uuid, permissions)
517 _impl = new BluetoothGattCharacteristicImpl(uuid, permissions, properties, value);
520 internal BluetoothGattCharacteristic(BluetoothGattCharacteristicImpl impl, string uuid, BluetoothGattPermission permission) : base(uuid, permission)
526 /// The CharacteristicValueChanged event is raised when the server notifies for change in this characteristic value.
529 /// Adding the event handle on characteristic on the server side will not have any effect.
531 public event EventHandler<ValueChangedEventArgs> ValueChanged
537 if (_characteristicValueChanged == null)
539 _characteristicValueChangedCallback = (gattHandle, characteristicValue, len, userData) =>
541 _characteristicValueChanged?.Invoke(this, new ValueChangedEventArgs(characteristicValue));
544 _impl.SetCharacteristicValueChangedEvent(_characteristicValueChangedCallback);
546 _characteristicValueChanged = value;
553 _characteristicValueChanged = null;
554 if (_characteristicValueChanged == null)
556 _impl.UnsetCharacteristicValueChangedEvent();
564 /// The NotificationStateChanged event is called when the client enables or disables the Notification/Indication for particular characteristics.
567 /// Adding event handle on the characteristic on the client side will not have any effect.
569 public event EventHandler<NotificationStateChangedEventArg> NotificationStateChanged
575 if (_notificationStateChangedCallback == null)
577 _notificationStateChangedCallback = (notify, serverHandle, characteristicHandle, userData) =>
579 _notificationStateChanged?.Invoke(this, new NotificationStateChangedEventArg(Server, notify));
582 _impl.SetNotificationStateChangedEvent(_notificationStateChangedCallback);
585 _notificationStateChanged = value;
592 _notificationStateChanged = null;
593 // CAPI does not allow unsetting ReadValueRequestedEventCallback.
599 /// The property for this characteristic.
601 public BluetoothGattProperty Properties
605 return _impl.GetProperties();
611 _impl.SetProperties(value);
617 /// The write type to be used for write operations.
619 public BluetoothGattWriteType WriteType
623 return _impl.GetWriteType();
627 _impl.SetWriteType(value);
631 internal override BluetoothGattClient Client
635 return _parent?.GetGattClient();
639 internal override BluetoothGattServer Server
643 return _parent?.GetGattServer();
647 internal override BluetoothGattAttributeImpl Impl
656 /// Adds a descriptor to this characteristic.
658 /// <param name="descriptor">The descriptor to be added.</param>
659 /// <returns>true on success, false otherwise.</returns>
660 /// <exception cref="InvalidOperationException">Thrown when the add GATT descriptor procedure fails.</exception>
661 public void AddDescriptor(BluetoothGattDescriptor descriptor)
665 BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotSupported);
668 if (descriptor.GetCharacteristic() != null)
670 BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.InvalidParameter);
673 _impl.AddDescriptor(descriptor);
674 descriptor.SetParent(this);
678 /// Gets the descriptor with the given UUID that belongs to this characteristic.
680 /// <param name="uuid">The UUID for the descriptor to get.</param>
681 /// <returns>The descriptor with a given UUID if it exists, null otherwise.</returns>
682 public BluetoothGattDescriptor GetDescriptor(string uuid)
684 return _impl.GetDescriptor(this, uuid);
688 /// Gets the list of descriptors that belongs to this characteristic.
690 /// <returns>The list of descriptors that belongs to this characteristic.</returns>
691 public IEnumerable<BluetoothGattDescriptor> GetDescriptors()
693 return _impl.GetDescriptors(this);
697 /// Gets the service instance, which the specified characterstic belongs to.
699 /// <returns>The characteristic instance, the specified characterstic belongs to.</returns>
700 public BluetoothGattService GetService()
705 internal void SetParent(BluetoothGattService parent)
710 ReleaseHandleOwnership();
716 /// The Bluetooth GATT descriptor.
718 public class BluetoothGattDescriptor : BluetoothGattAttribute
720 private BluetoothGattCharacteristic _parent = null;
721 private BluetoothGattDescriptorImpl _impl;
726 /// <param name="uuid">The UUID of the descriptor.</param>
727 /// <param name="permisions">Permissions for the descriptor.</param>
728 /// <param name="value">The value associated with the descriptor.</param>
729 /// <remarks>throws in case of internal error.</remarks>
730 /// <exception cref="InvalidOperationException">Thrown when the create GATT descriptor procedure fails.</exception>
731 public BluetoothGattDescriptor(string uuid, BluetoothGattPermission permisions, byte[] value) : base (uuid, permisions)
733 _impl = new BluetoothGattDescriptorImpl(uuid, permisions, value);
736 internal BluetoothGattDescriptor(BluetoothGattDescriptorImpl impl, string uuid, BluetoothGattPermission permission) : base(uuid, permission)
741 internal override BluetoothGattClient Client
745 return _parent?.Client;
749 internal override BluetoothGattServer Server
753 return _parent?.Server;
757 internal override BluetoothGattAttributeImpl Impl
766 /// Gets the characteristic instance, which the specified descriptor belongs to.
768 /// <returns>The characteristic instance, the specified descriptor belongs to.</returns>
769 public BluetoothGattCharacteristic GetCharacteristic()
774 internal void SetParent(BluetoothGattCharacteristic parent)
779 ReleaseHandleOwnership();
785 /// The Bluetooth GATT attribute.
787 public abstract class BluetoothGattAttribute
789 private Interop.Bluetooth.BtGattServerReadValueRequestedCallback _readValueRequestedCallback;
790 private Interop.Bluetooth.BtGattServerWriteValueRequestedCallback _writeValueRequestedCallback;
792 private EventHandler<ReadRequestedEventArgs> _readValueRequested;
793 private EventHandler<WriteRequestedEventArgs> _writeValueRequested;
798 /// <param name="uuid">The UUID of the GATT attribute.</param>
799 /// <param name="permission">Permission for the GATT attribute.</param>
800 public BluetoothGattAttribute(string uuid, BluetoothGattPermission permission)
803 Permissions = permission;
809 /// This event is called when the client request to read the value of a characteristic or a descriptor.
811 /// <exception cref="InvalidOperationException">Thrown when the set read value requested callback procedure fails.</exception>
812 public event EventHandler<ReadRequestedEventArgs> ReadRequested
816 if (Server == null) return;
817 if (_readValueRequestedCallback == null)
819 _readValueRequestedCallback = (clientAddress, requestId, serverHandle, gattHandle, offset, userData) =>
821 _readValueRequested?.Invoke(this, new ReadRequestedEventArgs(Server, clientAddress, requestId, offset));
823 Impl.SetReadValueRequestedEventCallback(_readValueRequestedCallback);
825 _readValueRequested = value;
829 if (Server == null) return;
830 _readValueRequested = null;
831 // CAPI does not allow unsetting ReadValueRequestedEventCallback.
836 /// This event is called when a value of a characteristic or a descriptor has been changed by a client.
838 /// <exception cref="InvalidOperationException">Thrown when the set write value requested callback procedure fails.</exception>
839 public event EventHandler<WriteRequestedEventArgs> WriteRequested
843 if (Server == null) return;
844 if (_writeValueRequested == null)
846 _writeValueRequestedCallback = (clientAddress, requestId, serverHandle, gattHandle, offset, response_needed, valueToWrite, len, userData) =>
848 _writeValueRequested?.Invoke(this, new WriteRequestedEventArgs(Server, clientAddress, requestId, valueToWrite, offset, response_needed));
850 Impl.SetWriteValueRequestedEventCallback(_writeValueRequestedCallback);
852 _writeValueRequested = value;
856 if (Server == null) return;
857 _writeValueRequested = null;
858 // CAPI does not allow unsetting ReadValueRequestedEventCallback.
863 /// The attribute's UUID.
865 public string Uuid { get; }
868 /// Permissions for this attribute.
870 public BluetoothGattPermission Permissions { get; }
873 /// The value of this descriptor.
879 return Impl.GetValue();
883 Impl.SetValue(value);
887 internal abstract BluetoothGattClient Client { get; }
888 internal abstract BluetoothGattServer Server { get; }
889 internal abstract BluetoothGattAttributeImpl Impl { get; }
892 /// Returns a string value at the specified offset.
894 /// <param name="offset"></param>
895 /// <returns>The string value at specified offset.</returns>
896 public string GetValue(int offset)
898 return Impl.GetValue(offset);
902 /// Sets the string value as a specified offset.
904 /// <param name="value">value to set</param>
905 /// <exception cref="InvalidOperationException">Throws exception if the value is null.</exception>
906 public void SetValue(string value)
908 if (string.IsNullOrEmpty(value))
909 GattUtil.ThrowForError((int)BluetoothError.InvalidParameter, "value should not be null");
911 byte[] val = Encoding.UTF8.GetBytes(value);
916 /// Returns a value at specified offset as the int value of the specified type.
918 /// <param name="type">The type of the int value.</param>
919 /// <param name="offset">An offset in the attribute value buffer.</param>
920 /// <returns>The int value at given offset.</returns>
921 /// <exception cref="InvalidOperationException">Throws exception if (offset + size of int value) is greater than the length of the value buffer.</exception>
922 public int GetValue(IntDataType type, int offset)
924 return Impl.GetValue(type, offset);
928 /// Updates a value at the specified offset by the int value of the specified type.
930 /// <param name="type">The type of the int value.</param>
931 /// <param name="value">The value to set.</param>
932 /// <param name="offset">An offset in the attribute value buffer.</param>
933 /// <exception cref="InvalidOperationException">Throws exception if (offset + size of int value) is greater than the length of the value buffer.</exception>
934 public void SetValue(IntDataType type, int value, int offset)
936 Impl.SetValue(type, value, offset);
940 /// Returns a value at the specified offset as the float value of the specified type.
942 /// <param name="type">The type of the float value.</param>
943 /// <param name="offset">An offset in the attribute value buffer.</param>
944 /// <returns>The float value at given offset.</returns>
945 /// <exception cref="InvalidOperationException">Throws exception if (offset + size of float value) is greater than the length of the value buffer.</exception>
946 public float GetValue(FloatDataType type, int offset)
948 return Impl.GetValue(type, offset);
952 /// Updates the value at the specified offset by the float value of the specified type.
954 /// <param name="type">The type of the float value.</param>
955 /// <param name="mantissa">The mantissa of the float value.</param>
956 /// <param name="exponent">An exponent of the float value.</param>
957 /// <param name="offset">An offset in the attribute value buffer.</param>
958 /// <exception cref="InvalidOperationException">Throws exception if (offset + size of float value) is greater than the length of the value buffer.</exception>
959 public void SetValue(FloatDataType type, int mantissa, int exponent, int offset)
961 Impl.SetValue(type, mantissa, exponent, offset);
964 internal void ReleaseHandleOwnership()
966 Impl.ReleaseHandleOwnership();
969 internal BluetoothGattAttributeHandle GetHandle()
971 return Impl.GetHandle();