Пример #1
0
        // Remove a device from YAPI after an unplug detected by device refresh
        internal virtual void imm_forgetDevice(string serial)
        {
            YDevice dev = _devs[serial];

            if (dev == null)
            {
                return;
            }
            string lname = dev.imm_getLogicalName();

            _devs.Remove(serial);
            if (_snByName.ContainsKey(lname) && _snByName[lname].Equals(serial))
            {
                _snByName.Remove(lname);
            }
            YFunctionType module = _fnByType["Module"];

            module.imm_forgetFunction(serial + ".module");
            int count = dev.imm_functionCount();

            for (int i = 0; i < count; i++)
            {
                YPEntry yp = dev.imm_getYPEntryFromOfs(i);
                if (_fnByType.ContainsKey(yp.Classname))
                {
                    YFunctionType functionType = _fnByType[yp.Classname];
                    functionType.imm_forgetFunction(yp.HardwareId);
                }
            }
        }
Пример #2
0
        // Reindex a device in YAPI after a name change detected by device refresh
        internal virtual void imm_reindexDevice(YDevice dev)
        {
            string serial = dev.imm_getSerialNumber();
            string lname  = dev.imm_getLogicalName();

            _devs[serial] = dev;

            if (!lname.Equals(""))
            {
                _snByName[lname] = serial;
            }

            YFunctionType module        = _fnByType["Module"];
            YPEntry       moduleYPEntry = dev.ModuleYPEntry;

            module.imm_reindexFunction(moduleYPEntry);
            int count = dev.imm_functionCount();

            for (int i = 0; i < count; i++)
            {
                YPEntry       yp        = dev.imm_getYPEntryFromOfs(i);
                string        classname = yp.Classname;
                YFunctionType functionType;
                if (_fnByType.ContainsKey(classname))
                {
                    functionType = _fnByType[classname];
                }
                else
                {
                    functionType         = new YFunctionType(classname, _yctx);
                    _fnByType[classname] = functionType;
                }
                functionType.imm_reindexFunction(yp);
            }
        }
Пример #3
0
        protected internal virtual async Task updateFromWpAndYp(List <WPEntry> whitePages, Dictionary <string, List <YPEntry> > yellowPages)
        {
            // by default consider all known device as unplugged
            List <YDevice> toRemove = new List <YDevice>(_devices.Values);

            foreach (WPEntry wp in whitePages)
            {
                string serial = wp.SerialNumber;
                if (_devices.ContainsKey(serial))
                {
                    // already there
                    YDevice currdev = _devices[serial];
                    if (!currdev.imm_getLogicalName().Equals(wp.LogicalName))
                    {
                        // Reindex device from its own data
                        await currdev.refresh();

                        _yctx._pushPlugEvent(YAPIContext.PlugEvent.Event.CHANGE, serial);
                    }
                    else if (currdev.imm_getBeacon() > 0 != wp.Beacon > 0)
                    {
                        await currdev.refresh();
                    }

                    toRemove.Remove(currdev);
                }
                else
                {
                    YDevice dev = new YDevice(this, wp, yellowPages);
                    _yctx._yHash.imm_reindexDevice(dev);
                    _devices[serial] = dev;
                    _yctx._pushPlugEvent(YAPIContext.PlugEvent.Event.PLUG, serial);
                    _yctx._Log("HUB: device " + serial + " has been plugged\n");
                }
            }

            foreach (YDevice dev in toRemove)
            {
                string serial = dev.imm_getSerialNumber();
                _yctx._pushPlugEvent(YAPIContext.PlugEvent.Event.UNPLUG, serial);
                _yctx._Log("HUB: device " + serial + " has been unplugged\n");
                _devices.Remove(serial);
            }

            if (_hubSerialNumber == null)
            {
                foreach (WPEntry wp in whitePages)
                {
                    if (wp.NetworkUrl.Equals(""))
                    {
                        _hubSerialNumber = wp.SerialNumber;
                    }
                }
            }

            _yctx._yHash.imm_reindexYellowPages(yellowPages);
        }