internal NotificationSentEventArg(BluetoothGattServer server, string clientAddress, int result, bool completed) { Result = result; ClientAddress = clientAddress; Server = server; Completed = completed; }
internal ReadRequestedEventArgs(BluetoothGattServer server, string clientAddress, int requestId, int offset) { Server = server; ClientAddress = clientAddress; RequestId = requestId; Offset = offset; }
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 SetParent(BluetoothGattServer parent) { if (!IsRegistered()) { _parentServer = parent; _impl.ReleaseHandleOwnership(); } }
/// <summary> /// Releases all the resources currently used by this instance. /// </summary> /// <param name="disposing">true if the managed resources should be disposed, otherwise false.</param> /// <since_tizen> 6 </since_tizen> protected virtual void Dispose(bool disposing) { if (disposing) { _impl?.GetHandle()?.Dispose(); _instance = null; } }
internal WriteRequestedEventArgs(BluetoothGattServer server, string clientAddress, int requestId, byte[] value, int offset, bool response_needed) { Server = server; ClientAddress = clientAddress; RequestId = requestId; Value = value; Offset = offset; Response_needed = response_needed; }
/// <summary> /// Creates the Bluetooth GATT server. /// </summary> /// <returns>The BluetoothGattServer instance.</returns> /// <exception cref="NotSupportedException">Thrown when the BT/BTLE is not supported.</exception> /// <exception cref="InvalidOperationException">Thrown when the create GATT server fails.</exception> /// <since_tizen> 3 </since_tizen> public static BluetoothGattServer CreateServer() { if (_instance == null) { BluetoothGattServer server = new BluetoothGattServer(); if (server.IsValid()) { _instance = server; } } return(_instance); }
internal BluetoothGattService GetService(BluetoothGattServer server, string uuid) { BluetoothGattAttributeHandle serviceHandle; int err = Interop.Bluetooth.BtGattServerGetService(_handle, uuid, out serviceHandle); if (err.IsFailed()) { GattUtil.Error(err, string.Format("Failed to get service with UUID ({0})", uuid)); return(null); } BluetoothGattService service = new BluetoothGattService(new BluetoothGattServiceImpl(serviceHandle), uuid);; service.SetParent(server); return(service); }
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 IEnumerable <BluetoothGattService> GetServices(BluetoothGattServer server) { List <BluetoothGattService> attribututeList = new List <BluetoothGattService>(); Interop.Bluetooth.BtGattForeachCallback cb = (total, index, attributeHandle, userData) => { BluetoothGattAttributeHandle handle = new BluetoothGattAttributeHandle(attributeHandle, false); BluetoothGattService service = BluetoothGattServiceImpl.CreateBluetoothGattService(handle, "");; if (service != null) { service.SetParent(server); attribututeList.Add(service); } return(true); }; int err = Interop.Bluetooth.BtGattServerForeachServices(_handle, cb, IntPtr.Zero); GattUtil.Error(err, "Failed to get all services"); return(attribututeList); }
internal Task <bool> SendIndicationAsync(BluetoothGattServer server, BluetoothGattCharacteristic characteristic, string clientAddress) { TaskCompletionSource <bool> task = new TaskCompletionSource <bool>(); int requestId = 0; lock (this) { requestId = _requestId++; _sendIndicationTaskSource[requestId] = task; } int err = Interop.Bluetooth.BtGattServerNotify(characteristic.GetHandle(), _sendIndicationCallback, clientAddress, (IntPtr)requestId); if (err.IsFailed()) { GattUtil.Error(err, string.Format("Failed to send value changed indication for characteristic uuid {0}", characteristic.Uuid)); task.SetResult(false); _sendIndicationTaskSource.Remove(requestId); BluetoothErrorFactory.ThrowBluetoothException(err); } return(task.Task); }
internal void UnregisterAllGattServices(BluetoothGattServer server) { int err = Interop.Bluetooth.BtGattServerUnregisterAllServices(_handle); GattUtil.ThrowForError(err, "Failed to Unregister all services"); }
internal void UnregisterService() { _parentServer = null; _parentClient = null; _parentService = null; }
internal NotificationStateChangedEventArg(BluetoothGattServer server, bool value) { Server = server; Value = value; }