void DevicesView::AddDeviceAndChildren(device_node_cookie *node, Device* parent) { Attributes attributes; Device* newDevice = NULL; // Copy all its attributes, // necessary because we can only request them once from the device manager char data[256]; struct device_attr_info attr; attr.cookie = 0; attr.node_cookie = *node; attr.value.raw.data = data; attr.value.raw.length = sizeof(data); while (dm_get_next_attr(&attr) == B_OK) { BString attrString; switch (attr.type) { case B_STRING_TYPE: attrString << attr.value.string; break; case B_UINT8_TYPE: attrString << attr.value.ui8; break; case B_UINT16_TYPE: attrString << attr.value.ui16; break; case B_UINT32_TYPE: attrString << attr.value.ui32; break; case B_UINT64_TYPE: attrString << attr.value.ui64; break; default: attrString << "Raw data"; } attributes.push_back(Attribute(attr.name, attrString)); } // Determine what type of device it is and create it for (unsigned int i = 0; i < attributes.size(); i++) { // Devices Root if (attributes[i].fName == B_DEVICE_PRETTY_NAME && attributes[i].fValue == "Devices Root") { newDevice = new Device(parent, BUS_NONE, CAT_COMPUTER, B_TRANSLATE("Computer")); break; } // ACPI Controller if (attributes[i].fName == B_DEVICE_PRETTY_NAME && attributes[i].fValue == "ACPI") { newDevice = new Device(parent, BUS_ACPI, CAT_BUS, B_TRANSLATE("ACPI bus")); break; } // PCI bus if (attributes[i].fName == B_DEVICE_PRETTY_NAME && attributes[i].fValue == "PCI") { newDevice = new Device(parent, BUS_PCI, CAT_BUS, B_TRANSLATE("PCI bus")); break; } // ISA bus if (attributes[i].fName == B_DEVICE_BUS && attributes[i].fValue == "isa") { newDevice = new Device(parent, BUS_ISA, CAT_BUS, B_TRANSLATE("ISA bus")); break; } // PCI device if (attributes[i].fName == B_DEVICE_BUS && attributes[i].fValue == "pci") { newDevice = new DevicePCI(parent); break; } // ACPI device if (attributes[i].fName == B_DEVICE_BUS && attributes[i].fValue == "acpi") { newDevice = new DeviceACPI(parent); break; } // ATA / SCSI / IDE controller if (attributes[i].fName == "controller_name") { newDevice = new Device(parent, BUS_PCI, CAT_MASS, attributes[i].fValue); } // SCSI device node if (attributes[i].fName == B_DEVICE_BUS && attributes[i].fValue == "scsi") { newDevice = new DeviceSCSI(parent); break; } // Last resort, lets look for a pretty name if (attributes[i].fName == B_DEVICE_PRETTY_NAME) { newDevice = new Device(parent, BUS_NONE, CAT_NONE, attributes[i].fValue); break; } } // A completely unknown device if (newDevice == NULL) { newDevice = new Device(parent, BUS_NONE, CAT_NONE, B_TRANSLATE("Unknown device")); } // Add its attributes to the device, initialize it and add to the list. for (unsigned int i = 0; i < attributes.size(); i++) { newDevice->SetAttribute(attributes[i].fName, attributes[i].fValue); } newDevice->InitFromAttributes(); fDevices.push_back(newDevice); // Process children status_t err; device_node_cookie child = *node; if (get_child(&child) != B_OK) return; do { AddDeviceAndChildren(&child, newDevice); } while ((err = get_next_child(&child)) == B_OK); }