IOReturn IOHIDEventSystemUserClient::clientMemoryForType( UInt32 type,
        UInt32 * flags, IOMemoryDescriptor ** memory )
{
    IODataQueue *   eventQueue = NULL;
    IOReturn        ret = kIOReturnNoMemory;

	if (type == kIOHIDEventSystemKernelQueueID)
		eventQueue = kernelQueue;
	else
		eventQueue  = copyDataQueueWithID(type);

    if ( eventQueue ) {
        IOMemoryDescriptor * desc = NULL;
        *flags = 0;

        desc = eventQueue->getMemoryDescriptor();

        if ( desc ) {
            desc->retain();
            ret = kIOReturnSuccess;
        }

        *memory = desc;
		if (type != kIOHIDEventSystemKernelQueueID)
			eventQueue->release();

    } else {
        ret = kIOReturnBadArgument;
    }

    return ret;
}
IOReturn IOHIDEventSystemUserClient::destroyEventQueueGated(void*p1,void*p2,void*,void*)
{
    UInt32          type       = (uintptr_t) p1;
    UInt32          queueID    = (uintptr_t) p2;
    IODataQueue *   eventQueue = NULL;

	if (queueID == kIOHIDEventSystemKernelQueueID) {
		eventQueue = kernelQueue;
		type = kIOHIDEventQueueTypeKernel;
	} else {
		eventQueue = copyDataQueueWithID(queueID);
		type = kIOHIDEventQueueTypeUser;
	}

    if ( !eventQueue )
        return kIOReturnBadArgument;

    switch ( type ) {
        case kIOHIDEventQueueTypeKernel:
			kernelQueue->setState(false);
			if (owner) owner->unregisterEventQueue(kernelQueue);
			kernelQueue->release();
			kernelQueue = NULL;
			break;
        case kIOHIDEventQueueTypeUser:
            if (userQueues)
                userQueues->removeObject(eventQueue);
			removeIDForDataQueue(eventQueue);
			eventQueue->release();
            break;
    }

    return kIOReturnSuccess;
}
IODataQueue *
IOHIDEventSystemUserClient::copyDataQueueWithID(UInt32 queueID)
{
	IODataQueue * eventQueue;

	IOLockLock(gAllUserQueuesLock);
	eventQueue = OSDynamicCast(IODataQueue, gAllUserQueues->getObject(queueID - kIOHIDEventSystemUserQueueID));
	if (eventQueue)
		eventQueue->retain();
	IOLockUnlock(gAllUserQueuesLock);

	return (eventQueue);
}
示例#4
0
IODataQueue *IODataQueue::withEntries(UInt32 numEntries, UInt32 entrySize)
{
    IODataQueue *dataQueue = new IODataQueue;

    if (dataQueue) {
        if (!dataQueue->initWithEntries(numEntries, entrySize)) {
            dataQueue->release();
            dataQueue = 0;
        }
    }

    return dataQueue;
}
示例#5
0
IODataQueue *IODataQueue::withCapacity(UInt32 size)
{
    IODataQueue *dataQueue = new IODataQueue;

    if (dataQueue) {
        if  (!dataQueue->initWithCapacity(size)) {
            dataQueue->release();
            dataQueue = 0;
        }
    }

    return dataQueue;
}
IOReturn IOHIDEventSystemUserClient::createEventQueueGated(void*p1,void*p2,void*p3, void*)
{
    UInt32          type        = (uintptr_t)p1;
    IOByteCount     size        = (uintptr_t)p2;
    UInt32 *        pToken      = (UInt32 *)p3;
    UInt32          token       = 0;
    IODataQueue *   eventQueue  = NULL;

    if( !size )
        return kIOReturnBadArgument;

    switch ( type ) {
        case kIOHIDEventQueueTypeKernel:
            if (!owner)
                return kIOReturnOffline;
            if ( !kernelQueue ) {
                kernelQueue = IOHIDEventServiceQueue::withCapacity(size);
                if ( kernelQueue ) {
                    kernelQueue->setState(true);
                    owner->registerEventQueue(kernelQueue);
                }
            }
            eventQueue = kernelQueue;
			token = kIOHIDEventSystemKernelQueueID;
			if ( pToken ) {
				*pToken = kIOHIDEventSystemKernelQueueID;
			}
            break;
        case kIOHIDEventQueueTypeUser:
            if (!userQueues)
                userQueues = OSSet::withCapacity(4);

            eventQueue = IOHIDEventSystemQueue::withCapacity(size);
			token = createIDForDataQueue(eventQueue);
			if (eventQueue && userQueues) {
				userQueues->setObject(eventQueue);
				eventQueue->release();
			}
            break;
    }

    if( !eventQueue )
        return kIOReturnNoMemory;

    if ( pToken ) {
		*pToken = token;
	}

    return kIOReturnSuccess;
}
IOReturn IOHIDEventSystemUserClient::registerNotificationPort(
    mach_port_t 	port,
    UInt32		type,
    UInt32		refCon )
{
    IODataQueue *   eventQueue  = OSDynamicCast(IODataQueue, (OSObject*)type);

    if ( !eventQueue )
        return kIOReturnBadArgument;

    eventQueue->setNotificationPort(port);

    return( kIOReturnSuccess);
}
IOReturn IOHIDEventSystemUserClient::createEventQueue(void*p1,void*p2,void*p3,void*,void*,void*)
{
    UInt32          type        = (UInt32)p1;
    IOByteCount     size        = (IOByteCount)p2;
    UInt32 *        pToken      = (UInt32*)p3;
    IODataQueue *   eventQueue  = NULL;

    if( !size )
        return kIOReturnBadArgument;

    switch ( type ) {
    case kIOHIDEventQueueTypeKernel:
        if ( !kernelQueue ) {
            kernelQueue = IOHIDEventServiceQueue::withCapacity(size);
            if ( kernelQueue ) {
                kernelQueue->setState(true);
                owner->registerEventQueue(kernelQueue);
            }
        }
        eventQueue = kernelQueue;
        break;
    case kIOHIDEventQueueTypeUser:
        if ( !userQueues )
            userQueues = OSSet::withCapacity(4);

        eventQueue = IOSharedDataQueue::withCapacity(size);

        userQueues->setObject(eventQueue);

        eventQueue->release();

        break;
    }

    if( !eventQueue )
        return kIOReturnNoMemory;

    if ( pToken )
        *pToken = (UInt32)eventQueue;

    return kIOReturnSuccess;
}
IOReturn IOHIDEventSystemUserClient::registerNotificationPort(
		mach_port_t 	port,
		UInt32		type,
		UInt32		refCon __unused )
{
    IODataQueue * eventQueue = NULL;

	if (type == kIOHIDEventSystemKernelQueueID)
		eventQueue = kernelQueue;
	else
		eventQueue = copyDataQueueWithID(type);

    if ( !eventQueue )
        return kIOReturnBadArgument;

    eventQueue->setNotificationPort(port);

	if (type != kIOHIDEventSystemKernelQueueID)
		eventQueue->release();

    return (kIOReturnSuccess);
}
示例#10
0
IOReturn IOHIDEventSystemUserClient::clientMemoryForType( UInt32 type,
        UInt32 * flags, IOMemoryDescriptor ** memory )
{
    IODataQueue *   eventQueue  = OSDynamicCast(IODataQueue, (OSObject*)type);
    IOReturn        ret         = kIOReturnNoMemory;

    if ( eventQueue ) {
        IOMemoryDescriptor * desc = NULL;
        *flags = 0;

        desc = eventQueue->getMemoryDescriptor();

        if ( desc ) {
            desc->retain();
            ret = kIOReturnSuccess;
        }

        *memory = desc;
    } else {
        ret = kIOReturnBadArgument;
    }

    return ret;
}