示例#1
0
        public override IObservable <IGattDescriptor> WhenDescriptorDiscovered()
        {
            this.descriptorOb = this.descriptorOb ?? Observable.Create <IGattDescriptor>(ob =>
            {
                var descriptors = new Dictionary <Guid, IGattDescriptor>();

                var p       = this.native.Service.Peripheral;
                var handler = new EventHandler <CBCharacteristicEventArgs>((sender, args) =>
                {
                    if (this.native.Descriptors == null)
                    {
                        return;
                    }

                    foreach (var dnative in this.native.Descriptors)
                    {
                        var wrap = new GattDescriptor(this, dnative);
                        if (!descriptors.ContainsKey(wrap.Uuid))
                        {
                            descriptors.Add(wrap.Uuid, wrap);
                            ob.OnNext(wrap);
                        }
                    }
                });
                p.DiscoveredDescriptor += handler;
                p.DiscoverDescriptors(this.native);

                return(() => p.DiscoveredDescriptor -= handler);
            })
                                .Replay()
                                .RefCount();

            return(this.descriptorOb);
        }
示例#2
0
 public override IObservable <IGattDescriptor> WhenDescriptorDiscovered()
 {
     this.descriptorOb = this.descriptorOb ?? Observable.Create <IGattDescriptor>(ob =>
     {
         var natives = this.native.GetAllDescriptors();
         foreach (var dnative in natives)
         {
             var descriptor = new GattDescriptor(dnative, this);
             ob.OnNext(descriptor);
         }
         return(Disposable.Empty);
     })
                         .Replay();
     return(this.descriptorOb);
 }
        public override IObservable <IGattDescriptor> WhenDescriptorDiscovered()
        {
            this.descriptorOb = this.descriptorOb ?? Observable.Create <IGattDescriptor>(ob =>
            {
                foreach (var nd in this.native.Descriptors)
                {
                    var wrap = new GattDescriptor(this, this.context, nd);
                    ob.OnNext(wrap);
                }
                return(Disposable.Empty);
            })
                                .Replay()
                                .RefCount();

            return(this.descriptorOb);
        }