OSNumber* Xbox360ControllerClass::newLocationIDNumber() const { IOUSBDevice *device; OSNumber *number; UInt32 location = 0; device = GetOwnerProvider(this); if (device) { if ((number = OSDynamicCast(OSNumber, device->getProperty("locationID")))) { location = number->unsigned32BitValue(); } else { // Make up an address if ((number = OSDynamicCast(OSNumber, device->getProperty("USB Address")))) location |= number->unsigned8BitValue() << 24; if ((number = OSDynamicCast(OSNumber, device->getProperty("idProduct")))) location |= number->unsigned8BitValue() << 16; } } return (location != 0) ? OSNumber::withNumber(location, 32) : 0; }
OSString* Xbox360ControllerClass::newProductString() const { OSString *retString = getDeviceString(GetOwnerProvider(this)->GetProductStringIndex()); if (retString->isEqualTo("Controller")) { retString->release(); return OSString::withCString("Xbox 360 Wired Controller"); } else { return retString; } }
// Returns the string for the specified index from the USB device's string list, with an optional default OSString* Xbox360ControllerClass::getDeviceString(UInt8 index,const char *def) const { IOReturn err; char buf[1024]; const char *string; err = GetOwnerProvider(this)->GetStringDescriptor(index, buf, sizeof(buf)); if(err==kIOReturnSuccess) string=buf; else { if(def == NULL) string = "Unknown"; else string = def; } return OSString::withCString(string); }
OSNumber* Xbox360ControllerClass::newVendorIDNumber() const { return OSNumber::withNumber(GetOwnerProvider(this)->GetVendorID(),16); }
OSString* Xbox360ControllerClass::newSerialNumberString() const { return getDeviceString(GetOwnerProvider(this)->GetSerialNumberStringIndex()); }
OSString* Xbox360ControllerClass::newManufacturerString() const { return getDeviceString(GetOwnerProvider(this)->GetManufacturerStringIndex()); }