// 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>();
 }
        internal void OnConnected(CentralManager connectionSource, byte connectionHandle)
        {
            ThrowIfDisposed();

            ConnectedCentralDevice = connectionSource;
            ConnectionHandle       = connectionHandle;
            ClearServices();
            State = PeripheralState.Connected;
            StateChanged?.Invoke(this, new PeripheralStateChangedEventArgs(State));
        }
        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));
        }