Example #1
0
        /// <summary>
        /// Processes a received IAm request
        /// </summary>
        /// <param name="appgram">The appgram that contained the request</param>
        /// <param name="request">The IAm request</param>
        /// <returns>The created device table entry</returns>
        private DeviceTableEntry _processIAmRequest(InboundAppgram appgram, IAmRequest request)
        {
            DeviceTableEntry entry = new DeviceTableEntry(
                request.IAmDeviceIdentifier.Instance,
                appgram.Source,
                request.MaxAPDULengthAccepted,
                request.SegmentationSupported,
                (ushort)request.VendorID);

            lock (_lock)
            {
                _devices.Upsert(entry);

                for (var node = _deviceSearches.First; node != null; node = node.Next)
                {
                    if (node.Value.Feed(entry))
                    {
                        node.Value.Dispose();
                        _deviceSearches.Remove(node);
                    }
                }
            }

            return(entry);
        }
Example #2
0
        /// <summary>
        /// Upserts a new entry into the device table
        /// </summary>
        /// <param name="entry">The entry to upsert</param>
        public void Upsert(DeviceTableEntry entry)
        {
            for (int i = 0; i < _count; i++)
            {
                int index    = (_start + i) % _entries.Length;
                var oldEntry = _entries[index];
                if (oldEntry != null && oldEntry.Instance == entry.Instance)
                {
                    _entries[index] = entry;
                    return;
                }
            }

            if (_count < _entries.Length)
            {
                int insertIndex = (_start + _count) % _entries.Length;
                _entries[insertIndex] = entry;
                _count++;
            }
            else
            {
                _entries[_start] = entry;
                _start           = (_start + 1) % _entries.Length;
            }
        }
Example #3
0
        /// <summary>
        /// Processes a received unconfirmed request
        /// </summary>
        /// <param name="appgram">The inbound appgram</param>
        /// <param name="message">The unconfirmed request message</param>
        /// <param name="buffer">The buffer containing the request content</param>
        /// <param name="offset">The offset of the request content in the buffer</param>
        /// <param name="end">The end of the request content</param>
        private InboundUnconfirmedRequest _processUnconfirmedRequest(InboundAppgram appgram, UnconfirmedRequestMessage message, byte[] buffer, int offset, int end)
        {
            UnconfirmedServiceChoice choice  = (UnconfirmedServiceChoice)message.ServiceChoice;
            IUnconfirmedRequest      request = _loadUnconfirmedRequest(choice, buffer, offset, end);
            DeviceTableEntry         source  = null;

            if (request.ServiceChoice == UnconfirmedServiceChoice.IAm)
            {
                // the only request that we handle at the host level is an IAm request,
                // which is necessary for TSM operations, since information about the remote
                // host is needed
                source = _processIAmRequest(appgram, (IAmRequest)request);
            }
            else
            {
                source = _devices.GetByAddress(appgram.Source);
            }

            InboundUnconfirmedRequest inbound = new InboundUnconfirmedRequest(
                appgram.Source,
                source,
                request);

            return(inbound);
        }
Example #4
0
            /// <summary>
            /// Feeds a new device table entry into the
            /// search
            /// </summary>
            /// <param name="entry">The to feed</param>
            /// <returns>True if the search is now satisfied, false otherwise</returns>
            public bool Feed(DeviceTableEntry entry)
            {
                bool satisfies = false;

                if (IsInstanceSearch && entry.Instance == Instance)
                {
                    satisfies = true;
                }
                else if (!IsInstanceSearch && entry.Instance != Instance)
                {
                    satisfies = true;
                }

                if (satisfies)
                {
                    this.Callback.DeviceFound(entry);
                }
                return(satisfies);
            }
Example #5
0
        /// <summary>
        /// Upserts a new entry into the device table
        /// </summary>
        /// <param name="entry">The entry to upsert</param>
        public void Upsert(DeviceTableEntry entry)
        {
            for(int i = 0; i < _count; i++)
            {
                int index = (_start + i) % _entries.Length;
                var oldEntry = _entries[index];
                if (oldEntry != null &&  oldEntry.Instance == entry.Instance)
                {
                    _entries[index] = entry;
                    return;
                }
            }

            if(_count < _entries.Length)
            {
                int insertIndex = (_start + _count) % _entries.Length;
                _entries[insertIndex] = entry;
                _count++;
            }
            else
            {
                _entries[_start] = entry;
                _start = (_start + 1) % _entries.Length;
            }
        }
 /// <summary>
 /// Constructs a new inbound unconfirmed request
 /// </summary>
 /// <param name="sourceAddress">The device that sent the request</param>
 /// <param name="source">The device table entry of the device that sent the request</param>
 /// <param name="request">The request instance</param>
 public InboundUnconfirmedRequest(Address sourceAddress, DeviceTableEntry source, IUnconfirmedRequest request)
 {
     this.SourceAddress = sourceAddress;
     this.Source = source;
     this.Request = request;
 }
 /// <summary>
 /// Constructs a new inbound unconfirmed request
 /// </summary>
 /// <param name="sourceAddress">The device that sent the request</param>
 /// <param name="source">The device table entry of the device that sent the request</param>
 /// <param name="request">The request instance</param>
 public InboundUnconfirmedRequest(Address sourceAddress, DeviceTableEntry source, IUnconfirmedRequest request)
 {
     this.SourceAddress = sourceAddress;
     this.Source        = source;
     this.Request       = request;
 }