internal void RegisterGattService(BluetoothGattServer server, BluetoothGattService service) { int err = Interop.Bluetooth.BtGattServerRegisterService(_handle, service.GetHandle()); GattUtil.ThrowForError(err, "Failed to Register service"); service.SetParent(server); }
internal void UnregisterGattService(BluetoothGattService service) { int err = Interop.Bluetooth.BtGattServerUnregisterService(_handle, service.GetHandle()); GattUtil.ThrowForError(err, "Failed to Unregister service"); service.UnregisterService(); }
internal BluetoothGattServerImpl() { int err = Interop.Bluetooth.BtGattServerInitialize(); GattUtil.ThrowForError(err, "Failed to initialize server"); err = Interop.Bluetooth.BtGattServerCreate(out _handle); GattUtil.ThrowForError(err, "Failed to create server"); }
internal string GetRemoteAddress() { string remoteAddress; int err = Interop.Bluetooth.BtGattClientGetRemoteAddress(_handle, out remoteAddress); GattUtil.ThrowForError(err, "Failed to get remote address for this client"); return(remoteAddress); }
/// <summary> /// Sets the string value as a specified offset. /// </summary> /// <param name="value">value to set</param> /// <exception cref="InvalidOperationException">Throws exception if the value is null.</exception> /// <since_tizen> 3 </since_tizen> public void SetValue(string value) { if (string.IsNullOrEmpty(value)) { GattUtil.ThrowForError((int)BluetoothError.InvalidParameter, "value should not be null"); } byte[] val = Encoding.UTF8.GetBytes(value); Impl.SetValue(val); }
internal BluetoothGattServerImpl() { _sendIndicationCallback = SendIndicationCallback; int err = Interop.Bluetooth.BtGattServerInitialize(); GattUtil.ThrowForError(err, "Failed to initialize server"); err = Interop.Bluetooth.BtGattServerCreate(out _handle); GattUtil.ThrowForError(err, "Failed to create server"); }
internal BluetoothGattClientImpl(string remoteAddress) { if (BluetoothAdapter.IsBluetoothEnabled) { int err = Interop.Bluetooth.BtGattClientCreate(remoteAddress, out _handle); GattUtil.ThrowForError(err, "Failed to get native client handle"); } else { BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled); } }
internal static BluetoothGattService CreateBluetoothGattService(BluetoothGattAttributeHandle handle, string uuid) { if (uuid == "") { int err = Interop.Bluetooth.BtGattGetUuid(handle, out uuid); GattUtil.ThrowForError(err, "Failed to get UUID"); } BluetoothGattServiceImpl impl = new BluetoothGattServiceImpl(handle); return(new BluetoothGattService(impl, uuid)); }
internal static BluetoothGattDescriptor CreateBluetoothGattDescriptor(BluetoothGattAttributeHandle handle, string uuid) { int permission; int err = Interop.Bluetooth.BtGattDescriptorGetPermissions(handle, out permission); GattUtil.ThrowForError(err, string.Format("Failed to get permissions with UUID ({0})", uuid)); if (uuid == "") { int ret = Interop.Bluetooth.BtGattGetUuid(handle, out uuid); GattUtil.ThrowForError(ret, "Failed to get UUID"); } BluetoothGattDescriptorImpl impl = new BluetoothGattDescriptorImpl(handle); return(new BluetoothGattDescriptor(impl, uuid, (BluetoothGattPermission)permission)); }
internal static BluetoothGattCharacteristic CreateBluetoothGattGattCharacteristic(BluetoothGattAttributeHandle handle, string uuid) { int permission; int err = Interop.Bluetooth.BtGattCharacteristicGetPermissions(handle, out permission); GattUtil.ThrowForError(err, "Failed to get permissions"); if (uuid == "") { err = Interop.Bluetooth.BtGattGetUuid(handle, out uuid); GattUtil.ThrowForError(err, "Failed to get UUID"); } BluetoothGattCharacteristicImpl impl = new BluetoothGattCharacteristicImpl(handle); return(new BluetoothGattCharacteristic(impl, uuid, (BluetoothGattPermission)permission)); }
internal Task <bool> SendIndicationAsync(BluetoothGattServer server, BluetoothGattCharacteristic characteristic, string clientAddress) { TaskCompletionSource <bool> tcs = new TaskCompletionSource <bool>(); Interop.Bluetooth.BtGattServerNotificationSentCallback cb = (result, address, serverHandle, characteristicHandle, completed, userData) => { _notificationSent?.Invoke(characteristic, new NotificationSentEventArg(server, address, result, completed)); if (completed) { tcs.SetResult(true); } }; int err = Interop.Bluetooth.BtGattServerNotify(characteristic.GetHandle(), cb, clientAddress, IntPtr.Zero); GattUtil.ThrowForError(err, string.Format("Failed to send value changed indication for characteristic uuid {0}", characteristic.Uuid)); return(tcs.Task); }
internal void AddDescriptor(BluetoothGattDescriptor descriptor) { int err = Interop.Bluetooth.BtGattCharacteristicAddDescriptor(_handle, descriptor.GetHandle()); GattUtil.ThrowForError(err, string.Format("Failed to add descriptor with UUID ({0})", descriptor.Uuid)); }
internal BluetoothGattCharacteristicImpl(string uuid, BluetoothGattPermission permission, BluetoothGattProperty property, byte[] value) { int err = Interop.Bluetooth.BtGattCharacteristicCreate(uuid, (int)permission, (int)property, value, value.Length, out _handle); GattUtil.ThrowForError(err, "Failed to get native characteristic handle"); }
internal void Connect(string remoteAddress, bool autoConnect) { int err = Interop.Bluetooth.GattConnect(remoteAddress, autoConnect); GattUtil.ThrowForError(err, "Failed to connect to remote address"); }
internal void Start() { int err = Interop.Bluetooth.BtGattServerStart(); GattUtil.ThrowForError(err, "Failed to start server"); }
internal void SetValue(FloatDataType type, int mantissa, int exponent, int offset) { int err = Interop.Bluetooth.BtGattSetFloatValue(_handle, (int)type, mantissa, exponent, offset); GattUtil.ThrowForError(err, "Failed to set attribute float value at offset"); }
internal void SendNotification(BluetoothGattCharacteristic characteristic, string clientAddress) { int err = Interop.Bluetooth.BtGattServerNotify(characteristic.GetHandle(), null, clientAddress, IntPtr.Zero); GattUtil.ThrowForError(err, string.Format("Failed to send value changed notification for characteristic uuid {0}", characteristic.Uuid)); }
internal BluetoothGattDescriptorImpl(string uuid, BluetoothGattPermission permission, byte[] value) { int err = Interop.Bluetooth.BtGattDescriptorCreate(uuid, (int)permission, value, value.Length, out _handle); GattUtil.ThrowForError(err, "Failed to get native descriptor handle"); }
internal BluetoothGattServiceImpl(string uuid, BluetoothGattServiceType type) { int err = Interop.Bluetooth.BtGattServiceCreate(uuid, (int)type, out _handle); GattUtil.ThrowForError(err, "Failed to get native service handle"); }
internal void Disconnect(string remoteAddress) { int err = Interop.Bluetooth.GattDisconnect(remoteAddress); GattUtil.ThrowForError(err, "Failed to disconnect to remote address"); }
internal void SetValue(IntDataType type, int value, int offset) { int err = Interop.Bluetooth.BtGattSetIntValue(_handle, (int)type, value, offset); GattUtil.ThrowForError(err, "Failed to set attribute int value at offset"); }
internal void SendResponse(int requestId, int request_type, int status, byte[] value, int offset) { int err = Interop.Bluetooth.BtGattServerSendResponse(requestId, request_type, offset, status, value, value.Length); GattUtil.ThrowForError(err, string.Format("Failed to send response for request Id {0}", requestId)); }
internal void SetValue(byte[] value) { int err = Interop.Bluetooth.BtGattSetValue(_handle, value, value.Length); GattUtil.ThrowForError(err, "Failed to set attribute value"); }
internal void AddCharacteristic(BluetoothGattCharacteristic characteristic) { int err = Interop.Bluetooth.BtGattServiceAddCharacteristic(_handle, characteristic.GetHandle()); GattUtil.ThrowForError(err, string.Format("Failed to add characteristic with UUID ({0})", characteristic.Uuid)); }
internal void UnregisterAllGattServices(BluetoothGattServer server) { int err = Interop.Bluetooth.BtGattServerUnregisterAllServices(_handle); GattUtil.ThrowForError(err, "Failed to Unregister all services"); }
internal void AddIncludeService(BluetoothGattService includedService) { int err = Interop.Bluetooth.BtGattServiceAddIncludedService(_handle, includedService.GetHandle()); GattUtil.ThrowForError(err, string.Format("Failed to add service with UUID ({0})", includedService.Uuid)); }
internal void SetWriteValueRequestedEventCallback(Interop.Bluetooth.BtGattServerWriteValueRequestedCallback callback) { int err = Interop.Bluetooth.BtGattServerSetWriteValueRequestedCallback(_handle, callback, IntPtr.Zero); GattUtil.ThrowForError(err, "Failed to set attribute write value requested callback"); }
internal BluetoothGattClientImpl(string remoteAddress) { int err = Interop.Bluetooth.BtGattClientCreate(remoteAddress, out _handle); GattUtil.ThrowForError(err, "Failed to get native client handle"); }