/*
 *------------------------------------------------------------------------------
 *
 * HIDCloseReportDescriptor - Close the Descriptor
 *
 *	 Input:
 *			  ptPreparsedData		- The PreParsedData Structure
 *	 Output:
 *			  ptPreparsedData		- The PreParsedData Structure
 *	 Returns:
 *			  kHIDSuccess		   - Success
 *			  kHIDNullPointerErr	  - Argument, Pointer was Null
 *
 *------------------------------------------------------------------------------
*/
OSStatus HIDCloseReportDescriptor(HIDPreparsedDataRef preparsedDataRef)
{
	HIDPreparsedDataPtr ptPreparsedData = (HIDPreparsedDataPtr) preparsedDataRef;
	OSStatus iStatus;
/*
 *	Disallow NULL Pointers
*/
	if (ptPreparsedData == NULL)
		return kHIDNullPointerErr;
/*
 *	If it's marked closed then don't do anything
*/
	if (ptPreparsedData->hidTypeIfValid != kHIDOSType)
		return kHIDInvalidPreparsedDataErr;
/*
 *	Free any memory that was allocated
*/
	if (ptPreparsedData->rawMemPtr != NULL)
	{
		PoolDeallocate (ptPreparsedData->rawMemPtr, ptPreparsedData->numBytesAllocated);
		ptPreparsedData->rawMemPtr = NULL;
	}
/*
 *	Mark closed
*/
	ptPreparsedData->hidTypeIfValid = 0;
/*
 *	Deallocate the preparsed data
*/
	iStatus = PoolDeallocate (ptPreparsedData, sizeof(HIDPreparsedData));

	return iStatus;
}
Exemplo n.º 2
0
//////////////////////////////////////////////
//
// DVDisposeNotification
//
//	remove notification from list
//
OSErr DVCDisposeNotification( DVCDeviceConnectionID connID, DVCNotificationID notifyID )
{
    DVNotificationEntryPtr	pEntry;
    OSErr					error = noErr;

    // we're not going to do a check, but it's REAL important not to call
    // this function from anywhere but task level.

    // go find the entry and remove it from the list
    pEntry = (DVNotificationEntryPtr) notifyID;

    if ( pEntry != nil )
    {
        PBDequeue( (QElemPtr) pEntry, gpFamilyGlobals->notificationQueue );
        PoolDeallocate( (void*) pEntry );
    }
    else
        error = paramErr;

    return error;
}
Exemplo n.º 3
0
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;
}