/////////////////////////////////////////////////////////////////////// // // DVNewNotification // // create new notification record // OSErr DVCNewNotification( DVCDeviceConnectionID connID, DVCNotifyProc notifyProc, void *userData, DVCNotificationID *pNotifyID ) { DVNotificationEntryPtr pEntry; DVCDeviceID deviceID; OSErr error = noErr; // check the parameters if ( notifyProc == nil ) error = paramErr; // create new entry if ( error == noErr ) { pEntry = (DVNotificationEntryPtr) PoolAllocateResident( sizeof( DVNotificationEntry ), true ); if ( pEntry == nil ) error = memFullErr; } // get the deviceID from the connectionID deviceID = (DVCDeviceID) connID; // fill it out if ( error == noErr ) { pEntry->deviceID = deviceID; pEntry->wantedEvents = nil; pEntry->notifyProc = notifyProc; pEntry->userRefCon = userData; *pNotifyID = (DVCNotificationID) pEntry; // notification id // put new entry at the back of the line error = PBEnqueueLast( (QElemPtr) pEntry, gpFamilyGlobals->notificationQueue ); } return error; }
/* *------------------------------------------------------------------------------ * * HIDCountDescriptorItems * * Input: * ptDescriptor - Descriptor Pointer Structure * ptPreparsedData - The PreParsedData Structure * Output: * ptPreparsedData - The PreParsedData Structure * Returns: * kHIDSuccess - Success * kHIDNullPointerErr - Argument, Pointer was Null * *------------------------------------------------------------------------------ */ OSStatus HIDCountDescriptorItems(HIDReportDescriptor *ptDescriptor, HIDPreparsedDataPtr ptPreparsedData) { OSStatus iStatus; IOByteCount iSpaceRequired; HIDItem *ptItem; UInt8 *pMem; /* * Initialize Counters */ int collectionCount = 1; int reportItemCount = 0; int iUsages = 0; int iUsageRanges = 0; int iStrings = 0; int iStringRanges = 0; int iDesigs = 0; int iDesigRanges = 0; int reportCount = 1; int globalsNesting = 0; int iMaxGlobalsNesting = 0; int collectionNesting = 0; int iMaxCollectionNesting = 0; /* * Disallow NULL Pointers */ if ((ptDescriptor == NULL) || (ptPreparsedData == NULL)) return kHIDNullPointerErr; /* * Initialize the memory allocation pointer */ ptPreparsedData->rawMemPtr = NULL; /* * Initialize the Descriptor Pointer Structure */ ptDescriptor->index = 0; ptItem = &ptDescriptor->item; /* * Count various items in the descriptor */ while ((iStatus = HIDNextItem(ptDescriptor)) == kHIDSuccess) { switch (ptItem->itemType) { case kHIDTypeMain: switch (ptItem->tag) { case kHIDTagCollection: collectionCount++; collectionNesting++; if (collectionNesting > iMaxCollectionNesting) iMaxCollectionNesting = collectionNesting; break; case kHIDTagEndCollection: if (collectionNesting-- == 0) return kHIDInvalidPreparsedDataErr; break; case kHIDTagInput: case kHIDTagOutput: case kHIDTagFeature: reportItemCount++; break; } break; case kHIDTypeGlobal: switch (ptItem->tag) { case kHIDTagReportID: reportCount++; break; case kHIDTagPush: globalsNesting++; if (globalsNesting > iMaxGlobalsNesting) iMaxGlobalsNesting = globalsNesting; break; case kHIDTagPop: globalsNesting--; if (globalsNesting < 0) return kHIDInvalidPreparsedDataErr; break; } break; case kHIDTypeLocal: switch (ptItem->tag) { case kHIDTagUsage: iUsages++; break; case kHIDTagUsageMinimum: case kHIDTagUsageMaximum: iUsageRanges++; break; case kHIDTagStringIndex: iStrings++; break; case kHIDTagStringMinimum: case kHIDTagStringMaximum: iStringRanges++; break; case kHIDTagDesignatorIndex: iDesigs++; break; case kHIDTagDesignatorMinimum: case kHIDTagDesignatorMaximum: iDesigRanges++; break; } } } /* * Disallow malformed descriptors */ if ((collectionNesting != 0) || (collectionCount == 1) || (reportItemCount == 0) || ((iUsageRanges & 1) == 1) || ((iStringRanges & 1) == 1) || ((iDesigRanges & 1) == 1)) return kHIDInvalidPreparsedDataErr; /* * Summarize the Indices and Ranges */ iUsages += (iUsageRanges/2); iStrings += (iStringRanges/2); iDesigs += (iDesigRanges/2); /* * Calculate the space needed for the structures */ iSpaceRequired = (sizeof(HIDCollection) * collectionCount) + (sizeof(HIDReportItem) * reportItemCount) + (sizeof(HIDReportSizes) * reportCount) + (sizeof(HIDP_UsageItem) * iUsages) + (sizeof(HIDStringItem) * iStrings) + (sizeof(HIDDesignatorItem) * iDesigs) + (sizeof(int) * iMaxCollectionNesting) + (sizeof(HIDGlobalItems) * iMaxGlobalsNesting); pMem = PoolAllocateResident(iSpaceRequired, kShouldClearMem); if (pMem == NULL) return kHIDNotEnoughMemoryErr; ptPreparsedData->rawMemPtr = pMem; ptPreparsedData->numBytesAllocated = iSpaceRequired; /* * Allocate space to the various structures */ ptPreparsedData->collections = (HIDCollection *) pMem; ptPreparsedData->collectionCount = 0; pMem += (sizeof(HIDCollection) * collectionCount); ptPreparsedData->reportItems = (HIDReportItem *) pMem; ptPreparsedData->reportItemCount = 0; pMem += (sizeof(HIDReportItem) * reportItemCount); ptPreparsedData->reports = (HIDReportSizes *) pMem; ptPreparsedData->reportCount = 0; pMem += (sizeof(HIDReportSizes) * reportCount); ptPreparsedData->usageItems = (HIDP_UsageItem *) pMem; ptPreparsedData->usageItemCount = 0; pMem += (sizeof(HIDP_UsageItem) * iUsages); ptPreparsedData->stringItems = (HIDStringItem *) pMem; ptPreparsedData->stringItemCount = 0; pMem += (sizeof(HIDStringItem) * iStrings); ptPreparsedData->desigItems = (HIDDesignatorItem *) pMem; ptPreparsedData->desigItemCount = 0; pMem += (sizeof(HIDDesignatorItem) * iDesigs); ptDescriptor->collectionStack = (SInt32 *) pMem; ptDescriptor->collectionNesting = 0; pMem += (sizeof(SInt32) * iMaxCollectionNesting); ptDescriptor->globalsStack = (HIDGlobalItems *) pMem; ptDescriptor->globalsNesting = 0; if (iStatus == kHIDEndOfDescriptorErr) return kHIDSuccess; return iStatus; }
static int DoExtendISTTree( RegEntryID *root_id, RegEntryID *funcs, int num_funcs, ISTProperty *istp ) { ISTParentInfo *p; InterruptSetID setID; OSStatus status=noErr; int i; /* tree needs to be extended */ lprintf("Extending interrupt tree...\n"); p = PoolAllocateResident( sizeof(ISTParentInfo), true /*clear*/ ); if( !p ) { lprintf("Could not allocate resident memory!\n"); return -1; } p->num_members = num_funcs; status = GetInterruptFunctions( (*istp)[kISTChipInterruptSource].setID, (*istp)[kISTChipInterruptSource].member, &p->info.oldInterruptSetRefcon, &p->info.oldInterruptServiceFunction, &p->info.oldInterruptEnableFunction, &p->info.oldInterruptDisableFunction); if( status ) goto err; /* disable interrupts */ if( p->info.oldInterruptDisableFunction ) p->info.oldInterruptDisableFunction( p->info.interruptSetMember, p->info.oldInterruptSetRefcon ); status = CreateInterruptSet( (*istp)[kISTChipInterruptSource].setID, (*istp)[kISTChipInterruptSource].member, num_funcs, &setID, kReturnToParentWhenNotComplete ); if( status ) goto err; status = InstallInterruptFunctions( (*istp)[kISTChipInterruptSource].setID, (*istp)[kISTChipInterruptSource].member, p, TransversalISR, NULL, NULL ); if( status ) goto err; /* Add driver-ist properties */ RegistryPropertyDelete( root_id, kISTPropertyName ); RegistryPropertyCreate( root_id, "driver-ist-parent", istp, sizeof(ISTProperty) ); for( i=0; i<num_funcs; i++ ) { ISTProperty child; CLEAR( child ); child[kISTChipInterruptSource].setID = setID; child[kISTChipInterruptSource].member = i+1; // lprintf("Adding driver-ist property\n"); RegistryPropertyCreate( &funcs[i], kISTPropertyName, &child, sizeof(child) ); InstallInterruptFunctions( setID, i+1, NULL, NULL, ChildInterruptEnabler, ChildInterruptDisabler ); } /* enable interrupts */ if( p->info.oldInterruptEnableFunction ) p->info.oldInterruptEnableFunction( p->info.interruptSetMember, p->info.oldInterruptSetRefcon); err: if( status != noErr ) { lprintf("Unexpected error %d\n", status ); PoolDeallocate( p ); } return status; }
/* *------------------------------------------------------------------------------ * * HIDOpenReportDescriptor - Initialize the HID Parser * * Input: * psHidReportDescriptor - The HID Report Descriptor (String) * descriptorLength - Length of the Descriptor in bytes * ptPreparsedData - The PreParsedData Structure * Output: * ptPreparsedData - The PreParsedData Structure * Returns: * kHIDSuccess - Success * kHIDNullPointerErr - Argument, Pointer was Null * *------------------------------------------------------------------------------ */ OSStatus HIDOpenReportDescriptor (void * hidReportDescriptor, IOByteCount descriptorLength, HIDPreparsedDataRef * preparsedDataRef, UInt32 flags) { HIDPreparsedDataPtr ptPreparsedData = NULL; OSStatus iStatus; HIDReportDescriptor tDescriptor; /* * Disallow NULL Pointers */ if ((hidReportDescriptor == NULL) || (preparsedDataRef == NULL)) return kHIDNullPointerErr; /* * Initialize the return result, and allocate space for preparsed data */ *preparsedDataRef = NULL; ptPreparsedData = PoolAllocateResident (sizeof (HIDPreparsedData), kShouldClearMem); /* * Make sure we got the memory */ if (ptPreparsedData == NULL) return kHIDNotEnoughMemoryErr; /* * Copy the flags field */ ptPreparsedData->flags = flags; /* * Initialize the memory allocation pointer */ ptPreparsedData->rawMemPtr = NULL; /* * Set up the descriptor structure */ tDescriptor.descriptor = hidReportDescriptor; tDescriptor.descriptorLength = descriptorLength; /* * Count various items in the descriptor * allocate space within the PreparsedData structure * and initialize the counters there */ iStatus = HIDCountDescriptorItems(&tDescriptor,ptPreparsedData); /* * Parse the Descriptor * filling in the structures in the PreparsedData structure */ if (iStatus == kHIDSuccess) { iStatus = HIDParseDescriptor(&tDescriptor,ptPreparsedData); /* * Mark the PreparsedData initialized, maybe */ if (iStatus == kHIDSuccess && ptPreparsedData->rawMemPtr != NULL) { ptPreparsedData->hidTypeIfValid = kHIDOSType; *preparsedDataRef = (HIDPreparsedDataRef) ptPreparsedData; return kHIDSuccess; } } // something failed, deallocate everything, and make sure we return an error if (ptPreparsedData->rawMemPtr != NULL) PoolDeallocate (ptPreparsedData->rawMemPtr, ptPreparsedData->numBytesAllocated); PoolDeallocate (ptPreparsedData, sizeof(HIDPreparsedData)); if (iStatus == kHIDSuccess) iStatus = kHIDNotEnoughMemoryErr; return iStatus; }