예제 #1
0
 internal void SetParent(BluetoothGattClient parent)
 {
     if (!IsRegistered())
     {
         _parentClient = parent;
         _impl.ReleaseHandleOwnership();
     }
 }
예제 #2
0
        internal BluetoothGattService GetService(BluetoothGattClient client, string uuid)
        {
            BluetoothGattAttributeHandle serviceHandle;
            int err = Interop.Bluetooth.BtGattClientGetService(_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(client);
            return(service);
        }
예제 #3
0
        internal IEnumerable <BluetoothGattService> GetServices(BluetoothGattClient client)
        {
            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(client);
                    attribututeList.Add(service);
                }
                return(true);
            };

            int err = Interop.Bluetooth.BtGattClientForeachServices(_handle, cb, IntPtr.Zero);

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

            return(attribututeList);
        }
예제 #4
0
        public BluetoothGattClient GattConnect(bool autoConnect)
        {
            BluetoothGattClient client = null;

            if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
            {
                int ret = BluetoothLeImplAdapter.Instance.GattConnect(_remoteAddress, autoConnect);
                if (ret != (int)BluetoothError.None)
                {
                    Log.Error(Globals.LogTag, "Failed to create GATT Connection with remote device- " + (BluetoothError)ret);
                }
                else
                {
                    client = BluetoothGattClient.CreateClient(_remoteAddress);
                }
            }
            else
            {
                BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
            }
            return(client);
        }
예제 #5
0
 internal void UnregisterService()
 {
     _parentServer  = null;
     _parentClient  = null;
     _parentService = null;
 }
예제 #6
0
        internal static BluetoothGattClient CreateClient(string remoteAddress)
        {
            BluetoothGattClient client = new BluetoothGattClient(remoteAddress);

            return(client.Isvalid() ? client : null);
        }