示例#1
0
 internal NotificationSentEventArg(BluetoothGattServer server, string clientAddress, int result, bool completed)
 {
     Result        = result;
     ClientAddress = clientAddress;
     Server        = server;
     Completed     = completed;
 }
示例#2
0
 internal ReadRequestedEventArgs(BluetoothGattServer server, string clientAddress, int requestId, int offset)
 {
     Server        = server;
     ClientAddress = clientAddress;
     RequestId     = requestId;
     Offset        = offset;
 }
示例#3
0
        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);
        }
示例#4
0
 internal void SetParent(BluetoothGattServer parent)
 {
     if (!IsRegistered())
     {
         _parentServer = parent;
         _impl.ReleaseHandleOwnership();
     }
 }
示例#5
0
 /// <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;
     }
 }
示例#6
0
 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;
 }
示例#7
0
 /// <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);
 }
示例#8
0
        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);
        }
示例#9
0
        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);
        }
示例#10
0
        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);
        }
示例#11
0
        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);
        }
示例#12
0
        internal void UnregisterAllGattServices(BluetoothGattServer server)
        {
            int err = Interop.Bluetooth.BtGattServerUnregisterAllServices(_handle);

            GattUtil.ThrowForError(err, "Failed to Unregister all services");
        }
示例#13
0
 internal void UnregisterService()
 {
     _parentServer  = null;
     _parentClient  = null;
     _parentService = null;
 }
示例#14
0
 internal NotificationStateChangedEventArg(BluetoothGattServer server, bool value)
 {
     Server = server;
     Value  = value;
 }