private static int DevicePriorityComparison( BusDeviceBase x, BusDeviceBase y) { if (x == y) { return(0); } if (x is IUlaDevice) // should be first { return(-1); } if (x is IMemoryDevice) // should be last { return(1); } if (y is IUlaDevice) // should be first { return(1); } if (y is IMemoryDevice) // should be last { return(-1); } // priority for other devices is not implemented yet return(x.BusOrder <y.BusOrder ? -1 : x.BusOrder> y.BusOrder ? 1 : 0); }
public void Init(BusManager bmgr, IHostService host, BusDeviceBase device) { m_bmgr = bmgr; m_device = device; txtDevice.Text = device.Name; txtDescription.Text = device.Description.Replace("\n", Environment.NewLine); }
public static void Refresh() { lock (s_syncRoot) { PreLoadPlugins(); var listDescriptors = new List <BusDeviceDescriptor>(); foreach (var asm in AppDomain.CurrentDomain.GetAssemblies()) { try { var refName = typeof(BusDeviceBase).Assembly.GetName().FullName; var hasRef = asm.GetName().FullName == refName || asm.GetReferencedAssemblies() .Any(name => name.FullName == refName); if (!hasRef) { // skip assemblies without reference on assembly which contains BusDeviceBase continue; } foreach (var type in asm.GetTypes()) { if (type.IsClass && !type.IsAbstract && typeof(BusDeviceBase).IsAssignableFrom(type)) { try { BusDeviceBase device = (BusDeviceBase)Activator.CreateInstance(type); var bdd = new BusDeviceDescriptor( type, device.Category, device.Name, device.Description); listDescriptors.Add(bdd); } catch (Exception ex) { Logger.Error(ex, type.FullName); } } } } catch (Exception ex) { Logger.Error(ex, asm.FullName); } } s_descriptors = listDescriptors; } }
private void insertListViewItem(int index, UserControl control, BusDeviceBase device) { control.Location = new Point(0, 0); control.Size = pnlSettings.ClientSize; control.Visible = false; pnlSettings.Controls.Add(control); var csc = (ConfigScreenControl)control; m_ctlList.Insert(index, csc); m_devList.Insert(index, device); var lvi = new ListViewItem(); lvi.Tag = csc; lvi.Text = device.Category.ToString(); lvi.SubItems.Add(device.Name); lvi.ImageIndex = FindImageIndex(device.Category); lstNavigation.Items.Insert(index, lvi); }
public void Remove(BusDeviceBase device) { if (m_connected) { throw new InvalidOperationException("Cannot remove device from connected bus!"); } if (device is IUlaDevice) { if (m_ula != device) { throw new InvalidOperationException("Cannot remove non-existing ULA device!"); } else { m_ula = null; } } m_deviceList.Remove(device); }
public void Add(BusDeviceBase device) { if (m_connected) { throw new InvalidOperationException("Cannot add device into connected bus!"); } foreach (var device2 in m_deviceList) { if (device2.GetType() == device.GetType()) { throw new InvalidOperationException( string.Format( "Cannot add device {0}, because this device already exist!", device.Name)); } } if (device is IJtagDevice && FindDevice <IJtagDevice>() != null) { throw new InvalidOperationException( string.Format( "Cannot add second instance of JtagDevice! '{0}'", device.Name)); } var ula = device as IUlaDevice; if (ula != null) { if (m_ula != null) { throw new InvalidOperationException("Cannot add second ULA device!"); } else { m_ula = ula; } } device.BusOrder = m_deviceList.Count; m_deviceList.Add(device); }
private static UserControl CreateGenericScreenControl(BusManager workBus, IHostService host, BusDeviceBase device) { var control = new CtlSettingsGenericDevice(); try { control.Init(workBus, host, device); return(control); } catch { control.Dispose(); throw; } }
private UserControl ResolveScreenControl(BusManager workBus, IHostService host, BusDeviceBase device) { var control = CreateConfigScreenControl(workBus, device); try { if (control != null) { return(control); } return(CreateGenericScreenControl(workBus, host, device)); } catch { if (control != null) { control.Dispose(); } throw; } }
public BusDeviceProxy(BusDeviceBase device) { Device = device; }
public void LoadConfigXml(XmlNode busNode) { //LogAgent.Debug("time begin BusManager.LoadConfig"); Disconnect(); Name = null; if (busNode.Attributes["name"] != null) { Name = busNode.Attributes["name"].InnerText; } ModelId = ModelId.None; if (busNode.Attributes["modelId"] != null) { var value = busNode.Attributes["modelId"].InnerText; var modelId = ModelId.None; if (!Enum.TryParse <ModelId>(value, out modelId)) { Logger.Warn("Unknown modelId: {0}", value); } else { ModelId = modelId; } } // store old devices to allow reuse & save state var oldDevices = new Dictionary <string, BusDeviceBase>(); foreach (BusDeviceBase device in m_deviceList) { oldDevices.Add(getDeviceKey(device.GetType()), device); } Clear(); var orderCounter = 0; // "Device" var deviceNodes = busNode.ChildNodes .OfType <XmlNode>() .Where(node => string.Compare(node.Name, "Device", true) == 0) .Where(node => !string.IsNullOrEmpty(GetAttrString(node, "type"))) .Where(node => GetAttrString(node, "type").Trim() != string.Empty); foreach (XmlNode node in deviceNodes) { try { var fullTypeName = GetAttrString(node, "type"); var type = GetTypeByName(fullTypeName, GetAttrString(node, "assembly")); if (type == null) { Logger.Error("Type not found: {0}", fullTypeName); continue; } if (!typeof(BusDeviceBase).IsAssignableFrom(type)) { Logger.Error("Invalid Device: {0}", type.FullName); continue; } BusDeviceBase device = null; string key = getDeviceKey(type); if (oldDevices.ContainsKey(key)) { //reuse device = oldDevices[key]; } else { //create new device = (BusDeviceBase)Activator.CreateInstance(type); } device.BusOrder = orderCounter++; device.LoadConfigXml(node); Add(device); } catch (Exception ex) { Logger.Error(ex); Locator.Resolve <IUserMessage>() .Error("Load device failed: {0}", ex.Message); } } Sort(); Connect(); //LogAgent.Debug("time end BusManager.LoadConfig"); }