/*--------------------------------------------------------------------------- * Update all the registry properties associated with an interface ---------------------------------------------------------------------------*/ void EInterfaces::update_interface_property(void) { int n; debug("update_interface_property - m_nInterfacesInUse=%d\n", m_nInterfacesInUse); if ( m_pProvider ) { m_pProvider->removeProperty(ENABLED_INTERFACES_PROPERTY); if ( m_nInterfacesInUse ) { OSArray* pInterfaces = OSArray::withCapacity(m_nInterfacesInUse); if ( pInterfaces ) { for(n=0; n<numberof(m_aInterfaces); n++) if ( m_aInterfaces[n].m_fEnabled ) { OSNumber* pNumber = OSNumber::withNumber(n, 32); if ( pNumber ) { pInterfaces->setObject(pNumber); pNumber->release(); } } m_pProvider->setProperty(ENABLED_INTERFACES_PROPERTY, (OSObject* )pInterfaces); pInterfaces->release(); } } } }
void SuperIO::LoadConfiguration(IOService* provider) { m_Service = provider; OSBoolean* fanControl = OSDynamicCast(OSBoolean, provider->getProperty("Enable Fan Control")); m_FanControl = fanControl->getValue(); OSBoolean* alternateRegisters = OSDynamicCast(OSBoolean, provider->getProperty("Register number alternative variant")); m_AlternateRegisters = alternateRegisters->getValue(); OSArray* fanIDs = OSDynamicCast(OSArray, provider->getProperty("Fan Names")); if (fanIDs) fanIDs = OSArray::withArray(fanIDs); if (fanIDs) { UInt32 count = fanIDs->getCount(); if(count > 5) count = 5; for (UInt32 i = 0; i < count; i++) { OSString* name = OSDynamicCast(OSString, fanIDs->getObject(i)); FanName[i] = name->getCStringNoCopy(); } fanIDs->release(); } }
UInt32 ACPIBacklightPanel::queryACPICurentBrightnessLevel() { //DbgLog("%s::%s()\n", this->getName(),__FUNCTION__); if (_backlightHandler) return _backlightHandler->getBacklightLevel(); UInt32 level = minAC; const char* method = _extended ? "XBQC" : "_BQC"; if (kIOReturnSuccess == backLightDevice->evaluateInteger(method, &level)) { //DbgLog("%s: queryACPICurentBrightnessLevel %s = %d\n", this->getName(), method, level); OSBoolean * useIdx = OSDynamicCast(OSBoolean, getProperty("BQC use index")); if (useIdx && useIdx->isTrue()) { OSArray * levels = queryACPISupportedBrightnessLevels(); if (levels) { OSNumber *num = OSDynamicCast(OSNumber, levels->getObject(level)); if (num) level = num->unsigned32BitValue(); levels->release(); } } //DbgLog("%s: queryACPICurentBrightnessLevel returning %d\n", this->getName(), level); } else { IOLog("ACPIBacklight: Error in queryACPICurentBrightnessLevel %s\n", method); } //some laptops didn't return anything on startup, return then max value (first entry in _BCL): return level; }
bool CompareDeviceUsagePairs( IOService * owner, OSDictionary * matching, SInt32 * score, SInt32 increment) { // We return success if we match the key in the dictionary with the key in // the property table, or if the prop isn't present // OSArray * pairArray; OSDictionary * pair; bool matches = true; int count; pairArray = OSDynamicCast(OSArray, matching->getObject( kIOHIDDeviceUsagePairsKey )); if (pairArray) { count = pairArray->getCount(); for (int i=0; i<count; i++) { if ( !(pair = OSDynamicCast(OSDictionary,pairArray->getObject(i))) ) continue; if ( !(matches = CompareDeviceUsage(owner, pair, score, increment)) ) continue; break; } } return matches; }
volatile int kmod_start(void) { libkern_init0(); OSString* one = OSString::withCString("Anal sex"); OSString* two = OSString::withCString("Cunnilingus"); OSArray* sexthings = OSArray::withCapacity(2); sexthings->setObject(one); sexthings->setObject(two); printk("Hello from IOKit!\n"); printk("Put: %p %p\n", one, two); printk("OSArray: %p\n", sexthings); printk("Get: %p %p\n", sexthings->getObject(0), sexthings->getObject(1)); OSSerialize* ser = OSSerialize::withCapacity(1024); sexthings->serialize(ser); printk("Serialized: %s \n", ser->text()); return 0; }
void IOCatalogue::initialize(void) { OSArray * array; OSString * errorString; bool rc; extern const char * gIOKernelConfigTables; array = OSDynamicCast(OSArray, OSUnserialize(gIOKernelConfigTables, &errorString)); if (!array && errorString) { IOLog("KernelConfigTables syntax error: %s\n", errorString->getCStringNoCopy()); errorString->release(); } gIOClassKey = OSSymbol::withCStringNoCopy( kIOClassKey ); gIOProbeScoreKey = OSSymbol::withCStringNoCopy( kIOProbeScoreKey ); gIOModuleIdentifierKey = OSSymbol::withCStringNoCopy( kCFBundleIdentifierKey ); assert( array && gIOClassKey && gIOProbeScoreKey && gIOModuleIdentifierKey); gIOCatalogue = new IOCatalogue; assert(gIOCatalogue); rc = gIOCatalogue->init(array); assert(rc); array->release(); }
OSArray * IODeviceMemory::arrayFromList( InitElement list[], IOItemCount count ) { OSArray * array; IODeviceMemory * range; IOItemCount i; array = OSArray::withCapacity( count ); if( 0 == array ) return( 0); for( i = 0; i < count; i++) { range = IODeviceMemory::withRange( list[i].start, list[i].length ); if( range) { range->setTag( list[i].tag ); array->setObject( range); range->release(); } else { array->release(); array = 0; break; } } return( array ); }
bool CompareNumberPropertyArray( IOService * owner, OSDictionary * matching, const char * arrayName, const char * key, SInt32 * score, SInt32 increment) { OSNumber *registryProperty = (OSNumber *)owner->copyProperty(key); OSArray *propertyArray = (OSArray *)matching->getObject(arrayName); CONVERT_TO_STACK_RETAIN(registryProperty); // If the property in the matching doesn't exist return true if ( OSDynamicCast(OSArray, propertyArray) ) { if ( OSDynamicCast(OSNumber, registryProperty ) ) { OSNumber *propertyFromArray; int i = 0; for ( i = 0; i < propertyArray->getCount(); i ++ ) { propertyFromArray = OSDynamicCast(OSNumber, propertyArray->getObject(i)); if ( propertyFromArray && propertyFromArray->isEqualTo(registryProperty) ) { if ( score ) *score += increment; return true; } } } } else return true; return false; }
OSArray * IOHIDInterface::createMatchingElements ( OSDictionary * matching, IOOptionBits options __unused) { UInt32 count = _elementArray->getCount(); IOHIDElementPrivate * element = NULL; OSArray * elements = NULL; if ( count ) { if ( matching ) { elements = OSArray::withCapacity(count); for ( UInt32 i = 0; i < count; i ++) { // Compare properties. if (( element = (IOHIDElementPrivate *)_elementArray->getObject(i) ) && element->matchProperties(matching)) { elements->setObject(element); } } } else elements = OSArray::withArray(_elementArray); } return elements; }
bool IORangeAllocator::serialize(OSSerialize *s) const { OSArray * array = OSArray::withCapacity( numElements * 2 ); OSNumber * num; UInt32 index; bool ret; if( !array) return( false ); LOCK(); for( index = 0; index < numElements; index++) { if( (num = OSNumber::withNumber( elements[index].start, 8 * sizeof(IORangeScalar) ))) { array->setObject(num); num->release(); } if( (num = OSNumber::withNumber( elements[index].end, 8 * sizeof(IORangeScalar) ))) { array->setObject(num); num->release(); } } UNLOCK(); ret = array->serialize(s); array->release(); return( ret ); }
UInt32 ACPIBacklightPanel::setupIndexedLevels() { DbgLog("%s::%s()\n", this->getName(),__FUNCTION__); OSNumber * num; OSArray * levels = queryACPISupportedBrightnessLevels(); if (levels) { BCLlevelsCount = levels->getCount(); if (BCLlevelsCount < 3) return 0; //verify the types of objects is good once for all for (int i = 0; i< BCLlevelsCount; i++) { if (!OSDynamicCast(OSNumber, levels->getObject(i))) return 0; } //TODO : manage the case when the list has no order! Linux do that //test the order of the list UInt32 min, max; num = OSDynamicCast(OSNumber, levels->getObject(2)); min = num->unsigned32BitValue(); num = OSDynamicCast(OSNumber, levels->getObject(BCLlevelsCount-1)); max = num->unsigned32BitValue(); if (max < min) //list is reverted ! { BCLlevels = new UInt32[BCLlevelsCount]; for (int i = 0; i< BCLlevelsCount; i++) { num = OSDynamicCast(OSNumber, levels->getObject(BCLlevelsCount -1 -i)); BCLlevels[i] = num->unsigned32BitValue(); } } else { BCLlevelsCount = BCLlevelsCount -2; BCLlevels = new UInt32[BCLlevelsCount]; for (int i = 0; i< BCLlevelsCount; i++) { num = OSDynamicCast(OSNumber, levels->getObject(i+2)); BCLlevels[i] = num->unsigned32BitValue(); } } //2 first items are min on ac and max on bat num = OSDynamicCast(OSNumber, levels->getObject(0)); minAC = findIndexForLevel(num->unsigned32BitValue()); setDebugProperty("BCL: Min on AC", num); num = OSDynamicCast(OSNumber, levels->getObject(1)); maxBat = findIndexForLevel(num->unsigned32BitValue()); setDebugProperty("BCL: Max on Bat", num); setDebugProperty("Brightness Control Levels", levels); levels->release(); return BCLlevelsCount-1; } return 0; }
OSCollection * OSSet::copyCollection(OSDictionary *cycleDict) { bool allocDict = !cycleDict; OSCollection *ret = 0; OSSet *newSet = 0; if (allocDict) { cycleDict = OSDictionary::withCapacity(16); if (!cycleDict) return 0; } do { // Check for a cycle ret = super::copyCollection(cycleDict); if (ret) continue; // Found it newSet = OSSet::withCapacity(members->capacity); if (!newSet) continue; // Couldn't create new set abort // Insert object into cycle Dictionary cycleDict->setObject((const OSSymbol *) this, newSet); OSArray *newMembers = newSet->members; newMembers->capacityIncrement = members->capacityIncrement; // Now copy over the contents into the new duplicate for (unsigned int i = 0; i < members->count; i++) { OSObject *obj = EXT_CAST(members->array[i]); OSCollection *coll = OSDynamicCast(OSCollection, obj); if (coll) { OSCollection *newColl = coll->copyCollection(cycleDict); if (newColl) { obj = newColl; // Rely on cycleDict ref for a bit newColl->release(); } else goto abortCopy; }; newMembers->setObject(obj); }; ret = newSet; newSet = 0; } while(false); abortCopy: if (newSet) newSet->release(); if (allocDict) cycleDict->release(); return ret; }
bool IOCatalogue::removePersonalities(OSArray * personalitiesToRemove) { bool result = true; OSArray * arrayCopy = NULL; // do not release OSCollectionIterator * iterator = NULL; // must release OSDictionary * personality = NULL; // do not release OSDictionary * checkPersonality = NULL; // do not release unsigned int count, i; // remove configs from catalog. arrayCopy = OSArray::withArray(array); if (!arrayCopy) { result = false; goto finish; } iterator = OSCollectionIterator::withCollection(arrayCopy); arrayCopy->release(); if (!iterator) { result = false; goto finish; } array->flushCollection(); count = personalitiesToRemove->getCount(); /* Go through the old catalog's list of personalities and add back any that * are *not* found in 'personalitiesToRemove'. */ while ((personality = (OSDictionary *)iterator->getNextObject())) { bool found = false; for (i = 0; i < count; i++) { checkPersonality = OSDynamicCast(OSDictionary, personalitiesToRemove->getObject(i)); /* Do isEqualTo() with the single-arg version to make an exact * comparison (unlike _removeDrivers() above). */ if (personality->isEqualTo(checkPersonality)) { found = true; break; } } if (!found) { array->setObject(personality); } } finish: OSSafeRelease(iterator); return result; }
//==================================================================================================== // IOHIDEventOverrideDriver::dispatchKeyboardEvent //==================================================================================================== bool IOHIDEventOverrideDriver::handleStart( IOService * provider ) { OSArray * maps = NULL; if ( !super::handleStart(provider) ) return false; maps = OSDynamicCast(OSArray, getProperty("ButtonMaps")); if ( maps ) { int index; for ( index=0; index<maps->getCount(); index++ ) { OSDictionary * map; OSNumber * number; uint32_t button; uint32_t usagePage; uint32_t usage; uint32_t eventType; map = OSDynamicCast(OSDictionary, maps->getObject(index)); if ( !map ) continue; number = OSDynamicCast(OSNumber, map->getObject("ButtonNumber")); if ( !number ) continue; button = number->unsigned32BitValue(); if ( !button || button>32 ) continue; number = OSDynamicCast(OSNumber, map->getObject("EventType")); if ( !number ) continue; eventType = number->unsigned32BitValue(); number = OSDynamicCast(OSNumber, map->getObject("UsagePage")); if ( !number ) continue; usagePage = number->unsigned32BitValue(); number = OSDynamicCast(OSNumber, map->getObject("Usage")); if ( !number ) continue; usage = number->unsigned32BitValue(); _buttonMap[button-1].eventType = eventType; _buttonMap[button-1].usagePage = usagePage; _buttonMap[button-1].usage = usage; } } return true; }
// <rdar://8202424> IOReturn IOAudioSelectorControl::addAvailableSelection(SInt32 selectionValue, OSString *selectionDescription, const char* tagName, OSObject* tag) { OSArray *newSelections; OSArray *oldAvailableSelections; IOReturn result = kIOReturnSuccess; oldAvailableSelections = availableSelections; newSelections = OSArray::withArray(availableSelections); if (!newSelections) return kIOReturnNoMemory; if (selectionDescription == NULL) { result = kIOReturnBadArgument; } else { if (valueExists(selectionValue)) { result = kIOReturnError; } else { OSDictionary *newSelection; newSelection = OSDictionary::withCapacity(2); if (newSelection) { OSNumber *number; number = OSNumber::withNumber(selectionValue, sizeof(SInt32)*8); if (number) { newSelection->setObject(kIOAudioSelectorControlSelectionValueKey, number); newSelection->setObject(kIOAudioSelectorControlSelectionDescriptionKey, selectionDescription); newSelections->setObject(newSelection); number->release(); } else { result = kIOReturnError; } if ( tagName && tag ) { newSelection->setObject(tagName, tag); } availableSelections = newSelections; setProperty(kIOAudioSelectorControlAvailableSelectionsKey, availableSelections); oldAvailableSelections->release(); newSelection->release(); } else { result = kIOReturnError; } } } if (kIOReturnSuccess == result) { sendChangeNotification(kIOAudioControlRangeChangeNotification); } return result; }
/********************************************************************* * Remove drivers from the catalog which match the * properties in the matching dictionary. *********************************************************************/ bool IOCatalogue::removeDrivers( OSDictionary * matching, bool doNubMatching) { OSOrderedSet * set; OSCollectionIterator * iter; OSDictionary * dict; OSArray * array; const OSSymbol * key; unsigned int idx; if ( !matching ) return false; set = OSOrderedSet::withCapacity(10, IOServiceOrdering, (void *)gIOProbeScoreKey); if ( !set ) return false; iter = OSCollectionIterator::withCollection(personalities); if (!iter) { set->release(); return (false); } IORWLockWrite(lock); while ((key = (const OSSymbol *) iter->getNextObject())) { array = (OSArray *) personalities->getObject(key); if (array) for (idx = 0; (dict = (OSDictionary *) array->getObject(idx)); idx++) { /* This comparison must be done with only the keys in the * "matching" dict to enable general searches. */ if ( dict->isEqualTo(matching, matching) ) { set->setObject(dict); array->removeObject(idx); idx--; } } // Start device matching. if ( doNubMatching && (set->getCount() > 0) ) { IOService::catalogNewDrivers(set); generation++; } } IORWLockUnlock(lock); set->release(); iter->release(); return true; }
bool CompareDeviceUsage( IOService * owner, OSDictionary * matching, SInt32 * score, SInt32 increment) { // We return success if we match the key in the dictionary with the key in // the property table, or if the prop isn't present // OSObject * usage; OSObject * usagePage; OSArray * functions; OSDictionary * pair; bool matches = true; int count; usage = matching->getObject( kIOHIDDeviceUsageKey ); usagePage = matching->getObject( kIOHIDDeviceUsagePageKey ); functions = OSDynamicCast(OSArray, owner->copyProperty( kIOHIDDeviceUsagePairsKey )); if ( functions ) { if ( usagePage || usage ) { count = functions->getCount(); for (int i=0; i<count; i++) { if ( !(pair = (OSDictionary *)functions->getObject(i)) ) continue; if ( !usagePage || !(matches = usagePage->isEqualTo(pair->getObject(kIOHIDDeviceUsagePageKey))) ) continue; if ( score && !usage ) { *score += increment / 2; break; } if ( !usage || !(matches = usage->isEqualTo(pair->getObject(kIOHIDDeviceUsageKey))) ) continue; if ( score ) *score += increment; break; } } functions->release(); } else { matches = false; } return matches; }
OSArray *OSArray::withCapacity(unsigned int capacity) { OSArray *me = new OSArray; if (me && !me->initWithCapacity(capacity)) { me->release(); return 0; } return me; }
OSCollection * OSArray::copyCollection(OSDictionary *cycleDict) { bool allocDict = !cycleDict; OSCollection *ret = 0; OSArray *newArray = 0; if (allocDict) { cycleDict = OSDictionary::withCapacity(16); if (!cycleDict) return 0; } do { // Check for a cycle ret = super::copyCollection(cycleDict); if (ret) continue; newArray = OSArray::withArray(this); if (!newArray) continue; // Insert object into cycle Dictionary cycleDict->setObject((const OSSymbol *) this, newArray); for (unsigned int i = 0; i < count; i++) { OSCollection *coll = OSDynamicCast(OSCollection, EXT_CAST(newArray->array[i])); if (coll) { OSCollection *newColl = coll->copyCollection(cycleDict); if (!newColl) goto abortCopy; newArray->replaceObject(i, newColl); newColl->release(); }; }; ret = newArray; newArray = 0; } while (false); abortCopy: if (newArray) newArray->release(); if (allocDict) cycleDict->release(); return ret; }
OSArray *OSArray::withArray(const OSArray *array, unsigned int capacity) { OSArray *me = new OSArray; if (me && !me->initWithArray(array, capacity)) { me->release(); return 0; } return me; }
OSArray *OSArray::withObjects(const OSObject *objects[], unsigned int count, unsigned int capacity) { OSArray *me = new OSArray; if (me && !me->initWithObjects(objects, count, capacity)) { me->release(); return 0; } return me; }
void IOCatalogue::addPersonality(OSDictionary * dict) { const OSSymbol * sym; OSArray * arr; sym = OSDynamicCast(OSSymbol, dict->getObject(gIOProviderClassKey)); if (!sym) return; arr = (OSArray *) personalities->getObject(sym); if (arr) arr->setObject(dict); else { arr = OSArray::withObjects((const OSObject **)&dict, 1, 2); personalities->setObject(sym, arr); arr->release(); } }
bool IOPlatformExpert::RegisterServiceInTree (IOService * theService, OSDictionary * theTreeNode, OSDictionary * theTreeParentNode, IOService * theProvider) { IOService * aService; bool registered = false; OSArray * children; unsigned int numChildren; OSDictionary * child; // make sure someone is not already registered here if ( NULL == theTreeNode->getObject ("service") ) { if ( theTreeNode->setObject ("service", OSDynamicCast ( OSObject, theService)) ) { // 1. CHILDREN ------------------ // we registered the node in the tree...now if the node has children // registered we must tell this service to add them. if ( NULL != (children = (OSArray *) theTreeNode->getObject ("children")) ) { numChildren = children->getCount (); for ( unsigned int i = 0; i < numChildren; i++ ) { if ( NULL != (child = (OSDictionary *) children->getObject (i)) ) { if ( NULL != (aService = (IOService *) child->getObject ("service")) ) theService->addPowerChild (aService); } } } // 2. PARENT -------------------- // also we must notify the parent of this node (if a registered service // exists there) of a new child. if ( theTreeParentNode ) { if ( NULL != (aService = (IOService *) theTreeParentNode->getObject ("service")) ) if (aService != theProvider) aService->addPowerChild (theService); } registered = true; } } return registered; }
IOReturn IOAudioSelectorControl::replaceAvailableSelection(SInt32 selectionValue, OSString *selectionDescription) { OSCollectionIterator *iterator; OSArray *newSelections; OSArray *oldAvailableSelections; IOReturn result = kIOReturnSuccess; assert(availableSelections); oldAvailableSelections = availableSelections; newSelections = OSArray::withArray(availableSelections); if (!newSelections) return kIOReturnNoMemory; iterator = OSCollectionIterator::withCollection(newSelections); if (iterator) { OSDictionary * selection; UInt32 index; index = 0; while ( (selection = (OSDictionary *)iterator->getNextObject() )) { OSNumber * sValue; sValue = (OSNumber *)selection->getObject(kIOAudioSelectorControlSelectionValueKey); if (sValue && ((SInt32)sValue->unsigned32BitValue() == selectionValue)) { // Replace the selected dictionary in the array newSelections->replaceObject(index, selectionDescription); result = kIOReturnSuccess; break; } index++; } availableSelections = newSelections; setProperty(kIOAudioSelectorControlAvailableSelectionsKey, availableSelections); oldAvailableSelections->release(); iterator->release(); } if (kIOReturnSuccess == result) { sendChangeNotification(kIOAudioControlRangeChangeNotification); } return result; }
void loadPStateOverride(OSArray* dict) { //return; // autodetect /* Here we load the override pstate table from the given array */ NumberOfPStates = dict->getCount(); for (int i = 0; i < NumberOfPStates; i++) { OSArray* onePstate = (OSArray*) dict->getObject(i); PStates[i].AcpiFreq = ((OSNumber*) onePstate->getObject(0))->unsigned16BitValue(); PStates[i].Frequency = MHz_to_FID(PStates[i].AcpiFreq); // this accounts for N/2 automatically PStates[i].OriginalVoltage = mV_to_VID(((OSNumber*) onePstate->getObject(1))->unsigned16BitValue()); PStates[i].Voltage = PStates[i].OriginalVoltage; PStates[i].TimesChosen = 0; info("P-State %d: %d MHz Fr: %d at %d mV\n", i, PStates[i].AcpiFreq, PStates[i].Frequency, VID_to_mV(PStates[i].OriginalVoltage)); } info("Loaded %d PStates from Info.plist\n", NumberOfPStates); }
OSArray * OSDictionary::copyKeys(void) { OSArray * array; array = OSArray::withCapacity(count); if (!array) return (0); for (unsigned int i = 0; i < count; i++) { if (!array->setObject(i, dictionary[i].key)) { array->release(); array = 0; break; } } return (array); }
// This routine will look to see if the OSArray contains any matching keys. The OSArray has to contain a list of OSNumbers. bool IOUSBNub::USBComparePropertyInArrayWithMask( OSDictionary *matching, const char * arrayName, const char * key, const char * maskKey, UInt32 * theProductIDThatMatched ) { // We return success iff we match any entry in the array with the key OSArray * propertyIDArray = NULL; OSNumber * registryProperty = NULL; OSNumber * propertyFromArrayItem = NULL; OSNumber * dictionaryMask = NULL; bool matches = false; unsigned int index; *theProductIDThatMatched = 0; // Get our nub's value for the key registryProperty = OSDynamicCast(OSNumber, getProperty(key)); propertyIDArray = OSDynamicCast(OSArray, matching->getObject(arrayName)); dictionaryMask = OSDynamicCast(OSNumber, matching->getObject(maskKey)); // Iterate over the array looking for the entries if (propertyIDArray && registryProperty && dictionaryMask) { USBLog(7, "%s[%p]::USBComparePropertyInArrayWithMask - found array with capacity of %d", getName(), this, propertyIDArray->getCount()); for (index = 0; index < propertyIDArray->getCount(); index++) { propertyFromArrayItem = OSDynamicCast(OSNumber, propertyIDArray->getObject(index)); if (propertyFromArrayItem) { UInt32 registryValue = registryProperty->unsigned32BitValue(); UInt32 arrayValue = propertyFromArrayItem->unsigned32BitValue(); UInt32 mask = dictionaryMask->unsigned32BitValue(); if ( (registryValue & mask) == (arrayValue & mask) ) { USBLog(7, "%s[%p]::USBComparePropertyInArrayWithMask - 0x%x, 0x%x, mask 0x%x matched", getName(), this, (uint32_t)arrayValue, (uint32_t)registryValue, (uint32_t)mask); *theProductIDThatMatched = registryValue; matches = true; } } } } return matches; }
// This routine will look to see if the OSArray contains any matching keys. The OSArray has to contain a list of OSNumbers. bool IOUSBNub::USBComparePropertyInArray( OSDictionary *matching, const char * arrayName, const char * key, UInt32 * theProductIDThatMatched ) { // We return success iff we match any entry in the array with the key OSArray * propertyIDArray = NULL; OSNumber * registryProperty = NULL; OSNumber * propertyFromArrayItem = NULL; bool matches = false; unsigned int index; *theProductIDThatMatched = 0; // Get our nub's value for the key registryProperty = OSDynamicCast(OSNumber, getProperty(key)); propertyIDArray = OSDynamicCast(OSArray, matching->getObject(arrayName)); // Iterate over the array looking for the entries if (propertyIDArray && registryProperty) { USBLog(7, "%s[%p]::USBComparePropertyInArray - found array with capacity of %d", getName(), this, propertyIDArray->getCount()); for (index = 0; index < propertyIDArray->getCount(); index++) { propertyFromArrayItem = OSDynamicCast(OSNumber, propertyIDArray->getObject(index)); if (propertyFromArrayItem) { // See if this item has the same value as the one in our registry for this key matches = propertyFromArrayItem->isEqualTo( registryProperty); if (matches) { *theProductIDThatMatched = propertyFromArrayItem->unsigned32BitValue(); USBLog(7, "%s[%p]::USBComparePropertyInArray - item %d matched: id = 0x%x", getName(), this, index, (uint32_t) *theProductIDThatMatched); break; } else { USBLog(7, "%s[%p]::USBComparePropertyInArray - item %d did not match", getName(), this, index); } } } } return matches; }
/********************************************************************* * Is personality already in the catalog? *********************************************************************/ OSOrderedSet * IOCatalogue::findDrivers( OSDictionary * matching, SInt32 * generationCount) { OSCollectionIterator * iter; OSDictionary * dict; OSOrderedSet * set; OSArray * array; const OSSymbol * key; unsigned int idx; OSKext::uniquePersonalityProperties(matching); set = OSOrderedSet::withCapacity( 1, IOServiceOrdering, (void *)gIOProbeScoreKey ); if (!set) return (0); iter = OSCollectionIterator::withCollection(personalities); if (!iter) { set->release(); return (0); } IORWLockRead(lock); while ((key = (const OSSymbol *) iter->getNextObject())) { array = (OSArray *) personalities->getObject(key); if (array) for (idx = 0; (dict = (OSDictionary *) array->getObject(idx)); idx++) { /* This comparison must be done with only the keys in the * "matching" dict to enable general searches. */ if ( dict->isEqualTo(matching, matching) ) set->setObject(dict); } } *generationCount = getGenerationCount(); IORWLockUnlock(lock); iter->release(); return set; }
OSArray * ACPIBacklightPanel::queryACPISupportedBrightnessLevels() { DbgLog("%s::%s()\n", this->getName(),__FUNCTION__); OSObject * ret; backLightDevice->evaluateObject("_BCL", &ret); OSArray * data = OSDynamicCast(OSArray, ret); if (data) { DbgLog("%s: %s _BCL %d\n", this->getName(), backLightDevice->getName(), data->getCount() ); return data; } else { DbgLog("%s: Cast Error _BCL is %s\n", this->getName(), ret ? ret->getMetaClass()->getClassName() : "ret=NULL"); } OSSafeRelease(ret); return NULL; }