예제 #1
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);
        }
예제 #2
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);
        }
예제 #3
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);
        }
예제 #4
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);
        }
예제 #5
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);
        }