// Returns true on success, false on an error condition. bool OSDictionary::merge(const OSDictionary *srcDict) { const OSSymbol * sym; OSCollectionIterator * iter; if ( !OSDynamicCast(OSDictionary, srcDict) ) return false; iter = OSCollectionIterator::withCollection(const_cast<OSDictionary *>(srcDict)); if ( !iter ) return false; while ( (sym = (const OSSymbol *)iter->getNextObject()) ) { const OSMetaClassBase * obj; obj = srcDict->getObject(sym); if ( !setObject(sym, obj) ) { iter->release(); return false; } } iter->release(); return true; }
void ARMIO::publishBelow( IORegistryEntry * root ) { OSCollectionIterator * kids; IORegistryEntry * next; IOService * nub; // infanticide kids = IODTFindMatchingEntries( root, kIODTRecursive, deleteList() ); if( kids) { while( (next = (IORegistryEntry *)kids->getNextObject())) { next->detachAll( gIODTPlane); } kids->release(); } // publish everything below, minus excludeList kids = IODTFindMatchingEntries( root, kIODTRecursive | kIODTExclusive, excludeList()); if( kids) { while( (next = (IORegistryEntry *)kids->getNextObject())) { if( 0 == (nub = createNub( next ))) continue; nub->attach( this ); processNub(nub); nub->registerService(); } kids->release(); } }
void IOHIDEventQueue::removeElement( IOHIDElementPrivate * element ) { OSCollectionIterator * iterator; IOHIDElementPrivate * temp; UInt32 size = 0; UInt32 maxSize = DEFAULT_HID_ENTRY_SIZE; if ( !element || !_elementSet || !_elementSet->containsObject( element )) return; _elementSet->removeObject( element ); if ( NULL != (iterator = OSCollectionIterator::withCollection(_elementSet)) ) { while ( NULL != (temp = (IOHIDElementPrivate *)iterator->getNextObject()) ) { size = temp->getElementValueSize() + sizeof(void *); if ( maxSize < size ) maxSize = size; } iterator->release(); } _maxEntrySize = maxSize; }
/* static */ void OSMetaClass::printInstanceCounts() { OSCollectionIterator * classes; OSSymbol * className; OSMetaClass * meta; IOLockLock(sAllClassesLock); classes = OSCollectionIterator::withCollection(sAllClassesDict); assert(classes); while( (className = (OSSymbol *)classes->getNextObject())) { meta = (OSMetaClass *)sAllClassesDict->getObject(className); assert(meta); printf("%24s count: %03d x 0x%03x = 0x%06x\n", className->getCStringNoCopy(), meta->getInstanceCount(), meta->getClassSize(), meta->getInstanceCount() * meta->getClassSize() ); } printf("\n"); classes->release(); IOLockUnlock(sAllClassesLock); return; }
bool IOAudioSelectorControl::valueExists(SInt32 selectionValue) { bool found = false; OSCollectionIterator *iterator; assert(availableSelections); iterator = OSCollectionIterator::withCollection(availableSelections); if (iterator) { OSDictionary *selection; while ( (selection = (OSDictionary *)iterator->getNextObject()) ) { OSNumber *sValue; sValue = (OSNumber *)selection->getObject(kIOAudioSelectorControlSelectionValueKey); if (sValue && ((SInt32)sValue->unsigned32BitValue() == selectionValue)) { found = true; break; } } iterator->release(); } return found; }
void OSMetaClass::reportModInstances(const char *kmodName) { OSSet *kmodClasses; OSCollectionIterator *iter; OSMetaClass *checkClass; kmodClasses = OSDynamicCast(OSSet, sKModClassesDict->getObject(kmodName)); if (!kmodClasses) return; iter = OSCollectionIterator::withCollection(kmodClasses); if (!iter) return; while ( (checkClass = (OSMetaClass *) iter->getNextObject()) ) if (checkClass->getInstanceCount()) { printf("%s: %s has %d instance(s)\n", kmodName, checkClass->getClassName(), checkClass->getInstanceCount()); } iter->release(); }
void IOAudioPort::deactivateAudioControls() { OSCollectionIterator *iterator; if (!audioControls) { return; } iterator = OSCollectionIterator::withCollection(audioControls); if (iterator) { IOAudioControl *control; while ( (control = (IOAudioControl *)iterator->getNextObject()) ) { // Should we check to see if we're the provider? if (!isInactive()) { control->terminate(); } } iterator->release(); } audioControls->flushCollection(); }
void IOFireWireUserClientIniter::mergeProperties( IORegistryEntry * dest, OSDictionary * src ) { //IOLog( "IOFireWireUserClientIniter<0x%08lx>::mergeProperties - dest = 0x%08lx, src = 0x%08lx\n", this, dest, src ); if( !dest || !src ) return; OSCollectionIterator* srcIterator = OSCollectionIterator::withCollection( src ); OSSymbol* keyObject = NULL; OSObject* destObject = NULL; OSObject* srcObject = NULL; while( NULL != (keyObject = OSDynamicCast(OSSymbol, srcIterator->getNextObject())) ) { srcObject = src->getObject(keyObject); destObject = dest->getProperty(keyObject); OSDictionary * destDictionary = OSDynamicCast( OSDictionary, destObject ); OSDictionary * srcDictionary = OSDynamicCast( OSDictionary, srcObject ); if( destDictionary && srcDictionary ) { // if there's already already a property defined in the destination // and the source and destination are dictionaries, we need to do // a recursive merge // shallow copy the destination directory destDictionary = OSDictionary::withDictionary( destDictionary ); // recurse mergeDictionaries( destDictionary, srcDictionary ); // set the property dest->setProperty( keyObject, destDictionary ); destDictionary->release(); } else { // if the property is not already in destination dictionary // or both source a destination are not dictionaries // then we can set the property without merging // any dictionaries in the source should already // have been deep copied before we began merging dest->setProperty( keyObject, srcObject ); } } // have to release this, or we'll leak. srcIterator->release(); //IOLog( "IOFireWireUserClientIniter<0x%08lx>::mergeProperties - return\n", this ); }
/********************************************************************* * 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; }
void PAEngine::sendNotification(UInt32 notificationType, UInt32 value) { OSCollectionIterator *iter = OSCollectionIterator::withCollection(virtualDeviceArray); PAVirtualDevice *dev; while ((dev = OSDynamicCast(PAVirtualDevice, iter->getNextObject()))) dev->sendNotification(notificationType, value); iter->release(); }
OSCollectionIterator * OSCollectionIterator::withCollection(const OSCollection *inColl) { OSCollectionIterator *me = new OSCollectionIterator; if (me && !me->initWithCollection(inColl)) { me->release(); return 0; } return me; }
bool IOHIDUserClientIniter::mergeDictionaryIntoDictionary(OSDictionary * parentSourceDictionary, OSDictionary * parentTargetDictionary) { OSCollectionIterator* srcIterator = NULL; OSSymbol* keyObject = NULL; bool result = false; if (!parentSourceDictionary || !parentTargetDictionary) return false ; // Get our source dictionary // srcIterator = OSCollectionIterator::withCollection(parentSourceDictionary); while (NULL != (keyObject = OSDynamicCast(OSSymbol, srcIterator->getNextObject()))) { OSDictionary * childSourceDictionary = NULL; OSDictionary * childTargetDictionary = NULL; OSObject * childTargetObject = NULL; // Check to see if our destination already has the same entry. // childTargetObject = parentTargetDictionary->getObject(keyObject); if ( childTargetObject ) childTargetDictionary = OSDynamicCast(OSDictionary, childTargetObject); // See if our source entry is also a dictionary // childSourceDictionary = OSDynamicCast(OSDictionary, parentSourceDictionary->getObject(keyObject)); if ( childTargetDictionary && childSourceDictionary) { // Our destination dictionary already has the entry for this same object AND our // source is also a dcitionary, so we need to recursively add it. // result = mergeDictionaryIntoDictionary(childSourceDictionary, childTargetDictionary) ; if ( !result ) break; } else { // We have a property that we need to merge into our parent dictionary. // result = parentTargetDictionary->setObject(keyObject, parentSourceDictionary->getObject(keyObject)) ; if ( !result ) break; } } srcIterator->release(); return result; }
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; }
OSDictionary* IOFireWireUserClientIniter::dictionaryDeepCopy( OSDictionary* srcDictionary) { //IOLog( "IOFireWireUserClientIniter<0x%08lx>::dictionaryDeepCopy - srcDictionary = 0x%08lx\n", this, srcDictionary ); OSDictionary* result = NULL; OSObject* srcObject = NULL; OSCollectionIterator* srcIterator = NULL; OSSymbol* keyObject = NULL; result = OSDictionary::withCapacity(srcDictionary->getCount()); if (result) { srcIterator = OSCollectionIterator::withCollection(srcDictionary); if (srcIterator) { while ( (keyObject = OSDynamicCast(OSSymbol, srcIterator->getNextObject())) ) { srcObject = srcDictionary->getObject(keyObject); if (OSDynamicCast(OSDictionary, srcObject)) { srcObject = dictionaryDeepCopy((OSDictionary*)srcObject); result->setObject(keyObject, srcObject); // copyDictionaryProperty creates a new dictionary, so we should release // it after we add it to our dictionary srcObject->release(); } else { result->setObject(keyObject, srcObject); } } srcIterator->release(); } } //IOLog( "IOFireWireUserClientIniter<0x%08lx>::dictionaryDeepCopy - return\n", this ); return result; }
/* static */ void OSMetaClass::serializeClassDictionary(OSDictionary * serializeDictionary) { OSDictionary * classDict = NULL; IOLockLock(sAllClassesLock); classDict = OSDictionary::withCapacity(sAllClassesDict->getCount()); if (!classDict) { goto finish; } do { OSCollectionIterator * classes; const OSSymbol * className; classes = OSCollectionIterator::withCollection(sAllClassesDict); if (!classes) { break; } while ((className = (const OSSymbol *)classes->getNextObject())) { const OSMetaClass * meta; OSNumber * count; meta = (OSMetaClass *)sAllClassesDict->getObject(className); count = OSNumber::withNumber(meta->getInstanceCount(), 32); if (count) { classDict->setObject(className, count); count->release(); } } classes->release(); serializeDictionary->setObject("Classes", classDict); } while (0); finish: OSSafeRelease(classDict); IOLockUnlock(sAllClassesLock); return; }
/********************************************************************* * 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; }
bool CLASS::mergeProperties( OSDictionary * dict ) { bool success = true; OSCollectionIterator * iter = OSCollectionIterator::withCollection(dict); if ( iter ) { const OSSymbol * key; while ((key = (const OSSymbol *) iter->getNextObject())) { if (setProperty(key, dict->getObject(key)) == false) { success = false; break; } } iter->release(); } return success; }
OSMetaClass::~OSMetaClass() { do { OSCollectionIterator *iter; if (sAllClassesDict) sAllClassesDict->removeObject(className); iter = OSCollectionIterator::withCollection(sKModClassesDict); if (!iter) break; OSSymbol *iterKey; while ( (iterKey = (OSSymbol *) iter->getNextObject()) ) { OSSet *kmodClassSet; kmodClassSet = (OSSet *) sKModClassesDict->getObject(iterKey); if (kmodClassSet && kmodClassSet->containsObject(this)) { kmodClassSet->removeObject(this); break; } } iter->release(); } while (false); if (sStalled) { unsigned int i; // First pass find class in stalled list for (i = 0; i < sStalled->count; i++) if (this == sStalled->classes[i]) break; if (i < sStalled->count) { sStalled->count--; if (i < sStalled->count) memmove(&sStalled->classes[i], &sStalled->classes[i+1], (sStalled->count - i) * sizeof(OSMetaClass *)); } return; } }
void AppleGPIO::publishStrings(OSCollection *strings) { OSCollectionIterator *strIter; OSSymbol *key; if (!strings) return; strIter = OSCollectionIterator::withCollection(strings); if (strIter) { while ((key = OSDynamicCast(OSSymbol, strIter->getNextObject())) != 0) { //DLOG("AppleGPIO::publishStrings 0x%x %s\n", // fGPIOID, key->getCStringNoCopy()); publishResource(key, this); } strIter->release(); } }
void PAEngine::removeVirtualDeviceWithRefcon(void *refCon) { OSCollectionIterator *iter = OSCollectionIterator::withCollection(virtualDeviceArray); PAVirtualDevice *dev; while ((dev = OSDynamicCast(PAVirtualDevice, iter->getNextObject()))) { UInt index = virtualDeviceArray->getNextIndexOfObject((OSMetaClassBase *) dev, 0); if (dev->refCon == refCon) { if (state == kIOAudioEngineRunning) dev->sendNotification(kPAVirtualDeviceUserClientNotificationEngineStopped, 0); dev->detachFromParent(this, gIOServicePlane); dev->stop(this); dev->terminate(0); virtualDeviceArray->removeObject(index); } } iter->release(); }
void IOAudioPort::registerService(IOOptionBits options) { super::registerService(options); if (audioControls && !isRegistered) { OSCollectionIterator *iterator; iterator = OSCollectionIterator::withCollection(audioControls); if (iterator) { IOAudioControl *control; while ( (control = (IOAudioControl *)iterator->getNextObject()) ) { if (control->getProvider() == this) { control->registerService(); } } iterator->release(); } } isRegistered = true; }
static KeyboardReserved * GetKeyboardReservedStructEventForService(IOHIKeyboard *service, UInt32 * index = 0) { KeyboardReserved * retVal = 0; if (gKeyboardReservedArray) { OSCollectionIterator * iterator = 0; iterator = OSCollectionIterator::withCollection(gKeyboardReservedArray); if (iterator) { bool done = false; while (!done) { OSObject * obj = 0; while (!done && (NULL != (obj = iterator->getNextObject()))) { OSData * data = OSDynamicCast(OSData, obj); if (data) { retVal = (KeyboardReserved *)data->getBytesNoCopy(); if (retVal && (retVal->service == service)) { if (index) *index = gKeyboardReservedArray->getNextIndexOfObject(obj, 0); done = true; } else { retVal = 0; } } } if (iterator->isValid()) { done = true; } else { iterator->reset(); } } iterator->release(); } } return retVal; }
bool OSDictionary::isEqualTo(const OSDictionary *srcDict, const OSCollection *keys) const { OSCollectionIterator * iter; unsigned int keysCount; const OSMetaClassBase * obj1; const OSMetaClassBase * obj2; OSString * aKey; bool ret; if ( this == srcDict ) return true; keysCount = keys->getCount(); if ( (count < keysCount) || (srcDict->getCount() < keysCount) ) return false; iter = OSCollectionIterator::withCollection(keys); if ( !iter ) return false; ret = true; while ( (aKey = OSDynamicCast(OSString, iter->getNextObject())) ) { obj1 = getObject(aKey); obj2 = srcDict->getObject(aKey); if ( !obj1 || !obj2 ) { ret = false; break; } if ( !obj1->isEqualTo(obj2) ) { ret = false; break; } } iter->release(); return ret; }
bool SoundflowerDevice::createAudioEngines() { OSArray* audioEngineArray = OSDynamicCast(OSArray, getProperty(AUDIO_ENGINES_KEY)); OSCollectionIterator* audioEngineIterator; OSDictionary* audioEngineDict; if (!audioEngineArray) { IOLog("SoundflowerDevice[%p]::createAudioEngine() - Error: no AudioEngine array in personality.\n", this); return false; } audioEngineIterator = OSCollectionIterator::withCollection(audioEngineArray); if (!audioEngineIterator) { IOLog("SoundflowerDevice: no audio engines available.\n"); return true; } while ((audioEngineDict = (OSDictionary*)audioEngineIterator->getNextObject())) { SoundflowerEngine* audioEngine = NULL; if (OSDynamicCast(OSDictionary, audioEngineDict) == NULL) continue; audioEngine = new SoundflowerEngine; if (!audioEngine) continue; if (!audioEngine->init(audioEngineDict)) continue; initControls(audioEngine); activateAudioEngine(audioEngine); // increments refcount and manages the object audioEngine->release(); // decrement refcount so object is released when the manager eventually releases it } audioEngineIterator->release(); return true; }
bool OSMetaClass::modHasInstance(const char *kmodName) { bool result = false; if (!loadLock) { loadLock = mutex_alloc(ETAP_IO_AHA); mutex_lock(loadLock); } else mutex_lock(loadLock); do { OSSet *kmodClasses; OSCollectionIterator *iter; OSMetaClass *checkClass; kmodClasses = OSDynamicCast(OSSet, sKModClassesDict->getObject(kmodName)); if (!kmodClasses) break; iter = OSCollectionIterator::withCollection(kmodClasses); if (!iter) break; while ( (checkClass = (OSMetaClass *) iter->getNextObject()) ) if (checkClass->getInstanceCount()) { result = true; break; } iter->release(); } while (false); mutex_unlock(loadLock); return result; }
static IOReturn _removeDrivers( OSArray * array, OSDictionary * matching ) { OSCollectionIterator * tables; OSDictionary * dict; OSArray * arrayCopy; IOReturn ret = kIOReturnSuccess; // remove configs from catalog. arrayCopy = OSArray::withCapacity(100); if ( !arrayCopy ) return kIOReturnNoMemory; tables = OSCollectionIterator::withCollection(arrayCopy); arrayCopy->release(); if ( !tables ) return kIOReturnNoMemory; arrayCopy->merge(array); array->flushCollection(); tables->reset(); while ( (dict = (OSDictionary *)tables->getNextObject()) ) { /* Remove from the catalogue's array any personalities * that match the matching dictionary. * This comparison must be done with only the keys in the * "matching" dict to enable general matching. */ if ( dict->isEqualTo(matching, matching) ) continue; array->setObject(dict); } tables->release(); return ret; }
void OSMetaClass::serializeClassDictionary(OSDictionary *serializeDictionary) { OSDictionary *classDict; classDict = OSDictionary::withCapacity(sAllClassesDict->getCount()); if (!classDict) return; mutex_lock(loadLock); do { OSCollectionIterator *classes; const OSSymbol *className; classes = OSCollectionIterator::withCollection(sAllClassesDict); if (!classes) break; while ((className = (const OSSymbol *) classes->getNextObject())) { const OSMetaClass *meta; OSNumber *count; meta = (OSMetaClass *) sAllClassesDict->getObject(className); count = OSNumber::withNumber(meta->getInstanceCount(), 32); if (count) { classDict->setObject(className, count); count->release(); } } classes->release(); serializeDictionary->setObject("Classes", classDict); } while (0); mutex_unlock(loadLock); classDict->release(); }
IOReturn IOCatalogue::_removeDrivers(OSDictionary * matching) { IOReturn ret = kIOReturnSuccess; OSCollectionIterator * iter; OSDictionary * dict; OSArray * array; const OSSymbol * key; unsigned int idx; // remove configs from catalog. iter = OSCollectionIterator::withCollection(personalities); if (!iter) return (kIOReturnNoMemory); while ((key = (const OSSymbol *) iter->getNextObject())) { array = (OSArray *) personalities->getObject(key); if (array) for (idx = 0; (dict = (OSDictionary *) array->getObject(idx)); idx++) { /* Remove from the catalogue's array any personalities * that match the matching dictionary. * This comparison must be done with only the keys in the * "matching" dict to enable general matching. */ if (dict->isEqualTo(matching, matching)) { array->removeObject(idx); idx--; } } } iter->release(); return ret; }
bool eqMac2DriverEngine::createAudioStreams(IOAudioSampleRate *initialSampleRate) { bool result = false; OSNumber* number = NULL; UInt32 numStreams; UInt32 streamNum; OSArray* formatArray = NULL; OSArray* sampleRateArray = NULL; UInt32 startingChannelID = 1; OSString* desc; desc = OSDynamicCast(OSString, getProperty(DESCRIPTION_KEY)); if (desc) setDescription(desc->getCStringNoCopy()); number = OSDynamicCast(OSNumber, getProperty(NUM_STREAMS_KEY)); if (number) numStreams = number->unsigned32BitValue(); else numStreams = NUM_STREAMS; formatArray = OSDynamicCast(OSArray, getProperty(FORMATS_KEY)); if (formatArray == NULL) { IOLog("SF formatArray is NULL\n"); goto Done; } sampleRateArray = OSDynamicCast(OSArray, getProperty(SAMPLE_RATES_KEY)); if (sampleRateArray == NULL) { IOLog("SF sampleRateArray is NULL\n"); goto Done; } for (streamNum = 0; streamNum < numStreams; streamNum++) { UInt32 maxBitWidth = 0; UInt32 maxNumChannels = 0; OSCollectionIterator* formatIterator = NULL; OSCollectionIterator* sampleRateIterator = NULL; OSDictionary* formatDict; IOAudioSampleRate sampleRate; IOAudioStreamFormat initialFormat; bool initialFormatSet; UInt32 channelID; char outputStreamName[64]; char inputStreamName[64]; initialFormatSet = false; sampleRate.whole = 0; sampleRate.fraction = 0; inputStream = new IOAudioStream; if (inputStream == NULL) { IOLog("SF could not create new input IOAudioStream\n"); goto Error; } outputStream = new IOAudioStream; if (outputStream == NULL) { IOLog("SF could not create new output IOAudioStream\n"); goto Error; } snprintf(inputStreamName, 64, "eqMac2Driver Input Stream #%u", (unsigned int)streamNum + 1); snprintf(outputStreamName, 64, "eqMac2Driver Output Stream #%u", (unsigned int)streamNum + 1); if (!inputStream->initWithAudioEngine(this, kIOAudioStreamDirectionInput, startingChannelID, inputStreamName) || !outputStream->initWithAudioEngine(this, kIOAudioStreamDirectionOutput, startingChannelID, outputStreamName)) { IOLog("SF could not init one of the streams with audio engine. \n"); goto Error; } formatIterator = OSCollectionIterator::withCollection(formatArray); if (!formatIterator) { IOLog("SF NULL formatIterator\n"); goto Error; } sampleRateIterator = OSCollectionIterator::withCollection(sampleRateArray); if (!sampleRateIterator) { IOLog("SF NULL sampleRateIterator\n"); goto Error; } formatIterator->reset(); while ((formatDict = (OSDictionary *)formatIterator->getNextObject())) { IOAudioStreamFormat format; if (OSDynamicCast(OSDictionary, formatDict) == NULL) { IOLog("SF error casting formatDict\n"); goto Error; } if (IOAudioStream::createFormatFromDictionary(formatDict, &format) == NULL) { IOLog("SF error in createFormatFromDictionary()\n"); goto Error; } if (!initialFormatSet) { initialFormat = format; } sampleRateIterator->reset(); while ((number = (OSNumber *)sampleRateIterator->getNextObject())) { if (!OSDynamicCast(OSNumber, number)) { IOLog("SF error iterating sample rates\n"); goto Error; } sampleRate.whole = number->unsigned32BitValue(); inputStream->addAvailableFormat(&format, &sampleRate, &sampleRate); outputStream->addAvailableFormat(&format, &sampleRate, &sampleRate); if (format.fNumChannels > maxNumChannels) { maxNumChannels = format.fNumChannels; } if (format.fBitWidth > maxBitWidth) { maxBitWidth = format.fBitWidth; } if (initialSampleRate->whole == 0) { initialSampleRate->whole = sampleRate.whole; } } } mBufferSize = blockSize * numBlocks * maxNumChannels * maxBitWidth / 8; //IOLog("eqMac2Driver streamBufferSize: %ld\n", mBufferSize); if (mBuffer == NULL) { mBuffer = (void *)IOMalloc(mBufferSize); if (!mBuffer) { IOLog("eqMac2Driver: Error allocating output buffer - %lu bytes.\n", (unsigned long)mBufferSize); goto Error; } mThruBuffer = (float*)IOMalloc(mBufferSize); if (!mThruBuffer) { IOLog("eqMac2Driver: Error allocating thru buffer - %lu bytes.\n", (unsigned long)mBufferSize); goto Error; } memset((UInt8*)mThruBuffer, 0, mBufferSize); } inputStream->setFormat(&initialFormat); inputStream->setSampleBuffer(mBuffer, mBufferSize); addAudioStream(inputStream); inputStream->release(); outputStream->setFormat(&initialFormat); outputStream->setSampleBuffer(mBuffer, mBufferSize); addAudioStream(outputStream); outputStream->release(); formatIterator->release(); sampleRateIterator->release(); for (channelID = startingChannelID; channelID < (startingChannelID + maxNumChannels); channelID++) { char channelName[20]; snprintf(channelName, 20, "Channel %u", (unsigned int)channelID); } startingChannelID += maxNumChannels; continue; Error: IOLog("eqMac2DriverEngine[%p]::createAudioStreams() - ERROR\n", this); if (inputStream) inputStream->release(); if (outputStream) outputStream->release(); if (formatIterator) formatIterator->release(); if (sampleRateIterator) sampleRateIterator->release(); goto Done; } result = true; Done: if (!result) IOLog("eqMac2DriverEngine[%p]::createAudioStreams() - failed!\n", this); return result; }
//================================================================================================ // // MergeDictionaryIntoDictionary( parentSourceDictionary, parentTargetDictionary) // // This routine will merge the contents of parentSourceDictionary into the parentTargetDictionary, recursively. // Note that we are only modifying copies of the parentTargetDictionary, so we don't expect anybody // else to be accessing them at the same time. // //================================================================================================ // bool IOUSBUserClientInit::MergeDictionaryIntoDictionary(OSDictionary * parentSourceDictionary, OSDictionary * parentTargetDictionary) { OSCollectionIterator* srcIterator = NULL; OSSymbol* keyObject = NULL ; OSObject* targetObject = NULL ; bool result = false; USBLog(6,"+%s[%p]::MergeDictionaryIntoDictionary(%p => %p)", getName(), this, parentSourceDictionary, parentTargetDictionary); if (!parentSourceDictionary || !parentTargetDictionary) return false ; // Get our source dictionary // srcIterator = OSCollectionIterator::withCollection(parentSourceDictionary) ; while (NULL != (keyObject = OSDynamicCast(OSSymbol, srcIterator->getNextObject()))) { const char * str; OSDictionary * childSourceDictionary = NULL; OSDictionary * childTargetDictionary = NULL; OSObject * childTargetObject = NULL; // Get the symbol name for debugging // str = keyObject->getCStringNoCopy(); USBLog(6,"%s[%p]::MergeDictionaryIntoDictionary merging \"%s\"", getName(), this, str); // Check to see if our destination already has the same entry. // childTargetObject = parentTargetDictionary->getObject(keyObject); if ( childTargetObject ) { childTargetDictionary = OSDynamicCast(OSDictionary, childTargetObject); if ( childTargetDictionary ) { USBLog(6,"%s[%p]::MergeDictionaryIntoDictionary target object %s is a dictionary (%p)", getName(), this, str, childTargetDictionary); } } // See if our source entry is also a dictionary // childSourceDictionary = OSDynamicCast(OSDictionary, parentSourceDictionary->getObject(keyObject)); if ( childSourceDictionary ) { USBLog(6,"%s[%p]::MergeDictionaryIntoDictionary source dictionary had %s as a dictionary (%p)", getName(), this, str, childSourceDictionary); } if ( childTargetDictionary && childSourceDictionary) { // Our destination dictionary already has the entry for this same object AND our // source is also a dcitionary, so we need to recursively add it. // USBLog(6,"%s[%p]::MergeDictionaryIntoDictionary recursing(%p,%p)", getName(), this, childSourceDictionary, childTargetDictionary); result = MergeDictionaryIntoDictionary(childSourceDictionary, childTargetDictionary) ; if ( !result ) { USBLog(6,"%s[%p]::MergeDictionaryIntoDictionary recursing (%p,%p) failed", getName(), this, childSourceDictionary, childTargetDictionary); break; } } else { // We have a property that we need to merge into our parent dictionary. // USBLog(6,"%s[%p]::MergeDictionaryIntoDictionary setting object %s into dictionary %p", getName(), this, str, parentTargetDictionary); result = parentTargetDictionary->setObject(keyObject, parentSourceDictionary->getObject(keyObject)) ; if ( !result ) { USBLog(6,"%s[%p]::MergeDictionaryIntoDictionary setObject %s, returned false", getName(), this, str); break; } } } srcIterator->release(); USBLog(6,"-%s[%p]::MergeDictionaryIntoDictionary(%p=>(%p) result %d", getName(), this, parentSourceDictionary, parentTargetDictionary, result); return result; }