Example #1
0
 // Can only be constructed internally by subclasses of CentralManager.
 internal Peripheral(string address, bool isPublicAddress, sbyte rssi = 0, CentralManager source = null)
 {
     State                  = PeripheralState.Disconnected;
     Address                = address;
     IsAddressPublic        = isPublicAddress;
     RSSI                   = rssi;
     ConnectedCentralDevice = source;
     _services              = new ConcurrentBag <Service>();
 }
Example #2
0
        internal void OnConnected(CentralManager connectionSource, byte connectionHandle)
        {
            ThrowIfDisposed();

            ConnectedCentralDevice = connectionSource;
            ConnectionHandle       = connectionHandle;
            ClearServices();
            State = PeripheralState.Connected;
            StateChanged?.Invoke(this, new PeripheralStateChangedEventArgs(State));
        }
Example #3
0
        internal void OnDisconnected(CentralManager connectionSource)
        {
            ThrowIfDisposed();

            if (State == PeripheralState.Disconnected)
            {
                return;
            }
            State = PeripheralState.Disconnected;

            if (!ReferenceEquals(ConnectedCentralDevice, connectionSource))
            {
                return;
            }
            ConnectedCentralDevice = null;

            foreach (var service in _services)
            {
                service.Dispose();
            }
            ClearServices();

            StateChanged?.Invoke(this, new PeripheralStateChangedEventArgs(State));
        }