Esempio n. 1
0
        internal void UnregisterGattService(BluetoothGattService service)
        {
            int err = Interop.Bluetooth.BtGattServerUnregisterService(_handle, service.GetHandle());

            GattUtil.ThrowForError(err, "Failed to Unregister service");

            service.UnregisterService();
        }
Esempio n. 2
0
 /// <summary>
 /// Registers a specified service to this server.
 /// </summary>
 /// <param name="service">The service, which needs to be registered with this server.</param>
 /// <exception cref="NotSupportedException">Thrown when the BT/BTLE is not supported.</exception>
 /// <exception cref="InvalidOperationException">Thrown when the register service fails.</exception>
 /// <since_tizen> 3 </since_tizen>
 public void RegisterGattService(BluetoothGattService service)
 {
     if (service.IsRegistered())
     {
         BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.InvalidParameter);
     }
     _impl.RegisterGattService(this, service);
 }
Esempio n. 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);
        }
Esempio n. 4
0
 internal void SetParent(BluetoothGattService parent)
 {
     if (_parent == null)
     {
         _parent = parent;
         ReleaseHandleOwnership();
     }
 }
Esempio n. 5
0
 internal void SetParent(BluetoothGattService parent)
 {
     if (!IsRegistered())
     {
         _parentService = parent;
         _impl.ReleaseHandleOwnership();
     }
 }
Esempio n. 6
0
        /// <summary>
        /// Unregisters a specified service from this server.
        /// </summary>
        /// <param name="service">The service, which needs to be unregistered from this server.</param>
        /// <remarks>
        /// Once unregistered, the service object will become invalid and should not be used to access sevices or any children attribute's methods/members.
        /// </remarks>
        /// <exception cref="NotSupportedException">Thrown when the BT/BTLE is not supported.</exception>
        /// <exception cref="InvalidOperationException">Thrown when the unregister service fails.</exception>
        /// <since_tizen> 3 </since_tizen>
        public void UnregisterGattService(BluetoothGattService service)
        {
            if (service.GetGattServer() != this)
            {
                BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.InvalidParameter);
            }

            _impl.UnregisterGattService(service);
        }
Esempio n. 7
0
        /// <summary>
        /// Includes a service to this service.
        /// </summary>
        /// <param name="service">The service to be included.</param>
        /// <returns>true on success, false otherwise</returns>
        /// <exception cref="InvalidOperationException">Thrown when the add GATT service procedure fails.</exception>///
        /// <since_tizen> 3 </since_tizen>
        public void AddService(BluetoothGattService service)
        {
            if (GetGattClient() != null)
            {
                BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotSupported);
            }

            if (service.IsRegistered())
            {
                BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.InvalidParameter);
            }

            _impl.AddIncludeService(service);
            service.SetParent(this);
        }
Esempio n. 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);
        }
Esempio n. 9
0
        internal BluetoothGattCharacteristic GetCharacteristic(BluetoothGattService service, string uuid)
        {
            BluetoothGattAttributeHandle attributeHandle;
            int err = Interop.Bluetooth.BtGattServiceGetCharacteristic(_handle, uuid, out attributeHandle);

            if (err.IsFailed())
            {
                GattUtil.Error(err, string.Format("Failed to get Characteristic with UUID ({0})", uuid));
                return(null);
            }

            BluetoothGattCharacteristic Characteristic = BluetoothGattCharacteristicImpl.CreateBluetoothGattGattCharacteristic(attributeHandle, uuid);

            Characteristic.SetParent(service);
            return(Characteristic);
        }
Esempio n. 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);
        }
Esempio n. 11
0
        internal IEnumerable <BluetoothGattCharacteristic> GetCharacteristics(BluetoothGattService service)
        {
            List <BluetoothGattCharacteristic> attribututeList = new List <BluetoothGattCharacteristic>();

            Interop.Bluetooth.BtGattForeachCallback cb = (total, index, attributeHandle, userData) =>
            {
                BluetoothGattAttributeHandle handle         = new BluetoothGattAttributeHandle(attributeHandle, false);
                BluetoothGattCharacteristic  Characteristic = BluetoothGattCharacteristicImpl.CreateBluetoothGattGattCharacteristic(handle, "");
                if (Characteristic != null)
                {
                    Characteristic.SetParent(service);
                    attribututeList.Add(Characteristic);
                }
                return(true);
            };

            int err = Interop.Bluetooth.BtGattServiceForeachCharacteristics(service.GetHandle(), cb, IntPtr.Zero);

            GattUtil.Error(err, "Failed to get all Characteristic");

            return(attribututeList);
        }
Esempio n. 12
0
        internal IEnumerable <BluetoothGattService> GetIncludeServices(BluetoothGattService parentService)
        {
            List <BluetoothGattService> attribututeList = new List <BluetoothGattService>();

            _includedServiceForeachCallback = (total, index, attributeHandle, userData) =>
            {
                BluetoothGattAttributeHandle handle  = new BluetoothGattAttributeHandle(attributeHandle, false);
                BluetoothGattService         service = BluetoothGattServiceImpl.CreateBluetoothGattService(handle, "");
                if (service != null)
                {
                    service.SetParent(parentService);
                    attribututeList.Add(service);
                }
                return(true);
            };

            int err = Interop.Bluetooth.BtGattServiceForeachIncludedServices(parentService.GetHandle(), _includedServiceForeachCallback, IntPtr.Zero);

            GattUtil.Error(err, "Failed to get all services");

            return(attribututeList);
        }
Esempio n. 13
0
        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));
        }
Esempio n. 14
0
 internal void UnregisterService()
 {
     _parentServer  = null;
     _parentClient  = null;
     _parentService = null;
 }